Class IfThenElseImpl

All Implemented Interfaces:
BytecodeCreator, IfThenElse, AutoCloseable

class IfThenElseImpl extends BytecodeCreatorImpl implements IfThenElse
  • Field Details

    • state

      private byte state
    • result

      private BranchResult result
    • INIT

      private static byte INIT
    • THEN

      private static byte THEN
    • ELSEIF

      private static byte ELSEIF
    • ELSE

      private static byte ELSE
  • Constructor Details

  • Method Details

    • then

      public BytecodeCreator then()
      Description copied from interface: IfThenElse
      This block is executed if the result handle that was passed to BytecodeCreator.ifThenElse(ResultHandle) is evaluated as true.
      Specified by:
      then in interface IfThenElse
      Returns:
      the then block
    • elseIf

      public BytecodeCreator elseIf(ResultHandle value)
      Description copied from interface: IfThenElse
      Creates a new else-if statement. The block is executed if the condition result handle is evaluated as true.

      Note that the condition result handle must already exist.

       boolean test = foo.testIsOk();
       if (someOtherCondition) {
           // do action "A"
       } else if (test) {
           // do action "B"
       }
       
      If you need to create the condition result handle inside the if-else statement then use the IfThenElse.elseIf(Function) method instead.
      Specified by:
      elseIf in interface IfThenElse
      Parameters:
      value -
      Returns:
      the else-if block
    • elseIf

      Description copied from interface: IfThenElse
      Creates a new else-if statement. The block is executed if the condition result handle returned from the function is evaluated as true.

      The argument of the function represents the block that is executed when the else-if statement is evaluated.

      In order to generate the bytecode for the "action B" branch in the following example:

       if (someOtherCondition) {
           // do action "A"
       } else if (foo.testIsOk()) {
           // do action "B"
       }
       
      The code needs to look like:
       IfThenElse ifAction = method.ifThenElse(someOtherCondition);
       BytecodeCreator ifTestOk = ifValue.elseIf(b -> b.invokeVirtualMethod(testIsOkMethodDescriptor, fooInstance)));
       // do action "B"
       
      Specified by:
      elseIf in interface IfThenElse
      Parameters:
      test -
      Returns:
      the else-if block
    • elseThen

      public BytecodeCreator elseThen()
      Description copied from interface: IfThenElse
      This block is executed if no condition result handle was evaluated as true.
      Specified by:
      elseThen in interface IfThenElse
      Returns:
      the else block
    • initialThenNotCreated

      private IllegalStateException initialThenNotCreated()
    • elseAlreadyCreated

      private IllegalStateException elseAlreadyCreated()