public class InstructionAdapter extends MethodVisitor
MethodVisitor providing a more detailed API to generate and transform instructions.| Modifier and Type | Field and Description |
|---|---|
static Type |
OBJECT_TYPE
The type of the java.lang.Object class.
|
api, mv| Modifier | Constructor and Description |
|---|---|
protected |
InstructionAdapter(int api,
MethodVisitor methodVisitor)
Constructs a new
InstructionAdapter. |
|
InstructionAdapter(MethodVisitor methodVisitor)
Constructs a new
InstructionAdapter. |
| Modifier and Type | Method and Description |
|---|---|
void |
aconst(java.lang.Object value)
Generates the instruction to push the given value on the stack.
|
void |
add(Type type) |
void |
aload(Type type) |
void |
and(Type type) |
void |
anew(Type type) |
void |
areturn(Type type) |
void |
arraylength() |
void |
astore(Type type) |
void |
athrow() |
void |
cast(Type from,
Type to)
Generates the instruction to cast from the first given type to the other.
|
void |
cconst(ConstantDynamic constantDynamic)
Generates the instruction to push the given constant dynamic on the stack.
|
void |
checkcast(Type type) |
void |
cmpg(Type type) |
void |
cmpl(Type type) |
void |
dconst(double doubleValue)
Generates the instruction to push the given value on the stack.
|
void |
div(Type type) |
void |
dup() |
void |
dup2() |
void |
dup2X1() |
void |
dup2X2() |
void |
dupX1() |
void |
dupX2() |
void |
fconst(float floatValue)
Generates the instruction to push the given value on the stack.
|
void |
getfield(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor) |
void |
getstatic(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor) |
void |
goTo(Label label) |
void |
hconst(Handle handle)
Generates the instruction to push the given handle on the stack.
|
void |
iconst(int intValue)
Generates the instruction to push the given value on the stack.
|
void |
ifacmpeq(Label label) |
void |
ifacmpne(Label label) |
void |
ifeq(Label label) |
void |
ifge(Label label) |
void |
ifgt(Label label) |
void |
ificmpeq(Label label) |
void |
ificmpge(Label label) |
void |
ificmpgt(Label label) |
void |
ificmple(Label label) |
void |
ificmplt(Label label) |
void |
ificmpne(Label label) |
void |
ifle(Label label) |
void |
iflt(Label label) |
void |
ifne(Label label) |
void |
ifnonnull(Label label) |
void |
ifnull(Label label) |
void |
iinc(int var,
int increment) |
void |
instanceOf(Type type) |
void |
invokedynamic(java.lang.String name,
java.lang.String descriptor,
Handle bootstrapMethodHandle,
java.lang.Object[] bootstrapMethodArguments)
Generates the instruction to call the given dynamic method.
|
void |
invokeinterface(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
Generates the instruction to call the given interface method.
|
void |
invokespecial(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
Deprecated.
use
invokespecial(String, String, String, boolean) instead. |
void |
invokespecial(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor,
boolean isInterface)
Generates the instruction to call the given special method.
|
void |
invokestatic(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
Deprecated.
use
invokestatic(String, String, String, boolean) instead. |
void |
invokestatic(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor,
boolean isInterface)
Generates the instruction to call the given static method.
|
void |
invokevirtual(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
Deprecated.
use
invokevirtual(String, String, String, boolean) instead. |
void |
invokevirtual(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor,
boolean isInterface)
Generates the instruction to call the given virtual method.
|
void |
jsr(Label label) |
void |
lcmp() |
void |
lconst(long longValue)
Generates the instruction to push the given value on the stack.
|
void |
load(int var,
Type type) |
void |
lookupswitch(Label dflt,
int[] keys,
Label[] labels) |
void |
mark(Label label) |
void |
monitorenter() |
void |
monitorexit() |
void |
mul(Type type) |
void |
multianewarray(java.lang.String descriptor,
int numDimensions) |
void |
neg(Type type) |
void |
newarray(Type type)
Generates the instruction to create and push on the stack an array of the given type.
|
void |
nop()
Generates a nop instruction.
|
void |
or(Type type) |
void |
pop() |
void |
pop2() |
void |
putfield(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor) |
void |
putstatic(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor) |
void |
rem(Type type) |
void |
ret(int var) |
void |
shl(Type type) |
void |
shr(Type type) |
void |
store(int var,
Type type) |
void |
sub(Type type) |
void |
swap() |
void |
tableswitch(int min,
int max,
Label dflt,
Label... labels) |
void |
tconst(Type type)
Generates the instruction to push the given type on the stack.
|
void |
ushr(Type type) |
void |
visitFieldInsn(int opcode,
java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
Visits a field instruction.
|
void |
visitIincInsn(int var,
int increment)
Visits an IINC instruction.
|
void |
visitInsn(int opcode)
Visits a zero operand instruction.
|
void |
visitIntInsn(int opcode,
int operand)
Visits an instruction with a single int operand.
|
void |
visitInvokeDynamicInsn(java.lang.String name,
java.lang.String descriptor,
Handle bootstrapMethodHandle,
java.lang.Object... bootstrapMethodArguments)
Visits an invokedynamic instruction.
|
void |
visitJumpInsn(int opcode,
Label label)
Visits a jump instruction.
|
void |
visitLabel(Label label)
Visits a label.
|
void |
visitLdcInsn(java.lang.Object value)
Visits a LDC instruction.
|
void |
visitLookupSwitchInsn(Label dflt,
int[] keys,
Label[] labels)
Visits a LOOKUPSWITCH instruction.
|
void |
visitMethodInsn(int opcodeAndSource,
java.lang.String owner,
java.lang.String name,
java.lang.String descriptor,
boolean isInterface)
Visits a method instruction.
|
void |
visitMultiANewArrayInsn(java.lang.String descriptor,
int numDimensions)
Visits a MULTIANEWARRAY instruction.
|
void |
visitTableSwitchInsn(int min,
int max,
Label dflt,
Label... labels)
Visits a TABLESWITCH instruction.
|
void |
visitTypeInsn(int opcode,
java.lang.String type)
Visits a type instruction.
|
void |
visitVarInsn(int opcode,
int var)
Visits a local variable instruction.
|
void |
xor(Type type) |
visitAnnotableParameterCount, visitAnnotation, visitAnnotationDefault, visitAttribute, visitCode, visitEnd, visitFrame, visitInsnAnnotation, visitLineNumber, visitLocalVariable, visitLocalVariableAnnotation, visitMaxs, visitMethodInsn, visitParameter, visitParameterAnnotation, visitTryCatchAnnotation, visitTryCatchBlock, visitTypeAnnotationpublic static final Type OBJECT_TYPE
public InstructionAdapter(MethodVisitor methodVisitor)
InstructionAdapter. Subclasses must not use this constructor.
Instead, they must use the InstructionAdapter(int, MethodVisitor) version.methodVisitor - the method visitor to which this adapter delegates calls.java.lang.IllegalStateException - If a subclass calls this constructor.protected InstructionAdapter(int api,
MethodVisitor methodVisitor)
InstructionAdapter.api - the ASM API version implemented by this visitor. Must be one of Opcodes.ASM4, Opcodes.ASM5, Opcodes.ASM6, Opcodes.ASM7, Opcodes.ASM8 or Opcodes.ASM9.methodVisitor - the method visitor to which this adapter delegates calls.public void visitInsn(int opcode)
MethodVisitorvisitInsn in class MethodVisitoropcode - the opcode of the instruction to be visited. This opcode is either NOP,
ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5,
LCONST_0, LCONST_1, FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD,
FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE, DASTORE,
AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2,
SWAP, IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV,
FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR,
LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I,
D2L, D2F, I2B, I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, FRETURN,
DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER, or MONITOREXIT.public void visitIntInsn(int opcode,
int operand)
MethodVisitorvisitIntInsn in class MethodVisitoropcode - the opcode of the instruction to be visited. This opcode is either BIPUSH, SIPUSH
or NEWARRAY.operand - the operand of the instruction to be visited.Opcodes.T_BOOLEAN, Opcodes.T_CHAR, Opcodes.T_FLOAT, Opcodes.T_DOUBLE, Opcodes.T_BYTE,
Opcodes.T_SHORT, Opcodes.T_INT or Opcodes.T_LONG.public void visitVarInsn(int opcode,
int var)
MethodVisitorvisitVarInsn in class MethodVisitoropcode - the opcode of the local variable instruction to be visited. This opcode is either
ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.var - the operand of the instruction to be visited. This operand is the index of a local
variable.public void visitTypeInsn(int opcode,
java.lang.String type)
MethodVisitorvisitTypeInsn in class MethodVisitoropcode - the opcode of the type instruction to be visited. This opcode is either NEW,
ANEWARRAY, CHECKCAST or INSTANCEOF.type - the operand of the instruction to be visited. This operand must be the internal
name of an object or array class (see Type.getInternalName()).public void visitFieldInsn(int opcode,
java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
MethodVisitorvisitFieldInsn in class MethodVisitoropcode - the opcode of the type instruction to be visited. This opcode is either
GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.owner - the internal name of the field's owner class (see Type.getInternalName()).name - the field's name.descriptor - the field's descriptor (see Type).public void visitMethodInsn(int opcodeAndSource,
java.lang.String owner,
java.lang.String name,
java.lang.String descriptor,
boolean isInterface)
MethodVisitorvisitMethodInsn in class MethodVisitoropcodeAndSource - the opcode of the type instruction to be visited. This opcode is either
INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE.owner - the internal name of the method's owner class (see Type.getInternalName()).name - the method's name.descriptor - the method's descriptor (see Type).isInterface - if the method's owner class is an interface.public void visitInvokeDynamicInsn(java.lang.String name,
java.lang.String descriptor,
Handle bootstrapMethodHandle,
java.lang.Object... bootstrapMethodArguments)
MethodVisitorvisitInvokeDynamicInsn in class MethodVisitorname - the method's name.descriptor - the method's descriptor (see Type).bootstrapMethodHandle - the bootstrap method.bootstrapMethodArguments - the bootstrap method constant arguments. Each argument must be
an Integer, Float, Long, Double, String, Type, Handle or ConstantDynamic value. This method is allowed to modify
the content of the array so a caller should expect that this array may change.public void visitJumpInsn(int opcode,
Label label)
MethodVisitorvisitJumpInsn in class MethodVisitoropcode - the opcode of the type instruction to be visited. This opcode is either IFEQ,
IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT,
IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.label - the operand of the instruction to be visited. This operand is a label that
designates the instruction to which the jump instruction may jump.public void visitLabel(Label label)
MethodVisitorvisitLabel in class MethodVisitorlabel - a Label object.public void visitLdcInsn(java.lang.Object value)
MethodVisitor
if (cst instanceof Integer) {
// ...
} else if (cst instanceof Float) {
// ...
} else if (cst instanceof Long) {
// ...
} else if (cst instanceof Double) {
// ...
} else if (cst instanceof String) {
// ...
} else if (cst instanceof Type) {
int sort = ((Type) cst).getSort();
if (sort == Type.OBJECT) {
// ...
} else if (sort == Type.ARRAY) {
// ...
} else if (sort == Type.METHOD) {
// ...
} else {
// throw an exception
}
} else if (cst instanceof Handle) {
// ...
} else if (cst instanceof ConstantDynamic) {
// ...
} else {
// throw an exception
}
visitLdcInsn in class MethodVisitorvalue - the constant to be loaded on the stack. This parameter must be a non null Integer, a Float, a Long, a Double, a String, a Type of OBJECT or ARRAY sort for .class constants, for classes whose version is
49, a Type of METHOD sort for MethodType, a Handle for MethodHandle
constants, for classes whose version is 51 or a ConstantDynamic for a constant
dynamic for classes whose version is 55.public void visitIincInsn(int var,
int increment)
MethodVisitorvisitIincInsn in class MethodVisitorvar - index of the local variable to be incremented.increment - amount to increment the local variable by.public void visitTableSwitchInsn(int min,
int max,
Label dflt,
Label... labels)
MethodVisitorvisitTableSwitchInsn in class MethodVisitormin - the minimum key value.max - the maximum key value.dflt - beginning of the default handler block.labels - beginnings of the handler blocks. labels[i] is the beginning of the
handler block for the min + i key.public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels)
MethodVisitorvisitLookupSwitchInsn in class MethodVisitordflt - beginning of the default handler block.keys - the values of the keys.labels - beginnings of the handler blocks. labels[i] is the beginning of the
handler block for the keys[i] key.public void visitMultiANewArrayInsn(java.lang.String descriptor,
int numDimensions)
MethodVisitorvisitMultiANewArrayInsn in class MethodVisitordescriptor - an array type descriptor (see Type).numDimensions - the number of dimensions of the array to allocate.public void nop()
public void aconst(java.lang.Object value)
value - the constant to be pushed on the stack. This parameter must be an Integer,
a Float, a Long, a Double, a String, a Type of
OBJECT or ARRAY sort for .class constants, for classes whose version is 49, a
Type of METHOD sort for MethodType, a Handle for MethodHandle constants,
for classes whose version is 51 or a ConstantDynamic for a constant dynamic for
classes whose version is 55.public void iconst(int intValue)
intValue - the constant to be pushed on the stack.public void lconst(long longValue)
longValue - the constant to be pushed on the stack.public void fconst(float floatValue)
floatValue - the constant to be pushed on the stack.public void dconst(double doubleValue)
doubleValue - the constant to be pushed on the stack.public void tconst(Type type)
type - the type to be pushed on the stack.public void hconst(Handle handle)
handle - the handle to be pushed on the stack.public void cconst(ConstantDynamic constantDynamic)
constantDynamic - the constant dynamic to be pushed on the stack.public void load(int var,
Type type)
public void aload(Type type)
public void store(int var,
Type type)
public void astore(Type type)
public void pop()
public void pop2()
public void dup()
public void dup2()
public void dupX1()
public void dupX2()
public void dup2X1()
public void dup2X2()
public void swap()
public void add(Type type)
public void sub(Type type)
public void mul(Type type)
public void div(Type type)
public void rem(Type type)
public void neg(Type type)
public void shl(Type type)
public void shr(Type type)
public void ushr(Type type)
public void and(Type type)
public void or(Type type)
public void xor(Type type)
public void iinc(int var,
int increment)
public void cast(Type from, Type to)
from - a Type.to - a Type.public void lcmp()
public void cmpl(Type type)
public void cmpg(Type type)
public void ifeq(Label label)
public void ifne(Label label)
public void iflt(Label label)
public void ifge(Label label)
public void ifgt(Label label)
public void ifle(Label label)
public void ificmpeq(Label label)
public void ificmpne(Label label)
public void ificmplt(Label label)
public void ificmpge(Label label)
public void ificmpgt(Label label)
public void ificmple(Label label)
public void ifacmpeq(Label label)
public void ifacmpne(Label label)
public void goTo(Label label)
public void jsr(Label label)
public void ret(int var)
public void areturn(Type type)
public void getstatic(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
public void putstatic(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
public void getfield(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
public void putfield(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
@Deprecated
public void invokevirtual(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
invokevirtual(String, String, String, boolean) instead.owner - the internal name of the method's owner class.name - the method's name.descriptor - the method's descriptor (see Type).public void invokevirtual(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor,
boolean isInterface)
owner - the internal name of the method's owner class (see Type.getInternalName()).name - the method's name.descriptor - the method's descriptor (see Type).isInterface - if the method's owner class is an interface.@Deprecated
public void invokespecial(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
invokespecial(String, String, String, boolean) instead.owner - the internal name of the method's owner class.name - the method's name.descriptor - the method's descriptor (see Type).public void invokespecial(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor,
boolean isInterface)
owner - the internal name of the method's owner class (see Type.getInternalName()).name - the method's name.descriptor - the method's descriptor (see Type).isInterface - if the method's owner class is an interface.@Deprecated
public void invokestatic(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
invokestatic(String, String, String, boolean) instead.owner - the internal name of the method's owner class.name - the method's name.descriptor - the method's descriptor (see Type).public void invokestatic(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor,
boolean isInterface)
owner - the internal name of the method's owner class (see Type.getInternalName()).name - the method's name.descriptor - the method's descriptor (see Type).isInterface - if the method's owner class is an interface.public void invokeinterface(java.lang.String owner,
java.lang.String name,
java.lang.String descriptor)
owner - the internal name of the method's owner class (see Type.getInternalName()).name - the method's name.descriptor - the method's descriptor (see Type).public void invokedynamic(java.lang.String name,
java.lang.String descriptor,
Handle bootstrapMethodHandle,
java.lang.Object[] bootstrapMethodArguments)
name - the method's name.descriptor - the method's descriptor (see Type).bootstrapMethodHandle - the bootstrap method.bootstrapMethodArguments - the bootstrap method constant arguments. Each argument must be
an Integer, Float, Long, Double, String, Type, Handle or ConstantDynamic value. This method is allowed to modify
the content of the array so a caller should expect that this array may change.public void anew(Type type)
public void newarray(Type type)
type - an array Type.public void arraylength()
public void athrow()
public void checkcast(Type type)
public void instanceOf(Type type)
public void monitorenter()
public void monitorexit()
public void multianewarray(java.lang.String descriptor,
int numDimensions)
public void ifnull(Label label)
public void ifnonnull(Label label)
public void mark(Label label)