public interface MethodBuilder
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.
Modifier and Type | Method and Description |
---|---|
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 a conditional which completes the false code path.
|
void |
conditionalIf()
Initiate a conditional sequence.
|
void |
conditionalIfNull()
Initiate a conditional sequence.
|
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 |
pop()
Pop the top value off the stack
Stack ..., 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 |
setField(LocalField field)
Pop the top stack value and store it in the local field.
|
void |
startElseCode()
Complete the true code path of a conditional.
|
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.
|
void addThrownException(java.lang.String exceptionClass)
java.lang.String getName()
void complete()
void getParameter(int id)
Stack ... => ...,param_value
id
- position of the parameter (zero based).void push(byte value)
Stack ... => ...,byte_value
void push(boolean value)
Stack ... => ...,boolean_value
void push(short value)
Stack ... => ...,short_value
void push(int value)
Stack ... => ...,int_value
void push(long value)
Stack ... => ...,long_value
void push(float value)
Stack ... => ...,float_value
void push(double value)
Stack ... => ...,double_value
void push(java.lang.String value)
Stack ... => ...,String_value
void pushNull(java.lang.String className)
Stack ... => ...,null
void getField(LocalField field)
Stack ... => ...,field_value
void getField(java.lang.String declaringClass, java.lang.String fieldName, java.lang.String fieldType)
Stack ...,field_ref => ...,field_value
void getStaticField(java.lang.String declaringClass, java.lang.String fieldName, java.lang.String fieldType)
Stack ... => ...,field_value
void setField(LocalField field)
Stack ...,value => ...
void putField(LocalField field)
Stack ...,value => ...,value
void putField(java.lang.String fieldName, java.lang.String fieldType)
Stack ...,value => ...,value
void putField(java.lang.String declaringClass, java.lang.String fieldName, java.lang.String fieldType)
Stack ...,field_ref,value => ...,value
void pushNewStart(java.lang.String className)
Stack ... => [unchanged] ...
className
- class name of object to be created.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).void pushNewArray(java.lang.String className, int size)
Stack ... => ...,array_ref
className
- - type of array.size
- - number of elements in the arrayvoid pushThis()
Stack ... => ...,this_ref
void upCast(java.lang.String className)
Stack ...,ref => ...,ref
void cast(java.lang.String className)
Stack ...,value => ...,cast_value
className
- type (primitive, interface or class) to cast to.void isInstanceOf(java.lang.String className)
Stack ...,ref => ...,boolean_value.
void pop()
Stack ..., value => ....
void endStatement()
Stack value => :empty: or Stack :empty: => :empty:.
void methodReturn()
Stack value => :empty: or Stack :empty: => :empty:.
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 => ....
void conditionalIf()
Stack ...,boolean_value => ....
void startElseCode()
void completeConditional()
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).java.lang.Object describeMethod(short opcode, java.lang.String declaringClass, java.lang.String methodName, java.lang.String returnType)
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]
void callSuper()
Stack ... => ...
void getArrayElement(int element)
Stack ...,array_ref => ...,value
element
- Offset into the array (zero based)void setArrayElement(int element)
Stack ...,array_ref, value => ...
element
- Offset into the array (zero based)void swap()
Stack ...,valueA,valueB => ...,valueB,valueA
void dup()
Stack ...,value => ...,value,value
boolean statementNumHitLimit(int noStatementsAdded)
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.