- All Superinterfaces:
ClassfileBuilder<CodeElement,,CodeBuilder> Consumer<CodeElement>
- All Known Subinterfaces:
CodeBuilder.BlockCodeBuilder,TerminalCodeBuilder
- All Known Implementing Classes:
BlockCodeBuilderImpl,BufferedCodeBuilder,ChainedCodeBuilder,DirectCodeBuilder,NonterminalCodeBuilder,TransformingCodeBuilder
MethodBuilder.withCode(Consumer) or to code transforms. The elements of a
code can be specified abstractly, by passing a CodeElement to ClassfileBuilder.with(ClassfileElement) or concretely by calling the various withXxx
methods.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA builder for blocks of code.static interfaceA builder to add catch blocks. -
Method Summary
Modifier and TypeMethodDescriptiondefault CodeBuilderaaload()default CodeBuilderaastore()default CodeBuilderintallocateLocal(TypeKind typeKind) Returns the local variable slot of a fresh local variable.default CodeBuilderaload(int slot) default CodeBuilderdefault CodeBuilderanewarray(ClassEntry classEntry) default CodeBuilderareturn()default CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderastore(int slot) default CodeBuilderathrow()default CodeBuilderbaload()default CodeBuilderbastore()default CodeBuilderbipush(int b) default CodeBuilderblock(Consumer<CodeBuilder.BlockCodeBuilder> handler) Add a lexical block to the method being built.default CodeBuilderbranchInstruction(Opcode op, Label target) default CodeBuildercaload()default CodeBuildercastore()default CodeBuildercharacterRange(Label startScope, Label endScope, int characterRangeStart, int characterRangeEnd, int flags) default CodeBuilderdefault CodeBuildercheckcast(ClassEntry type) default CodeBuilderconstantInstruction(ConstantDesc value) default CodeBuilderconstantInstruction(Opcode opcode, ConstantDesc value) default CodeBuilderconvertInstruction(TypeKind fromType, TypeKind toType) default CodeBuilderd2f()default CodeBuilderd2i()default CodeBuilderd2l()default CodeBuilderdadd()default CodeBuilderdaload()default CodeBuilderdastore()default CodeBuilderdcmpg()default CodeBuilderdcmpl()default CodeBuilderdconst_0()default CodeBuilderdconst_1()default CodeBuilderddiv()default CodeBuilderdload(int slot) default CodeBuilderdmul()default CodeBuilderdneg()default CodeBuilderdrem()default CodeBuilderdreturn()default CodeBuilderdstore(int slot) default CodeBuilderdsub()default CodeBuilderdup()default CodeBuilderdup_x1()default CodeBuilderdup_x2()default CodeBuilderdup2()default CodeBuilderdup2_x1()default CodeBuilderdup2_x2()endLabel()Returns the label associated with the end of the current block.default CodeBuilderexceptionCatch(Label start, Label end, Label handler, ClassDesc catchType) default CodeBuilderexceptionCatch(Label start, Label end, Label handler, Optional<ClassEntry> catchType) default CodeBuilderexceptionCatch(Label start, Label end, Label handler, ClassEntry catchType) default CodeBuilderexceptionCatchAll(Label start, Label end, Label handler) default CodeBuilderf2d()default CodeBuilderf2i()default CodeBuilderf2l()default CodeBuilderfadd()default CodeBuilderfaload()default CodeBuilderfastore()default CodeBuilderfcmpg()default CodeBuilderfcmpl()default CodeBuilderfconst_0()default CodeBuilderfconst_1()default CodeBuilderfconst_2()default CodeBuilderfdiv()default CodeBuilderfieldInstruction(Opcode opcode, ClassDesc owner, String name, ClassDesc type) default CodeBuilderfieldInstruction(Opcode opcode, FieldRefEntry ref) default CodeBuilderfload(int slot) default CodeBuilderfmul()default CodeBuilderfneg()default CodeBuilderfrem()default CodeBuilderfreturn()default CodeBuilderfstore(int slot) default CodeBuilderfsub()default CodeBuilderdefault CodeBuildergetfield(FieldRefEntry ref) default CodeBuilderdefault CodeBuildergetstatic(FieldRefEntry ref) default CodeBuilderdefault CodeBuilderdefault CodeBuilderi2b()default CodeBuilderi2c()default CodeBuilderi2d()default CodeBuilderi2f()default CodeBuilderi2l()default CodeBuilderi2s()default CodeBuilderiadd()default CodeBuilderiaload()default CodeBuilderiand()default CodeBuilderiastore()default CodeBuildericonst_0()default CodeBuildericonst_1()default CodeBuildericonst_2()default CodeBuildericonst_3()default CodeBuildericonst_4()default CodeBuildericonst_5()default CodeBuilderdefault CodeBuilderidiv()default CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderif_nonnull(Label target) default CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderifThen(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler) Add an "if-then" block that is conditional on the boolean value on top of the operand stack.default CodeBuilderifThen(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler) Add an "if-then" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode.default CodeBuilderifThenElse(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler) Add an "if-then-else" block that is conditional on the boolean value on top of the operand stack.default CodeBuilderifThenElse(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler) Add an "if-then-else" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode.default CodeBuilderiinc(int slot, int val) default CodeBuilderiload(int slot) default CodeBuilderimul()default CodeBuilderincrementInstruction(int slot, int val) default CodeBuilderineg()default CodeBuilderinstanceof_(ClassDesc target) default CodeBuilderinstanceof_(ClassEntry target) default CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderdefault CodeBuilderinvokeInstruction(Opcode opcode, ClassDesc owner, String name, MethodTypeDesc desc, boolean isInterface) default CodeBuilderinvokeInstruction(Opcode opcode, MemberRefEntry ref) default CodeBuilderinvokeinterface(ClassDesc owner, String name, MethodTypeDesc type) default CodeBuilderdefault CodeBuilderinvokespecial(ClassDesc owner, String name, MethodTypeDesc type) default CodeBuilderinvokespecial(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) default CodeBuilderdefault CodeBuilderdefault CodeBuilderinvokestatic(ClassDesc owner, String name, MethodTypeDesc type) default CodeBuilderinvokestatic(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) default CodeBuilderdefault CodeBuilderdefault CodeBuilderinvokevirtual(ClassDesc owner, String name, MethodTypeDesc type) default CodeBuilderdefault CodeBuilderior()default CodeBuilderirem()default CodeBuilderireturn()default CodeBuilderishl()default CodeBuilderishr()default CodeBuilderistore(int slot) default CodeBuilderisub()default CodeBuilderiushr()default CodeBuilderixor()default CodeBuilderl2d()default CodeBuilderl2f()default CodeBuilderl2i()default CodeBuilderlabelBinding(Label label) default CodeBuilderladd()default CodeBuilderlaload()default CodeBuilderland()default CodeBuilderlastore()default CodeBuilderlcmp()default CodeBuilderlconst_0()default CodeBuilderlconst_1()default CodeBuilderldc(LoadableConstantEntry entry) default CodeBuilderldiv()default CodeBuilderlineNumber(int line) default CodeBuilderlload(int slot) default CodeBuilderlmul()default CodeBuilderlneg()default CodeBuilderloadInstruction(TypeKind tk, int slot) default CodeBuilderlocalVariable(int slot, String name, ClassDesc descriptor, Label startScope, Label endScope) default CodeBuilderlocalVariable(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry, Label startScope, Label endScope) default CodeBuilderlocalVariableType(int slot, String name, Signature signature, Label startScope, Label endScope) default CodeBuilderlocalVariableType(int slot, Utf8Entry nameEntry, Utf8Entry signatureEntry, Label startScope, Label endScope) default CodeBuilderlookupswitch(Label defaultTarget, List<SwitchCase> cases) default CodeBuilderlookupSwitchInstruction(Label defaultTarget, List<SwitchCase> cases) default CodeBuilderlor()default CodeBuilderlrem()default CodeBuilderlreturn()default CodeBuilderlshl()default CodeBuilderlshr()default CodeBuilderlstore(int slot) default CodeBuilderlsub()default CodeBuilderlushr()default CodeBuilderlxor()default CodeBuilderdefault CodeBuilderdefault CodeBuildermonitorInstruction(Opcode opcode) default CodeBuildermultianewarray(ClassDesc array, int dims) default CodeBuildermultianewarray(ClassEntry array, int dims) default CodeBuilderdefault CodeBuildernew_(ClassEntry clazz) default CodeBuilderdefault LabelnewLabel()Returns a fresh unbound label.default CodeBuildernewMultidimensionalArrayInstruction(int dimensions, ClassDesc type) default CodeBuildernewMultidimensionalArrayInstruction(int dimensions, ClassEntry type) default CodeBuilderdefault CodeBuilderdefault CodeBuildernewPrimitiveArrayInstruction(TypeKind typeKind) default CodeBuilderdefault CodeBuilderdefault CodeBuildernop()default CodeBuilderdefault CodeBuilderoperatorInstruction(Opcode opcode) original()intparameterSlot(int paramNo) Returns the local variable slot associated with the specified parameter.default CodeBuilderpop()default CodeBuilderpop2()default CodeBuilderdefault CodeBuilderputfield(FieldRefEntry ref) default CodeBuilderdefault CodeBuilderputstatic(FieldRefEntry ref) intReturns the local variable slot associated with the receiver.default CodeBuilderreturn_()default CodeBuilderdefault CodeBuildersaload()default CodeBuildersastore()default CodeBuildersipush(int s) default CodeBuilderstackInstruction(Opcode opcode) Returns the label associated with the beginning of the current block.default CodeBuilderstoreInstruction(TypeKind tk, int slot) default CodeBuilderswap()default CodeBuildertableswitch(int low, int high, Label defaultTarget, List<SwitchCase> cases) default CodeBuildertableswitch(Label defaultTarget, List<SwitchCase> cases) default CodeBuildertableSwitchInstruction(int lowValue, int highValue, Label defaultTarget, List<SwitchCase> cases) default CodeBuilderdefault CodeBuildertransforming(CodeTransform transform, Consumer<CodeBuilder> handler) Apply a transform to the code built by a handler, directing results to this builder.default CodeBuildertrying(Consumer<CodeBuilder.BlockCodeBuilder> tryHandler, Consumer<CodeBuilder.CatchBuilder> catchesHandler) Adds a "try-catch" block comprising one try block and zero or more catch blocks.default CodeBuildertypeCheckInstruction(Opcode opcode, ClassDesc type) default CodeBuildertypeCheckInstruction(Opcode opcode, ClassEntry type) Methods inherited from interface org.glavo.classfile.ClassfileBuilder
accept, canWriteDirect, constantPool, transform, with
-
Method Details
-
original
-
newLabel
Label newLabel()Returns a fresh unbound label.- Returns:
- a fresh unbound label
-
startLabel
Label startLabel()Returns the label associated with the beginning of the current block. If the current CodeBuilder is not a "block" builder, such as those provided byblock(Consumer)orifThenElse(Consumer, Consumer), the current block will be the entire method body.- Returns:
- the label associated with the beginning of the current block
-
endLabel
Label endLabel()Returns the label associated with the end of the current block. If the current CodeBuilder is not a "block" builder, such as those provided byblock(Consumer)orifThenElse(Consumer, Consumer), the current block will be the entire method body.- Returns:
- the label associated with the end of the current block
-
receiverSlot
int receiverSlot()Returns the local variable slot associated with the receiver..- Returns:
- the local variable slot associated with the receiver
- Throws:
IllegalStateException- if this is not a static method
-
parameterSlot
int parameterSlot(int paramNo) 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 thatlonganddoublevalues require two slots.- Parameters:
paramNo- the index of the parameter- Returns:
- the local variable slot associated with the specified parameter
-
allocateLocal
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 themaxLocalsof 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
block(Consumer),ifThen(Consumer), orifThenElse(Consumer, Consumer), at the end of the block, locals are reset to their value at the beginning of the block.- Parameters:
typeKind- the type of the local variable- Returns:
- the local variable slot of a fresh local variable
-
transforming
Apply a transform to the code built by a handler, directing results to this builder.- Parameters:
transform- the transform to apply to the code built by the handlerhandler- the handler that receives a CodeBuilder to build the code.- Returns:
- this builder
-
block
Add a lexical block to the method being built.Within this block, the
startLabel()andendLabel()correspond to the start and end of the block, and theCodeBuilder.BlockCodeBuilder.breakLabel()also corresponds to the end of the block.- Parameters:
handler- handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of the lexical block.
-
ifThen
Add an "if-then" block that is conditional on the boolean value on top of the operand stack.The
CodeBuilder.BlockCodeBuilder.breakLabel()for the "then" block corresponds to the end of that block.- Parameters:
thenHandler- handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of theif- Returns:
- this builder
-
ifThen
Add an "if-then" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode.The
CodeBuilder.BlockCodeBuilder.breakLabel()for the "then" block corresponds to the end of that block.- Parameters:
opcode- the operation code for a branch instructions that accepts one or two operands on the stackthenHandler- handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of theif- Returns:
- this builder
- Throws:
IllegalArgumentException- if the operation code is not for a branch instruction that accepts one or two operands
-
ifThenElse
default CodeBuilder ifThenElse(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler) Add an "if-then-else" block that is conditional on the boolean value on top of the operand stack.The
CodeBuilder.BlockCodeBuilder.breakLabel()for each block corresponds to the end of the "else" block.- Parameters:
thenHandler- handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of theifelseHandler- handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of theelse- Returns:
- this builder
-
ifThenElse
default CodeBuilder ifThenElse(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler) Add an "if-then-else" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode.The
CodeBuilder.BlockCodeBuilder.breakLabel()for each block corresponds to the end of the "else" block.- Parameters:
opcode- the operation code for a branch instructions that accepts one or two operands on the stackthenHandler- handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of theifelseHandler- handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of theelse- Returns:
- this builder
- Throws:
IllegalArgumentException- if the operation code is not for a branch instruction that accepts one or two operands
-
trying
default CodeBuilder trying(Consumer<CodeBuilder.BlockCodeBuilder> tryHandler, Consumer<CodeBuilder.CatchBuilder> catchesHandler) Adds a "try-catch" block comprising one try block and zero or more catch blocks. Exceptions thrown by instructions in the try block may be caught by catch blocks.- Parameters:
tryHandler- handler that receives a CodeBuilder to generate the body of the try block.catchesHandler- a handler that receives a CodeBuilder.CatchBuilder to generate bodies of catch blocks.- Returns:
- this builder
- See Also:
-
loadInstruction
-
storeInstruction
-
incrementInstruction
-
branchInstruction
-
lookupSwitchInstruction
-
tableSwitchInstruction
default CodeBuilder tableSwitchInstruction(int lowValue, int highValue, Label defaultTarget, List<SwitchCase> cases) -
returnInstruction
-
throwInstruction
-
fieldInstruction
-
fieldInstruction
-
invokeInstruction
-
invokeInstruction
default CodeBuilder invokeInstruction(Opcode opcode, ClassDesc owner, String name, MethodTypeDesc desc, boolean isInterface) -
invokeDynamicInstruction
-
invokeDynamicInstruction
-
newObjectInstruction
-
newObjectInstruction
-
newPrimitiveArrayInstruction
-
newReferenceArrayInstruction
-
newReferenceArrayInstruction
-
newMultidimensionalArrayInstruction
-
newMultidimensionalArrayInstruction
-
arrayLoadInstruction
-
arrayStoreInstruction
-
typeCheckInstruction
-
typeCheckInstruction
-
convertInstruction
-
stackInstruction
-
operatorInstruction
-
constantInstruction
-
constantInstruction
-
monitorInstruction
-
nopInstruction
-
nop
-
newBoundLabel
-
labelBinding
-
lineNumber
-
exceptionCatch
-
exceptionCatch
default CodeBuilder exceptionCatch(Label start, Label end, Label handler, Optional<ClassEntry> catchType) -
exceptionCatch
-
exceptionCatchAll
-
characterRange
default CodeBuilder characterRange(Label startScope, Label endScope, int characterRangeStart, int characterRangeEnd, int flags) -
localVariable
default CodeBuilder localVariable(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry, Label startScope, Label endScope) -
localVariable
default CodeBuilder localVariable(int slot, String name, ClassDesc descriptor, Label startScope, Label endScope) -
localVariableType
default CodeBuilder localVariableType(int slot, Utf8Entry nameEntry, Utf8Entry signatureEntry, Label startScope, Label endScope) -
localVariableType
default CodeBuilder localVariableType(int slot, String name, Signature signature, Label startScope, Label endScope) -
aconst_null
-
aaload
-
aastore
-
aload
-
anewarray
-
anewarray
-
areturn
-
arraylength
-
astore
-
athrow
-
baload
-
bastore
-
bipush
-
caload
-
castore
-
checkcast
-
checkcast
-
d2f
-
d2i
-
d2l
-
dadd
-
daload
-
dastore
-
dcmpg
-
dcmpl
-
dconst_0
-
dconst_1
-
ddiv
-
dload
-
dmul
-
dneg
-
drem
-
dreturn
-
dstore
-
dsub
-
dup
-
dup2
-
dup2_x1
-
dup2_x2
-
dup_x1
-
dup_x2
-
f2d
-
f2i
-
f2l
-
fadd
-
faload
-
fastore
-
fcmpg
-
fcmpl
-
fconst_0
-
fconst_1
-
fconst_2
-
fdiv
-
fload
-
fmul
-
fneg
-
frem
-
freturn
-
fstore
-
fsub
-
getfield
-
getfield
-
getstatic
-
getstatic
-
goto_
-
goto_w
-
i2b
-
i2c
-
i2d
-
i2f
-
i2l
-
i2s
-
iadd
-
iaload
-
iand
-
iastore
-
iconst_0
-
iconst_1
-
iconst_2
-
iconst_3
-
iconst_4
-
iconst_5
-
iconst_m1
-
idiv
-
if_acmpeq
-
if_acmpne
-
if_icmpeq
-
if_icmpge
-
if_icmpgt
-
if_icmple
-
if_icmplt
-
if_icmpne
-
if_nonnull
-
if_null
-
ifeq
-
ifge
-
ifgt
-
ifle
-
iflt
-
ifne
-
iinc
-
iload
-
imul
-
ineg
-
instanceof_
-
instanceof_
-
invokedynamic
-
invokedynamic
-
invokeinterface
-
invokeinterface
-
invokespecial
-
invokespecial
-
invokespecial
-
invokespecial
default CodeBuilder invokespecial(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) -
invokestatic
-
invokestatic
-
invokestatic
-
invokestatic
default CodeBuilder invokestatic(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) -
invokevirtual
-
invokevirtual
-
ior
-
irem
-
ireturn
-
ishl
-
ishr
-
istore
-
isub
-
iushr
-
ixor
-
lookupswitch
-
l2d
-
l2f
-
l2i
-
ladd
-
laload
-
land
-
lastore
-
lcmp
-
lconst_0
-
lconst_1
-
ldc
-
ldiv
-
lload
-
lmul
-
lneg
-
lor
-
lrem
-
lreturn
-
lshl
-
lshr
-
lstore
-
lsub
-
lushr
-
lxor
-
monitorenter
-
monitorexit
-
multianewarray
-
multianewarray
-
new_
-
new_
-
newarray
-
pop
-
pop2
-
putfield
-
putfield
-
putstatic
-
putstatic
-
return_
-
saload
-
sastore
-
sipush
-
swap
-
tableswitch
-
tableswitch
-