Class DirectCodeBuilder

All Implemented Interfaces:
Consumer<CodeElement>, ClassFileBuilder<CodeElement,CodeBuilder>, CodeBuilder, LabelContext, TerminalCodeBuilder

public final class DirectCodeBuilder extends AbstractDirectBuilder<CodeModel> implements TerminalCodeBuilder, LabelContext
  • Method Details

    • build

      public static Attribute<CodeAttribute> build(MethodInfo methodInfo, Consumer<? super CodeBuilder> handler, SplitConstantPool constantPool, ClassFileImpl context, CodeModel original)
    • with

      public CodeBuilder with(CodeElement element)
      Description copied from interface: ClassFileBuilder
      Integrate the ClassFileElement into the entity being built.
      Specified by:
      with in interface ClassFileBuilder<CodeElement,CodeBuilder>
      Parameters:
      element - the element
      Returns:
      this builder
    • newLabel

      public Label newLabel()
      Description copied from interface: CodeBuilder
      Returns a fresh unbound label.
      Specified by:
      newLabel in interface CodeBuilder
      Specified by:
      newLabel in interface LabelContext
      Returns:
      a fresh unbound label
    • startLabel

      public Label startLabel()
      Description copied from interface: CodeBuilder
      Returns the label associated with the beginning of the current block. If the current CodeBuilder is not a "block" builder, such as those provided by CodeBuilder.block(Consumer) or CodeBuilder.ifThenElse(Consumer, Consumer), the current block will be the entire method body.
      Specified by:
      startLabel in interface CodeBuilder
      Returns:
      the label associated with the beginning of the current block
    • endLabel

      public Label endLabel()
      Description copied from interface: CodeBuilder
      Returns the label associated with the end of the current block. If the current CodeBuilder is not a "block" builder, such as those provided by CodeBuilder.block(Consumer) or CodeBuilder.ifThenElse(Consumer, Consumer), the current block will be the entire method body.
      Specified by:
      endLabel in interface CodeBuilder
      Returns:
      the label associated with the end of the current block
    • receiverSlot

      public int receiverSlot()
      Description copied from interface: CodeBuilder
      Returns the local variable slot associated with the receiver..
      Specified by:
      receiverSlot in interface CodeBuilder
      Returns:
      the local variable slot associated with the receiver
    • parameterSlot

      public int parameterSlot(int paramNo)
      Description copied from interface: CodeBuilder
      Returns the local variable slot associated with the specified parameter.. The returned value is adjusted for the receiver slot (if the method is an instance method) and for the requirement that long and double values require two slots.
      Specified by:
      parameterSlot in interface CodeBuilder
      Parameters:
      paramNo - the index of the parameter
      Returns:
      the local variable slot associated with the specified parameter
    • curTopLocal

      public int curTopLocal()
    • allocateLocal

      public int allocateLocal(TypeKind typeKind)
      Description copied from interface: CodeBuilder
      Returns the local variable slot of a fresh local variable. This method makes reasonable efforts to determine which slots are in use and which are not. When transforming a method, fresh locals begin at the maxLocals of the original method. For a method being built directly, fresh locals begin after the last parameter slot.

      If the current code builder is a "block" code builder provided by CodeBuilder.block(Consumer), CodeBuilder.ifThen(Consumer), or CodeBuilder.ifThenElse(Consumer, Consumer), at the end of the block, locals are reset to their value at the beginning of the block.

      Specified by:
      allocateLocal in interface CodeBuilder
      Parameters:
      typeKind - the type of the local variable
      Returns:
      the local variable slot of a fresh local variable
    • curPc

      public int curPc()
    • methodInfo

      public MethodInfo methodInfo()
    • writeBytecode

      public void writeBytecode(Opcode opcode)
    • writeLocalVar

      public void writeLocalVar(Opcode opcode, int localVar)
    • writeIncrement

      public void writeIncrement(int slot, int val)
    • writeBranch

      public void writeBranch(Opcode op, Label target)
    • writeLookupSwitch

      public void writeLookupSwitch(Label defaultTarget, List<SwitchCase> cases)
    • writeTableSwitch

      public void writeTableSwitch(int low, int high, Label defaultTarget, List<SwitchCase> cases)
    • writeFieldAccess

      public void writeFieldAccess(Opcode opcode, FieldRefEntry ref)
    • writeInvokeNormal

      public void writeInvokeNormal(Opcode opcode, MemberRefEntry ref)
    • writeInvokeInterface

      public void writeInvokeInterface(Opcode opcode, InterfaceMethodRefEntry ref, int count)
    • writeInvokeDynamic

      public void writeInvokeDynamic(InvokeDynamicEntry ref)
    • writeNewObject

      public void writeNewObject(ClassEntry type)
    • writeNewPrimitiveArray

      public void writeNewPrimitiveArray(int newArrayCode)
    • writeNewReferenceArray

      public void writeNewReferenceArray(ClassEntry type)
    • writeNewMultidimensionalArray

      public void writeNewMultidimensionalArray(int dimensions, ClassEntry type)
    • writeTypeCheck

      public void writeTypeCheck(Opcode opcode, ClassEntry type)
    • writeArgumentConstant

      public void writeArgumentConstant(Opcode opcode, int value)
    • writeLoadConstant

      public void writeLoadConstant(Opcode opcode, LoadableConstantEntry value)
    • getLabel

      public Label getLabel(int bci)
      Specified by:
      getLabel in interface LabelContext
    • labelToBci

      public int labelToBci(Label label)
      Specified by:
      labelToBci in interface LabelContext
    • setLineNumber

      public void setLineNumber(int lineNo)
    • setLabelTarget

      public void setLabelTarget(Label label)
    • setLabelTarget

      public void setLabelTarget(Label label, int bci)
      Specified by:
      setLabelTarget in interface LabelContext
    • addCharacterRange

      public void addCharacterRange(CharacterRange element)
    • addHandler

      public void addHandler(ExceptionCatch element)
    • addLocalVariable

      public void addLocalVariable(LocalVariable element)
    • addLocalVariableType

      public void addLocalVariableType(LocalVariableType element)
    • toString

      public String toString()
      Overrides:
      toString in class Object