public abstract class MethodBuilder extends BindingMethod
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
EXCEPTION_CONSTRUCTOR_SIGNATURE1 |
static java.lang.String |
EXCEPTION_CONSTRUCTOR_SIGNATURE2 |
static java.lang.String |
FRAMEWORK_EXCEPTION_CLASS |
protected java.util.ArrayList |
m_exceptions
Exceptions needing to be handled in method (lazy create,
null if not used). |
protected org.apache.bcel.generic.MethodGen |
m_generator
Generator for constructing method.
|
protected int |
m_hashCode
Accumulated hash code from adding instructions.
|
protected InstructionBuilder |
m_instructionBuilder
Builder for class instructions.
|
private org.apache.bcel.generic.InstructionList |
m_instructionList
List of instructions in method definition.
|
protected ClassItem |
m_item
Method class item information.
|
private java.util.ArrayList |
m_localTypes
Value types associated with local variable slots.
|
protected org.apache.bcel.classfile.Method |
m_method
Actual generated method information.
|
private StringStack |
m_stackState
List of types currently on stack.
|
protected BranchWrapper[] |
m_targetBranches
Branch to be aimed at next appended instruction.
|
protected java.util.HashMap |
m_valueMap
Map for initialized properties (lazy create,
null if not
used). |
protected static java.util.ArrayList |
s_argNameLists
Table of argument name lists (generated as needed).
|
static int |
SYNTHETIC_ACCESS_FLAG |
Modifier | Constructor and Description |
---|---|
protected |
MethodBuilder(java.lang.String name,
org.apache.bcel.generic.Type ret,
org.apache.bcel.generic.Type[] args,
ClassFile cf,
int access)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addException(java.lang.String name)
Add exception to those needing handling.
|
int |
addLocal(java.lang.String name,
org.apache.bcel.generic.Type type)
Add local variable to method.
|
ClassItem |
addMethod()
Add constructed method to class.
|
void |
addMethodExceptions(ClassItem method)
Add exceptions thrown by called method to those needing handling.
|
private void |
append(org.apache.bcel.generic.CompoundInstruction ins)
Append compound instruction to method.
|
private void |
append(org.apache.bcel.generic.Instruction ins)
Append instruction to method.
|
void |
appendAASTORE()
Append an AASTORE to the instruction list.
|
void |
appendACONST_NULL()
Append an ACONST_NULL to the instruction list.
|
void |
appendALOAD(java.lang.String type)
Append appropriate array load to the instruction list.
|
void |
appendARRAYLENGTH()
Append an ARRAYLENGTH to the instruction list.
|
void |
appendASTORE(java.lang.String type)
Append the appropriate array store to the instruction list.
|
void |
appendCall(ClassItem item)
Create invoke instruction for static, member, or interface method and
append to method.
|
void |
appendCallInit(java.lang.String name,
java.lang.String signature)
Create invoke initializer instruction from signature and append to
method.
|
void |
appendCallInterface(java.lang.String method,
java.lang.String signature)
Create invoke interface method instruction from signature and append to
method.
|
void |
appendCallStatic(java.lang.String method,
java.lang.String signature)
Create invoke static method instruction from signature and append to
method.
|
void |
appendCallVirtual(java.lang.String method,
java.lang.String signature)
Create invoke virtual method instruction from signature and append to
method.
|
void |
appendCreateArray(java.lang.String type)
Append instruction to create instance of array.
|
void |
appendCreateCast(java.lang.String to)
Append check cast instruction from object (if needed).
|
void |
appendCreateCast(java.lang.String from,
java.lang.String to)
Append check cast instruction (if needed).
|
void |
appendCreateNew(java.lang.String name)
Append instruction to create instance of class.
|
void |
appendDCMPG()
Append an DCMPG to the instruction list.
|
void |
appendDUP_X1()
Append a DUP_X1 to the instruction list.
|
void |
appendDUP()
Append a DUP to the instruction list.
|
void |
appendDUP2()
Append a DUP2 to the instruction list.
|
void |
appendFCMPG()
Append an FCMPG to the instruction list.
|
void |
appendGet(ClassItem item)
Create get instruction and append to method.
|
void |
appendGetField(ClassItem item)
Create getfield instruction and append to method.
|
void |
appendGetStatic(ClassItem item)
Create getstatic instruction and append to method.
|
void |
appendIASTORE()
Append an IASTORE to the instruction list.
|
void |
appendICONST_0()
Append an ICONST_0 to the instruction list.
|
void |
appendICONST_1()
Append an ICONST_1 to the instruction list.
|
BranchWrapper |
appendIF_ICMPNE(java.lang.Object src)
Append IF_ICMPNE branch instruction to method.
|
BranchWrapper |
appendIFEQ(java.lang.Object src)
Append IFEQ branch instruction to method.
|
BranchWrapper |
appendIFGE(java.lang.Object src)
Append IFGE branch instruction to method.
|
BranchWrapper |
appendIFLT(java.lang.Object src)
Append IFLT branch instruction to method.
|
BranchWrapper |
appendIFNE(java.lang.Object src)
Append IFNE branch instruction to method.
|
BranchWrapper |
appendIFNONNULL(java.lang.Object src)
Append IFNONNULL branch instruction to method.
|
BranchWrapper |
appendIFNULL(java.lang.Object src)
Append IFNULL branch instruction to method.
|
void |
appendIncrementLocal(int inc,
int slot)
Append instruction to increment local integer variable.
|
void |
appendInstanceOf(java.lang.String to)
Append instanceof check instruction.
|
void |
appendISUB()
Append an ISUB to the instruction list.
|
void |
appendIXOR()
Append an IXOR to the instruction list.
|
void |
appendLCMP()
Append an LCMP to the instruction list.
|
void |
appendLoadConstant(int value)
Create load constant instruction and append to method.
|
void |
appendLoadConstant(java.lang.Object value)
Create load constant instruction and append to method.
|
void |
appendLoadConstant(java.lang.String value)
Create load constant instruction and append to method.
|
void |
appendLoadLocal(int slot)
Append instruction to load local variable.
|
void |
appendPOP()
Append a POP to the instruction list.
|
void |
appendPOP2()
Append a POP2 to the instruction list.
|
void |
appendPut(ClassItem item)
Create put instruction and append to method.
|
void |
appendPutField(ClassItem item)
Create putfield instruction and append to method.
|
void |
appendPutStatic(ClassItem item)
Create putstatic instruction and append to method.
|
void |
appendReturn()
Append simple return.
|
void |
appendReturn(java.lang.String type)
Append typed return.
|
void |
appendReturn(org.apache.bcel.generic.Type type)
Append typed return.
|
void |
appendStoreLocal(int slot)
Append instruction to store local variable.
|
void |
appendSWAP()
Append a SWAP to the instruction list.
|
void |
appendSWAP1For2()
Append instructions to exchange a single-word value on the top of the
stack with the double-word value below it on the stack.
|
BranchTarget |
appendTargetACONST_NULL()
Append an ACONST_NULL to the instruction list as a branch target.
|
BranchTarget |
appendTargetCreateNew(java.lang.String name)
Append instruction to create instance of class as a branch target.
|
private BranchTarget |
appendTargetInstruction(org.apache.bcel.generic.CompoundInstruction inst)
Append a compound instruction to the list as a branch target.
|
private BranchTarget |
appendTargetInstruction(org.apache.bcel.generic.Instruction inst)
Append an instruction to the list as a branch target.
|
BranchTarget |
appendTargetLoadConstant(int value)
Append a load constant instruction as a branch target.
|
BranchTarget |
appendTargetLoadConstant(java.lang.String value)
Append a load constant instruction as a branch target.
|
BranchTarget |
appendTargetNOP()
Append a NOP to the instruction list as a branch target.
|
void |
appendThrow()
Append exception throw.
|
BranchWrapper |
appendUnconditionalBranch(java.lang.Object src)
Append unconditional branch instruction to method.
|
void |
codeComplete(boolean suffix)
Complete method construction.
|
protected org.apache.bcel.generic.LocalVariableGen |
createLocal(java.lang.String name,
org.apache.bcel.generic.Type type)
Add local variable to method.
|
private java.lang.String |
describeStack()
Generate description of current stack state.
|
int |
getAccessFlags()
Get access flags.
|
protected org.apache.bcel.generic.InstructionHandle |
getFirstInstruction()
Get first instruction in method.
|
ClassItem |
getItem()
Get the method item.
|
java.lang.Object |
getKeyValue(java.lang.Object key)
Get local variable for object.
|
protected org.apache.bcel.generic.InstructionHandle |
getLastInstruction()
Get last instruction in method.
|
org.apache.bcel.classfile.Method |
getMethod()
Get the actual method.
|
java.lang.String |
getName()
Get name of method being constructed.
|
java.lang.String |
getSignature()
Get signature.
|
protected abstract void |
handleExceptions()
Process accumulated exceptions.
|
int |
hashCode()
Get hash code.
|
void |
initStackState(BranchWrapper branch)
Initialize stack state to match branch source.
|
void |
initStackState(BranchWrapper branch,
int pop)
Initialize stack state to partially match branch source.
|
protected void |
initStackState(java.lang.String[] types)
Initialize stack state to array of value types.
|
protected org.apache.bcel.generic.InstructionHandle |
internalAppendCreateNew(java.lang.String name)
Internal append instruction to create instance of class.
|
boolean |
isStackTopLong()
Check if top item on stack is a long value.
|
void |
setAccessFlags(int flags)
Set access flags.
|
java.lang.Object |
setKeyValue(java.lang.Object key,
java.lang.Object value)
Add keyed value to method definition.
|
protected void |
setTarget(org.apache.bcel.generic.InstructionHandle inst)
Target branches if pending.
|
void |
targetNext(BranchWrapper branch)
Set branch target as next instruction added to method.
|
void |
targetNext(BranchWrapper[] branches)
Set branch targets as next instruction added to method.
|
private java.lang.String |
verifyArray()
Verify the top value in the stack state resulting from the current
instruction list is an array.
|
private void |
verifyArray(java.lang.String type)
Verify the top value in the stack state resulting from the current
instruction list is an array of the specified type.
|
private void |
verifyCallStack(java.lang.String[] types)
Verify the top values in the stack state resulting from the current
instruction list.
|
private void |
verifyCallStack(java.lang.String clas,
java.lang.String[] types)
Verify the top values in the stack state resulting from the current
instruction list.
|
private void |
verifyCompatible(java.lang.String type,
java.lang.String need)
Verify that a pair of value types represent compatible types.
|
private void |
verifyStack(java.lang.String t1)
Verify the top value in the stack state resulting from the current
instruction list.
|
private void |
verifyStack(java.lang.String t1,
java.lang.String t2)
Verify the top two values in the stack state resulting from the current
instruction list.
|
private void |
verifyStackDepth(int count)
Verify that at least the specified number of items are present on the
stack.
|
private void |
verifyStackObject()
Verify that the top value in the stack state resulting from the current
instruction list is an object reference.
|
computeMethodHash, equals, getClassFile, makeAccessible
public static final java.lang.String FRAMEWORK_EXCEPTION_CLASS
public static final java.lang.String EXCEPTION_CONSTRUCTOR_SIGNATURE1
public static final java.lang.String EXCEPTION_CONSTRUCTOR_SIGNATURE2
public static final int SYNTHETIC_ACCESS_FLAG
protected static java.util.ArrayList s_argNameLists
protected InstructionBuilder m_instructionBuilder
private org.apache.bcel.generic.InstructionList m_instructionList
private StringStack m_stackState
protected org.apache.bcel.generic.MethodGen m_generator
protected org.apache.bcel.classfile.Method m_method
protected ClassItem m_item
private java.util.ArrayList m_localTypes
protected java.util.ArrayList m_exceptions
null
if not used).protected int m_hashCode
protected BranchWrapper[] m_targetBranches
protected java.util.HashMap m_valueMap
null
if not
used).protected MethodBuilder(java.lang.String name, org.apache.bcel.generic.Type ret, org.apache.bcel.generic.Type[] args, ClassFile cf, int access)
name
- method name to be builtret
- method return typeargs
- types of argumentscf
- owning class file informationaccess
- flags for method accesspublic java.lang.String getName()
getName
in class BindingMethod
public java.lang.String getSignature()
getSignature
in class BindingMethod
public int getAccessFlags()
getAccessFlags
in class BindingMethod
public void setAccessFlags(int flags)
setAccessFlags
in class BindingMethod
flags
- access type to be setpublic org.apache.bcel.classfile.Method getMethod()
codeComplete(boolean)
method is called).getMethod
in class BindingMethod
public java.lang.Object setKeyValue(java.lang.Object key, java.lang.Object value)
key
- retrieval keyvalue
- keyed valuepublic java.lang.Object getKeyValue(java.lang.Object key)
key
- object key for local variablepublic void addException(java.lang.String name)
name
- fully qualified name of exception classpublic void addMethodExceptions(ClassItem method)
method
- information for method to be handledprotected org.apache.bcel.generic.InstructionHandle getFirstInstruction()
protected org.apache.bcel.generic.InstructionHandle getLastInstruction()
protected final void setTarget(org.apache.bcel.generic.InstructionHandle inst)
targetNext(org.jibx.binding.classes.BranchWrapper)
method.inst
- handle for appended instructionprivate java.lang.String describeStack()
private void verifyCompatible(java.lang.String type, java.lang.String need)
type
- actual known type of valueneed
- type neededprivate void verifyStackDepth(int count)
count
- minimum number of items requiredprivate void verifyStack(java.lang.String t1)
t1
- expected type for top item on stackprivate java.lang.String verifyArray()
private void verifyArray(java.lang.String type)
type
- array item typeprivate void verifyStack(java.lang.String t1, java.lang.String t2)
t1
- expected type for first item on stackt2
- expected type for second item on stackprivate void verifyCallStack(java.lang.String[] types)
types
- expected parameter types on stackprivate void verifyCallStack(java.lang.String clas, java.lang.String[] types)
clas
- name of method classtypes
- expected parameter types on stackprivate void verifyStackObject()
public BranchWrapper appendIFEQ(java.lang.Object src)
src
- object responsible for generating branchpublic BranchWrapper appendIFGE(java.lang.Object src)
src
- object responsible for generating branchpublic BranchWrapper appendIFLT(java.lang.Object src)
src
- object responsible for generating branchpublic BranchWrapper appendIFNE(java.lang.Object src)
src
- object responsible for generating branchpublic BranchWrapper appendIFNONNULL(java.lang.Object src)
src
- object responsible for generating branchpublic BranchWrapper appendIFNULL(java.lang.Object src)
src
- object responsible for generating branchpublic BranchWrapper appendIF_ICMPNE(java.lang.Object src)
src
- object responsible for generating branchpublic BranchWrapper appendUnconditionalBranch(java.lang.Object src)
src
- object responsible for generating branchprivate void append(org.apache.bcel.generic.CompoundInstruction ins)
ins
- instruction to be appendedprivate void append(org.apache.bcel.generic.Instruction ins)
ins
- instruction to be appendedpublic void appendLoadConstant(int value)
value
- constant value to be loadedpublic void appendLoadConstant(java.lang.String value)
String
reference from the constant pool.value
- constant value to be loadedpublic void appendLoadConstant(java.lang.Object value)
value
- constant value to be loadedpublic void appendGetField(ClassItem item)
item
- information for field to be gottonpublic void appendGetStatic(ClassItem item)
item
- information for field to be setpublic void appendGet(ClassItem item)
item
- information for field to be gottenpublic void appendPutField(ClassItem item)
item
- information for field to be setpublic void appendPutStatic(ClassItem item)
item
- information for field to be setpublic void appendPut(ClassItem item)
item
- information for field to be gottenpublic void appendCall(ClassItem item)
item
- information for method to be calledpublic void appendCallStatic(java.lang.String method, java.lang.String signature)
method
- fully qualified class and method namesignature
- method signature in standard formpublic void appendCallVirtual(java.lang.String method, java.lang.String signature)
method
- fully qualified class and method namesignature
- method signature in standard formpublic void appendCallInterface(java.lang.String method, java.lang.String signature)
method
- fully qualified interface and method namesignature
- method signature in standard formpublic void appendCreateNew(java.lang.String name)
name
- fully qualified class namepublic void appendCallInit(java.lang.String name, java.lang.String signature)
name
- fully qualified class namesignature
- method signature in standard formpublic void appendCreateArray(java.lang.String type)
type
- fully qualified type name of array elementspublic void appendCreateCast(java.lang.String from, java.lang.String to)
from
- fully qualified name of current typeto
- fully qualified name of desired typepublic void appendCreateCast(java.lang.String to)
to
- fully qualified name of desired typepublic void appendInstanceOf(java.lang.String to)
to
- fully qualified name of type to checkprotected org.apache.bcel.generic.LocalVariableGen createLocal(java.lang.String name, org.apache.bcel.generic.Type type)
name
- local variable name (may be null
to use default)type
- variable typepublic int addLocal(java.lang.String name, org.apache.bcel.generic.Type type)
name
- local variable nametype
- variable typepublic void appendLoadLocal(int slot)
slot
- local variable slot to loadpublic void appendStoreLocal(int slot)
slot
- local variable slot to storepublic void appendIncrementLocal(int inc, int slot)
inc
- amount of incrmentslot
- local variable slot to loadpublic void appendReturn()
public void appendReturn(org.apache.bcel.generic.Type type)
type
- returned type (may be Type.VOID
)public void appendReturn(java.lang.String type)
type
- returned type (may be void
)public void appendThrow()
public void appendALOAD(java.lang.String type)
type
- array item type expectedpublic void appendAASTORE()
public void appendASTORE(java.lang.String type)
type
- array item type expectedpublic void appendACONST_NULL()
public void appendARRAYLENGTH()
public void appendDCMPG()
public void appendDUP()
public void appendDUP2()
public void appendDUP_X1()
public void appendFCMPG()
public void appendIASTORE()
public void appendICONST_0()
public void appendICONST_1()
public void appendISUB()
public void appendIXOR()
public void appendLCMP()
public void appendPOP()
public void appendPOP2()
public void appendSWAP()
public void appendSWAP1For2()
private BranchTarget appendTargetInstruction(org.apache.bcel.generic.CompoundInstruction inst)
inst
- compound instruction to be appended as branch targetprivate BranchTarget appendTargetInstruction(org.apache.bcel.generic.Instruction inst)
inst
- instruction to be appended as branch targetpublic BranchTarget appendTargetNOP()
public BranchTarget appendTargetACONST_NULL()
public BranchTarget appendTargetLoadConstant(int value)
value
- constant value to be loadedpublic BranchTarget appendTargetLoadConstant(java.lang.String value)
String
reference from the constant pool.value
- constant value to be loadedpublic BranchTarget appendTargetCreateNew(java.lang.String name)
name
- fully qualified class nameprotected org.apache.bcel.generic.InstructionHandle internalAppendCreateNew(java.lang.String name)
name
- fully qualified class namepublic boolean isStackTopLong()
true
if long value, false
if notpublic void initStackState(BranchWrapper branch)
branch
- wrapper for branch to be for stack initializationpublic void initStackState(BranchWrapper branch, int pop)
branch
- wrapper for branch to be for stack initializationpop
- number of items to be removed from branch source stack stateprotected void initStackState(java.lang.String[] types)
types
- array of type names on stackpublic void targetNext(BranchWrapper branch)
branch
- wrapper for branch to be aimed at next instruction (may be
null
, in which case nothing is done)public void targetNext(BranchWrapper[] branches)
branches
- wrappers for branches to be aimed at next instruction
(may be null
, in which case nothing is done)protected abstract void handleExceptions()
public void codeComplete(boolean suffix)
suffix
- add suffix to make method name uniquepublic ClassItem getItem()
getItem
in class BindingMethod
public int hashCode()
codeComplete(boolean)
method is called.hashCode
in class BindingMethod
public ClassItem addMethod()