Interface BytecodeCreator
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
CatchBlockCreator,MethodCreator,TryBlock
- All Known Implementing Classes:
AbstractSwitch,BytecodeCreatorImpl,CatchBlockCreatorImpl,ClassTransfromerMethodCreatorImpl,ClassTransfromerMethodCreatorImpl.ClassTransformerEnumSwitchImpl,EnumSwitchImpl,ForEachLoopImpl,FunctionCreatorImpl.FunctionBytecodeCreator,IfThenElseImpl,LoopImpl,MethodCreatorImpl,StringSwitchImpl,TryBlockImpl,WhileLoopImpl
This does not expose the full extent of Java bytecode, rather just the most common operations that generated classes are likely to use.
-
Method Summary
Modifier and TypeMethodDescriptionadd(ResultHandle a1, ResultHandle a2) Adds the two result handles together and returns the resultarrayLength(ResultHandle array) voidassign(AssignableResultHandle target, ResultHandle value) Assign the given value to the given assignable target.bitwiseAnd(ResultHandle a1, ResultHandle a2) Computes the bitwise AND of the two result handles and returns the resultbitwiseOr(ResultHandle a1, ResultHandle a2) Computes the bitwise OR of the two result handles and returns the resultbitwiseXor(ResultHandle a1, ResultHandle a2) Computes the bitwise XOR of the two result handles and returns the resultdefault voidGo to the end of this scope.voidbreakScope(BytecodeCreator scope) Go to the end of the given scope.default ResultHandlecheckCast(ResultHandle resultHandle, Class<?> castTarget) Perform a check cast operation which transforms the type of the given result handle.checkCast(ResultHandle resultHandle, String castTarget) Perform a check cast operation which transforms the type of the given result handle.default voidclose()Indicate that the scope is no longer in use.compareDouble(ResultHandle value1, ResultHandle value2, boolean nanComparesAsGreater) Compares twodoublevalues and pushes the resulting integer to the stack.compareFloat(ResultHandle value1, ResultHandle value2, boolean nanComparesAsGreater) Compares twofloatvalues and pushes the resulting integer to the stack.compareLong(ResultHandle value1, ResultHandle value2) Compares twolongvalues and pushes the resulting integer to the stack.default voidGo to the top of this scope.voidcontinueScope(BytecodeCreator scope) Go to the top of the given scope.convertPrimitive(ResultHandle value, Class<?> conversionTarget) Converts givenvalue, which must be of a primitive type, to the givenconversionTarget, which must be a primitive type, using primitive conversions defined by the Java language specification.createFunction(Class<?> functionalInterface) Creates an instance of a functional interfaceCreate a nested scope.default AssignableResultHandlecreateVariable(Class<?> type) Create a local variable which can be assigned within this scope.createVariable(String typeDescr) Create a local variable which can be assigned within this scope.divide(ResultHandle a1, ResultHandle a2) Divides the first result handle by the second and returns the result<E extends Enum<E>>
Switch.EnumSwitch<E> enumSwitch(ResultHandle value, Class<E> enumClass) Create a new switch construct for an enum constant.forEach(ResultHandle iterable) Create a new for-each loop construct.getMethodParam(int i) getThis()ifFalse(ResultHandle resultHandle) An if statement.ifGreaterEqualZero(ResultHandle resultHandle) An if statement.ifGreaterThanZero(ResultHandle resultHandle) An if statement.ifIntegerEqual(ResultHandle value1, ResultHandle value2) An if statement.ifIntegerGreaterEqual(ResultHandle value1, ResultHandle value2) An if statement.ifIntegerGreaterThan(ResultHandle value1, ResultHandle value2) An if statement.ifIntegerLessEqual(ResultHandle value1, ResultHandle value2) An if statement.ifIntegerLessThan(ResultHandle value1, ResultHandle value2) An if statement.ifLessEqualZero(ResultHandle resultHandle) An if statement.ifLessThanZero(ResultHandle resultHandle) An if statement.ifNonZero(ResultHandle resultHandle) An if statement.ifNotNull(ResultHandle resultHandle) An if statement.ifNull(ResultHandle resultHandle) An if statement.ifReferencesEqual(ResultHandle ref1, ResultHandle ref2) An if statement.ifReferencesNotEqual(ResultHandle ref1, ResultHandle ref2) An if statement.ifThenElse(ResultHandle condition) Create a new if-then-else construct.ifTrue(ResultHandle resultHandle) An if statement.ifZero(ResultHandle resultHandle) An if statement.default ResultHandleincrement(ResultHandle toIncrement) Increments a ResultHandledefault ResultHandleinstanceOf(ResultHandle resultHandle, Class<?> testType) Checks if the given resultHandle is an instance of the target typeinstanceOf(ResultHandle resultHandle, String testType) Checks if the given resultHandle is an instance of the target typeinvokeInterfaceMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args) Invokes a interface method, and returns aResultHandlewith the result, or null if the method is void.default ResultHandleinvokeInterfaceMethod(org.jboss.jandex.MethodInfo descriptor, ResultHandle object, ResultHandle... args) Invokes a interface method, and returns aResultHandlewith the result, or null if the method is void.invokeSpecialInterfaceMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args) Invokes a special interface method, and returns aResultHandlewith the result, or null if the method is void.default ResultHandleinvokeSpecialInterfaceMethod(org.jboss.jandex.MethodInfo descriptor, ResultHandle object, ResultHandle... args) Invokes a special interface method, and returns aResultHandlewith the result, or null if the method is void.invokeSpecialMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args) Invokes a special method, and returns aResultHandlewith the result, or null if the method is void.default ResultHandleinvokeSpecialMethod(org.jboss.jandex.MethodInfo descriptor, ResultHandle object, ResultHandle... args) Invokes a special method, and returns aResultHandlewith the result, or null if the method is void.invokeStaticInterfaceMethod(MethodDescriptor descriptor, ResultHandle... args) Invokes a static method of an interface, and returns aResultHandlewith the result, or null if the method is void.default ResultHandleinvokeStaticInterfaceMethod(org.jboss.jandex.MethodInfo descriptor, ResultHandle... args) Invokes a static method of an interface, and returns aResultHandlewith the result, or null if the method is void.invokeStaticMethod(MethodDescriptor descriptor, ResultHandle... args) Invokes a static method, and returns aResultHandlewith the result, or null if the method is void.default ResultHandleinvokeStaticMethod(org.jboss.jandex.MethodInfo descriptor, ResultHandle... args) Invokes a static method, and returns aResultHandlewith the result, or null if the method is void.invokeVirtualMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args) Invokes a virtual method, and returns aResultHandlewith the result, or null if the method is void.default ResultHandleinvokeVirtualMethod(org.jboss.jandex.MethodInfo descriptor, ResultHandle object, ResultHandle... args) Invokes a virtual method, and returns aResultHandlewith the result, or null if the method is void.booleanisScopedWithin(BytecodeCreator other) Determine if this bytecode creator is scoped within the given bytecode creator.load(boolean val) Returns aResultHandlerepresenting the specified valueload(byte val) Returns aResultHandlerepresenting the specified valueload(char val) Returns aResultHandlerepresenting the specified valueload(double val) Returns aResultHandlerepresenting the specified valueload(float val) Returns aResultHandlerepresenting the specified valueload(int val) Returns aResultHandlerepresenting the specified valueload(long val) Returns aResultHandlerepresenting the specified valueload(short val) Returns aResultHandlerepresenting the specified valuedefault ResultHandleReturns aResultHandlerepresenting the specified valueReturns aResultHandlerepresenting the specified valuedefault ResultHandleReturns aResultHandlerepresenting the specified class Note that in almost all circumstances you are better off usingloadClassFromTCCL(Class), as it can load classes that are not visible from the current class.Returns aResultHandlerepresenting the specified class Note that in almost all circumstances you are better off usingloadClassFromTCCL(String), as it can load classes that are not visible from the current class.default ResultHandleloadClass(org.jboss.jandex.ClassInfo val) Returns aResultHandlerepresenting the specified class Note that in almost all circumstances you are better off usingloadClassFromTCCL(ClassInfo), as it can load classes that are not visible from the current class.default ResultHandleloadClassFromTCCL(Class<?> val) Returns aResultHandlerepresenting the specified class loaded from the TCCL.loadClassFromTCCL(String className) Returns aResultHandlerepresenting the specified class This method can load all classes, including package private classes that are not visible to the current bytecode.default ResultHandleloadClassFromTCCL(org.jboss.jandex.ClassInfo val) Returns aResultHandlerepresenting the specified class This method can load all classes, including package private classes that are not visible to the current bytecode.loadNull()Returns aResultHandlerepresentingnull}default ResultHandlemarshalAsArray(Class<?> arrayClass, ResultHandle... params) multiply(ResultHandle a1, ResultHandle a2) Multiplies the two result handles together and returns the resultdefault ResultHandledefault ResultHandlenewArray(Class<?> type, ResultHandle length) default ResultHandlenewArray(String type, ResultHandle length) newInstance(MethodDescriptor descriptor, ResultHandle... args) Creates a new instance of a given type, by calling the specified constructor, and returns aResultHandlerepresenting the resultdefault ResultHandlenewInstance(org.jboss.jandex.MethodInfo descriptor, ResultHandle... args) Creates a new instance of a given type, by calling the specified constructor, and returns aResultHandlerepresenting the resultdefault ResultHandlereadArrayValue(ResultHandle array, int index) readArrayValue(ResultHandle array, ResultHandle index) readInstanceField(FieldDescriptor fieldDescriptor, ResultHandle instance) Reads an instance field and returns aResultHandlerepresenting the result.default ResultHandlereadInstanceField(org.jboss.jandex.FieldInfo fieldDescriptor, ResultHandle instance) Reads an instance field and returns aResultHandlerepresenting the result.readStaticField(FieldDescriptor fieldDescriptor) Reads a static field and returns aResultHandlerepresenting the result.default ResultHandlereadStaticField(org.jboss.jandex.FieldInfo fieldDescriptor) Reads a static field and returns aResultHandlerepresenting the result.remainder(ResultHandle a1, ResultHandle a2) Computes the remainder after division of the first result handle by the second and returns the resultdefault voidreturnBoolean(boolean value) Creates a return statement that returns given boolean constant.default voidreturnInt(int value) Creates a return statement that returns given integer constant.default voidCreates a return statement that returns thenullreference.voidreturnValue(ResultHandle returnValue) Represents a return statement.default voidMarks a return from avoidmethod or a constructor.stringSwitch(ResultHandle value) Create a new switch construct for a string value.subtract(ResultHandle a1, ResultHandle a2) Subtracts the second result handle from the first result and returns the resultvoidthrowException(ResultHandle exception) Throws an exceptiondefault <T extends Throwable>
voidthrowException(Class<T> exceptionType, String message) Throws an exception.default <T extends Throwable>
voidthrowException(Class<T> exceptionType, String message, ResultHandle existing) Rethrows an exception.tryBlock()Add atryblock.whileLoop(Function<BytecodeCreator, BranchResult> conditionFun) Create a new while loop statement.default voidwriteArrayValue(ResultHandle array, int index, ResultHandle value) voidwriteArrayValue(ResultHandle array, ResultHandle index, ResultHandle value) voidwriteInstanceField(FieldDescriptor fieldDescriptor, ResultHandle instance, ResultHandle value) Writes the specified value to an instance fielddefault voidwriteInstanceField(org.jboss.jandex.FieldInfo fieldDescriptor, ResultHandle instance, ResultHandle value) Writes the specified value to an instance fieldvoidwriteStaticField(FieldDescriptor fieldDescriptor, ResultHandle value) Writes the specified value to an static fielddefault voidwriteStaticField(org.jboss.jandex.FieldInfo fieldDescriptor, ResultHandle value) Writes the specified value to an static field
-
Method Details
-
getThis
ResultHandle getThis()- Returns:
- A
ResultHandlethat represents the current object
-
invokeVirtualMethod
ResultHandle invokeVirtualMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args) Invokes a virtual method, and returns aResultHandlewith the result, or null if the method is void.- Parameters:
descriptor- The method descriptorobject- AResultHandlerepresenting the object to invoke onargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeVirtualMethod
default ResultHandle invokeVirtualMethod(org.jboss.jandex.MethodInfo descriptor, ResultHandle object, ResultHandle... args) Invokes a virtual method, and returns aResultHandlewith the result, or null if the method is void.- Parameters:
descriptor- The method descriptorobject- AResultHandlerepresenting the object to invoke onargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeInterfaceMethod
ResultHandle invokeInterfaceMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args) Invokes a interface method, and returns aResultHandlewith the result, or null if the method is void.- Parameters:
descriptor- The method descriptorobject- AResultHandlerepresenting the object to invoke onargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeInterfaceMethod
default ResultHandle invokeInterfaceMethod(org.jboss.jandex.MethodInfo descriptor, ResultHandle object, ResultHandle... args) Invokes a interface method, and returns aResultHandlewith the result, or null if the method is void.- Parameters:
descriptor- The method descriptorobject- AResultHandlerepresenting the object to invoke onargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeStaticMethod
Invokes a static method, and returns aResultHandlewith the result, or null if the method is void.- Parameters:
descriptor- The method descriptorargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeStaticMethod
default ResultHandle invokeStaticMethod(org.jboss.jandex.MethodInfo descriptor, ResultHandle... args) Invokes a static method, and returns aResultHandlewith the result, or null if the method is void.- Parameters:
descriptor- The method descriptorargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeStaticInterfaceMethod
Invokes a static method of an interface, and returns aResultHandlewith the result, or null if the method is void.- Parameters:
descriptor- The method descriptorargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeStaticInterfaceMethod
default ResultHandle invokeStaticInterfaceMethod(org.jboss.jandex.MethodInfo descriptor, ResultHandle... args) Invokes a static method of an interface, and returns aResultHandlewith the result, or null if the method is void.- Parameters:
descriptor- The method descriptorargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeSpecialMethod
ResultHandle invokeSpecialMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args) Invokes a special method, and returns aResultHandlewith the result, or null if the method is void.Special methods are constructor invocations, or invocations on a superclass method of the current class.
- Parameters:
descriptor- The method descriptorobject- AResultHandlerepresenting the object to invoke onargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeSpecialMethod
default ResultHandle invokeSpecialMethod(org.jboss.jandex.MethodInfo descriptor, ResultHandle object, ResultHandle... args) Invokes a special method, and returns aResultHandlewith the result, or null if the method is void.Special methods are constructor invocations, or invocations on a superclass method of the current class.
- Parameters:
descriptor- The method descriptorobject- AResultHandlerepresenting the object to invoke onargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeSpecialInterfaceMethod
ResultHandle invokeSpecialInterfaceMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args) Invokes a special interface method, and returns aResultHandlewith the result, or null if the method is void.Special interface method invocations are invocations of a superinterface method of the current class.
- Parameters:
descriptor- The method descriptorobject- AResultHandlerepresenting the object to invoke onargs- The method parameters- Returns:
- The method result, or null if a void method
-
invokeSpecialInterfaceMethod
default ResultHandle invokeSpecialInterfaceMethod(org.jboss.jandex.MethodInfo descriptor, ResultHandle object, ResultHandle... args) Invokes a special interface method, and returns aResultHandlewith the result, or null if the method is void.Special interface method invocations are invocations of a superinterface method of the current class.
- Parameters:
descriptor- The method descriptorobject- AResultHandlerepresenting the object to invoke onargs- The method parameters- Returns:
- The method result, or null if a void method
-
newInstance
Creates a new instance of a given type, by calling the specified constructor, and returns aResultHandlerepresenting the result- Parameters:
descriptor- The constructor descriptorargs- The constructor parameters- Returns:
- The new instance
-
newInstance
Creates a new instance of a given type, by calling the specified constructor, and returns aResultHandlerepresenting the result- Parameters:
descriptor- The constructor descriptorargs- The constructor parameters- Returns:
- The new instance
-
newArray
-
newArray
-
newArray
-
newArray
-
load
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
loadClass
Returns aResultHandlerepresenting the specified class Note that in almost all circumstances you are better off usingloadClassFromTCCL(String), as it can load classes that are not visible from the current class. This method should only be used if you are sure that the class being loaded will be accessible from the generated bytecode.- Parameters:
className- The class name- Returns:
- A
ResultHandlerepresenting the specified class
-
loadClass
Returns aResultHandlerepresenting the specified class Note that in almost all circumstances you are better off usingloadClassFromTCCL(Class), as it can load classes that are not visible from the current class. This method should only be used if you are sure that the class being loaded will be accessible from the generated bytecode.- Parameters:
val- The class to load- Returns:
- A
ResultHandlerepresenting the specified class
-
loadClass
Returns aResultHandlerepresenting the specified class Note that in almost all circumstances you are better off usingloadClassFromTCCL(ClassInfo), as it can load classes that are not visible from the current class. This method should only be used if you are sure that the class being loaded will be accessible from the generated bytecode.- Parameters:
val- The class to load- Returns:
- A
ResultHandlerepresenting the specified class
-
loadClassFromTCCL
Returns aResultHandlerepresenting the specified class This method can load all classes, including package private classes that are not visible to the current bytecode.- Parameters:
className- The class name- Returns:
- A
ResultHandlerepresenting the specified class
-
loadClassFromTCCL
Returns aResultHandlerepresenting the specified class loaded from the TCCL. This method can load all classes, including package private classes that are not visible to the current bytecode.- Parameters:
val- The class to load- Returns:
- A
ResultHandlerepresenting the specified class
-
loadClassFromTCCL
Returns aResultHandlerepresenting the specified class This method can load all classes, including package private classes that are not visible to the current bytecode.- Parameters:
val- The class to load- Returns:
- A
ResultHandlerepresenting the specified class
-
loadNull
ResultHandle loadNull()Returns aResultHandlerepresentingnull}- Returns:
- A
ResultHandlerepresentingnull}
-
writeInstanceField
Writes the specified value to an instance field- Parameters:
fieldDescriptor- The field to write toinstance- AResultHandlerepresenting the instance that contains the fieldvalue- AResultHandlerepresenting the value
-
writeInstanceField
default void writeInstanceField(org.jboss.jandex.FieldInfo fieldDescriptor, ResultHandle instance, ResultHandle value) Writes the specified value to an instance field- Parameters:
fieldDescriptor- The field to write toinstance- AResultHandlerepresenting the instance that contains the fieldvalue- AResultHandlerepresenting the value
-
readInstanceField
Reads an instance field and returns aResultHandlerepresenting the result. The result of the read is stored in a local variable, so even if the field value changes theResultHandlewill represent the same result.- Parameters:
fieldDescriptor- The field to read frominstance- AResultHandlerepresenting the instance that contains the field- Returns:
- A
ResultHandlerepresenting the field value at the current point in time
-
readInstanceField
default ResultHandle readInstanceField(org.jboss.jandex.FieldInfo fieldDescriptor, ResultHandle instance) Reads an instance field and returns aResultHandlerepresenting the result. The result of the read is stored in a local variable, so even if the field value changes theResultHandlewill represent the same result.- Parameters:
fieldDescriptor- The field to read frominstance- AResultHandlerepresenting the instance that contains the field- Returns:
- A
ResultHandlerepresenting the field value at the current point in time
-
writeStaticField
Writes the specified value to an static field- Parameters:
fieldDescriptor- The field to write tovalue- AResultHandlerepresenting the value
-
writeStaticField
Writes the specified value to an static field- Parameters:
fieldDescriptor- The field to write tovalue- AResultHandlerepresenting the value
-
readStaticField
Reads a static field and returns aResultHandlerepresenting the result. The result of the read is stored in a local variable, so even if the field value changes theResultHandlewill represent the same result.- Parameters:
fieldDescriptor- The field to read from- Returns:
- A
ResultHandlerepresenting the field value at the current point in time
-
readStaticField
Reads a static field and returns aResultHandlerepresenting the result. The result of the read is stored in a local variable, so even if the field value changes theResultHandlewill represent the same result.- Parameters:
fieldDescriptor- The field to read from- Returns:
- A
ResultHandlerepresenting the field value at the current point in time
-
arrayLength
-
readArrayValue
-
writeArrayValue
-
readArrayValue
-
writeArrayValue
-
createVariable
Create a local variable which can be assigned within this scope.- Parameters:
typeDescr- the type descriptor of the variable's type (must not benull)- Returns:
- the assignable local variable (not
null)
-
createVariable
Create a local variable which can be assigned within this scope.- Parameters:
type- the type of the variable's type (must not benull)- Returns:
- the assignable local variable (not
null)
-
assign
Assign the given value to the given assignable target.- Parameters:
target- the assignment target (must not benull)value- the value to assign (must not benull)
-
tryBlock
TryBlock tryBlock()Add atryblock.- Returns:
- the
tryblock
-
compareLong
Compares twolongvalues and pushes the resulting integer to the stack. Ifvalue1is greater thanvalue2, the result is 1; ifvalue1is equal tovalue2, the result is 0; ifvalue1is less thanvalue2, the result is -1. One of theif*methods should be used to process the result. Both parameters must be of typelong.- Parameters:
value1- firstlongvalue to comparevalue2- secondlongvalue to compare- Returns:
- the comparison result
-
compareFloat
Compares twofloatvalues and pushes the resulting integer to the stack. Ifvalue1is greater thanvalue2, the result is 1; ifvalue1is equal tovalue2, the result is 0; ifvalue1is less thanvalue2, the result is -1. One of theif*methods should be used to process the result. Both parameters must be of typefloat.If one of the values is NaN, the result is 1 if
nanComparesAsGreateris true and -1 if not.- Parameters:
value1- firstlongvalue to comparevalue2- secondlongvalue to comparenanComparesAsGreater- whether presence of NaN should result in "greater"- Returns:
- the comparison result
-
compareDouble
Compares twodoublevalues and pushes the resulting integer to the stack. Ifvalue1is greater thanvalue2, the result is 1; ifvalue1is equal tovalue2, the result is 0; ifvalue1is less thanvalue2, the result is -1. One of theif*methods should be used to process the result. Both parameters must be of typedouble.If one of the values is NaN, the result is 1 if
nanComparesAsGreateris true and -1 if not.- Parameters:
value1- firstlongvalue to comparevalue2- secondlongvalue to comparenanComparesAsGreater- whether presence of NaN should result in "greater"- Returns:
- the comparison result
-
ifNonZero
An if statement.resultHandle must be an integer type or boolean. If this value is true or non-zero the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
resultHandle- The result to compare with zero- Returns:
- The branch result that is used to build the if statement
-
ifZero
An if statement.resultHandle must be an integer type or boolean. If this value is false or zero the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
resultHandle- The result to compare with zero- Returns:
- The branch result that is used to build the if statement
-
ifTrue
An if statement. An alias forifNonZero(ResultHandle).- Parameters:
resultHandle- The result to compare with zero- Returns:
- The branch result that is used to build the if statement
-
ifFalse
An if statement. An alias forifZero(ResultHandle).- Parameters:
resultHandle- The result to compare with zero- Returns:
- The branch result that is used to build the if statement
-
ifNull
An if statement. If the value isnulltheBranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
resultHandle-- Returns:
- The branch result that is used to build the if statement
-
ifNotNull
An if statement. If the value is notnulltheBranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
resultHandle-- Returns:
- The branch result that is used to build the if statement
-
ifGreaterThanZero
An if statement.resultHandle must be an integer type. If this value is greater than zero the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
resultHandle-- Returns:
- The branch result that is used to build the if statement
-
ifGreaterEqualZero
An if statement.resultHandle must be an integer type. If this value is greater or equals to zero the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
resultHandle-- Returns:
- The branch result that is used to build the if statement
-
ifLessThanZero
An if statement.resultHandle must be an integer type. If this value is lower than zero the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
resultHandle-- Returns:
- The branch result that is used to build the if statement
-
ifLessEqualZero
An if statement.resultHandle must be an integer type. If this value is lower or equals to zero the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
resultHandle-- Returns:
- The branch result that is used to build the if statement
-
ifIntegerEqual
An if statement.Values must be integer types. If value1 is equal to value2 the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
value1-value2-- Returns:
- The branch result that is used to build the if statement
-
ifIntegerGreaterThan
An if statement.Values must be integer types. If value1 is greater than value2 the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
value1-value2-- Returns:
- The branch result that is used to build the if statement
-
ifIntegerGreaterEqual
An if statement.Values must be integer types. If value1 is greater or equal to value2 the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
value1-value2-- Returns:
- The branch result that is used to build the if statement
-
ifIntegerLessThan
An if statement.Values must be integer types. If value1 is less than value2 the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
value1-value2-- Returns:
- The branch result that is used to build the if statement
-
ifThenElse
Create a new if-then-else construct.The
IfThenElse.then()block is executed if the condition result handle evaluates totrue.- Parameters:
condition-- Returns:
- the if-then-else construct
-
instanceOf
Checks if the given resultHandle is an instance of the target type- Parameters:
resultHandle- the result handletestType- the cast target class- Returns:
- a boolean result handle with the result of the instanceof call
-
instanceOf
Checks if the given resultHandle is an instance of the target type- Parameters:
resultHandle- the result handletestType- the cast target class- Returns:
- a boolean result handle with the result of the instanceof call
-
ifIntegerLessEqual
An if statement.Values must be integer types. If value1 is less or equal to value2 the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
value1-value2-- Returns:
- The branch result that is used to build the if statement
-
ifReferencesEqual
An if statement.If references are equal (object identity) the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.- Parameters:
ref1-ref2-- Returns:
- The branch result that is used to build the if statement
-
ifReferencesNotEqual
An if statement.If references are not equal (as in object identity) the
BranchResult.trueBranch()code will be executed, otherwise theBranchResult.falseBranch()will be run.This method is dual to
ifReferencesEqual(ResultHandle, ResultHandle)and can be used to emit bytecode that is closer to what javac emits, when useful.- Parameters:
ref1-ref2-- Returns:
- The branch result that is used to build the if statement
-
getMethodParam
- Parameters:
i- The method parameter number, zero indexed- Returns:
- A
ResultHandlerepresenting the parameter
-
createFunction
Creates an instance of a functional interfaceThe resulting
FunctionCreatorcan be used to both define the functions bytecode, and to get aResultHandlethat represents the instance of the function.- Parameters:
functionalInterface- A functional interface- Returns:
- The function builder
-
returnValue
Represents a return statement. If this is a void method the return value must be null, otherwise it must be aResultHandleof the correct type which will be returned from the method.- Parameters:
returnValue- The value to return
-
returnVoid
default void returnVoid()Marks a return from avoidmethod or a constructor.Equivalent to
returnValue(null).- See Also:
-
returnNull
default void returnNull()Creates a return statement that returns thenullreference.Equivalent to
returnValue(loadNull()).- See Also:
-
returnBoolean
default void returnBoolean(boolean value) Creates a return statement that returns given boolean constant.Equivalent to
returnValue(load(value)).- Parameters:
value- the boolean constant- See Also:
-
returnInt
default void returnInt(int value) Creates a return statement that returns given integer constant.Equivalent to
returnValue(load(value)).- Parameters:
value- the integer constant- See Also:
-
throwException
Throws an exception- Parameters:
exception- A result handle representing the exception to throw
-
checkCast
Perform a check cast operation which transforms the type of the given result handle.- Parameters:
resultHandle- the result handlecastTarget- the cast target type descriptor- Returns:
- a new result handle with updated type
-
checkCast
Perform a check cast operation which transforms the type of the given result handle.- Parameters:
resultHandle- the result handlecastTarget- the cast target class- Returns:
- a new result handle with updated type
-
convertPrimitive
Converts givenvalue, which must be of a primitive type, to the givenconversionTarget, which must be a primitive type, using primitive conversions defined by the Java language specification.Returns
valuedirectly when its static type is the same asconversionTarget.Throws an exception if any of the arguments is
null. Throws an exception when the static type ofvalueis not a primitive type or whenconversionTargetis not a primitive type. Throws an exception if no primitive conversion exists from the type ofvalueto theconversionTarget. (Note that "throws an exception" in this paragraph does not mean that a bytecode sequence for throwing an exception is emitted; instead, the methodconvertPrimitivethrows an exception directly and eagerly.)- Parameters:
value- the value to be convertedconversionTarget- the primitive type to which thevalueshould be converted- Returns:
- the converted value
-
throwException
Throws an exception. The exception must have a constructor that takes a single String argument- Parameters:
exceptionType- The exception typemessage- The exception message
-
throwException
default <T extends Throwable> void throwException(Class<T> exceptionType, String message, ResultHandle existing) Rethrows an exception. The exception must have a constructor that takes (String, Throwable)- Parameters:
exceptionType- The exception typemessage- The exception messageexisting- The exception to wrap
-
marshalAsArray
-
isScopedWithin
Determine if this bytecode creator is scoped within the given bytecode creator.- Parameters:
other- the other bytecode creator- Returns:
trueif this bytecode creator is scoped within the given creator,falseotherwise
-
continueScope
Go to the top of the given scope.- Parameters:
scope- the scope to continue
-
continueScope
default void continueScope()Go to the top of this scope. -
breakScope
Go to the end of the given scope.- Parameters:
scope- the scope to break out of
-
breakScope
default void breakScope()Go to the end of this scope. -
createScope
BytecodeCreator createScope()Create a nested scope. Bytecode added to the nested scope will be inserted at this point of the enclosing scope.- Returns:
- the nested scope
-
whileLoop
Create a new while loop statement.- Parameters:
conditionFun- A function used to create the condition. The true branch continues executing the block and the false branch terminates the statement.- Returns:
- the while loop statement
-
forEach
Create a new for-each loop construct.- Parameters:
iterable-- Returns:
- the for-each construct
-
add
Adds the two result handles together and returns the result- Parameters:
a1- The first number, aka the augenda2- The second number, aka the addend- Returns:
- The result
-
subtract
Subtracts the second result handle from the first result and returns the result- Parameters:
a1- The first number, aka the minuenda2- The second number, aka the subtrahend- Returns:
- The result
-
multiply
Multiplies the two result handles together and returns the result- Parameters:
a1- The first number, aka the multipliera2- The second number, aka the multiplicand- Returns:
- The result
-
divide
Divides the first result handle by the second and returns the result- Parameters:
a1- The first number, aka the numeratora2- The second number, aka the denominator- Returns:
- The result
-
remainder
Computes the remainder after division of the first result handle by the second and returns the result- Parameters:
a1- The first number, aka the numeratora2- The second number, aka the denominator- Returns:
- The result
-
bitwiseAnd
Computes the bitwise AND of the two result handles and returns the result- Parameters:
a1- The first numbera2- The second number- Returns:
- The result
-
bitwiseOr
Computes the bitwise OR of the two result handles and returns the result- Parameters:
a1- The first numbera2- The second number- Returns:
- The result
-
bitwiseXor
Computes the bitwise XOR of the two result handles and returns the result- Parameters:
a1- The first numbera2- The second number- Returns:
- The result
-
increment
Increments a ResultHandle- Parameters:
toIncrement- The number to increment- Returns:
- The result
-
stringSwitch
Create a new switch construct for a string value.- Parameters:
value- The string value to switch on- Returns:
- the switch construct
-
enumSwitch
Create a new switch construct for an enum constant.- Type Parameters:
E-- Parameters:
value- The enum constant to switch onenumClass-- Returns:
- the switch construct
-
close
default void close()Indicate that the scope is no longer in use. The scope may refuse additional instructions after this method is called.- Specified by:
closein interfaceAutoCloseable
-