Top Description Inners Fields Constructors Methods
org.python.core

public Class ModuleDef

extends Object
Class Inheritance
Imports
java.lang.invoke.MethodHandle, .MethodHandles.Lookup

A 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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
ModuleDef.MethodDef

A MethodDef describes a built-in function or method as it is declared in a Java module.

Field Summary

Modifier and TypeField and Description
pack-priv final Class<?>
definingClass

The Java class defining instances of the module.

private final ModuleDef.MethodDef[]
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.

Constructor Summary

AccessConstructor and Description
pack-priv
ModuleDef(String
of the module (e.g. "sys" or "math")
name
,
MethodHandles.Lookup
authorises access to the defining class.
lookup
)

Create a definition for the module, largely by introspection on the class and by forming MethodHandles on discovered attributes.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addMembers(JavaModule
to populate
module
)

Add members defined here to the dictionary of a module instance.

pack-priv ModuleDef.MethodDef[]

Returns:

the method definitions
getMethods
()

Get the method definitions.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

definingClassback to summary
pack-priv final Class<?> definingClass

The Java class defining instances of the module.

methodsback to summary
private final ModuleDef.MethodDef[] methods

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).

nameback to summary
pack-priv final String name

Name of the module.

Constructor Detail

ModuleDefback to summary
pack-priv ModuleDef(String name, MethodHandles.Lookup lookup)

Create a definition for the module, largely by introspection on the class and by forming MethodHandles on discovered attributes.

Parameters
name:String

of the module (e.g. "sys" or "math")

lookup:MethodHandles.Lookup

authorises access to the defining class.

Method Detail

addMembersback to summary
pack-priv void addMembers(JavaModule module)

Add members defined here to the dictionary of a module instance.

Parameters
module:JavaModule

to populate

getMethodsback to summary
pack-priv ModuleDef.MethodDef[] getMethods()

Get the method definitions. This method is provided for test use only. It isn't safe as for public use.

Returns:ModuleDef.MethodDef[]

the method definitions

org.python.core back to summary

pack-priv Class ModuleDef.MethodDef

extends Object
Class Inheritance

A 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.

Field Summary

Modifier and TypeField and Description
pack-priv final ArgParser
argParser

An argument parser constructed with this MethodDef from the description of the signature.

pack-priv final MethodHandle
handle

A handle to the implementation of the function or method.

Constructor Summary

AccessConstructor and Description
pack-priv
MethodDef(ArgParser
parser defining the method
argParser
,
MethodHandle
method handle prepared by sub-class
meth
)

Create a MethodDef of the given kind from the ArgParser provided.

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

argParserback to summary
pack-priv final ArgParser argParser

An argument parser constructed with this MethodDef from the description of the signature. Full information on the signature is available from this structure, and it is available to parse the arguments to a standard (Object[], String[]) call. (In simple sub-classes it is only used to generate error messages once simple checks fail.)

handleback 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 argParser describes.

Constructor Detail

MethodDefback to summary
pack-priv MethodDef(ArgParser argParser, MethodHandle meth)

Create a MethodDef of the given kind from the ArgParser provided.

Parameters
argParser:ArgParser

parser defining the method

meth:MethodHandle

method handle prepared by sub-class

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override