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

public interface BytecodeCreator extends AutoCloseable
An 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 Details

    • getThis

      ResultHandle getThis()
      Returns:
      A ResultHandle that represents the current object
    • invokeVirtualMethod

      ResultHandle invokeVirtualMethod(MethodDescriptor descriptor, ResultHandle object, ResultHandle... args)
      Invokes a virtual method, and returns a ResultHandle with the result, or null if the method is void.
      Parameters:
      descriptor - The method descriptor
      object - A ResultHandle representing the object to invoke on
      args - 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 a ResultHandle with the result, or null if the method is void.
      Parameters:
      descriptor - The method descriptor
      object - A ResultHandle representing the object to invoke on
      args - 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 a ResultHandle with the result, or null if the method is void.
      Parameters:
      descriptor - The method descriptor
      object - A ResultHandle representing the object to invoke on
      args - 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 a ResultHandle with the result, or null if the method is void.
      Parameters:
      descriptor - The method descriptor
      object - A ResultHandle representing the object to invoke on
      args - 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 a ResultHandle with the result, or null if the method is void.
      Parameters:
      descriptor - The method descriptor
      args - 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 a ResultHandle with the result, or null if the method is void.
      Parameters:
      descriptor - The method descriptor
      args - 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 a ResultHandle with the result, or null if the method is void.
      Parameters:
      descriptor - The method descriptor
      args - 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 a ResultHandle with the result, or null if the method is void.
      Parameters:
      descriptor - The method descriptor
      args - 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 a ResultHandle with 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 descriptor
      object - A ResultHandle representing the object to invoke on
      args - 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 a ResultHandle with 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 descriptor
      object - A ResultHandle representing the object to invoke on
      args - 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 a ResultHandle with 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 descriptor
      object - A ResultHandle representing the object to invoke on
      args - 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 a ResultHandle with 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 descriptor
      object - A ResultHandle representing the object to invoke on
      args - 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 a ResultHandle representing the result
      Parameters:
      descriptor - The constructor descriptor
      args - 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 a ResultHandle representing the result
      Parameters:
      descriptor - The constructor descriptor
      args - The constructor parameters
      Returns:
      The new instance
    • newArray

      ResultHandle newArray(String type, ResultHandle length)
    • newArray

      default ResultHandle newArray(String type, int length)
    • newArray

      default ResultHandle newArray(Class<?> type, ResultHandle length)
    • newArray

      default ResultHandle newArray(Class<?> type, int length)
    • load

      ResultHandle load(String val)
      Returns a ResultHandle representing the specified value
      Parameters:
      val - The value
      Returns:
      A ResultHandle representing the specified value
    • load

      ResultHandle load(byte val)
      Returns a ResultHandle representing the specified value
      Parameters:
      val - The value
      Returns:
      A ResultHandle representing the specified value
    • load

      ResultHandle load(short val)
      Returns a ResultHandle representing the specified value
      Parameters:
      val - The value
      Returns:
      A ResultHandle representing the specified value
    • load

      ResultHandle load(char val)
      Returns a ResultHandle representing the specified value
      Parameters:
      val - The value
      Returns:
      A ResultHandle representing the specified value
    • load

      ResultHandle load(int val)
      Returns a ResultHandle representing the specified value
      Parameters:
      val - The value
      Returns:
      A ResultHandle representing the specified value
    • load

      ResultHandle load(long val)
      Returns a ResultHandle representing the specified value
      Parameters:
      val - The value
      Returns:
      A ResultHandle representing the specified value
    • load

      ResultHandle load(float val)
      Returns a ResultHandle representing the specified value
      Parameters:
      val - The value
      Returns:
      A ResultHandle representing the specified value
    • load

      ResultHandle load(double val)
      Returns a ResultHandle representing the specified value
      Parameters:
      val - The value
      Returns:
      A ResultHandle representing the specified value
    • load

      ResultHandle load(boolean val)
      Returns a ResultHandle representing the specified value
      Parameters:
      val - The value
      Returns:
      A ResultHandle representing the specified value
    • load

      default ResultHandle load(Enum<?> val)
      Returns a ResultHandle representing the specified value
      Parameters:
      val - The value
      Returns:
      A ResultHandle representing the specified value
    • loadClass

      ResultHandle loadClass(String className)
      Returns a ResultHandle representing the specified class Note that in almost all circumstances you are better off using loadClassFromTCCL(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 ResultHandle representing the specified class
    • loadClass

      default ResultHandle loadClass(Class<?> val)
      Returns a ResultHandle representing the specified class Note that in almost all circumstances you are better off using loadClassFromTCCL(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 ResultHandle representing the specified class
    • loadClass

      default ResultHandle loadClass(org.jboss.jandex.ClassInfo val)
      Returns a ResultHandle representing the specified class Note that in almost all circumstances you are better off using loadClassFromTCCL(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 ResultHandle representing the specified class
    • loadClassFromTCCL

      ResultHandle loadClassFromTCCL(String className)
      Returns a ResultHandle representing 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 ResultHandle representing the specified class
    • loadClassFromTCCL

      default ResultHandle loadClassFromTCCL(Class<?> val)
      Returns a ResultHandle representing 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 ResultHandle representing the specified class
    • loadClassFromTCCL

      default ResultHandle loadClassFromTCCL(org.jboss.jandex.ClassInfo val)
      Returns a ResultHandle representing 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 ResultHandle representing the specified class
    • loadNull

      ResultHandle loadNull()
      Returns a ResultHandle representing null}
      Returns:
      A ResultHandle representing null}
    • writeInstanceField

      void writeInstanceField(FieldDescriptor fieldDescriptor, ResultHandle instance, ResultHandle value)
      Writes the specified value to an instance field
      Parameters:
      fieldDescriptor - The field to write to
      instance - A ResultHandle representing the instance that contains the field
      value - A ResultHandle representing 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 to
      instance - A ResultHandle representing the instance that contains the field
      value - A ResultHandle representing the value
    • readInstanceField

      ResultHandle readInstanceField(FieldDescriptor fieldDescriptor, ResultHandle instance)
      Reads an instance field and returns a ResultHandle representing the result. The result of the read is stored in a local variable, so even if the field value changes the ResultHandle will represent the same result.
      Parameters:
      fieldDescriptor - The field to read from
      instance - A ResultHandle representing the instance that contains the field
      Returns:
      A ResultHandle representing 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 a ResultHandle representing the result. The result of the read is stored in a local variable, so even if the field value changes the ResultHandle will represent the same result.
      Parameters:
      fieldDescriptor - The field to read from
      instance - A ResultHandle representing the instance that contains the field
      Returns:
      A ResultHandle representing 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 to
      value - A ResultHandle representing 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 to
      value - A ResultHandle representing the value
    • readStaticField

      ResultHandle readStaticField(FieldDescriptor fieldDescriptor)
      Reads a static field and returns a ResultHandle representing the result. The result of the read is stored in a local variable, so even if the field value changes the ResultHandle will represent the same result.
      Parameters:
      fieldDescriptor - The field to read from
      Returns:
      A ResultHandle representing the field value at the current point in time
    • readStaticField

      default ResultHandle readStaticField(org.jboss.jandex.FieldInfo fieldDescriptor)
      Reads a static field and returns a ResultHandle representing the result. The result of the read is stored in a local variable, so even if the field value changes the ResultHandle will represent the same result.
      Parameters:
      fieldDescriptor - The field to read from
      Returns:
      A ResultHandle representing 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(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 be null)
      Returns:
      the assignable local variable (not null)
    • createVariable

      default AssignableResultHandle createVariable(Class<?> type)
      Create a local variable which can be assigned within this scope.
      Parameters:
      type - the type of the variable's type (must not be null)
      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 be null)
      value - the value to assign (must not be null)
    • tryBlock

      TryBlock tryBlock()
      Add a try block.
      Returns:
      the try block
    • compareLong

      ResultHandle compareLong(ResultHandle value1, ResultHandle value2)
      Compares two long values and pushes the resulting integer to the stack. If value1 is greater than value2, the result is 1; if value1 is equal to value2, the result is 0; if value1 is less than value2, the result is -1. One of the if* methods should be used to process the result. Both parameters must be of type long.
      Parameters:
      value1 - first long value to compare
      value2 - second long value to compare
      Returns:
      the comparison result
    • compareFloat

      ResultHandle compareFloat(ResultHandle value1, ResultHandle value2, boolean nanComparesAsGreater)
      Compares two float values and pushes the resulting integer to the stack. If value1 is greater than value2, the result is 1; if value1 is equal to value2, the result is 0; if value1 is less than value2, the result is -1. One of the if* methods should be used to process the result. Both parameters must be of type float.

      If one of the values is NaN, the result is 1 if nanComparesAsGreater is true and -1 if not.

      Parameters:
      value1 - first long value to compare
      value2 - second long value to compare
      nanComparesAsGreater - whether presence of NaN should result in "greater"
      Returns:
      the comparison result
    • compareDouble

      ResultHandle compareDouble(ResultHandle value1, ResultHandle value2, boolean nanComparesAsGreater)
      Compares two double values and pushes the resulting integer to the stack. If value1 is greater than value2, the result is 1; if value1 is equal to value2, the result is 0; if value1 is less than value2, the result is -1. One of the if* methods should be used to process the result. Both parameters must be of type double.

      If one of the values is NaN, the result is 1 if nanComparesAsGreater is true and -1 if not.

      Parameters:
      value1 - first long value to compare
      value2 - second long value to compare
      nanComparesAsGreater - 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 the BranchResult.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 the BranchResult.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 for ifNonZero(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 for ifZero(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 is null the BranchResult.trueBranch() code will be executed, otherwise the BranchResult.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 not null the BranchResult.trueBranch() code will be executed, otherwise the BranchResult.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 the BranchResult.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 the BranchResult.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 the BranchResult.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 the BranchResult.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 the BranchResult.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 the BranchResult.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 the BranchResult.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 the BranchResult.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 to true.

      Parameters:
      condition -
      Returns:
      the if-then-else construct
    • instanceOf

      default ResultHandle instanceOf(ResultHandle resultHandle, Class<?> testType)
      Checks if the given resultHandle is an instance of the target type
      Parameters:
      resultHandle - the result handle
      testType - the cast target class
      Returns:
      a boolean result handle with the result of the instanceof call
    • instanceOf

      ResultHandle instanceOf(ResultHandle resultHandle, String testType)
      Checks if the given resultHandle is an instance of the target type
      Parameters:
      resultHandle - the result handle
      testType - 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 the BranchResult.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 the BranchResult.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 the BranchResult.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 ResultHandle representing the parameter
    • createFunction

      FunctionCreator createFunction(Class<?> functionalInterface)
      Creates an instance of a functional interface

      The resulting FunctionCreator can be used to both define the functions bytecode, and to get a ResultHandle that 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 a ResultHandle of the correct type which will be returned from the method.
      Parameters:
      returnValue - The value to return
    • returnVoid

      default void returnVoid()
      Marks a return from a void method or a constructor.

      Equivalent to returnValue(null).

      See Also:
    • returnNull

      default void returnNull()
      Creates a return statement that returns the null reference.

      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

      void throwException(ResultHandle exception)
      Throws an exception
      Parameters:
      exception - A result handle representing the exception to throw
    • checkCast

      ResultHandle checkCast(ResultHandle resultHandle, String castTarget)
      Perform a check cast operation which transforms the type of the given result handle.
      Parameters:
      resultHandle - the result handle
      castTarget - the cast target type descriptor
      Returns:
      a new result handle with updated type
    • checkCast

      default ResultHandle checkCast(ResultHandle resultHandle, Class<?> castTarget)
      Perform a check cast operation which transforms the type of the given result handle.
      Parameters:
      resultHandle - the result handle
      castTarget - the cast target class
      Returns:
      a new result handle with updated type
    • convertPrimitive

      ResultHandle convertPrimitive(ResultHandle value, Class<?> conversionTarget)
      Converts given value, which must be of a primitive type, to the given conversionTarget, which must be a primitive type, using primitive conversions defined by the Java language specification.

      Returns value directly when its static type is the same as conversionTarget.

      Throws an exception if any of the arguments is null. Throws an exception when the static type of value is not a primitive type or when conversionTarget is not a primitive type. Throws an exception if no primitive conversion exists from the type of value to the conversionTarget. (Note that "throws an exception" in this paragraph does not mean that a bytecode sequence for throwing an exception is emitted; instead, the method convertPrimitive throws an exception directly and eagerly.)

      Parameters:
      value - the value to be converted
      conversionTarget - the primitive type to which the value should be converted
      Returns:
      the converted value
    • throwException

      default <T extends Throwable> void throwException(Class<T> exceptionType, String message)
      Throws an exception. The exception must have a constructor that takes a single String argument
      Parameters:
      exceptionType - The exception type
      message - 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 type
      message - The exception message
      existing - The exception to wrap
    • marshalAsArray

      default ResultHandle marshalAsArray(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:
      true if this bytecode creator is scoped within the given creator, false otherwise
    • 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(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

      Adds the two result handles together and returns the result
      Parameters:
      a1 - The first number, aka the augend
      a2 - 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 minuend
      a2 - 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 multiplier
      a2 - 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 numerator
      a2 - 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 numerator
      a2 - 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 number
      a2 - The second number
      Returns:
      The result
    • bitwiseOr

      Computes the bitwise OR of the two result handles and returns the result
      Parameters:
      a1 - The first number
      a2 - 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 number
      a2 - 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 Enum<E>> Switch.EnumSwitch<E> enumSwitch(ResultHandle value, Class<E> enumClass)
      Create a new switch construct for an enum constant.
      Type Parameters:
      E -
      Parameters:
      value - The enum constant to switch on
      enumClass -
      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:
      close in interface AutoCloseable