Top Description Inners Fields Constructors Methods
org.python.expose.generate

public Class ExposedTypeProcessor

extends Object
implements Opcodes, PyTypes
Class Inheritance
All Implemented Interfaces
org.python.expose.generate.PyTypes, org.objectweb.asm.Opcodes
Imports
java.io.IOException, .InputStream, java.util.Collection, .List, .Map, org.python.expose.ExposedType, org.objectweb.asm.AnnotationVisitor, .ClassReader, .ClassVisitor, .ClassWriter, .FieldVisitor, .MethodVisitor, .Opcodes, .Type, org.python.util.Generic

Processes the bytecode of a Java class that has the ExposedType annotation on it and generates new bytecode for it containing the inner classes Jython needs to expose it as a type.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
ExposedTypeProcessor.TypeProcessor

The actual visitor that runs over the bytecode and figures out what to expose.

Field Summary

Modifier and TypeField and Description
private ClassWriter
private Map<String, DescriptorExposer>
private List<MethodExposer>
private Exposer
private Type
private TypeExposer
private String

Constructor Summary

AccessConstructor and Description
public
ExposedTypeProcessor(InputStream
- an InputStream to bytecode of an ExposedType
in
)

Method Summary

Modifier and TypeMethod and Description
public byte[]

Returns:

the processed bytecode
getBytecode
()

protected DescriptorExposer
public Collection<DescriptorExposer>
public String

Returns:

the name of the class being processed
getExposedClassName
()

public Collection<MethodExposer>

Returns:

MethodExposers for each method that needs to be exposed
getMethodExposers
()

public String

Returns:

the name of the exposed type.
getName
()

public Exposer

Returns:

The Exposer for __new__ for this type. Can be null if the type isn't instantiable.
getNewExposer
()

public TypeExposer
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cwback to summary
private ClassWriter cw
descExposersback to summary
private Map<String, DescriptorExposer> descExposers
methodExposersback to summary
private List<MethodExposer> methodExposers
newExposerback to summary
private Exposer newExposer
onTypeback to summary
private Type onType
typeExposerback to summary
private TypeExposer typeExposer
typeNameback to summary
private String typeName

Constructor Detail

ExposedTypeProcessorback to summary
public ExposedTypeProcessor(InputStream in) throws IOException
Parameters
in:InputStream

- an InputStream to bytecode of an ExposedType

Exceptions
InvalidExposingException:
- if the class doesn't have an annotation, or if one of the method annotations is malformed

Method Detail

getBytecodeback to summary
public byte[] getBytecode()
Returns:byte[]

the processed bytecode

getDescriptorExposerback to summary
protected DescriptorExposer getDescriptorExposer(String descName)
getDescriptorExposersback to summary
public Collection<DescriptorExposer> getDescriptorExposers()
getExposedClassNameback to summary
public String getExposedClassName()
Returns:String

the name of the class being processed

getMethodExposersback to summary
public Collection<MethodExposer> getMethodExposers()
Returns:Collection<MethodExposer>

MethodExposers for each method that needs to be exposed

getNameback to summary
public String getName()
Returns:String

the name of the exposed type.

getNewExposerback to summary
public Exposer getNewExposer()
Returns:Exposer

The Exposer for __new__ for this type. Can be null if the type isn't instantiable.

getTypeExposerback to summary
public TypeExposer getTypeExposer()
org.python.expose.generate back to summary

private final Class ExposedTypeProcessor.TypeProcessor

extends ClassVisitor
Class Inheritance

The actual visitor that runs over the bytecode and figures out what to expose.

Field Summary

Modifier and TypeField and Description
private Type
private String
private boolean
private boolean
Inherited from org.objectweb.asm.ClassVisitor:
apicv

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
addInnerClass(Type inner)

Adds an inner class reference to inner from the class being visited.

