Class CompactCodeAttributeComposer
- java.lang.Object
-
- proguard.classfile.editor.CompactCodeAttributeComposer
-
- All Implemented Interfaces:
AttributeVisitor
public class CompactCodeAttributeComposer extends java.lang.Object implements AttributeVisitor
ThisAttributeVisitor
accumulates instructions, exceptions and line numbers, in a compact and fluent style, and then adds them to a method or copies them into code attributes that it visits.The class supports composing instructions (
appendInstruction(Instruction)
), labels (createLabel()
andlabel(Label)
), exception handlers (catch_(Label, Label, String, Clazz)
), and line numbers (line(int)
).The labels are numeric labels that you can choose freely, for example instruction offsets from existing code that you are copying. You can then refer to them in branches and exception handlers. You can compose the code as a hierarchy of code fragments with their own local labels.
You should provide an estimated maximum size (expressed in number of bytes in the bytecode), so the implementation can efficiently allocate the necessary internal buffers without reallocating them as the code grows.
For example:
ProgramClass programClass = ... ProgramMethod programMethod = ... // Compose the code. CompactCodeAttributeComposer composer = new CompactCodeAttributeComposer(programClass); final Label TRY_START = composer.createLabel(); final Label TRY_END = composer.createLabel(); final Label ELSE = composer.createLabel(); composer .beginCodeFragment(50) .label(TRY_START) .iconst_1() .iconst_2() .ificmplt(ELSE) .iconst_1() .ireturn() .label(ELSE) .iconst_2() .ireturn() .label(TRY_END) .catch_(TRY_START, TRY_END, "java/lang/Exception", null) .iconst_m1() .ireturn() .endCodeFragment(); // Add the code as a code attribute to the given method. composer.addCodeAttribute(programClass, programMethod);
This class is mostly convenient to compose code programmatically from scratch. To compose code based on existing code, where the instructions are already available, see
CodeAttributeComposer
.If you're building many method bodies, it is more efficient to reuse a single instance of this composer for all methods that you add.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
CompactCodeAttributeComposer.Label
This class represents a label to which branch instructions and switch instructions can jump.
-
Constructor Summary
Constructors Constructor Description CompactCodeAttributeComposer(ConstantPoolEditor constantPoolEditor, boolean allowExternalBranchTargets, boolean allowExternalExceptionOffsets, boolean shrinkInstructions)
Creates a new CompactCodeAttributeComposer.CompactCodeAttributeComposer(ConstantPoolEditor constantPoolEditor, CodeAttributeComposer codeAttributeComposer)
Creates a new CompactCodeAttributeComposer.CompactCodeAttributeComposer(ProgramClass targetClass)
Creates a new CompactCodeAttributeComposer that doesn't allow external branch targets or exception offsets and that automatically shrinks instructions.CompactCodeAttributeComposer(ProgramClass targetClass, boolean allowExternalBranchTargets, boolean allowExternalExceptionOffsets, boolean shrinkInstructions)
Creates a new CompactCodeAttributeComposer.CompactCodeAttributeComposer(ProgramClass targetClass, boolean allowExternalBranchTargets, boolean allowExternalExceptionOffsets, boolean shrinkInstructions, ClassPool programClassPool, ClassPool libraryClassPool)
Creates a new CompactCodeAttributeComposer.CompactCodeAttributeComposer(ProgramClass targetClass, ClassPool programClassPool, ClassPool libraryClassPool)
Creates a new CompactCodeAttributeComposer that doesn't allow external branch targets or exception handlers and that automatically shrinks instructions.
-
Method Summary
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface proguard.classfile.attribute.visitor.AttributeVisitor
visitAnnotationDefaultAttribute, visitAnyAnnotationsAttribute, visitAnyParameterAnnotationsAttribute, visitAnyTypeAnnotationsAttribute, visitBootstrapMethodsAttribute, visitConstantValueAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitEnclosingMethodAttribute, visitExceptionsAttribute, visitInnerClassesAttribute, visitLineNumberTableAttribute, visitLocalVariableTableAttribute, visitLocalVariableTypeTableAttribute, visitMethodParametersAttribute, visitModuleAttribute, visitModuleMainClassAttribute, visitModulePackagesAttribute, visitNestHostAttribute, visitNestMembersAttribute, visitPermittedSubclassesAttribute, visitRecordAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleParameterAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeInvisibleTypeAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleParameterAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitRuntimeVisibleTypeAnnotationsAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSourceDebugExtensionAttribute, visitSourceDirAttribute, visitSourceFileAttribute, visitStackMapAttribute, visitStackMapTableAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitUnknownAttribute
-
-
-
-
Constructor Detail
-
CompactCodeAttributeComposer
public CompactCodeAttributeComposer(ProgramClass targetClass)
Creates a new CompactCodeAttributeComposer that doesn't allow external branch targets or exception offsets and that automatically shrinks instructions.- Parameters:
targetClass
- the class to be edited.
-
CompactCodeAttributeComposer
public CompactCodeAttributeComposer(ProgramClass targetClass, ClassPool programClassPool, ClassPool libraryClassPool)
Creates a new CompactCodeAttributeComposer that doesn't allow external branch targets or exception handlers and that automatically shrinks instructions.- Parameters:
targetClass
- the class to be edited.programClassPool
- the program class pool from which new constants can be initialized.libraryClassPool
- the library class pool from which new constants can be initialized.
-
CompactCodeAttributeComposer
public CompactCodeAttributeComposer(ProgramClass targetClass, boolean allowExternalBranchTargets, boolean allowExternalExceptionOffsets, boolean shrinkInstructions)
Creates a new CompactCodeAttributeComposer.- Parameters:
targetClass
- the class to be edited.allowExternalBranchTargets
- specifies whether branch targets can lie outside the code fragment of the branch instructions.allowExternalExceptionOffsets
- specifies whether exception offsets can lie outside the code fragment in which exceptions are defined.shrinkInstructions
- specifies whether instructions should automatically be shrunk before being written.
-
CompactCodeAttributeComposer
public CompactCodeAttributeComposer(ProgramClass targetClass, boolean allowExternalBranchTargets, boolean allowExternalExceptionOffsets, boolean shrinkInstructions, ClassPool programClassPool, ClassPool libraryClassPool)
Creates a new CompactCodeAttributeComposer.- Parameters:
targetClass
- the class to be edited.allowExternalBranchTargets
- specifies whether branch targets can lie outside the code fragment of the branch instructions.allowExternalExceptionOffsets
- specifies whether exception offsets can lie outside the code fragment in which exceptions are defined.shrinkInstructions
- specifies whether instructions should automatically be shrunk before being written.programClassPool
- the program class pool from which new constants can be initialized.libraryClassPool
- the library class pool from which new constants can be initialized.
-
CompactCodeAttributeComposer
public CompactCodeAttributeComposer(ConstantPoolEditor constantPoolEditor, boolean allowExternalBranchTargets, boolean allowExternalExceptionOffsets, boolean shrinkInstructions)
Creates a new CompactCodeAttributeComposer.- Parameters:
constantPoolEditor
- an editor for the constants in the class.allowExternalBranchTargets
- specifies whether branch targets can lie outside the code fragment of the branch instructions.allowExternalExceptionOffsets
- specifies whether exception offsets can lie outside the code fragment in which exceptions are defined.shrinkInstructions
- specifies whether instructions should automatically be shrunk before being written.
-
CompactCodeAttributeComposer
public CompactCodeAttributeComposer(ConstantPoolEditor constantPoolEditor, CodeAttributeComposer codeAttributeComposer)
Creates a new CompactCodeAttributeComposer.- Parameters:
constantPoolEditor
- an editor for the constants in the class.codeAttributeComposer
- an composer for the instructions in the method.
-
-
Method Detail
-
getTargetClass
public ProgramClass getTargetClass()
Returns the target class for which code is generated.
-
getConstantPoolEditor
public ConstantPoolEditor getConstantPoolEditor()
Returns a ConstantPoolEditor instance for the created or edited class instance. Reusing this instance is more efficient for classes that are created from scratch.
-
getCodeLength
public int getCodeLength()
Returns the current length (in bytes) of the code attribute being composed.
-
convertToTargetType
public CompactCodeAttributeComposer convertToTargetType(java.lang.String sourceType, java.lang.String targetType)
Adds the required instructions to the provided CodeAttributeComposer to convert the current value on the stack to the given targetType.
-
boxPrimitiveType
public CompactCodeAttributeComposer boxPrimitiveType(char sourceType)
Box the primitive value present on the stack.Operand stack: ..., primitive -> ..., boxed_primitive
- Parameters:
sourceType
- type of the primitive on the stack.
-
convertPrimitiveType
public CompactCodeAttributeComposer convertPrimitiveType(char source, char target)
Add instructions to convert the primitive on the stack to a different primitive type.- Parameters:
source
- The source type.target
- The target type.
-
unboxPrimitiveType
public CompactCodeAttributeComposer unboxPrimitiveType(java.lang.String sourceType, java.lang.String targetType)
Unbox the object on the stack to a primitive value.Operand stack: ..., boxed_primitive -> ..., primitive
- Parameters:
sourceType
- type of the primitive that should be unboxed.targetType
- resulting type.
-
reset
public CompactCodeAttributeComposer reset()
Starts a new code definition.
-
beginCodeFragment
public CompactCodeAttributeComposer beginCodeFragment(int maximumCodeFragmentLength)
Starts a new code fragment. Branch instructions that are added are assumed to be relative within such code fragments.- Parameters:
maximumCodeFragmentLength
- the maximum length of the code that will be added as part of this fragment (more precisely, the maximum old instruction offset or label that is specified, plus one).- Returns:
- this instance of CompactCodeAttributeComposer.
-
createLabel
public CompactCodeAttributeComposer.Label createLabel()
Creates a new label that can be specified and used in the code.
-
label
public CompactCodeAttributeComposer label(CompactCodeAttributeComposer.Label label)
Appends the given label at the current offset, so branch instructions and switch instructions can jump to it.- Parameters:
label
- the branch label.- Returns:
- this instance of CompactCodeAttributeComposer.
-
appendInstructions
public CompactCodeAttributeComposer appendInstructions(Instruction[] instructions)
Appends the given instruction without defined offsets.- Parameters:
instructions
- the instructions to be appended.- Returns:
- this instance of CompactCodeAttributeComposer.
-
appendInstruction
public CompactCodeAttributeComposer appendInstruction(Instruction instruction)
Appends the given instruction.- Parameters:
instruction
- the instruction to be appended.- Returns:
- this instance of CompactCodeAttributeComposer.
-
catchAll
public CompactCodeAttributeComposer catchAll(CompactCodeAttributeComposer.Label startLabel, CompactCodeAttributeComposer.Label endLabel)
Starts a catch-all handler at the current offset.- Parameters:
startLabel
- the start label of the try block.endLabel
- the end label of the try block.- Returns:
- this instance of CompactCodeAttributeComposer.
-
catchAll
public CompactCodeAttributeComposer catchAll(CompactCodeAttributeComposer.Label startLabel, CompactCodeAttributeComposer.Label endLabel, CompactCodeAttributeComposer.Label handlerLabel)
Adds a catch-all handler.- Parameters:
startLabel
- the start label of the try block.endLabel
- the end label of the try block.handlerLabel
- the label of the exception handler.- Returns:
- this instance of CompactCodeAttributeComposer.
-
catch_
public CompactCodeAttributeComposer catch_(CompactCodeAttributeComposer.Label startLabel, CompactCodeAttributeComposer.Label endLabel, java.lang.String catchType, Clazz referencedClass)
Starts a catch handler at the current offset.- Parameters:
startLabel
- the start label of the try block.endLabel
- the end label of the try block.catchType
- the exception type.referencedClass
- the exception class, if known.- Returns:
- this instance of CompactCodeAttributeComposer.
-
catch_
public CompactCodeAttributeComposer catch_(CompactCodeAttributeComposer.Label startLabel, CompactCodeAttributeComposer.Label endLabel, CompactCodeAttributeComposer.Label handlerLabel, java.lang.String catchType, Clazz referencedClass)
Adds a catch handler.- Parameters:
startLabel
- the start label of the try block.endLabel
- the end label of the try block.handlerLabel
- the label of the exception handler.catchType
- the exception type.referencedClass
- the exception class, if known.- Returns:
- this instance of CompactCodeAttributeComposer.
-
line
public CompactCodeAttributeComposer line(int lineNumber)
Adds a source line number for the current position.- Parameters:
lineNumber
- the line number from the source code.- Returns:
- this instance of CompactCodeAttributeComposer.
-
endCodeFragment
public CompactCodeAttributeComposer endCodeFragment()
Wraps up the current code fragment, continuing with the previous one on the stack.- Returns:
- this instance of CompactCodeAttributeComposer.
-
nop
public CompactCodeAttributeComposer nop()
-
aconst_null
public CompactCodeAttributeComposer aconst_null()
-
iconst
public CompactCodeAttributeComposer iconst(int constant)
-
iconst_m1
public CompactCodeAttributeComposer iconst_m1()
-
iconst_0
public CompactCodeAttributeComposer iconst_0()
-
iconst_1
public CompactCodeAttributeComposer iconst_1()
-
iconst_2
public CompactCodeAttributeComposer iconst_2()
-
iconst_3
public CompactCodeAttributeComposer iconst_3()
-
iconst_4
public CompactCodeAttributeComposer iconst_4()
-
iconst_5
public CompactCodeAttributeComposer iconst_5()
-
lconst
public CompactCodeAttributeComposer lconst(int constant)
-
lconst_0
public CompactCodeAttributeComposer lconst_0()
-
lconst_1
public CompactCodeAttributeComposer lconst_1()
-
fconst
public CompactCodeAttributeComposer fconst(int constant)
-
fconst_0
public CompactCodeAttributeComposer fconst_0()
-
fconst_1
public CompactCodeAttributeComposer fconst_1()
-
fconst_2
public CompactCodeAttributeComposer fconst_2()
-
dconst
public CompactCodeAttributeComposer dconst(int constant)
-
dconst_0
public CompactCodeAttributeComposer dconst_0()
-
dconst_1
public CompactCodeAttributeComposer dconst_1()
-
bipush
public CompactCodeAttributeComposer bipush(int constant)
-
sipush
public CompactCodeAttributeComposer sipush(int constant)
-
ldc
public CompactCodeAttributeComposer ldc(int value)
Appends an ldc instruction that loads an integer constant with the given value.
-
ldc
public CompactCodeAttributeComposer ldc(float value)
Appends an ldc instruction that loads a float constant with the given value.
-
ldc
public CompactCodeAttributeComposer ldc(java.lang.String string)
Appends an ldc instruction that loads a string constant with the given value.
-
ldc
public CompactCodeAttributeComposer ldc(java.lang.Object primitiveArray)
Appends an ldc instruction that loads an (internal) primitive array constant with the given value.
-
ldc
public CompactCodeAttributeComposer ldc(Clazz clazz, Member member)
Appends an ldc instruction that loads a string constant with the given class member name.
-
ldc
public CompactCodeAttributeComposer ldc(java.lang.String string, Clazz referencedClass, Member referencedMember)
Appends an ldc instruction that loads a string constant with the given value, that references the given class member.
-
ldc
public CompactCodeAttributeComposer ldc(ResourceFile resourceFile)
Appends an ldc instruction that loads a string constant with the given resource file name.
-
ldc
public CompactCodeAttributeComposer ldc(java.lang.String string, ResourceFile referencedResourceFile)
Appends an ldc instruction that loads a string constant with the given value, that references the given resource file.
-
ldc
public CompactCodeAttributeComposer ldc(Clazz clazz)
Appends an ldc instruction that loads a class constant for the given class.
-
ldc
public CompactCodeAttributeComposer ldc(java.lang.String typeName, Clazz referencedClass)
Appends an ldc instruction that loads a class constant for the given type name, that references the given class.
-
ldc_
public CompactCodeAttributeComposer ldc_(int constantIndex)
Appends an ldc instruction that loads the constant at the given index.
-
ldc_w
public CompactCodeAttributeComposer ldc_w(int value)
Appends an ldc_w instruction that loads an integer constant with the given value.
-
ldc_w
public CompactCodeAttributeComposer ldc_w(float value)
Appends an ldc_w instruction that loads a float constant with the given value.
-
ldc_w
public CompactCodeAttributeComposer ldc_w(java.lang.String string)
Appends an ldc_w instruction that loads a string constant with the given value.
-
ldc_w
public CompactCodeAttributeComposer ldc_w(java.lang.Object primitiveArray)
Appends an ldc_w instruction that loads an (internal) primitive array constant with the given value.
-
ldc_w
public CompactCodeAttributeComposer ldc_w(Clazz clazz, Member member)
Appends an ldc_w instruction that loads a string constant with the given class member name.
-
ldc_w
public CompactCodeAttributeComposer ldc_w(java.lang.String string, Clazz referencedClass, Member referencedMember)
Appends an ldc_w instruction that loads a string constant with the given value, that references the given class member.
-
ldc_w
public CompactCodeAttributeComposer ldc_w(ResourceFile resourceFile)
Appends an ldc_w instruction that loads a string constant with the given resource file name.
-
ldc_w
public CompactCodeAttributeComposer ldc_w(java.lang.String string, ResourceFile referencedResourceFile)
Appends an ldc_w instruction that loads a string constant with the given value, that references the given resource file.
-
ldc_w
public CompactCodeAttributeComposer ldc_w(Clazz clazz)
Appends an ldc_w instruction that loads a class constant for the given class.
-
ldc_w
public CompactCodeAttributeComposer ldc_w(java.lang.String typeName, Clazz referencedClass)
Appends an ldc_w instruction that loads a class constant for the given type name, that references the given class.
-
ldc_w_
public CompactCodeAttributeComposer ldc_w_(int constantIndex)
Appends an ldc_w instruction that loads the constant at the given index.
-
ldc2_w
public CompactCodeAttributeComposer ldc2_w(long value)
Appends an ldc2_w instruction that loads a long constant with the given value.
-
ldc2_w
public CompactCodeAttributeComposer ldc2_w(double value)
Appends an ldc2_w instruction that loads a double constant with the given value.
-
ldc2_w
public CompactCodeAttributeComposer ldc2_w(int constantIndex)
Appends an ldc2_w instruction that loads the Category 2 constant at the given index.
-
iload
public CompactCodeAttributeComposer iload(int variableIndex)
-
lload
public CompactCodeAttributeComposer lload(int variableIndex)
-
fload
public CompactCodeAttributeComposer fload(int variableIndex)
-
dload
public CompactCodeAttributeComposer dload(int variableIndex)
-
aload
public CompactCodeAttributeComposer aload(int variableIndex)
-
iload_0
public CompactCodeAttributeComposer iload_0()
-
iload_1
public CompactCodeAttributeComposer iload_1()
-
iload_2
public CompactCodeAttributeComposer iload_2()
-
iload_3
public CompactCodeAttributeComposer iload_3()
-
lload_0
public CompactCodeAttributeComposer lload_0()
-
lload_1
public CompactCodeAttributeComposer lload_1()
-
lload_2
public CompactCodeAttributeComposer lload_2()
-
lload_3
public CompactCodeAttributeComposer lload_3()
-
fload_0
public CompactCodeAttributeComposer fload_0()
-
fload_1
public CompactCodeAttributeComposer fload_1()
-
fload_2
public CompactCodeAttributeComposer fload_2()
-
fload_3
public CompactCodeAttributeComposer fload_3()
-
dload_0
public CompactCodeAttributeComposer dload_0()
-
dload_1
public CompactCodeAttributeComposer dload_1()
-
dload_2
public CompactCodeAttributeComposer dload_2()
-
dload_3
public CompactCodeAttributeComposer dload_3()
-
aload_0
public CompactCodeAttributeComposer aload_0()
-
aload_1
public CompactCodeAttributeComposer aload_1()
-
aload_2
public CompactCodeAttributeComposer aload_2()
-
aload_3
public CompactCodeAttributeComposer aload_3()
-
iaload
public CompactCodeAttributeComposer iaload()
-
laload
public CompactCodeAttributeComposer laload()
-
faload
public CompactCodeAttributeComposer faload()
-
daload
public CompactCodeAttributeComposer daload()
-
aaload
public CompactCodeAttributeComposer aaload()
-
baload
public CompactCodeAttributeComposer baload()
-
caload
public CompactCodeAttributeComposer caload()
-
saload
public CompactCodeAttributeComposer saload()
-
istore
public CompactCodeAttributeComposer istore(int variableIndex)
-
lstore
public CompactCodeAttributeComposer lstore(int variableIndex)
-
fstore
public CompactCodeAttributeComposer fstore(int variableIndex)
-
dstore
public CompactCodeAttributeComposer dstore(int variableIndex)
-
astore
public CompactCodeAttributeComposer astore(int variableIndex)
-
istore_0
public CompactCodeAttributeComposer istore_0()
-
istore_1
public CompactCodeAttributeComposer istore_1()
-
istore_2
public CompactCodeAttributeComposer istore_2()
-
istore_3
public CompactCodeAttributeComposer istore_3()
-
lstore_0
public CompactCodeAttributeComposer lstore_0()
-
lstore_1
public CompactCodeAttributeComposer lstore_1()
-
lstore_2
public CompactCodeAttributeComposer lstore_2()
-
lstore_3
public CompactCodeAttributeComposer lstore_3()
-
fstore_0
public CompactCodeAttributeComposer fstore_0()
-
fstore_1
public CompactCodeAttributeComposer fstore_1()
-
fstore_2
public CompactCodeAttributeComposer fstore_2()
-
fstore_3
public CompactCodeAttributeComposer fstore_3()
-
dstore_0
public CompactCodeAttributeComposer dstore_0()
-
dstore_1
public CompactCodeAttributeComposer dstore_1()
-
dstore_2
public CompactCodeAttributeComposer dstore_2()
-
dstore_3
public CompactCodeAttributeComposer dstore_3()
-
astore_0
public CompactCodeAttributeComposer astore_0()
-
astore_1
public CompactCodeAttributeComposer astore_1()
-
astore_2
public CompactCodeAttributeComposer astore_2()
-
astore_3
public CompactCodeAttributeComposer astore_3()
-
iastore
public CompactCodeAttributeComposer iastore()
-
lastore
public CompactCodeAttributeComposer lastore()
-
fastore
public CompactCodeAttributeComposer fastore()
-
dastore
public CompactCodeAttributeComposer dastore()
-
aastore
public CompactCodeAttributeComposer aastore()
-
bastore
public CompactCodeAttributeComposer bastore()
-
castore
public CompactCodeAttributeComposer castore()
-
sastore
public CompactCodeAttributeComposer sastore()
-
pop
public CompactCodeAttributeComposer pop()
-
pop2
public CompactCodeAttributeComposer pop2()
-
dup
public CompactCodeAttributeComposer dup()
-
dup_x1
public CompactCodeAttributeComposer dup_x1()
-
dup_x2
public CompactCodeAttributeComposer dup_x2()
-
dup2
public CompactCodeAttributeComposer dup2()
-
dup2_x1
public CompactCodeAttributeComposer dup2_x1()
-
dup2_x2
public CompactCodeAttributeComposer dup2_x2()
-
swap
public CompactCodeAttributeComposer swap()
-
iadd
public CompactCodeAttributeComposer iadd()
-
ladd
public CompactCodeAttributeComposer ladd()
-
fadd
public CompactCodeAttributeComposer fadd()
-
dadd
public CompactCodeAttributeComposer dadd()
-
isub
public CompactCodeAttributeComposer isub()
-
lsub
public CompactCodeAttributeComposer lsub()
-
fsub
public CompactCodeAttributeComposer fsub()
-
dsub
public CompactCodeAttributeComposer dsub()
-
imul
public CompactCodeAttributeComposer imul()
-
lmul
public CompactCodeAttributeComposer lmul()
-
fmul
public CompactCodeAttributeComposer fmul()
-
dmul
public CompactCodeAttributeComposer dmul()
-
idiv
public CompactCodeAttributeComposer idiv()
-
ldiv
public CompactCodeAttributeComposer ldiv()
-
fdiv
public CompactCodeAttributeComposer fdiv()
-
ddiv
public CompactCodeAttributeComposer ddiv()
-
irem
public CompactCodeAttributeComposer irem()
-
lrem
public CompactCodeAttributeComposer lrem()
-
frem
public CompactCodeAttributeComposer frem()
-
drem
public CompactCodeAttributeComposer drem()
-
ineg
public CompactCodeAttributeComposer ineg()
-
lneg
public CompactCodeAttributeComposer lneg()
-
fneg
public CompactCodeAttributeComposer fneg()
-
dneg
public CompactCodeAttributeComposer dneg()
-
ishl
public CompactCodeAttributeComposer ishl()
-
lshl
public CompactCodeAttributeComposer lshl()
-
ishr
public CompactCodeAttributeComposer ishr()
-
lshr
public CompactCodeAttributeComposer lshr()
-
iushr
public CompactCodeAttributeComposer iushr()
-
lushr
public CompactCodeAttributeComposer lushr()
-
iand
public CompactCodeAttributeComposer iand()
-
land
public CompactCodeAttributeComposer land()
-
ior
public CompactCodeAttributeComposer ior()
-
lor
public CompactCodeAttributeComposer lor()
-
ixor
public CompactCodeAttributeComposer ixor()
-
lxor
public CompactCodeAttributeComposer lxor()
-
iinc
public CompactCodeAttributeComposer iinc(int variableIndex, int constant)
-
i2l
public CompactCodeAttributeComposer i2l()
-
i2f
public CompactCodeAttributeComposer i2f()
-
i2d
public CompactCodeAttributeComposer i2d()
-
l2i
public CompactCodeAttributeComposer l2i()
-
l2f
public CompactCodeAttributeComposer l2f()
-
l2d
public CompactCodeAttributeComposer l2d()
-
f2i
public CompactCodeAttributeComposer f2i()
-
f2l
public CompactCodeAttributeComposer f2l()
-
f2d
public CompactCodeAttributeComposer f2d()
-
d2i
public CompactCodeAttributeComposer d2i()
-
d2l
public CompactCodeAttributeComposer d2l()
-
d2f
public CompactCodeAttributeComposer d2f()
-
i2b
public CompactCodeAttributeComposer i2b()
-
i2c
public CompactCodeAttributeComposer i2c()
-
i2s
public CompactCodeAttributeComposer i2s()
-
lcmp
public CompactCodeAttributeComposer lcmp()
-
fcmpl
public CompactCodeAttributeComposer fcmpl()
-
fcmpg
public CompactCodeAttributeComposer fcmpg()
-
dcmpl
public CompactCodeAttributeComposer dcmpl()
-
dcmpg
public CompactCodeAttributeComposer dcmpg()
-
ifeq
public CompactCodeAttributeComposer ifeq(CompactCodeAttributeComposer.Label branchLabel)
-
ifne
public CompactCodeAttributeComposer ifne(CompactCodeAttributeComposer.Label branchLabel)
-
iflt
public CompactCodeAttributeComposer iflt(CompactCodeAttributeComposer.Label branchLabel)
-
ifge
public CompactCodeAttributeComposer ifge(CompactCodeAttributeComposer.Label branchLabel)
-
ifgt
public CompactCodeAttributeComposer ifgt(CompactCodeAttributeComposer.Label branchLabel)
-
ifle
public CompactCodeAttributeComposer ifle(CompactCodeAttributeComposer.Label branchLabel)
-
ificmpeq
public CompactCodeAttributeComposer ificmpeq(CompactCodeAttributeComposer.Label branchLabel)
-
ificmpne
public CompactCodeAttributeComposer ificmpne(CompactCodeAttributeComposer.Label branchLabel)
-
ificmplt
public CompactCodeAttributeComposer ificmplt(CompactCodeAttributeComposer.Label branchLabel)
-
ificmpge
public CompactCodeAttributeComposer ificmpge(CompactCodeAttributeComposer.Label branchLabel)
-
ificmpgt
public CompactCodeAttributeComposer ificmpgt(CompactCodeAttributeComposer.Label branchLabel)
-
ificmple
public CompactCodeAttributeComposer ificmple(CompactCodeAttributeComposer.Label branchLabel)
-
ifacmpeq
public CompactCodeAttributeComposer ifacmpeq(CompactCodeAttributeComposer.Label branchLabel)
-
ifacmpne
public CompactCodeAttributeComposer ifacmpne(CompactCodeAttributeComposer.Label branchLabel)
-
goto_
public CompactCodeAttributeComposer goto_(CompactCodeAttributeComposer.Label branchLabel)
-
jsr
public CompactCodeAttributeComposer jsr(CompactCodeAttributeComposer.Label branchLabel)
-
ret
public CompactCodeAttributeComposer ret(int variableIndex)
-
tableswitch
public CompactCodeAttributeComposer tableswitch(CompactCodeAttributeComposer.Label defaultLabel, int lowCase, int highCase, CompactCodeAttributeComposer.Label[] jumpLabels)
-
lookupswitch
public CompactCodeAttributeComposer lookupswitch(CompactCodeAttributeComposer.Label defaultLabel, int[] cases, CompactCodeAttributeComposer.Label[] jumpLabels)
-
ireturn
public CompactCodeAttributeComposer ireturn()
-
lreturn
public CompactCodeAttributeComposer lreturn()
-
freturn
public CompactCodeAttributeComposer freturn()
-
dreturn
public CompactCodeAttributeComposer dreturn()
-
areturn
public CompactCodeAttributeComposer areturn()
-
return_
public CompactCodeAttributeComposer return_()
-
getstatic
public CompactCodeAttributeComposer getstatic(Clazz clazz, Field field)
-
getstatic
public CompactCodeAttributeComposer getstatic(java.lang.String className, java.lang.String name, java.lang.String descriptor)
-
getstatic
public CompactCodeAttributeComposer getstatic(java.lang.String className, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Field referencedField)
-
getstatic
public CompactCodeAttributeComposer getstatic(int constantIndex)
-
putstatic
public CompactCodeAttributeComposer putstatic(Clazz referencedClass, Field referencedField)
-
putstatic
public CompactCodeAttributeComposer putstatic(java.lang.String className, java.lang.String name, java.lang.String descriptor)
-
putstatic
public CompactCodeAttributeComposer putstatic(java.lang.String className, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Field referencedField)
-
putstatic
public CompactCodeAttributeComposer putstatic(int constantIndex)
-
getfield
public CompactCodeAttributeComposer getfield(Clazz clazz, Field field)
-
getfield
public CompactCodeAttributeComposer getfield(java.lang.String className, java.lang.String name, java.lang.String descriptor)
-
getfield
public CompactCodeAttributeComposer getfield(java.lang.String className, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Field referencedField)
-
getfield
public CompactCodeAttributeComposer getfield(int constantIndex)
-
putfield
public CompactCodeAttributeComposer putfield(Clazz clazz, Field field)
-
putfield
public CompactCodeAttributeComposer putfield(java.lang.String className, java.lang.String name, java.lang.String descriptor)
-
putfield
public CompactCodeAttributeComposer putfield(java.lang.String className, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Field referencedField)
-
putfield
public CompactCodeAttributeComposer putfield(int constantIndex)
-
invokevirtual
public CompactCodeAttributeComposer invokevirtual(Clazz clazz, Method method)
-
invokevirtual
public CompactCodeAttributeComposer invokevirtual(java.lang.String className, java.lang.String name, java.lang.String descriptor)
-
invokevirtual
public CompactCodeAttributeComposer invokevirtual(java.lang.String className, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Method referencedMethod)
-
invokevirtual
public CompactCodeAttributeComposer invokevirtual(int constantIndex)
-
invokespecial
public CompactCodeAttributeComposer invokespecial(Clazz clazz, Method method)
-
invokespecial
public CompactCodeAttributeComposer invokespecial(java.lang.String className, java.lang.String name, java.lang.String descriptor)
-
invokespecial
public CompactCodeAttributeComposer invokespecial(java.lang.String className, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Method referencedMethod)
-
invokespecial
public CompactCodeAttributeComposer invokespecial(int constantIndex)
-
invokestatic
public CompactCodeAttributeComposer invokestatic(Clazz clazz, Method method)
-
invokestatic
public CompactCodeAttributeComposer invokestatic(java.lang.String className, java.lang.String name, java.lang.String descriptor)
-
invokestatic
public CompactCodeAttributeComposer invokestatic(java.lang.String className, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Method referencedMethod)
-
invokestatic_interface
public CompactCodeAttributeComposer invokestatic_interface(Clazz clazz, Method method)
-
invokestatic_interface
public CompactCodeAttributeComposer invokestatic_interface(java.lang.String className, java.lang.String name, java.lang.String descriptor)
-
invokestatic_interface
public CompactCodeAttributeComposer invokestatic_interface(java.lang.String className, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Method referencedMethod)
-
invokestatic
public CompactCodeAttributeComposer invokestatic(int constantIndex)
-
invokeinterface
public CompactCodeAttributeComposer invokeinterface(Clazz clazz, Method method)
-
invokeinterface
public CompactCodeAttributeComposer invokeinterface(java.lang.String className, java.lang.String name, java.lang.String descriptor)
-
invokeinterface
public CompactCodeAttributeComposer invokeinterface(java.lang.String className, java.lang.String name, java.lang.String descriptor, Clazz referencedClass, Method referencedMethod)
-
invokeinterface
public CompactCodeAttributeComposer invokeinterface(int constantIndex, int constant)
-
invokedynamic
public CompactCodeAttributeComposer invokedynamic(int bootStrapMethodIndex, java.lang.String name, java.lang.String descriptor, Clazz[] referencedClasses)
-
invokedynamic
public CompactCodeAttributeComposer invokedynamic(int constantIndex)
-
new_
public CompactCodeAttributeComposer new_(Clazz clazz)
-
new_
public CompactCodeAttributeComposer new_(java.lang.String className)
-
new_
public CompactCodeAttributeComposer new_(java.lang.String className, Clazz referencedClass)
-
new_
public CompactCodeAttributeComposer new_(int constantIndex)
-
newarray
public CompactCodeAttributeComposer newarray(int constant)
-
anewarray
public CompactCodeAttributeComposer anewarray(java.lang.String className, Clazz referencedClass)
-
anewarray
public CompactCodeAttributeComposer anewarray(int constantIndex)
-
arraylength
public CompactCodeAttributeComposer arraylength()
-
athrow
public CompactCodeAttributeComposer athrow()
-
checkcast
public CompactCodeAttributeComposer checkcast(java.lang.String className)
-
checkcast
public CompactCodeAttributeComposer checkcast(java.lang.String className, Clazz referencedClass)
-
checkcast
public CompactCodeAttributeComposer checkcast(int constantIndex)
-
instanceof_
public CompactCodeAttributeComposer instanceof_(java.lang.String className, Clazz referencedClass)
-
instanceof_
public CompactCodeAttributeComposer instanceof_(int constantIndex)
-
monitorenter
public CompactCodeAttributeComposer monitorenter()
-
monitorexit
public CompactCodeAttributeComposer monitorexit()
-
wide
public CompactCodeAttributeComposer wide()
-
multianewarray
public CompactCodeAttributeComposer multianewarray(java.lang.String className, Clazz referencedClass, int dimensions)
-
multianewarray
public CompactCodeAttributeComposer multianewarray(int constantIndex, int dimensions)
-
ifnull
public CompactCodeAttributeComposer ifnull(CompactCodeAttributeComposer.Label branchLabel)
-
ifnonnull
public CompactCodeAttributeComposer ifnonnull(CompactCodeAttributeComposer.Label branchLabel)
-
goto_w
public CompactCodeAttributeComposer goto_w(CompactCodeAttributeComposer.Label branchLabel)
-
jsr_w
public CompactCodeAttributeComposer jsr_w(CompactCodeAttributeComposer.Label branchLabel)
-
pushPrimitive
public CompactCodeAttributeComposer pushPrimitive(java.lang.Object primitive, char internalType)
Pushes the given primitive value on the stack.Operand stack: ... -> ..., value
- Parameters:
primitive
- the primitive value to be pushed - should never be null.internalType
- the internal type of the primitive ('Z','B','I',...)
-
pushInt
public CompactCodeAttributeComposer pushInt(int value)
Pushes the given primitive int on the stack in the most efficient way (as an iconst, bipush, sipush, or ldc instruction).- Parameters:
value
- the int value to be pushed.
-
pushFloat
public CompactCodeAttributeComposer pushFloat(float value)
Pushes the given primitive float on the stack in the most efficient way (as an fconst or ldc instruction).- Parameters:
value
- the float value to be pushed.
-
pushLong
public CompactCodeAttributeComposer pushLong(long value)
Pushes the given primitive long on the stack in the most efficient way (as an lconst or ldc instruction).- Parameters:
value
- the long value to be pushed.
-
pushDouble
public CompactCodeAttributeComposer pushDouble(double value)
Pushes the given primitive double on the stack in the most efficient way (as a dconst or ldc instruction).- Parameters:
value
- the double value to be pushed.
-
pushNewArray
public CompactCodeAttributeComposer pushNewArray(java.lang.String elementTypeOrClassName, int size)
Pushes a new array on the stack.Operand stack: ... -> ..., array
- Parameters:
elementTypeOrClassName
- the array element type (or class name in case of objects).size
- the size of the array to be created.
-
load
public CompactCodeAttributeComposer load(int variableIndex, java.lang.String internalType)
Loads the given variable onto the stack.Operand stack: ... -> ..., value
- Parameters:
variableIndex
- the index of the variable to be loaded.internalType
- the type of the variable to be loaded.
-
load
public CompactCodeAttributeComposer load(int variableIndex, char internalType)
Loads the given variable of primitive type onto the stack.Operand stack: ... -> ..., value
- Parameters:
variableIndex
- the index of the variable to be loaded.internalType
- the primitive type of the variable to be loaded.
-
store
public CompactCodeAttributeComposer store(int variableIndex, java.lang.String internalType)
Stores the value on top of the stack in the variable with given index.Operand stsack: ..., value -> ...
- Parameters:
variableIndex
- the index of the variable where to store the value.internalType
- the type of the value to be stored.
-
store
public CompactCodeAttributeComposer store(int variableIndex, char internalType)
Stores the primitve value on top of the stack in the variable with given index.Operand stack: ..., value -> ...
- Parameters:
variableIndex
- the index of the variable where to store the value.internalType
- the primitive type of the value to be stored.
-
storeToArray
public CompactCodeAttributeComposer storeToArray(java.lang.String elementType)
Stores an element to an array.Operand stack: ..., array, index, value -> ...
- Parameters:
elementType
- the type of the value to be stored.
-
return_
public CompactCodeAttributeComposer return_(java.lang.String internalType)
Appends the proper return statement for the given internal type.- Parameters:
internalType
- the return type.
-
appendPrintIntegerInstructions
public CompactCodeAttributeComposer appendPrintIntegerInstructions(java.lang.String message)
Appends instructions to print out the given message and the top int on the stack.
-
appendPrintIntegerHexInstructions
public CompactCodeAttributeComposer appendPrintIntegerHexInstructions(java.lang.String message)
Appends instructions to print out the given message and the top int on the stack as a hexadecimal value.
-
appendPrintLongInstructions
public CompactCodeAttributeComposer appendPrintLongInstructions(java.lang.String message)
Appends instructions to print out the given message and the top long on the stack.
-
appendPrintStringInstructions
public CompactCodeAttributeComposer appendPrintStringInstructions(java.lang.String message)
Appends instructions to print out the given message and the top String on the stack.
-
appendPrintObjectInstructions
public CompactCodeAttributeComposer appendPrintObjectInstructions(java.lang.String message)
Appends instructions to print out the given message and the top Object on the stack.
-
appendPrintStackTraceInstructions
public CompactCodeAttributeComposer appendPrintStackTraceInstructions(java.lang.String message)
Appends instructions to print out the given message and the stack trace of the top Throwable on the stack.
-
appendPrintInstructions
public CompactCodeAttributeComposer appendPrintInstructions(java.lang.String message)
Appends instructions to print out the given message.
-
appendPrintIntegerInstructions
public CompactCodeAttributeComposer appendPrintIntegerInstructions()
Appends instructions to print out the top int on the stack.
-
appendPrintIntegerHexInstructions
public CompactCodeAttributeComposer appendPrintIntegerHexInstructions()
Appends instructions to print out the top integer on the stack as a hexadecimal value.
-
appendPrintLongInstructions
public CompactCodeAttributeComposer appendPrintLongInstructions()
Appends instructions to print out the top long on the stack.
-
appendPrintStringInstructions
public CompactCodeAttributeComposer appendPrintStringInstructions()
Appends instructions to print out the top String on the stack.
-
appendPrintObjectInstructions
public CompactCodeAttributeComposer appendPrintObjectInstructions()
Appends instructions to print out the top Object on the stack.
-
appendPrintStackTraceInstructions
public CompactCodeAttributeComposer appendPrintStackTraceInstructions()
Appends instructions to print out the stack trace of the top Throwable on the stack.
-
addCodeAttribute
public void addCodeAttribute(ProgramClass programClass, ProgramMethod programMethod)
Adds the code that has been built as a code attribute to the given method.
-
visitAnyAttribute
public void visitAnyAttribute(Clazz clazz, Attribute attribute)
Description copied from interface:AttributeVisitor
Visits any Attribute instance. The more specific default implementations of this interface delegate to this method.- Specified by:
visitAnyAttribute
in interfaceAttributeVisitor
-
visitCodeAttribute
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
Sets the code that has been built in the given code attribute.- Specified by:
visitCodeAttribute
in interfaceAttributeVisitor
-
main
public static void main(java.lang.String[] args)
Small sample application that illustrates the use of this class.
-
-