Class InstructionBuilderImpl
java.lang.Object
org.apache.tapestry5.internal.plastic.Lockable
org.apache.tapestry5.internal.plastic.InstructionBuilderImpl
- All Implemented Interfaces:
org.apache.tapestry5.internal.plastic.asm.Opcodes
,InstructionBuilder
public class InstructionBuilderImpl
extends Lockable
implements org.apache.tapestry5.internal.plastic.asm.Opcodes, InstructionBuilder
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final NameCache
protected final InstructionBuilderState
protected final org.apache.tapestry5.internal.plastic.asm.MethodVisitor
Fields inherited from interface org.apache.tapestry5.internal.plastic.asm.Opcodes
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_MANDATED, ACC_MODULE, ACC_NATIVE, ACC_OPEN, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_RECORD, ACC_STATIC, ACC_STATIC_PHASE, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_TRANSITIVE, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASM10_EXPERIMENTAL, ASM4, ASM5, ASM6, ASM7, ASM8, ASM9, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, H_GETFIELD, H_GETSTATIC, H_INVOKEINTERFACE, H_INVOKESPECIAL, H_INVOKESTATIC, H_INVOKEVIRTUAL, H_NEWINVOKESPECIAL, H_PUTFIELD, H_PUTSTATIC, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INTEGER, INVOKEDYNAMIC, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SOURCE_DEPRECATED, SOURCE_MASK, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, UNINITIALIZED_THIS, V_PREVIEW, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7, V1_8, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V9
-
Method Summary
Modifier and TypeMethodDescriptionExpects the top object on the stack to be an array.boxPrimitive
(String typeName) If the type name is a primitive type, adds code to box the type into the equivalent wrapper type, using static methods on the wrapper type.castOrUnbox
(String typeName) Casts the object on top of the stack to the indicated type.Adds a check that the object on top of the stack is assignable to the indicated class.compareSpecial
(String typeName) Special comparison logic for primitive float, double and long.doWhile
(Condition condition, WhileCallback callback) Implements a simple loop based on a condition.dupe()
Duplicates the top object on the stack.dupe
(int depth) Duplicates the top object on the stack, placing the result at some depth.dupeWide()
Duplicates a wide value (a primitive long or double).Loads a field onto the stack.Loads an instance field onto the stack.getField
(PlasticField field) Loads an instance or static field onto the stack.getStaticField
(String className, String fieldName, Class fieldType) Gets a static field; does not consume a value from the stack, but pushes the fields' value onto the stack.getStaticField
(String className, String fieldName, String typeName) Gets a static field; does not consume a value from the stack, but pushes the fields' value onto the stack.increment
(LocalVariable variable) Increments a local integer variable.instanceOf
(Class clazz) Adds a check that the object on top of the stack is assignable to the indicated class.instanceOf
(String className) Adds a check that the object on top of the stack is assignable to the indicated class.Automatically invokes an interface or virtual method.Automatically invokes an interface or virtual method.invokeConstructor
(Class clazz, Class... argumentTypes) invokeConstructor
(String className, String... argumentTypes) Invokes a constructor on a class.invokeInterface
(String interfaceName, String returnType, String methodName, String... argumentTypes) Invokes a standard virtual method.invokeSpecial
(String containingClassName, MethodDescription description) Invokes an instance method of a base class, or a private method of a class, using the target object and parameters already on the stack.invokeStatic
(Class clazz, Class returnType, String methodName, Class... argumentTypes) Invokes a static method of a class.invokeVirtual
(String className, String returnType, String methodName, String... argumentTypes) Invokes a standard virtual method.invokeVirtual
(PlasticMethod method) iterateArray
(InstructionBuilderCallback callback) Expects an array to be the top value on the stack.loadArgument
(int index) Loads an argument onto the stack, using the opcode appropriate to the argument's type.Loads all arguments for the current method onto the stack; this is used when invoking a method that takes the exact same parameters (often, a super-class implementation).Loads a value from an array object.loadArrayElement
(int index, String elementType) Loads a value from an array object, which must be the top element of the stack.loadConstant
(Object constant) Loads a constant valueloadNull()
Loads the null constant onto the stack.loadThis()
Loads this onto the stack.loadTypeConstant
(Class clazz) Loads a Java type (a Class instance) as a constant.loadTypeConstant
(String typeName) Loads a Java type (a Class instance) as a constant.Loads a value from a local variable and pushes it onto the stack.newInstance
(Class clazz) A convenience version ofInstructionBuilder.newInstance(String)
used when the class is known at build time.newInstance
(String className) Creates a new, uninitialized instance of the indicated class.pop()
Discards the top value on the stack.popWide()
Pops a wide value (a primitive long or double).Expects the stack to contain the instance to update, and the value to store into the field.putStaticField
(String className, String fieldName, Class fieldType) Sets a static field; the new field value should be on top of the stack.putStaticField
(String className, String fieldName, String typeName) Sets a static field; the new field value should be on top of the stack.Returns the default value for the method, which may be null, or a specific primitive value.Returns the top value on the stack.startSwitch
(int min, int max, SwitchCallback callback) Starts a switch statement.startTryCatch
(TryCatchCallback callback) Defines the start of a block that can have exception handlers and finally blocks applied.startVariable
(String type, LocalVariableCallback callback) Starts a block where the given name is active.Stores the value on top of the stack to a local variable (previously defined byInstructionBuilder.startVariable(String, LocalVariableCallback)
.swap()
Swaps the top element of the stack with the next element down.Throws the exception on the top of the stack.throwException
(Class<? extends Throwable> exceptionType, String message) throwException
(String className, String message) Throws an exception with a fixed message.unboxPrimitive
(String typeName) Unboxes a wrapper type to a primitive type if typeName is a primitive type name (the value on the stack should be the corresponding wrapper type instance).when
(Condition condition, InstructionBuilderCallback ifTrue) Simplified version ofInstructionBuilder.when(Condition, WhenCallback)
that simply executes the callback code when the condition is true and does nothing if the condition is false (the more general case).when
(Condition condition, WhenCallback callback) Executes conditional code based on aCondition
.
-
Field Details
-
state
-
v
-
cache
-
-
Method Details
-
returnDefaultValue
Description copied from interface:InstructionBuilder
Returns the default value for the method, which may be null, or a specific primitive value.- Specified by:
returnDefaultValue
in interfaceInstructionBuilder
-
loadThis
Description copied from interface:InstructionBuilder
Loads this onto the stack.- Specified by:
loadThis
in interfaceInstructionBuilder
-
loadNull
Description copied from interface:InstructionBuilder
Loads the null constant onto the stack.- Specified by:
loadNull
in interfaceInstructionBuilder
-
loadArgument
Description copied from interface:InstructionBuilder
Loads an argument onto the stack, using the opcode appropriate to the argument's type. In addition this automatically adjusts for arguments of primitive type long or double (which take up two local variable indexes, rather than one as for all other types)- Specified by:
loadArgument
in interfaceInstructionBuilder
- Parameters:
index
- to argument (0 is the first argument, not this)
-
loadArguments
Description copied from interface:InstructionBuilder
Loads all arguments for the current method onto the stack; this is used when invoking a method that takes the exact same parameters (often, a super-class implementation). A call toInstructionBuilder.loadThis()
(or some other way of identifying the target method) should precede this call.- Specified by:
loadArguments
in interfaceInstructionBuilder
-
invokeSpecial
Description copied from interface:InstructionBuilder
Invokes an instance method of a base class, or a private method of a class, using the target object and parameters already on the stack. Leaves the result on the stack (unless its a void method).- Specified by:
invokeSpecial
in interfaceInstructionBuilder
- Parameters:
containingClassName
- class name containing the methoddescription
- describes the method name, parameters and return type
-
invokeVirtual
- Specified by:
invokeVirtual
in interfaceInstructionBuilder
-
invokeVirtual
public InstructionBuilder invokeVirtual(String className, String returnType, String methodName, String... argumentTypes) Description copied from interface:InstructionBuilder
Invokes a standard virtual method.- Specified by:
invokeVirtual
in interfaceInstructionBuilder
-
invokeInterface
public InstructionBuilder invokeInterface(String interfaceName, String returnType, String methodName, String... argumentTypes) Description copied from interface:InstructionBuilder
Invokes a standard virtual method.- Specified by:
invokeInterface
in interfaceInstructionBuilder
-
invokeStatic
public InstructionBuilder invokeStatic(Class clazz, Class returnType, String methodName, Class... argumentTypes) Description copied from interface:InstructionBuilder
Invokes a static method of a class.- Specified by:
invokeStatic
in interfaceInstructionBuilder
-
invoke
Description copied from interface:InstructionBuilder
Automatically invokes an interface or virtual method. Remember to useInstructionBuilder.invokeConstructor(Class, Class...)
for constructors andInstructionBuilder.invokeSpecial(String, MethodDescription)
for private methods.- Specified by:
invoke
in interfaceInstructionBuilder
-
invoke
public InstructionBuilder invoke(Class clazz, Class returnType, String methodName, Class... argumentTypes) Description copied from interface:InstructionBuilder
Automatically invokes an interface or virtual method. Remember to useInstructionBuilder.invokeConstructor(Class, Class...)
for constructors andInstructionBuilder.invokeSpecial(String, MethodDescription)
for private methods.- Specified by:
invoke
in interfaceInstructionBuilder
-
returnResult
Description copied from interface:InstructionBuilder
Returns the top value on the stack. For void methods, no value should be on the stack and the method will simply return.- Specified by:
returnResult
in interfaceInstructionBuilder
-
boxPrimitive
Description copied from interface:InstructionBuilder
If the type name is a primitive type, adds code to box the type into the equivalent wrapper type, using static methods on the wrapper type. Does nothing if the type is not primitive, or type void.- Specified by:
boxPrimitive
in interfaceInstructionBuilder
-
unboxPrimitive
Description copied from interface:InstructionBuilder
Unboxes a wrapper type to a primitive type if typeName is a primitive type name (the value on the stack should be the corresponding wrapper type instance). Does nothing for non-primitive types.- Specified by:
unboxPrimitive
in interfaceInstructionBuilder
- Parameters:
typeName
- possibly primitive type name
-
getField
Description copied from interface:InstructionBuilder
Loads an instance field onto the stack. The object containing the field should already be loaded onto the stack (usually, viaInstructionBuilder.loadThis()
).- Specified by:
getField
in interfaceInstructionBuilder
- Parameters:
className
- name of class containing the fieldfieldName
- name of the fieldtypeName
- type of field
-
getStaticField
Description copied from interface:InstructionBuilder
Gets a static field; does not consume a value from the stack, but pushes the fields' value onto the stack.- Specified by:
getStaticField
in interfaceInstructionBuilder
- Parameters:
className
- name of class containing the fieldfieldName
- name of the fieldtypeName
- type of field
-
getStaticField
Description copied from interface:InstructionBuilder
Gets a static field; does not consume a value from the stack, but pushes the fields' value onto the stack.- Specified by:
getStaticField
in interfaceInstructionBuilder
- Parameters:
className
- name of class containing the fieldfieldName
- name of the fieldfieldType
- type of field
-
putStaticField
Description copied from interface:InstructionBuilder
Sets a static field; the new field value should be on top of the stack.- Specified by:
putStaticField
in interfaceInstructionBuilder
- Parameters:
className
- name of class containing the fieldfieldName
- name of the fieldfieldType
- type of field
-
putStaticField
Description copied from interface:InstructionBuilder
Sets a static field; the new field value should be on top of the stack.- Specified by:
putStaticField
in interfaceInstructionBuilder
- Parameters:
className
- name of class containing the fieldfieldName
- name of the fieldtypeName
- type of field
-
getField
Description copied from interface:InstructionBuilder
Loads an instance or static field onto the stack. The plastic class instance containing the field should already be loaded onto the stack (usually, viaInstructionBuilder.loadThis()
).- Specified by:
getField
in interfaceInstructionBuilder
- Parameters:
field
- identifies name, type and container of field to load
-
putField
Description copied from interface:InstructionBuilder
Expects the stack to contain the instance to update, and the value to store into the field.- Specified by:
putField
in interfaceInstructionBuilder
-
putField
- Specified by:
putField
in interfaceInstructionBuilder
-
getField
Description copied from interface:InstructionBuilder
Loads a field onto the stack. This version is used when the field type is known at build time, rather than discovered at runtime.- Specified by:
getField
in interfaceInstructionBuilder
- Parameters:
className
- name of class containing the fieldfieldName
- name of the fieldfieldType
- type of field
-
loadArrayElement
Description copied from interface:InstructionBuilder
Loads a value from an array object, which must be the top element of the stack.- Specified by:
loadArrayElement
in interfaceInstructionBuilder
- Parameters:
index
- constant index into the arrayelementType
- the type name of the elements of the array Note: currently only reference types (objects and arrays) are supported, not primitives
-
loadArrayElement
Description copied from interface:InstructionBuilder
Loads a value from an array object. The stack should have the array at depth 1, and an array index on top. Only object arrays (not arrays of primitives) are supported.- Specified by:
loadArrayElement
in interfaceInstructionBuilder
-
checkcast
Description copied from interface:InstructionBuilder
Adds a check that the object on top of the stack is assignable to the indicated class.- Specified by:
checkcast
in interfaceInstructionBuilder
- Parameters:
className
- class to cast to
-
checkcast
- Specified by:
checkcast
in interfaceInstructionBuilder
-
instanceOf
Description copied from interface:InstructionBuilder
Adds a check that the object on top of the stack is assignable to the indicated class.- Specified by:
instanceOf
in interfaceInstructionBuilder
- Parameters:
className
- class to cast to
-
instanceOf
Description copied from interface:InstructionBuilder
Adds a check that the object on top of the stack is assignable to the indicated class.- Specified by:
instanceOf
in interfaceInstructionBuilder
-
startTryCatch
Description copied from interface:InstructionBuilder
Defines the start of a block that can have exception handlers and finally blocks applied. Continue using this InstructionBuilder to define code inside the block, then call methods on the InstructionBlock to define the end of the block and set up handlers.- Specified by:
startTryCatch
in interfaceInstructionBuilder
- Parameters:
callback
- allows generation of try, catch, and finally clauses
-
newInstance
Description copied from interface:InstructionBuilder
Creates a new, uninitialized instance of the indicated class. This should be followed by code to call the new instance's constructor.- Specified by:
newInstance
in interfaceInstructionBuilder
- Parameters:
className
- of class to instantiate
-
newInstance
Description copied from interface:InstructionBuilder
A convenience version ofInstructionBuilder.newInstance(String)
used when the class is known at build time.- Specified by:
newInstance
in interfaceInstructionBuilder
- Parameters:
clazz
- to instantiate
-
invokeConstructor
Description copied from interface:InstructionBuilder
Invokes a constructor on a class. The instance should already be on the stack, followed by the right number and type of parameters. Note that a constructor acts like a void method, so you will often follow the sequence: newInstance(), dupe(0), invokeConstructor() so that a reference to the instance is left on the stack.F- Specified by:
invokeConstructor
in interfaceInstructionBuilder
- Parameters:
className
- the class containing the constructorargumentTypes
- java type names for each argument of the constructor
-
invokeConstructor
- Specified by:
invokeConstructor
in interfaceInstructionBuilder
-
dupe
Description copied from interface:InstructionBuilder
Duplicates the top object on the stack, placing the result at some depth.- Specified by:
dupe
in interfaceInstructionBuilder
- Parameters:
depth
- 0 (DUP), 1 (DUP_X1) or 2 (DUP_X2)
-
dupe
Description copied from interface:InstructionBuilder
Duplicates the top object on the stack. Commonly used withInstructionBuilder.when(Condition, WhenCallback)
.- Specified by:
dupe
in interfaceInstructionBuilder
- See Also:
-
pop
Description copied from interface:InstructionBuilder
Discards the top value on the stack. Assumes the value is a single word value: an object reference, or a small primitive) and not a double or long.- Specified by:
pop
in interfaceInstructionBuilder
-
swap
Description copied from interface:InstructionBuilder
Swaps the top element of the stack with the next element down. Note that this can cause problems if the top element on the stack is a long or double.- Specified by:
swap
in interfaceInstructionBuilder
-
loadConstant
Description copied from interface:InstructionBuilder
Loads a constant value- Specified by:
loadConstant
in interfaceInstructionBuilder
- Parameters:
constant
- Integer, Float, Double, Long, String or null
-
loadTypeConstant
Description copied from interface:InstructionBuilder
Loads a Java type (a Class instance) as a constant. This assumes the type name is the name of class (or array) but not a primitive type.- Specified by:
loadTypeConstant
in interfaceInstructionBuilder
- Parameters:
typeName
- Java class name
-
loadTypeConstant
Description copied from interface:InstructionBuilder
Loads a Java type (a Class instance) as a constant. This assumes the type name is the name of class (or array) but not a primitive type.- Specified by:
loadTypeConstant
in interfaceInstructionBuilder
- Parameters:
clazz
- Java type to load as a constant
-
castOrUnbox
Description copied from interface:InstructionBuilder
Casts the object on top of the stack to the indicated type. For primitive types, casts to the wrapper type and invokes the appropriate unboxing static method call, leaving a primitive type value on the stack.- Specified by:
castOrUnbox
in interfaceInstructionBuilder
- Parameters:
typeName
- to cast or unbox to
-
throwException
Description copied from interface:InstructionBuilder
Throws an exception with a fixed message. Assumes the exception class includes a constructor that takes a single string.- Specified by:
throwException
in interfaceInstructionBuilder
- Parameters:
className
- name of exception class to instantiatemessage
- message (passed as first and only parameter to constructor)
-
throwException
- Specified by:
throwException
in interfaceInstructionBuilder
-
throwException
Description copied from interface:InstructionBuilder
Throws the exception on the top of the stack.- Specified by:
throwException
in interfaceInstructionBuilder
-
startSwitch
Description copied from interface:InstructionBuilder
Starts a switch statement.- Specified by:
startSwitch
in interfaceInstructionBuilder
- Parameters:
min
- the minimum value to match againstmax
- the maximum value to match against
-
startVariable
Description copied from interface:InstructionBuilder
Starts a block where the given name is active.- Specified by:
startVariable
in interfaceInstructionBuilder
- Parameters:
type
- type of local variablecallback
- generates code used when variable is in effect
-
storeVariable
Description copied from interface:InstructionBuilder
Stores the value on top of the stack to a local variable (previously defined byInstructionBuilder.startVariable(String, LocalVariableCallback)
.- Specified by:
storeVariable
in interfaceInstructionBuilder
-
loadVariable
Description copied from interface:InstructionBuilder
Loads a value from a local variable and pushes it onto the stack. The variable is defined byInstructionBuilder.startVariable(String, LocalVariableCallback)
.- Specified by:
loadVariable
in interfaceInstructionBuilder
-
when
Description copied from interface:InstructionBuilder
Simplified version ofInstructionBuilder.when(Condition, WhenCallback)
that simply executes the callback code when the condition is true and does nothing if the condition is false (the more general case). The testing opcodes all pop the value off the stack, so this is usually preceded bydupe(0)
.- Specified by:
when
in interfaceInstructionBuilder
- Parameters:
condition
- to evaluateifTrue
- generates code for when condition is true- Returns:
- this builder
-
when
Description copied from interface:InstructionBuilder
Executes conditional code based on aCondition
. The testing opcodes all pop the value off the stack, so this is usually preceded bydupe(0)
.- Specified by:
when
in interfaceInstructionBuilder
- Parameters:
condition
- defines true and false casescallback
- provides code for true and false blocks- Returns:
- this builder
-
doWhile
Description copied from interface:InstructionBuilder
Implements a simple loop based on a condition. First the WhileCallback.buildTest(InstructionBuilder) code is executed, then the condition is evaluated (which will consume at least the top value on the stack). When the condition is false, the loop is exited. When the condition is true, the code defined byWhileCallback.buildBody(InstructionBuilder)
is executed, and then a GOTO back to the test code.- Specified by:
doWhile
in interfaceInstructionBuilder
- Returns:
- this builder
-
increment
Description copied from interface:InstructionBuilder
Increments a local integer variable.- Specified by:
increment
in interfaceInstructionBuilder
- Returns:
- this builder
-
arrayLength
Description copied from interface:InstructionBuilder
Expects the top object on the stack to be an array. Replaces it with the length of that array.- Specified by:
arrayLength
in interfaceInstructionBuilder
-
iterateArray
Description copied from interface:InstructionBuilder
Expects an array to be the top value on the stack. Iterates the array. The callback generates code that will have each successive value from the array as the top value on the stack. Creates a variable to store the loop index.- Specified by:
iterateArray
in interfaceInstructionBuilder
- Parameters:
callback
- to invoke. The element will be the top value on the stack. The callback is responsible for removing it from the stack.- Returns:
- this builder
-
dupeWide
Description copied from interface:InstructionBuilder
Duplicates a wide value (a primitive long or double).- Specified by:
dupeWide
in interfaceInstructionBuilder
-
popWide
Description copied from interface:InstructionBuilder
Pops a wide value (a primitive long or double).- Specified by:
popWide
in interfaceInstructionBuilder
-
compareSpecial
Description copied from interface:InstructionBuilder
Special comparison logic for primitive float, double and long. Expect two matching wide values on the stack. Reduces the two wide values to a single int value: -1, 0, or 1 depending on whether the deeper value is less than, equal to, or greater than the top value on the stack.- Specified by:
compareSpecial
in interfaceInstructionBuilder
-