private void
private void
public void
visit(int
the class version. The minor version is stored in the 16 most significant bits, and the major version in the 16 least significant bits.
version
,
int
the class's access flags (see Opcodes). This parameter also indicates if the class is deprecated Opcodes#ACC_DEPRECATED or a record Opcodes#ACC_RECORD.
access
,
String
the internal name of the class (see Type#getInternalName()).
name
,
String
the signature of this class. May be null if the class is not a generic one, and does not extend or implement generic classes or interfaces.
signature
,
String
the internal of name of the super class (see Type#getInternalName()). For interfaces, the super class is Object. May be null, but only for the Object class.
superName
,
String[]
the internal names of the class's interfaces (see Type#getInternalName()). May be null.
interfaces
)

Overrides org.objectweb.asm.ClassVisitor.visit.

Visits the header of the class.

public AnnotationVisitor
visitAnnotation(String
the class descriptor of the annotation class.
desc
,
boolean
true if the annotation is visible at runtime.
visible
)

Overrides org.objectweb.asm.ClassVisitor.visitAnnotation.

Visits an annotation of the class.

public void
visitEnd()

Overrides org.objectweb.asm.ClassVisitor.visitEnd.

Visits the end of the class.

public FieldVisitor
visitField(int
the field's access flags (see Opcodes). This parameter also indicates if the field is synthetic and/or deprecated.
access
,
final String
the field's name.
fieldName
,
final String
the field's descriptor (see Type).
desc
,
String
the field's signature. May be null if the field's type does not use generic types.
signature
,
Object
the field's initial value. This parameter, which may be null if the field does not have an initial value, must be an Integer, a Float, a Long, a Double or a String (for int, float, long or String fields respectively). This parameter is only used for static fields. Its value is ignored for non static fields, which must be initialized through bytecode instructions in constructors or methods.
value
)

Overrides org.objectweb.asm.ClassVisitor.visitField.

Visits a field of the class.

public MethodVisitor
visitMethod(int
the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.
access
,
final String
the method's name.
name
,
final String
the method's descriptor (see Type).
desc
,
String
the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.
signature
,
String[]
the internal names of the method's exception classes (see Type#getInternalName()). May be null.
exceptions
)

Overrides org.objectweb.asm.ClassVisitor.visitMethod.

Visits a method of the class.

Inherited from org.objectweb.asm.ClassVisitor:
getDelegatevisitAttributevisitInnerClassvisitModulevisitNestHostvisitNestMembervisitOuterClassvisitPermittedSubclassvisitRecordComponentvisitSourcevisitTypeAnnotation

Field Detail

baseTypeback to summary
private Type baseType
docback to summary
private String doc
generatedStaticBlockback to summary
private boolean generatedStaticBlock
isBaseTypeback to summary
private boolean isBaseType

Constructor Detail

TypeProcessorback to summary
private TypeProcessor(ClassVisitor cv)

Method Detail

addInnerClassback to summary
private void addInnerClass(Type inner)

Adds an inner class reference to inner from the class being visited.

generateAddBuilderback to summary
private void generateAddBuilder(MethodVisitor mv)
throwInvalidback to summary
private void throwInvalid(String msg)
visitback to summary
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)

Overrides org.objectweb.asm.ClassVisitor.visit.

Doc from org.objectweb.asm.ClassVisitor.visit.

Visits the header of the class.

Parameters
version:int

the class version. The minor version is stored in the 16 most significant bits, and the major version in the 16 least significant bits.

access:int

the class's access flags (see Opcodes). This parameter also indicates if the class is deprecated Opcodes#ACC_DEPRECATED or a record Opcodes#ACC_RECORD.

name:String

the internal name of the class (see Type#getInternalName()).

signature:String

the signature of this class. May be null if the class is not a generic one, and does not extend or implement generic classes or interfaces.

superName:String

the internal of name of the super class (see Type#getInternalName()). For interfaces, the super class is Object. May be null, but only for the Object class.

interfaces:String[]

the internal names of the class's interfaces (see Type#getInternalName()). May be null.

Annotations
@Override
visitAnnotationback to summary
public AnnotationVisitor visitAnnotation(String desc, boolean visible)

Overrides org.objectweb.asm.ClassVisitor.visitAnnotation.

Doc from org.objectweb.asm.ClassVisitor.visitAnnotation.

Visits an annotation of the class.

Parameters
desc:String

the class descriptor of the annotation class.

visible:boolean

true if the annotation is visible at runtime.

Returns:AnnotationVisitor

a visitor to visit the annotation values, or null if this visitor is not interested in visiting this annotation.

Annotations
@Override

visitEndback to summary
public void visitEnd()

Overrides org.objectweb.asm.ClassVisitor.visitEnd.

Doc from org.objectweb.asm.ClassVisitor.visitEnd.

Visits the end of the class. This method, which is the last one to be called, is used to inform the visitor that all the fields and methods of the class have been visited.

Annotations
@Override
visitFieldback to summary
public FieldVisitor visitField(int access, final String fieldName, final String desc, String signature, Object value)

Overrides org.objectweb.asm.ClassVisitor.visitField.

Doc from org.objectweb.asm.ClassVisitor.visitField.

Visits a field of the class.

Parameters
access:int

the field's access flags (see Opcodes). This parameter also indicates if the field is synthetic and/or deprecated.

fieldName:String

the field's name.

desc:String

the field's descriptor (see Type).

signature:String

the field's signature. May be null if the field's type does not use generic types.

value:Object

the field's initial value. This parameter, which may be null if the field does not have an initial value, must be an Integer, a Float, a Long, a Double or a String (for int, float, long or String fields respectively). This parameter is only used for static fields. Its value is ignored for non static fields, which must be initialized through bytecode instructions in constructors or methods.

Returns:FieldVisitor

a visitor to visit field annotations and attributes, or null if this class visitor is not interested in visiting these annotations and attributes.

Annotations
@Override

visitMethodback to summary
public MethodVisitor visitMethod(int access, final String name, final String desc, String signature, String[] exceptions)

Overrides org.objectweb.asm.ClassVisitor.visitMethod.

Doc from org.objectweb.asm.ClassVisitor.visitMethod.

Visits a method of the class. This method must return a new MethodVisitor instance (or null) each time it is called, i.e., it should not return a previously returned visitor.

Parameters
access:int

the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.

name:String

the method's name.

desc:String

the method's descriptor (see Type).

signature:String

the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.

exceptions:String[]

the internal names of the method's exception classes (see Type#getInternalName()). May be null.

Returns:MethodVisitor

an object to visit the byte code of the method, or null if this class visitor is not interested in visiting the code of this method.

Annotations
@Override