Interface BytecodeCreator
-
- All Superinterfaces:
java.lang.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
public interface BytecodeCreator extends java.lang.AutoCloseableAn interface for creating a methods bytecode.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
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description ResultHandleadd(ResultHandle a1, ResultHandle a2)Adds the two result handles together and returns the resultResultHandlearrayLength(ResultHandle array)voidassign(AssignableResultHandle target, ResultHandle value)Assign the given value to the given assignable target.ResultHandlebitwiseAnd(ResultHandle a1, ResultHandle a2)Computes the bitwise AND of the two result handles and returns the resultResultHandlebitwiseOr(ResultHandle a1, ResultHandle a2)Computes the bitwise OR of the two result handles and returns the resultResultHandlebitwiseXor(ResultHandle a1, ResultHandle a2)Computes the bitwise XOR of the two result handles and returns the resultdefault voidbreakScope()Go to the end of this scope.voidbreakScope(BytecodeCreator scope)Go to the end of the given scope.default ResultHandlecheckCast(ResultHandle resultHandle, java.lang.Class<?> castTarget)Perform a check cast operation which transforms the type of the given result handle.ResultHandlecheckCast(ResultHandle resultHandle, java.lang.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.ResultHandlecompareDouble(ResultHandle value1, ResultHandle value2, boolean nanComparesAsGreater)Compares twodoublevalues and pushes the resulting integer to the stack.ResultHandlecompareFloat(ResultHandle value1, ResultHandle value2, boolean nanComparesAsGreater)Compares twofloatvalues and pushes the resulting integer to the stack.ResultHandlecompareLong(ResultHandle value1, ResultHandle value2)Compares twolongvalues and pushes the resulting integer to the stack.default voidcontinueScope()Go to the top of this scope.voidcontinueScope(BytecodeCreator scope)Go to the top of the given scope.ResultHandleconvertPrimitive(ResultHandle value, java.lang.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.FunctionCreatorcreateFunction(java.lang.Class<?> functionalInterface)Creates an instance of a functional interfaceBytecodeCreatorcreateScope()Create a nested scope.default AssignableResultHandlecreateVariable(java.lang.Class<?> type)Create a local variable which can be assigned within this scope.AssignableResultHandlecreateVariable(java.lang.String typeDescr)Create a local variable which can be assigned within this scope.ResultHandledivide(ResultHandle a1, ResultHandle a2)Divides the first result handle by the second and returns the result<E extends java.lang.Enum<E>>
Switch.EnumSwitch<E>enumSwitch(ResultHandle value, java.lang.Class<E> enumClass)Create a new switch construct for an enum constant.ForEachLoopforEach(ResultHandle iterable)Create a new for-each loop construct.ResultHandlegetMethodParam(int i)ResultHandlegetThis()BranchResultifFalse(ResultHandle resultHandle)An if statement.BranchResultifGreaterEqualZero(ResultHandle resultHandle)An if statement.BranchResultifGreaterThanZero(ResultHandle resultHandle)An if statement.BranchResultifIntegerEqual(ResultHandle value1, ResultHandle value2)An if statement.BranchResultifIntegerGreaterEqual(ResultHandle value1, ResultHandle value2)An if statement.BranchResultifIntegerGreaterThan(ResultHandle value1, ResultHandle value2)An if statement.BranchResultifIntegerLessEqual(ResultHandle value1, ResultHandle value2)An if statement.BranchResultifIntegerLessThan(ResultHandle value1, ResultHandle value2)An if statement.BranchResultifLessEqualZero(ResultHandle resultHandle)An if statement.BranchResultifLessThanZero(ResultHandle resultHandle)An if statement.BranchResultifNonZero(ResultHandle resultHandle)An if statement.BranchResultifNotNull(ResultHandle resultHandle)An if statement.BranchResultifNull(ResultHandle resultHandle)An if statement.BranchResultifReferencesEqual(ResultHandle ref1, ResultHandle ref2)An if statement.BranchResultifReferencesNotEqual(ResultHandle ref1, ResultHandle ref2)An if statement.IfThenElseifThenElse(ResultHandle condition)Create a new if-then-else construct.BranchResultifTrue(ResultHandle resultHandle)An if statement.BranchResultifZero(ResultHandle resultHandle)An if statement.default ResultHandleincrement(ResultHandle toIncrement)Increments a ResultHandledefault ResultHandleinstanceOf(ResultHandle resultHandle, java.lang.Class<?> testType)Checks if the given resultHandle is an instance of the target typeResultHandleinstanceOf(ResultHandle resultHandle, java.lang.String testType)Checks if the given resultHandle is an instance of the target typeResultHandleinvokeInterfaceMethod(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.ResultHandleinvokeSpecialInterfaceMethod(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.ResultHandleinvokeSpecialMethod(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.ResultHandleinvokeStaticInterfaceMethod(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.ResultHandleinvokeStaticMethod(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.ResultHandleinvokeVirtualMethod(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.ResultHandleload(boolean val)Returns aResultHandlerepresenting the specified valueResultHandleload(byte val)Returns aResultHandlerepresenting the specified valueResultHandleload(char val)Returns aResultHandlerepresenting the specified valueResultHandleload(double val)Returns aResultHandlerepresenting the specified valueResultHandleload(float val)Returns aResultHandlerepresenting the specified valueResultHandleload(int val)Returns aResultHandlerepresenting the specified valueResultHandleload(long val)Returns aResultHandlerepresenting the specified valueResultHandleload(short val)Returns aResultHandlerepresenting the specified valuedefault ResultHandleload(java.lang.Enum<?> val)Returns aResultHandlerepresenting the specified valueResultHandleload(java.lang.String val)Returns aResultHandlerepresenting the specified valuedefault ResultHandleloadClass(java.lang.Class<?> val)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.ResultHandleloadClass(java.lang.String className)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(java.lang.Class<?> val)Returns aResultHandlerepresenting the specified class loaded from the TCCL.ResultHandleloadClassFromTCCL(java.lang.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.ResultHandleloadNull()Returns aResultHandlerepresentingnull}default ResultHandlemarshalAsArray(java.lang.Class<?> arrayClass, ResultHandle... params)ResultHandlemultiply(ResultHandle a1, ResultHandle a2)Multiplies the two result handles together and returns the resultdefault ResultHandlenewArray(java.lang.Class<?> type, int length)default ResultHandlenewArray(java.lang.Class<?> type, ResultHandle length)default ResultHandlenewArray(java.lang.String type, int length)ResultHandlenewArray(java.lang.String type, ResultHandle length)ResultHandlenewInstance(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)ResultHandlereadArrayValue(ResultHandle array, ResultHandle index)ResultHandlereadInstanceField(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.ResultHandlereadStaticField(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.ResultHandleremainder(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 voidreturnNull()Creates a return statement that returns thenullreference.voidreturnValue(ResultHandle returnValue)Represents a return statement.default voidreturnVoid()Marks a return from avoidmethod or a constructor.Switch.StringSwitchstringSwitch(ResultHandle value)Create a new switch construct for a string value.ResultHandlesubtract(ResultHandle a1, ResultHandle a2)Subtracts the second result handle from the first result and returns the resultvoidthrowException(ResultHandle exception)Throws an exceptiondefault <T extends java.lang.Throwable>
voidthrowException(java.lang.Class<T> exceptionType, java.lang.String message)Throws an exception.default <T extends java.lang.Throwable>
voidthrowException(java.lang.Class<T> exceptionType, java.lang.String message, ResultHandle existing)Rethrows an exception.TryBlocktryBlock()Add atryblock.WhileLoopwhileLoop(java.util.function.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 Detail
-
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
ResultHandle invokeStaticMethod(MethodDescriptor 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
-
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
ResultHandle invokeStaticInterfaceMethod(MethodDescriptor 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
-
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
ResultHandle newInstance(MethodDescriptor descriptor, ResultHandle... args)
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
default ResultHandle newInstance(org.jboss.jandex.MethodInfo descriptor, ResultHandle... args)
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
ResultHandle newArray(java.lang.String type, ResultHandle length)
-
newArray
default ResultHandle newArray(java.lang.String type, int length)
-
newArray
default ResultHandle newArray(java.lang.Class<?> type, ResultHandle length)
-
newArray
default ResultHandle newArray(java.lang.Class<?> type, int length)
-
load
ResultHandle load(java.lang.String val)
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
ResultHandle load(byte val)
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
ResultHandle load(short val)
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
ResultHandle load(char val)
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
ResultHandle load(int val)
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
ResultHandle load(long val)
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
ResultHandle load(float val)
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
ResultHandle load(double val)
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
ResultHandle load(boolean val)
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
load
default ResultHandle load(java.lang.Enum<?> val)
Returns aResultHandlerepresenting the specified value- Parameters:
val- The value- Returns:
- A
ResultHandlerepresenting the specified value
-
loadClass
ResultHandle loadClass(java.lang.String className)
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
default ResultHandle loadClass(java.lang.Class<?> val)
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
default ResultHandle loadClass(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. 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
ResultHandle loadClassFromTCCL(java.lang.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.- Parameters:
className- The class name- Returns:
- A
ResultHandlerepresenting the specified class
-
loadClassFromTCCL
default ResultHandle loadClassFromTCCL(java.lang.Class<?> val)
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
default ResultHandle loadClassFromTCCL(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.- Parameters:
val- The class to load- Returns:
- A
ResultHandlerepresenting the specified class
-
loadNull
ResultHandle loadNull()
Returns aResultHandlerepresentingnull}- Returns:
- A
ResultHandlerepresentingnull}
-
writeInstanceField
void writeInstanceField(FieldDescriptor 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
-
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
ResultHandle readInstanceField(FieldDescriptor 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
-
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
void writeStaticField(FieldDescriptor fieldDescriptor, ResultHandle value)
Writes the specified value to an static field- Parameters:
fieldDescriptor- The field to write tovalue- AResultHandlerepresenting the value
-
writeStaticField
default void writeStaticField(org.jboss.jandex.FieldInfo fieldDescriptor, ResultHandle value)Writes the specified value to an static field- Parameters:
fieldDescriptor- The field to write tovalue- AResultHandlerepresenting the value
-
readStaticField
ResultHandle readStaticField(FieldDescriptor fieldDescriptor)
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
default ResultHandle readStaticField(org.jboss.jandex.FieldInfo fieldDescriptor)
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
ResultHandle arrayLength(ResultHandle array)
-
readArrayValue
ResultHandle readArrayValue(ResultHandle array, ResultHandle index)
-
writeArrayValue
void writeArrayValue(ResultHandle array, ResultHandle index, ResultHandle value)
-
readArrayValue
default ResultHandle readArrayValue(ResultHandle array, int index)
-
writeArrayValue
default void writeArrayValue(ResultHandle array, int index, ResultHandle value)
-
createVariable
AssignableResultHandle createVariable(java.lang.String typeDescr)
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
default AssignableResultHandle createVariable(java.lang.Class<?> type)
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
void assign(AssignableResultHandle target, ResultHandle value)
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
ResultHandle compareLong(ResultHandle value1, ResultHandle value2)
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
ResultHandle compareFloat(ResultHandle value1, ResultHandle value2, boolean nanComparesAsGreater)
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
ResultHandle compareDouble(ResultHandle value1, ResultHandle value2, boolean nanComparesAsGreater)
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
BranchResult ifNonZero(ResultHandle resultHandle)
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
BranchResult ifZero(ResultHandle resultHandle)
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
BranchResult ifTrue(ResultHandle resultHandle)
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
BranchResult ifFalse(ResultHandle resultHandle)
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
BranchResult ifNull(ResultHandle resultHandle)
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
BranchResult ifNotNull(ResultHandle resultHandle)
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
BranchResult ifGreaterThanZero(ResultHandle resultHandle)
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
BranchResult ifGreaterEqualZero(ResultHandle resultHandle)
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
BranchResult ifLessThanZero(ResultHandle resultHandle)
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
BranchResult ifLessEqualZero(ResultHandle resultHandle)
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
BranchResult ifIntegerEqual(ResultHandle value1, ResultHandle value2)
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
BranchResult ifIntegerGreaterThan(ResultHandle value1, ResultHandle value2)
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
BranchResult ifIntegerGreaterEqual(ResultHandle value1, ResultHandle value2)
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
BranchResult ifIntegerLessThan(ResultHandle value1, ResultHandle value2)
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
IfThenElse ifThenElse(ResultHandle condition)
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
default ResultHandle instanceOf(ResultHandle resultHandle, java.lang.Class<?> testType)
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
ResultHandle instanceOf(ResultHandle resultHandle, java.lang.String testType)
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
BranchResult ifIntegerLessEqual(ResultHandle value1, ResultHandle value2)
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
BranchResult ifReferencesEqual(ResultHandle ref1, ResultHandle ref2)
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
BranchResult ifReferencesNotEqual(ResultHandle ref1, ResultHandle ref2)
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
ResultHandle getMethodParam(int i)
- Parameters:
i- The method parameter number, zero indexed- Returns:
- A
ResultHandlerepresenting the parameter
-
createFunction
FunctionCreator createFunction(java.lang.Class<?> functionalInterface)
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
void returnValue(ResultHandle 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:
returnValue(ResultHandle)
-
returnNull
default void returnNull()
Creates a return statement that returns thenullreference.Equivalent to
returnValue(loadNull()).- See Also:
returnValue(ResultHandle)
-
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:
returnValue(ResultHandle)
-
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:
returnValue(ResultHandle)
-
throwException
void throwException(ResultHandle exception)
Throws an exception- Parameters:
exception- A result handle representing the exception to throw
-
checkCast
ResultHandle checkCast(ResultHandle resultHandle, java.lang.String castTarget)
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
default ResultHandle checkCast(ResultHandle resultHandle, java.lang.Class<?> castTarget)
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
ResultHandle convertPrimitive(ResultHandle value, java.lang.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.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
default <T extends java.lang.Throwable> void throwException(java.lang.Class<T> exceptionType, java.lang.String message)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 java.lang.Throwable> void throwException(java.lang.Class<T> exceptionType, java.lang.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
default ResultHandle marshalAsArray(java.lang.Class<?> arrayClass, ResultHandle... params)
-
isScopedWithin
boolean isScopedWithin(BytecodeCreator other)
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
void continueScope(BytecodeCreator scope)
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
void breakScope(BytecodeCreator scope)
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
WhileLoop whileLoop(java.util.function.Function<BytecodeCreator,BranchResult> conditionFun)
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
ForEachLoop forEach(ResultHandle iterable)
Create a new for-each loop construct.- Parameters:
iterable-- Returns:
- the for-each construct
-
add
ResultHandle add(ResultHandle a1, ResultHandle a2)
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
ResultHandle subtract(ResultHandle a1, ResultHandle a2)
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
ResultHandle multiply(ResultHandle a1, ResultHandle a2)
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
ResultHandle divide(ResultHandle a1, ResultHandle a2)
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
ResultHandle remainder(ResultHandle a1, ResultHandle a2)
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
ResultHandle bitwiseAnd(ResultHandle a1, ResultHandle a2)
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
ResultHandle bitwiseOr(ResultHandle a1, ResultHandle a2)
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
ResultHandle bitwiseXor(ResultHandle a1, ResultHandle a2)
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
default ResultHandle increment(ResultHandle toIncrement)
Increments a ResultHandle- Parameters:
toIncrement- The number to increment- Returns:
- The result
-
stringSwitch
Switch.StringSwitch stringSwitch(ResultHandle value)
Create a new switch construct for a string value.- Parameters:
value- The string value to switch on- Returns:
- the switch construct
-
enumSwitch
<E extends java.lang.Enum<E>> Switch.EnumSwitch<E> enumSwitch(ResultHandle value, java.lang.Class<E> enumClass)
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 interfacejava.lang.AutoCloseable
-
-