|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
MethodBuilder is used to generate the code for a method.
The code for a method is built in a way that corresponds to the layout of the stack machine that is the Java Virtual Machine. Values are pushed on the stack, moved about on the stack and then popped off the stack by operations such as method calls. An understanding of hoe the JVM operates is useful before using this class.
All the method descriptions below are generating bytecode to achieved the desired behaviour when the generated class is loaded. None of this class's methods calls actually invoke methods or create objects described by the callers.
Method Summary | |
void |
addThrownException(java.lang.String exceptionClass)
Declare the method throws an exception. |
int |
callMethod(java.lang.Object methodDescriptor)
Call a method previously described by describeMethod(). |
int |
callMethod(short type,
java.lang.String declaringClass,
java.lang.String methodName,
java.lang.String returnType,
int numArgs)
Call a method. |
void |
callSuper()
Call super(). |
void |
cast(java.lang.String className)
Cast the top stack value. |
void |
complete()
Indicate the method is complete. |
void |
completeConditional()
Complete the a ? |
void |
conditionalIf()
Initiate a sequence that corresponds to the Java language ' value ? |
void |
conditionalIfNull()
Initiate a sequence that corresponds to the Java language 'ref == null ? |
java.lang.Object |
describeMethod(short opcode,
java.lang.String declaringClass,
java.lang.String methodName,
java.lang.String returnType)
Return an object that efficiently (to the implementation) describes a zero-argument method and can be used with the single argument callMethod(). |
void |
dup()
Duplicate the top value on the stack. |
void |
endStatement()
End a statement. |
void |
getArrayElement(int element)
Pop an array refrence off the stack and push an element from that array. |
void |
getField(LocalField field)
Push the contents of the local field onto the stack. |
void |
getField(java.lang.String declaringClass,
java.lang.String fieldName,
java.lang.String fieldType)
Push the contents of the described field onto the stack. |
java.lang.String |
getName()
return the name of the method. |
void |
getParameter(int id)
Push a parameter value. |
void |
getStaticField(java.lang.String declaringClass,
java.lang.String fieldName,
java.lang.String fieldType)
Push the contents of the described static field onto the stack. |
void |
isInstanceOf(java.lang.String className)
Pop the top stack value and push a boolean that is the result of an instanceof check on the popped reference. |
void |
methodReturn()
Return from a method, optionally with a value. |
void |
push(boolean value)
Push a boolean constant onto the stack Stack ... => ... |
void |
push(byte value)
Push a byte constant onto the stack Stack ... => ... |
void |
push(double value)
Push a double constant onto the stack Stack ... => ... |
void |
push(float value)
Push a float constant onto the stack Stack ... => ... |
void |
push(int value)
Push a int constant onto the stack Stack ... => ... |
void |
push(long value)
Push a long constant onto the stack Stack ... => ... |
void |
push(short value)
Push a short constant onto the stack Stack ... => ... |
void |
push(java.lang.String value)
Push a String constant onto the stack Stack ... => ... |
void |
pushNewArray(java.lang.String className,
int size)
Create an instance of an array and push it onto the stack. |
void |
pushNewComplete(int numArgs)
Complete the sequence that was started with pushNewStart(). |
void |
pushNewStart(java.lang.String className)
Initiate a sequence that calls a constructor, equivalent to the new operator in Java. |
void |
pushNull(java.lang.String className)
Push a typed null onto the stack Stack ... => ... |
void |
pushThis()
Push this onto the stack. |
void |
putField(LocalField field)
Pop the top stack value and store it in the local field. |
void |
putField(java.lang.String fieldName,
java.lang.String fieldType)
Pop the top stack value and store it in the instance field of this class. |
void |
putField(java.lang.String declaringClass,
java.lang.String fieldName,
java.lang.String fieldType)
Pop the top stack value and store it in the field. |
void |
setArrayElement(int element)
Pop an array reference off the stack, store a value in the array at the passed in offset. |
void |
startElseCode()
Complete the true code path of a ? |
boolean |
statementNumHitLimit(int noStatementsAdded)
Tell if statement number in this method builder hits limit. |
void |
swap()
Swap the top two values on the stack. |
void |
upCast(java.lang.String className)
Upcast the top stack value. |
Method Detail |
public void addThrownException(java.lang.String exceptionClass)
public java.lang.String getName()
public void complete()
public void getParameter(int id)
Stack ... => ...,param_value
id
- position of the parameter (zero based).public void push(byte value)
Stack ... => ...,byte_value
public void push(boolean value)
Stack ... => ...,boolean_value
public void push(short value)
Stack ... => ...,short_value
public void push(int value)
Stack ... => ...,int_value
public void push(long value)
Stack ... => ...,long_value
public void push(float value)
Stack ... => ...,float_value
public void push(double value)
Stack ... => ...,double_value
public void push(java.lang.String value)
Stack ... => ...,String_value
public void pushNull(java.lang.String className)
Stack ... => ...,null
public void getField(LocalField field)
Stack ... => ...,field_value
public void getField(java.lang.String declaringClass, java.lang.String fieldName, java.lang.String fieldType)
Stack ...,field_ref => ...,field_value
public void getStaticField(java.lang.String declaringClass, java.lang.String fieldName, java.lang.String fieldType)
Stack ... => ...,field_value
public void putField(LocalField field)
Stack ...,value => ...,value
public void putField(java.lang.String fieldName, java.lang.String fieldType)
Stack ...,value => ...,value
public void putField(java.lang.String declaringClass, java.lang.String fieldName, java.lang.String fieldType)
Stack ...,field_ref,value => ...,value
public void pushNewStart(java.lang.String className)
Stack ... => [unchanged] ...
className
- class name of object to be created.public void pushNewComplete(int numArgs)
Stack ...,value* => [numArgs number of values will be popped] ...,new_ref
numArgs
- number of arguments to the constructor (can be 0).public void pushNewArray(java.lang.String className, int size)
Stack ... => ...,array_ref
className
- - type of array.size
- - number of elements in the arraypublic void pushThis()
Stack ... => ...,this_ref
public void upCast(java.lang.String className)
Stack ...,ref => ...,ref
public void cast(java.lang.String className)
Stack ...,value => ...,cast_value
className
- type (primitive, interface or class) to cast to.public void isInstanceOf(java.lang.String className)
Stack ...,ref => ...,boolean_value.
public void endStatement()
Stack value => :empty: or Stack :empty: => :empty:.
public void methodReturn()
Stack value => :empty: or Stack :empty: => :empty:.
public void conditionalIfNull()
mb.callMethod(...); // pushes an object onto the stack mb.conditionalIfNull(); mb.push(3); mb.startElseCode(); mb.push(5); mb.completeConditional(); // at this point 3 or 5 will be on the stackEach path through the ?: statement must leave the stack at the same depth as the other.
Stack ...,ref => ....
public void conditionalIf()
Stack ...,boolean_value => ....
public void startElseCode()
public void completeConditional()
public int callMethod(short type, java.lang.String declaringClass, java.lang.String methodName, java.lang.String returnType, int numArgs)
static methods Stack ...,value* => [numArgs number of values will be popped] ...,return_value [void methods will not push a value] non-static methods Stack ...,ref,value* => [numArgs number of values will be popped] ...,return_value [void methods will not push a value]
type
- type of method invocationdeclaringClass
- Class or interface the method is declared in. If it is a non-static
method call then if declaringClass is null, the declared type is taken to be the
type of the reference that will be popped.methodName
- name of the methodreturnType
- class name or primitive type (including "void") of the return type of the method, can not be null.numArgs
- number of arguments to the method (can be 0).public java.lang.Object describeMethod(short opcode, java.lang.String declaringClass, java.lang.String methodName, java.lang.String returnType)
public int callMethod(java.lang.Object methodDescriptor)
static methods Stack ...,value* => [numArgs number of values will be popped] ...,return_value [void methods will not push a value] non-static methods Stack ...,ref,value* => [numArgs number of values will be popped] ...,return_value [void methods will not push a value]
public void callSuper()
Stack ... => ...
public void getArrayElement(int element)
Stack ...,array_ref => ...,value
element
- Offset into the array (zero based)public void setArrayElement(int element)
Stack ...,array_ref, value => ...
element
- Offset into the array (zero based)public void swap()
Stack ...,valueA,valueB => ...,valueB,valueA
public void dup()
Stack ...,value => ...,value,value
public boolean statementNumHitLimit(int noStatementsAdded)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |