Interface CodeBuilder.BlockCodeBuilder
- All Superinterfaces:
ClassFileBuilder<CodeElement, CodeBuilder>, CodeBuilder, Consumer<CodeElement>
- Enclosing interface:
CodeBuilder
A builder for blocks of code. Its
CodeBuilder.startLabel() and CodeBuilder.endLabel() do not enclose the entire method body, but from the start to
the end of the block.
The location where a block of code merges back to its parent block, as
represented by the breakLabel(), is expected to be reachable,
either from this block or the parent block. The built code may be
malformed if there is no executable code at that location.
- Since:
- 24
-
Nested Class Summary
Nested classes/interfaces declared in interface CodeBuilder
CodeBuilder.BlockCodeBuilder, CodeBuilder.CatchBuilderModifier and TypeInterfaceDescriptionstatic interfaceA builder for blocks of code.static interfaceA builder to add catch blocks. -
Method Summary
Modifier and TypeMethodDescriptionReturns the label locating where control is passed back to the parent block.Methods declared in interface ClassFileBuilder
accept, constantPool, transform, withModifier and TypeMethodDescriptiondefault voidIntegrates the member element into the structure being built.Returns the constant pool builder associated with this builder.default CodeBuildertransform(CompoundElement<CodeElement> model, ClassFileTransform<?, CodeElement, CodeBuilder> transform) Applies a transform to a compound structure, directing results to this builder.with(CodeElement e) Integrates the member element into the structure being built.Methods declared in interface CodeBuilder
aaload, aastore, aconst_null, allocateLocal, aload, anewarray, anewarray, areturn, arraylength, arrayLoad, arrayStore, astore, athrow, baload, bastore, bipush, block, branch, caload, castore, characterRange, checkcast, checkcast, conversion, d2f, d2i, d2l, dadd, daload, dastore, dcmpg, dcmpl, dconst_0, dconst_1, ddiv, dload, dmul, dneg, drem, dreturn, dstore, dsub, dup, dup_x1, dup_x2, dup2, dup2_x1, dup2_x2, endLabel, exceptionCatch, exceptionCatch, exceptionCatch, exceptionCatchAll, f2d, f2i, f2l, fadd, faload, fastore, fcmpg, fcmpl, fconst_0, fconst_1, fconst_2, fdiv, fieldAccess, fieldAccess, 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, ifeq, ifge, ifgt, ifle, iflt, ifne, ifnonnull, ifnull, ifThen, ifThen, ifThenElse, ifThenElse, iinc, iload, imul, ineg, instanceOf, instanceOf, invoke, invoke, invokedynamic, invokedynamic, invokeinterface, invokeinterface, invokespecial, invokespecial, invokespecial, invokespecial, invokestatic, invokestatic, invokestatic, invokestatic, invokevirtual, invokevirtual, ior, irem, ireturn, ishl, ishr, istore, isub, iushr, ixor, l2d, l2f, l2i, labelBinding, ladd, laload, land, lastore, lcmp, lconst_0, lconst_1, ldc, ldc, ldiv, lineNumber, lload, lmul, lneg, loadConstant, loadConstant, loadConstant, loadConstant, loadConstant, loadLocal, localVariable, localVariable, localVariableType, localVariableType, lookupswitch, lor, lrem, lreturn, lshl, lshr, lstore, lsub, lushr, lxor, monitorenter, monitorexit, multianewarray, multianewarray, new_, new_, newarray, newBoundLabel, newLabel, nop, parameterSlot, pop, pop2, putfield, putfield, putstatic, putstatic, receiverSlot, return_, return_, saload, sastore, sipush, startLabel, storeLocal, swap, tableswitch, tableswitch, transforming, tryingModifier and TypeMethodDescriptiondefault CodeBuilderaaload()Generates an instruction to load from areferencearray.default CodeBuilderaastore()Generates an instruction to store into areferencearray.default CodeBuilderGenerates an instruction pushing the null objectreferenceonto the operand stack.intallocateLocal(TypeKind typeKind) Returns the local variable slot of a fresh local variable.default CodeBuilderaload(int slot) Generates an instruction to load areferencefrom a local variable.default CodeBuilderanewarray(ClassEntry classEntry) Generates an instruction to create a new array ofreference.default CodeBuilderGenerates an instruction to create a new array ofreference.default CodeBuilderareturn()Generates an instruction to return areferencefrom this method.default CodeBuilderGenerates an instruction to get the length of an array.default CodeBuilderGenerates an instruction to load from an array.default CodeBuilderarrayStore(TypeKind tk) Generates an instruction to store into an array.default CodeBuilderastore(int slot) Generates an instruction to store areferenceinto a local variable.default CodeBuilderathrow()Generates an instruction to throw an exception or error.default CodeBuilderbaload()default CodeBuilderbastore()default CodeBuilderbipush(int b) default CodeBuilderblock(Consumer<CodeBuilder.BlockCodeBuilder> handler) Adds a lexical block to the method being built.default CodeBuilderGenerates a branch instruction.default CodeBuildercaload()Generates an instruction to load from achararray.default CodeBuildercastore()Generates an instruction to store into achararray.default CodeBuildercharacterRange(Label startScope, Label endScope, int characterRangeStart, int characterRangeEnd, int flags) Declares a character range entry.default CodeBuildercheckcast(ClassEntry type) Generates an instruction to check whether an object is of the given type, throwing aClassCastExceptionif the check fails.default CodeBuilderGenerates an instruction to check whether an object is of the given type, throwing aClassCastExceptionif the check fails.default CodeBuilderconversion(TypeKind fromType, TypeKind toType) Generates instruction(s) to convertfromTypetotoType.default CodeBuilderd2f()default CodeBuilderd2i()default CodeBuilderd2l()default CodeBuilderdadd()Generates an instruction to add twodoubles.default CodeBuilderdaload()Generates an instruction to load from adoublearray.default CodeBuilderdastore()Generates an instruction to store into adoublearray.default CodeBuilderdcmpg()default CodeBuilderdcmpl()default CodeBuilderdconst_0()Generates an instruction pushingdoubleconstant 0 onto the operand stack.default CodeBuilderdconst_1()Generates an instruction pushingdoubleconstant 1 onto the operand stack.default CodeBuilderddiv()Generates an instruction to dividedoubles.default CodeBuilderdload(int slot) Generates an instruction to load adoublefrom a local variable.default CodeBuilderdmul()Generates an instruction to multiplydoubles.default CodeBuilderdneg()Generates an instruction to negate adouble.default CodeBuilderdrem()Generates an instruction to calculatedoubleremainder.default CodeBuilderdreturn()Generates an instruction to return adoublefrom this method.default CodeBuilderdstore(int slot) Generates an instruction to store adoubleinto a local variable.default CodeBuilderdsub()Generates an instruction to subtractdoubles.default CodeBuilderdup()Generates an instruction to duplicate the top operand stack value.default CodeBuilderdup_x1()Generates an instruction to duplicate the top operand stack value and insert two values down.default CodeBuilderdup_x2()Generates an instruction to duplicate the top operand stack value and insert two or three values down.default CodeBuilderdup2()Generates an instruction to duplicate the top one or two operand stack value.default CodeBuilderdup2_x1()Generates an instruction to duplicate the top one or two operand stack values and insert two or three values down.default CodeBuilderdup2_x2()Generates an instruction to duplicate the top one or two operand stack values and insert two, three, or four values down.endLabel()Returns the label associated with the end of the current block.default CodeBuilderexceptionCatch(Label start, Label end, Label handler, ClassEntry catchType) Declares an exception table entry.default CodeBuilderexceptionCatch(Label start, Label end, Label handler, ClassDesc catchType) Declares an exception table entry.default CodeBuilderexceptionCatch(Label start, Label end, Label handler, Optional<ClassEntry> catchType) Declares an exception table entry.default CodeBuilderexceptionCatchAll(Label start, Label end, Label handler) Declares an exception table entry catching all exceptions and errors.default CodeBuilderf2d()default CodeBuilderf2i()default CodeBuilderf2l()default CodeBuilderfadd()Generates an instruction to add twofloats.default CodeBuilderfaload()Generates an instruction to load from afloatarray.default CodeBuilderfastore()Generates an instruction to store into afloatarray.default CodeBuilderfcmpg()default CodeBuilderfcmpl()default CodeBuilderfconst_0()Generates an instruction pushingfloatconstant 0 onto the operand stack.default CodeBuilderfconst_1()Generates an instruction pushingfloatconstant 1 onto the operand stack.default CodeBuilderfconst_2()Generates an instruction pushingfloatconstant 2 onto the operand stack.default CodeBuilderfdiv()Generates an instruction to dividefloats.default CodeBuilderfieldAccess(Opcode opcode, FieldRefEntry ref) Generates an instruction to access a field.default CodeBuilderfieldAccess(Opcode opcode, ClassDesc owner, String name, ClassDesc type) Generates an instruction to access a field.default CodeBuilderfload(int slot) Generates an instruction to load afloatfrom a local variable.default CodeBuilderfmul()Generates an instruction to multiplyfloats.default CodeBuilderfneg()Generates an instruction to negate afloat.default CodeBuilderfrem()Generates an instruction to calculatefloatsremainder.default CodeBuilderfreturn()Generates an instruction to return afloatfrom this method.default CodeBuilderfstore(int slot) Generates an instruction to store afloatinto a local variable.default CodeBuilderfsub()Generates an instruction to subtractfloats.default CodeBuildergetfield(FieldRefEntry ref) Generates an instruction to fetch field from an object.default CodeBuilderGenerates an instruction to fetch field from an object.default CodeBuildergetstatic(FieldRefEntry ref) Generates an instruction to get static field from a class or interface.default CodeBuilderGenerates an instruction to get static field from a class or interface.default CodeBuilderGenerates an instruction to branch always.default CodeBuilderGenerates an instruction to branch always with wide index.default CodeBuilderi2b()default CodeBuilderi2c()default CodeBuilderi2d()default CodeBuilderi2f()default CodeBuilderi2l()default CodeBuilderi2s()default CodeBuilderiadd()Generates an instruction to add twoints.default CodeBuilderiaload()Generates an instruction to load from anintarray.default CodeBuilderiand()default CodeBuilderiastore()Generates an instruction to store into anintarray.default CodeBuildericonst_0()Generates an instruction pushingintconstant 0 onto the operand stack.default CodeBuildericonst_1()Generates an instruction pushingintconstant 1 onto the operand stack.default CodeBuildericonst_2()Generates an instruction pushingintconstant 2 onto the operand stack.default CodeBuildericonst_3()Generates an instruction pushingintconstant 3 onto the operand stack.default CodeBuildericonst_4()Generates an instruction pushingintconstant 4 onto the operand stack.default CodeBuildericonst_5()Generates an instruction pushingintconstant 5 onto the operand stack.default CodeBuilderGenerates an instruction pushingintconstant -1 onto the operand stack.default CodeBuilderidiv()Generates an instruction to divideints.default CodeBuilderGenerates an instruction to branch ifreferencecomparisonoperand1 == operand2succeeds.default CodeBuilderGenerates an instruction to branch ifreferencecomparisonoperand1 != operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparisonoperand1 == operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparisonoperand1 >= operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparisonoperand1 > operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparisonoperand1 <= operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparisonoperand1 < operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparisonoperand1 != operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparison with zero== 0succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparison with zero>= 0succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparison with zero> 0succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparison with zero<= 0succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparison with zero< 0succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparison with zero!= 0succeeds.default CodeBuilderGenerates an instruction to branch ifreferenceis notnull.default CodeBuilderGenerates an instruction to branch ifreferenceisnull.default CodeBuilderifThen(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler) Adds an "if-then" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode.default CodeBuilderifThen(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler) Adds an "if-then" block that is conditional on thebooleanvalue on top of the operand stack.default CodeBuilderifThenElse(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler) Adds 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 CodeBuilderifThenElse(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler) Adds an "if-then-else" block that is conditional on thebooleanvalue on top of the operand stack.default CodeBuilderiinc(int slot, int val) Generates an instruction to increment anintlocal variable by a constant.default CodeBuilderiload(int slot) Generates an instruction to load anintfrom a local variable.default CodeBuilderimul()Generates an instruction to multiplyints.default CodeBuilderineg()Generates an instruction to negate anint.default CodeBuilderinstanceOf(ClassEntry target) Generates an instruction to determine if an object is of the given type, producing abooleanresult on the operand stack.default CodeBuilderinstanceOf(ClassDesc target) Generates an instruction to determine if an object is of the given type, producing abooleanresult on the operand stack.default CodeBuilderinvoke(Opcode opcode, MemberRefEntry ref) Generates an instruction to invoke a method.default CodeBuilderinvoke(Opcode opcode, ClassDesc owner, String name, MethodTypeDesc desc, boolean isInterface) Generates an instruction to invoke a method.default CodeBuilderGenerates an instruction to invoke a dynamically-computed call site.default CodeBuilderGenerates an instruction to invoke a dynamically-computed call site.default CodeBuilderGenerates an instruction to invoke an interface method.default CodeBuilderinvokeinterface(ClassDesc owner, String name, MethodTypeDesc type) Generates an instruction to invoke an interface method.default CodeBuilderGenerates an instruction to invoke an instance method in an interface; direct invocation of methods of the current class and its supertypes.default CodeBuilderGenerates an instruction to invoke an instance method in a class; direct invocation of instance initialization methods and methods of the current class and its supertypes.default CodeBuilderinvokespecial(ClassDesc owner, String name, MethodTypeDesc type) Generates an instruction to invoke an instance method in a class; direct invocation of instance initialization methods and methods of the current class and its supertypes.default CodeBuilderinvokespecial(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) Generates an instruction to invoke an instance method; direct invocation of instance initialization methods and methods of the current class and its supertypes.default CodeBuilderGenerates an instruction to invoke a class (static) method of an interface.default CodeBuilderGenerates an instruction to invoke a class (static) method of a class.default CodeBuilderinvokestatic(ClassDesc owner, String name, MethodTypeDesc type) Generates an instruction to invoke a class (static) method of a class.default CodeBuilderinvokestatic(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) Generates an instruction to invoke a class (static) method.default CodeBuilderGenerates an instruction to invoke an instance method; dispatch based on class.default CodeBuilderinvokevirtual(ClassDesc owner, String name, MethodTypeDesc type) Generates an instruction to invoke an instance method; dispatch based on class.default CodeBuilderior()default CodeBuilderirem()Generates an instruction to calculateintsremainder.default CodeBuilderireturn()Generates an instruction to return anintfrom this method.default CodeBuilderishl()Generates an instruction to shift anintleft.default CodeBuilderishr()Generates an instruction to shift anintright.default CodeBuilderistore(int slot) Generates an instruction to store anintinto a local variable.default CodeBuilderisub()Generates an instruction to subtractints.default CodeBuilderiushr()Generates an instruction to logical shift anintright.default CodeBuilderixor()Generates an instruction to calculate bitwise XOR ofints.default CodeBuilderl2d()default CodeBuilderl2f()default CodeBuilderl2i()default CodeBuilderlabelBinding(Label label) Binds a label to the current position.default CodeBuilderladd()Generates an instruction to add twolongs.default CodeBuilderlaload()Generates an instruction to load from alongarray.default CodeBuilderland()Generates an instruction to calculate bitwise AND oflongs.default CodeBuilderlastore()Generates an instruction to store into alongarray.default CodeBuilderlcmp()Generates an instruction to comparelongs.default CodeBuilderlconst_0()Generates an instruction pushinglongconstant 0 onto the operand stack.default CodeBuilderlconst_1()Generates an instruction pushinglongconstant 1 onto the operand stack.default CodeBuilderldc(LoadableConstantEntry entry) Generates an instruction pushing an item from the run-time constant pool onto the operand stack.default CodeBuilderldc(ConstantDesc value) Generates an instruction pushing an item from the run-time constant pool onto the operand stack.default CodeBuilderldiv()Generates an instruction to dividelongs.default CodeBuilderlineNumber(int line) Declares a source line number beginning at the current position.default CodeBuilderlload(int slot) Generates an instruction to load alongfrom a local variable.default CodeBuilderlmul()Generates an instruction to multiplylongs.default CodeBuilderlneg()Generates an instruction to negate along.default CodeBuilderloadConstant(double value) Generates an instruction pushing a constantdoublevalue onto the operand stack.default CodeBuilderloadConstant(float value) Generates an instruction pushing a constantfloatvalue onto the operand stack.default CodeBuilderloadConstant(int value) Generates an instruction pushing a constantintvalue onto the operand stack.default CodeBuilderloadConstant(long value) Generates an instruction pushing a constantlongvalue onto the operand stack.default CodeBuilderloadConstant(ConstantDesc value) Generates an instruction pushing a constant onto the operand stack.default CodeBuilderGenerates an instruction to load a value from a local variable.default CodeBuilderlocalVariable(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry, Label startScope, Label endScope) Declares a local variable entry.default CodeBuilderlocalVariable(int slot, String name, ClassDesc descriptor, Label startScope, Label endScope) Declares a local variable entry.default CodeBuilderlocalVariableType(int slot, Utf8Entry nameEntry, Utf8Entry signatureEntry, Label startScope, Label endScope) Declares a local variable type entry.default CodeBuilderlocalVariableType(int slot, String name, Signature signature, Label startScope, Label endScope) Declares a local variable type entry.default CodeBuilderlookupswitch(Label defaultTarget, List<SwitchCase> cases) Generates an instruction to access a jump table by key match and jump.default CodeBuilderlor()Generates an instruction to calculate bitwise OR oflongs.default CodeBuilderlrem()Generates an instruction to calculatelongsremainder.default CodeBuilderlreturn()Generates an instruction to return alongfrom this method.default CodeBuilderlshl()Generates an instruction to shift alongleft.default CodeBuilderlshr()Generates an instruction to shift alongright.default CodeBuilderlstore(int slot) Generates an instruction to store alonginto a local variable.default CodeBuilderlsub()Generates an instruction to subtractlongs.default CodeBuilderlushr()Generates an instruction to logical shift alongright.default CodeBuilderlxor()Generates an instruction to calculate bitwise XOR oflongs.default CodeBuilderGenerates an instruction to enter monitor for an object.default CodeBuilderGenerates an instruction to exit monitor for an object.default CodeBuildermultianewarray(ClassEntry array, int dims) Generates an instruction to create a new multidimensional array.default CodeBuildermultianewarray(ClassDesc array, int dims) Generates an instruction to create a new multidimensional array.default CodeBuildernew_(ClassEntry clazz) Generates an instruction to create a new object.default CodeBuilderGenerates an instruction to create a new object.default CodeBuilderGenerates an instruction to create a new array of a primitive type.default LabelCreates a new label bound at the current position.newLabel()Returns a fresh unbound label.default CodeBuildernop()Generates a do-nothing instruction.intparameterSlot(int paramNo) Returns the local variable slot associated with the specified parameter.default CodeBuilderpop()Generates an instruction to pop the top operand stack value.default CodeBuilderpop2()Generates an instruction to pop the top one or two operand stack values.default CodeBuilderputfield(FieldRefEntry ref) Generates an instruction to set field in an object.default CodeBuilderGenerates an instruction to set field in an object.default CodeBuilderputstatic(FieldRefEntry ref) Generates an instruction to set static field in a class.default CodeBuilderGenerates an instruction to set static field in a class.intReturns the local variable slot associated with the receiver.default CodeBuilderreturn_()Generates an instruction to returnvoidfrom this method.default CodeBuilderGenerates a return instruction.default CodeBuildersaload()Generates an instruction to load from ashortarray.default CodeBuildersastore()Generates an instruction to store into ashortarray.default CodeBuildersipush(int s) Returns the label associated with the beginning of the current block.default CodeBuilderstoreLocal(TypeKind tk, int slot) Generates an instruction to store a value to a local variable.default CodeBuilderswap()Generates an instruction to swap the top two operand stack values.default CodeBuildertableswitch(int low, int high, Label defaultTarget, List<SwitchCase> cases) Generates an instruction to access a jump table by index and jump.default CodeBuildertableswitch(Label defaultTarget, List<SwitchCase> cases) Generates an instruction to access a jump table by index and jump.default 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.Methods declared in interface Consumer
andThenModifier and TypeMethodDescriptiondefault Consumer<CodeElement> andThen(Consumer<? super CodeElement> after) Returns a composedConsumerthat performs, in sequence, this operation followed by theafteroperation.
-
Method Details
-
breakLabel
Label breakLabel()Returns the label locating where control is passed back to the parent block. A branch to this label "break"'s out of the current block.If the last instruction in this block does not lead to the break label, Class-File API may append instructions to target the "break" label to the built block.
- Returns:
- the label locating where control is passed back to the parent block
-