ModuleDef
is a definition from which instances of a module
may be made. It stands in relation to the Java classes that define
Python modules, somewhat in the way a Python type
object
stands in relation to the Java classes that define Python objects.
What we most often encounter as "a module", a Python source file, is
actually just a definition from which a module object may be made.
This happens once in each interpreter where the module is
imported. A distinct object, with mutable state, represents that
module in each interpreter. There must therefore be a factory object
that has access to the definition of the module, but is able to
instantiate it (equivalent to executing the body of a module defined
in Python). A ModuleDef
is that factory.
This initialisation cannot be identified with the static initialisation of the Java class, since that cannot be repeated, but must happen per instance. It is useful, however, to have an intermediate cache of the results of processing the defining Java class once statically initialised.
Modifier and Type | Class and Description |
---|---|
pack-priv static class | ModuleDef.MethodDef
A |
Modifier and Type | Field and Description |
---|---|
pack-priv final Class | definingClass
The Java class defining instances of the module. |
private final ModuleDef. | methods
Definitions for the members that appear in the dictionary of instances of the module named. |
pack-priv final String | name
Name of the module. |
Access | Constructor and Description |
---|---|
pack-priv | ModuleDef(String
of the module (e.g. "sys" or "math") name, MethodHandles.authorises access to the defining class. lookupCreate a definition for the module, largely by introspection on
the class and by forming |
Modifier and Type | Method and Description |
---|---|
pack-priv void | addMembers(JavaModule
to populate module)Add members defined here to the dictionary of a module instance. |
pack-priv ModuleDef. |
definingClass | back to summary |
---|---|
pack-priv final Class<?> definingClass The Java class defining instances of the module. |
methods | back to summary |
---|---|
private final ModuleDef. Definitions for the members that appear in the dictionary of instances of the module named. Instances receive members by copy, by binding to the module instance (descriptors), or by reference (if immutable). |
name | back to summary |
---|---|
pack-priv final String name Name of the module. |
ModuleDef | back to summary |
---|---|
pack-priv ModuleDef(String name, MethodHandles. Create a definition for the module, largely by introspection on
the class and by forming
|
addMembers | back to summary |
---|---|
pack-priv void addMembers(JavaModule module) Add members defined here to the dictionary of a module instance.
|
getMethods | back to summary |
---|---|
pack-priv ModuleDef. Get the method definitions. This method is provided for test use only. It isn't safe as for public use. |
MethodDef
describes a built-in function or method as it
is declared in a Java module. It holds an argument parser and a
handle for calling the method.
Recall that a module definition may have multiple instances. The
MethodDef
represents the method between the definition of
the module (exposure as a ModuleDef
) and the creation of
actual JavaModule
instances.
When a method is declared in Java as an instance method of the
module, the MethodDef
that describes it discounts the
self
argument. The PyJavaFunction
created from it
binds the module instance that is its target, so that it is is
correct for a call to that PyJavaFunction
. This is
consistent with CPython.
Modifier and Type | Field and Description |
---|---|
pack-priv final ArgParser | argParser
An argument parser constructed with this |
pack-priv final MethodHandle | handle
A handle to the implementation of the function or method. |
Access | Constructor and Description |
---|---|
pack-priv | MethodDef(ArgParser
parser defining the method argParser, MethodHandle method handle prepared by sub-class meth)Create a |
Modifier and Type | Method and Description |
---|---|
public String |
argParser | back to summary |
---|---|
pack-priv final ArgParser argParser An argument parser constructed with this |
handle | back to summary |
---|---|
pack-priv final MethodHandle handle A handle to the implementation of the function or method.
This is generated by reflecting the same object that
|
MethodDef | back to summary |
---|---|
pack-priv MethodDef(ArgParser argParser, MethodHandle meth) Create a
|
toString | back to summary |
---|---|
public String toString() Overrides java. Doc from java. Returns a string representation of the object. |