public static class DmoAsmWorker.Library
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,java.lang.String> |
primitives
Map of Java primitive data type common names to their internal type names
|
Constructor and Description |
---|
Library() |
Modifier and Type | Method and Description |
---|---|
void |
assign(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType)
Assemble the initial bytecode instructions for the DMO
assign method. |
void |
assignField(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String fieldType,
java.lang.String getterOrFieldName,
java.lang.String setterMethName,
boolean inLoop)
Assemble the bytecode instructions to assign a single field or element of a composite
field from a DMO instance passed as an argument to the DMO
assign method
(hereafter, "source" DMO) into the current DMO (hereafter, "target" DMO) object's
matching field. |
java.lang.Object |
assignLoopBegin(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
int extent)
Assemble the bytecode instructions for the top of a loop in the DMO
assign
method, which is used to assign one or more composite fields. |
void |
assignLoopEnd(org.objectweb.asm.MethodVisitor mv,
java.lang.Object labelArray)
Assemble the bytecode instructions for the bottom of a loop in the DMO
assign method, which is used to assign one or more composite fields. |
void |
compositeGetter(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String compFieldName,
java.lang.String compClassName,
java.lang.String compMethName,
java.lang.String returnDesc)
Assemble the bytecode instructions for a composite getter method, which accesses a
composite object from an array list field, invokes a simple getter method on it, and
returns the result.
|
void |
compositeSetter(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String compFieldName,
java.lang.String compClassName,
java.lang.String compMethName,
java.lang.String elementDesc)
Assemble the bytecode instructions for a composite setter method, which accesses a
composite object from an array list field, invokes a simple setter method on it.
|
java.lang.String |
convertTypeName(java.lang.String name,
boolean forSig)
Given a common type name for a primitive data type or Java object, convert it to the
internal type form name or descriptor needed for assembly.
|
org.objectweb.asm.AnnotationVisitor |
createAnnotationVisitor(org.objectweb.asm.AnnotationVisitor av,
java.lang.String name)
Create an
AnnotationVisitor for the purpose of implementing a nested Java
annotation (an element in an array of annotations). |
org.objectweb.asm.AnnotationVisitor |
createAnnotationVisitor(org.objectweb.asm.ClassWriter cw,
java.lang.String name)
Create an
AnnotationVisitor for the purpose of implementing a class-level
Java annotation. |
org.objectweb.asm.AnnotationVisitor |
createAnnotationVisitor(org.objectweb.asm.FieldVisitor fv,
java.lang.String name)
Create an
AnnotationVisitor for the purpose of implementing a field-level
Java annotation. |
org.objectweb.asm.ClassWriter |
createInnerClassWriter(java.lang.String outerName,
java.lang.String shortInnerName,
java.lang.String fullInnerName)
Create and initialize a
ClassWriter for an inner class. |
org.objectweb.asm.ClassWriter |
createInnerIfaceClassWriter(java.lang.String outerName)
Create and initialize a
ClassWriter for a static, inner interface named
Buf , which extends com.goldencode.p2j.persist.Buffer and the
enclosing, top-level interface. |
org.objectweb.asm.ClassWriter |
createTopClassWriter(java.lang.String implName,
java.lang.String ifaceName,
java.util.List<java.lang.String> innerNames)
Create and initialize a
ClassWriter for a top-level, DMO implementation
class of the given type, which implements the given DMO interface. |
org.objectweb.asm.ClassWriter |
createTopIfaceClassWriter(java.lang.String ifaceName)
Create and initialize a
ClassWriter for a top-level, DMO interface of the
given type. |
org.objectweb.asm.FieldVisitor |
declareInstanceVariable(org.objectweb.asm.ClassWriter cw,
java.lang.String name,
java.lang.String type,
boolean isFinal)
Create an initialized
FieldVisitor for the purpose of declaring a DMO field
as an instance variable. |
void |
declareMethod(org.objectweb.asm.ClassWriter cw,
java.lang.String name,
java.lang.String sig)
Implement the declaration of an abstract, public method with the given name and
signature in a DMO interface.
|
void |
deepCopy(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType)
Assemble the bytecode instructions for the DMO
deepCopy method, which
instantiates a new DMO of this class' type, assigns the current DMO's data to it, and
returns it. |
void |
defaultCtorCommon(org.objectweb.asm.MethodVisitor mv)
Assemble the bytecode instructions common to the beginning of a top-level DMO's default
constructor and an inner class' default constructor.
|
org.objectweb.asm.MethodVisitor |
defineMethod(org.objectweb.asm.ClassWriter cw,
java.lang.String name,
java.lang.String sig)
Create a
MethodVisitor for the purpose of defining the implementation of a
public method. |
void |
delegatingIndexedGetter(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String delMethName,
java.lang.String returnDesc)
Assemble the bytecode instructions for an indexed getter method which accepts a
NumberType parameter for the index value. |
void |
delegatingIndexedSetter(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String delMethName,
java.lang.String elementDesc)
Assemble the bytecode instructions for an indexed setter method which accepts a
NumberType parameter for the index value. |
void |
directGetter(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String fieldName,
java.lang.String fieldDesc)
Assemble the bytecode instructions for a DMO method which retrieves and returns the
object in the specified field.
|
void |
directSetter(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String fieldName,
java.lang.String fieldDesc)
Assemble the bytecode instructions for a DMO method which sets the value of the
specified field to an object passed into the method.
|
void |
indexedSetterFromArray(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String fieldType,
java.lang.String compName,
java.lang.String idxSetterMethName)
Assemble the bytecode instructions for a composite field setter method which accepts an
array of values and assigns the elements of the composite field to the values in the
array on a best-efforts basis.
|
void |
indexedSetterFromScalar(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String fieldType,
java.lang.String compName,
java.lang.String idxSetterMethName)
Assemble the bytecode instructions for a composite field setter method which accepts a
scalar value and assigns all elements of the composite field to that value.
|
void |
initCompositeLoop(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String fieldName,
java.lang.String compType,
int extent)
Assemble the bytecode instructions to initialize a list of composite, inner class
objects.
|
void |
initDirectFieldNull(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String fieldName,
java.lang.String fieldDesc)
Assemble the bytecode instructions to initialize a DMO field to
null in a
default constructor. |
void |
initFieldBuiltin(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String fieldName,
java.lang.String fieldType,
java.lang.String fieldDesc,
java.lang.String methName,
java.lang.String initText)
Assemble the bytecode instructions to initialize a DMO field using an static method
implementation of a Progress-compatible builtin function (e.g.,
date.today ). |
void |
initSimpleField(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String fieldName,
java.lang.String fieldDesc,
Aast ctorAst)
Assemble the bytecode instructions to initialize a DMO field using a constructor
specific to the field's type.
|
void |
multiplexCtor(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType)
Assemble the bytecode instructions for the DMO constructor variant which accepts a
multiplex ID.
|
void |
simpleGetter(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String fieldName,
java.lang.String fieldType,
java.lang.String fieldDesc)
Assemble the bytecode instructions for a DMO method which retrieves and returns the
value of the specified simple (i.e., non-indexed) field.
|
void |
simpleGetterExtent(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String fieldType,
int extent,
java.lang.String idxGetterMethName)
Assemble the bytecode instructions for a getter method which returns all of the values
of a composite field as an array.
|
void |
simpleSetter(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String fieldName,
java.lang.String fieldType,
java.lang.String fieldDesc)
Assemble the bytecode instructions for a DMO method which sets the value of the specified
simple (i.e., non-indexed) field.
|
void |
sizer(org.objectweb.asm.MethodVisitor mv,
java.lang.String classType,
java.lang.String compName)
Assemble the bytecode instructions for a method which returns the number of elements of
a composite field as a P2J
integer object. |
void |
voidReturn(org.objectweb.asm.MethodVisitor mv)
Assemble the bytecode instruction for a void return from a method.
|
private static java.util.Map<java.lang.String,java.lang.String> primitives
public java.lang.String convertTypeName(java.lang.String name, boolean forSig)
.
) characters with forward slash
(/
) and involves additional transformation if forSig
is
true
(see below).name
- Common name (e.g. com.goldencode.p2j.util.integer
for the P2J
integer
class or int
for the Java primitive integer)forSig
- If true
, assume the result is being used for a method signature,
and thus needs to be formatted as a descriptor. This prepends open square
bracket ([
) for arrays, and for object names, prepends capital
L (L
) and appends semi-colon(;
).public org.objectweb.asm.ClassWriter createTopIfaceClassWriter(java.lang.String ifaceName)
ClassWriter
for a top-level, DMO interface of the
given type. The interface must extend com.goldencode.p2j.persist.Temporary
.ifaceName
- Fully qualified, internal type name of the DMO interface.ClassWriter
.public org.objectweb.asm.ClassWriter createInnerIfaceClassWriter(java.lang.String outerName)
ClassWriter
for a static, inner interface named
Buf
, which extends com.goldencode.p2j.persist.Buffer
and the
enclosing, top-level interface.outerName
- Fully qualified, internal type name of enclosing interface.ClassWriter
.public org.objectweb.asm.ClassWriter createTopClassWriter(java.lang.String implName, java.lang.String ifaceName, java.util.List<java.lang.String> innerNames)
ClassWriter
for a top-level, DMO implementation
class of the given type, which implements the given DMO interface. In addition, the
class will implement:
java.io.Serializable
com.goldencode.p2j.persist.Persistable
implName
- Fully qualified, internal type name of the DMO implementation class.ifaceName
- Fully qualified, internal type name of the DMO interface which the class must
implement.innerNames
- Optional list of fully qualified, internal type names which the DMO class will
enclose as static inner classes. May be null
or an empty list.ClassWriter
.public org.objectweb.asm.ClassWriter createInnerClassWriter(java.lang.String outerName, java.lang.String shortInnerName, java.lang.String fullInnerName)
ClassWriter
for an inner class.outerName
- Fully qualified, internal type name of enclosing class.shortInnerName
- Short name of inner class.fullInnerName
- Fully qualified, internal type name of inner class.ClassWriter
.public void declareMethod(org.objectweb.asm.ClassWriter cw, java.lang.String name, java.lang.String sig)
cw
- Class writer for the method's interface.name
- Method name.sig
- Method signature, using internal type descriptors for parameters and return
type.public org.objectweb.asm.MethodVisitor defineMethod(org.objectweb.asm.ClassWriter cw, java.lang.String name, java.lang.String sig)
MethodVisitor
for the purpose of defining the implementation of a
public method. The caller will use this object to assemble the instructions of the
method; typically, it will be passed to additional methods in this library to complete
the implementation.cw
- Class writer for the method's class.name
- Method name.sig
- Method signature, using internal type descriptors for parameters and return
type.public org.objectweb.asm.FieldVisitor declareInstanceVariable(org.objectweb.asm.ClassWriter cw, java.lang.String name, java.lang.String type, boolean isFinal)
FieldVisitor
for the purpose of declaring a DMO field
as an instance variable. The initialization of the field itself is implemented in the
DMO implementation class' (or inner class') default constructor. The field visitor is
used by the caller to implement annotations.cw
- Class writer for the field's class.name
- Field name.type
- Field descriptor.isFinal
- true
if the field is final, else false
.public org.objectweb.asm.AnnotationVisitor createAnnotationVisitor(org.objectweb.asm.ClassWriter cw, java.lang.String name)
AnnotationVisitor
for the purpose of implementing a class-level
Java annotation.cw
- Class writer for the enclosing class.name
- Unqualified annotation name.public org.objectweb.asm.AnnotationVisitor createAnnotationVisitor(org.objectweb.asm.AnnotationVisitor av, java.lang.String name)
AnnotationVisitor
for the purpose of implementing a nested Java
annotation (an element in an array of annotations).av
- Annotation visitor for the enclosing annotation.name
- Unqualified annotation name.public org.objectweb.asm.AnnotationVisitor createAnnotationVisitor(org.objectweb.asm.FieldVisitor fv, java.lang.String name)
AnnotationVisitor
for the purpose of implementing a field-level
Java annotation.fv
- Field visitor for the associated field.name
- Unqualified annotation name.public void defaultCtorCommon(org.objectweb.asm.MethodVisitor mv)
java.lang.Object
.mv
- The default constructor's method visitor.public void initDirectFieldNull(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String fieldName, java.lang.String fieldDesc)
null
in a
default constructor. This is used for the DMO's primary key and multiplex ID fields.mv
- The default constructor's method visitor.classType
- Fully qualified internal type name of enclosing class.fieldName
- Field name.fieldDesc
- Field descriptor.public void initSimpleField(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String fieldName, java.lang.String fieldDesc, Aast ctorAst)
If the initializer provided in ctorAst
cannot be converted to a value of
the required type for the field, an error is logged and the field type's default
constructor is used, which generally will result in the field being initialized to
unknown value. Note that we do not support initializers for the following types at this
time, and these always will be initialized using their default constructors:
mv
- The default constructor's method visitor.classType
- Fully qualified internal type name of enclosing class.fieldName
- Field name.fieldDesc
- Field descriptor.ctorAst
- Java AST node representing the field-level constructor to be invoked to
initialize the field.public void initFieldBuiltin(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String fieldName, java.lang.String fieldType, java.lang.String fieldDesc, java.lang.String methName, java.lang.String initText)
date.today
).
The instructions are added to a DMO's default constructor. Assumes that the static method
either accepts no arguments, or a single argument of type java.lang.String
.mv
- The default constructor's method visitor.classType
- Fully qualified internal type name of enclosing class.fieldName
- Field name.fieldType
- Fully qualified, internal type name of field.fieldDesc
- Field descriptor.methName
- Static method name.initText
- String to be passed to the static method; null
if the method takes
no arguments.public void initCompositeLoop(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String fieldName, java.lang.String compType, int extent)
extent
times. In each pass, the default
constructor of the inner class is invoked, and the resulting object is added to the
list.mv
- The default constructor's method visitor.classType
- Fully qualified internal type name of enclosing class.fieldName
- Composite list field name.compType
- Fully qualified internal type name of composite inner class.extent
- List size.public void multiplexCtor(org.objectweb.asm.MethodVisitor mv, java.lang.String classType)
_multiplex
field.mv
- The constructor's method visitor.classType
- Fully qualified internal type name of enclosing class.public void deepCopy(org.objectweb.asm.MethodVisitor mv, java.lang.String classType)
deepCopy
method, which
instantiates a new DMO of this class' type, assigns the current DMO's data to it, and
returns it. The work of copying the data is delegated to the DMO's assign
method.mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.public void assign(org.objectweb.asm.MethodVisitor mv, java.lang.String classType)
assign
method.
These instructions load the Undoable
object and cast it to the current
DMO's type. The remainder of the method's implementation varies according to the fields
in the DMO. The full implementation consists of the following flow:
assign(MethodVisitor, String)
assignField(MethodVisitor, String, String, String,
String, boolean)
assignLoopBegin(MethodVisitor, String, int)
assignField(MethodVisitor, String, String, String,
String, boolean)
voidReturn(MethodVisitor)
mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.public void assignField(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String fieldType, java.lang.String getterOrFieldName, java.lang.String setterMethName, boolean inLoop)
assign
method
(hereafter, "source" DMO) into the current DMO (hereafter, "target" DMO) object's
matching field.
For scalar fields, this is accomplished by invoking the target DMO's setter field and passing in the source DMO's corresponding instance member.
For composite fields, this is accomplished by invoking the source DMO's getter method for the desired field and storing the result in the target DMO by invoking its matching setter method.
The setter instructions will differ slightly if the field is part of a composite inner class, in that an index parameter must be handled for the method call.
mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.fieldType
- Fully qualified, internal type name of field.getterOrFieldName
- Name of getter method to be invoked on source DMO.setterMethName
- Name of setter method to be invoked on target DMO.inLoop
- true
if the assignment takes place within the context of an assign
loop (for a composite field), else false
.assign(MethodVisitor, String)
public java.lang.Object assignLoopBegin(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, int extent)
assign
method, which is used to assign one or more composite fields. The actual assignment is
assembled in assignField(MethodVisitor, String, String, String, String, boolean)
and the bottom of the loop is assembled in assignLoopEnd(MethodVisitor, Object)
.mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.extent
- List size.Label
objects, where the first element marks
the top of the loop and the second the bottom. This is returned as type
Object
to enable TRPL to handle it, since TRPL cannot deal with
arrays. A List
was considered, but an array was deemed to have
lower overhead.public void assignLoopEnd(org.objectweb.asm.MethodVisitor mv, java.lang.Object labelArray)
assign
method, which is used to assign one or more composite fields.mv
- The method visitor.labelArray
- A size 2 array of ASM Label
objects, where the first element marks
the top of the loop and the second the bottom.assign(MethodVisitor, String)
,
assignLoopBegin(MethodVisitor, String, int)
public void voidReturn(org.objectweb.asm.MethodVisitor mv)
mv
- The method visitor.public void directGetter(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String fieldName, java.lang.String fieldDesc)
mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.fieldName
- Field name.fieldDesc
- Field descriptor.public void directSetter(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String fieldName, java.lang.String fieldDesc)
mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.fieldName
- Field name.fieldDesc
- Field descriptor.public void simpleGetter(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String fieldName, java.lang.String fieldType, java.lang.String fieldDesc)
mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.fieldName
- Field name.fieldType
- Fully qualified, internal type name of field.fieldDesc
- Field descriptor.public void simpleSetter(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String fieldName, java.lang.String fieldType, java.lang.String fieldDesc)
assign
method which is appropriate for the field's
BaseDataType
subclass. This prevents outside code from making any changes to
the field's state, other than through the DMO's API.mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.fieldName
- Field name.fieldType
- Fully qualified, internal type name of field.fieldDesc
- Field descriptor.public void compositeGetter(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String compFieldName, java.lang.String compClassName, java.lang.String compMethName, java.lang.String returnDesc)
mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.compFieldName
- Short name of field in enclosing class which contains the array list of
composites we need to access.compClassName
- Short name of composite inner class.compMethName
- Name of composite's simple getter method.returnDesc
- Type descriptor for the return type of the field's getter method.public void compositeSetter(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String compFieldName, java.lang.String compClassName, java.lang.String compMethName, java.lang.String elementDesc)
mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.compFieldName
- Short name of field in enclosing class which contains the array list of
composites we need to access.compClassName
- Short name of composite inner class.compMethName
- Name of composite's simple getter method.elementDesc
- Type descriptor for the element
parameter passed to the field's
setter method.public void simpleGetterExtent(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String fieldType, int extent, java.lang.String idxGetterMethName)
mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.fieldType
- Fully qualified, internal type name of field.extent
- List size.idxGetterMethName
- Indexed getter method name.public void delegatingIndexedGetter(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String delMethName, java.lang.String returnDesc)
NumberType
parameter for the index value. The implementation extracts the
primitive int
value from the NumberType
parameter and delegates
the main work to the associated getter method which accepts an int
for the
index.mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.delMethName
- Name of getter method to which to delegate.returnDesc
- Return type descriptor.public void delegatingIndexedSetter(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String delMethName, java.lang.String elementDesc)
NumberType
parameter for the index value. The implementation extracts the
primitive int
value from the NumberType
parameter and delegates
the main work to the associated getter method which accepts an int
for the
index.mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.delMethName
- Name of setter method to which to delegate.elementDesc
- Element type descriptor.public void indexedSetterFromScalar(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String fieldType, java.lang.String compName, java.lang.String idxSetterMethName)
mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.fieldType
- Fully qualified, internal type name of field.compName
- Field name which holds the list of composite elements.idxSetterMethName
- Indexed setter method name.public void indexedSetterFromArray(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String fieldType, java.lang.String compName, java.lang.String idxSetterMethName)
mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.fieldType
- Fully qualified, internal type name of field.compName
- Field name which holds the list of composite elements.idxSetterMethName
- Indexed setter method name.public void sizer(org.objectweb.asm.MethodVisitor mv, java.lang.String classType, java.lang.String compName)
integer
object.mv
- The method visitor.classType
- Fully qualified internal type name of enclosing class.compName
- Field name which holds the list of composite elements.