Package org.objectweb.asm.commons
Class AdviceAdapter
- java.lang.Object
-
- org.objectweb.asm.MethodVisitor
-
- org.objectweb.asm.commons.LocalVariablesSorter
-
- org.objectweb.asm.commons.GeneratorAdapter
-
- org.objectweb.asm.commons.AdviceAdapter
-
- All Implemented Interfaces:
org.objectweb.asm.Opcodes
public abstract class AdviceAdapter extends GeneratorAdapter implements org.objectweb.asm.Opcodes
AMethodVisitorto insert before, after and around advices in methods and constructors. For constructors, the code keeps track of the elements on the stack in order to detect when the super class constructor is called (note that there can be multiple such calls in different branches).onMethodEnteris called after each super class constructor call, because the object cannot be used before it is properly initialized.- Author:
- Eugene Kuleshov, Eric Bruneton
-
-
Field Summary
Fields Modifier and Type Field Description protected intmethodAccessThe access flags of the visited method.protected java.lang.StringmethodDescThe descriptor of the visited method.-
Fields inherited from class org.objectweb.asm.commons.GeneratorAdapter
ADD, AND, DIV, EQ, GE, GT, LE, LT, MUL, NE, NEG, OR, REM, SHL, SHR, SUB, USHR, XOR
-
Fields inherited from class org.objectweb.asm.commons.LocalVariablesSorter
firstLocal, nextLocal
-
Fields inherited from interface org.objectweb.asm.Opcodes
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_MANDATED, ACC_MODULE, ACC_NATIVE, ACC_OPEN, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STATIC_PHASE, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_TRANSITIVE, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASM4, ASM5, ASM6, ASM7, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, H_GETFIELD, H_GETSTATIC, H_INVOKEINTERFACE, H_INVOKESPECIAL, H_INVOKESTATIC, H_INVOKEVIRTUAL, H_NEWINVOKESPECIAL, H_PUTFIELD, H_PUTSTATIC, 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, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INTEGER, INVOKEDYNAMIC, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, V_PREVIEW, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7, V1_8, V10, V11, V12, V9
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAdviceAdapter(int api, org.objectweb.asm.MethodVisitor methodVisitor, int access, java.lang.String name, java.lang.String descriptor)Constructs a newAdviceAdapter.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidonMethodEnter()Generates the "before" advice for the visited method.protected voidonMethodExit(int opcode)Generates the "after" advice for the visited method.voidvisitCode()voidvisitFieldInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String descriptor)voidvisitInsn(int opcode)voidvisitIntInsn(int opcode, int operand)voidvisitInvokeDynamicInsn(java.lang.String name, java.lang.String descriptor, org.objectweb.asm.Handle bootstrapMethodHandle, java.lang.Object... bootstrapMethodArguments)voidvisitJumpInsn(int opcode, org.objectweb.asm.Label label)voidvisitLabel(org.objectweb.asm.Label label)voidvisitLdcInsn(java.lang.Object value)voidvisitLookupSwitchInsn(org.objectweb.asm.Label dflt, int[] keys, org.objectweb.asm.Label[] labels)voidvisitMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String descriptor)Deprecated.voidvisitMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String descriptor, boolean isInterface)voidvisitMultiANewArrayInsn(java.lang.String descriptor, int numDimensions)voidvisitTableSwitchInsn(int min, int max, org.objectweb.asm.Label dflt, org.objectweb.asm.Label... labels)voidvisitTryCatchBlock(org.objectweb.asm.Label start, org.objectweb.asm.Label end, org.objectweb.asm.Label handler, java.lang.String type)voidvisitTypeInsn(int opcode, java.lang.String type)voidvisitVarInsn(int opcode, int var)-
Methods inherited from class org.objectweb.asm.commons.GeneratorAdapter
arrayLength, arrayLoad, arrayStore, box, cast, catchException, checkCast, dup, dup2, dup2X1, dup2X2, dupX1, dupX2, endMethod, getAccess, getArgumentTypes, getField, getLocalType, getName, getReturnType, getStatic, goTo, ifCmp, ifICmp, ifNonNull, ifNull, ifZCmp, iinc, instanceOf, invokeConstructor, invokeDynamic, invokeInterface, invokeStatic, invokeVirtual, loadArg, loadArgArray, loadArgs, loadArgs, loadLocal, loadLocal, loadThis, mark, mark, math, monitorEnter, monitorExit, newArray, newInstance, newLabel, not, pop, pop2, push, push, push, push, push, push, push, push, push, putField, putStatic, ret, returnValue, setLocalType, storeArg, storeLocal, storeLocal, swap, swap, tableSwitch, tableSwitch, throwException, throwException, unbox, valueOf
-
Methods inherited from class org.objectweb.asm.commons.LocalVariablesSorter
newLocal, newLocalMapping, updateNewLocals, visitFrame, visitIincInsn, visitLocalVariable, visitLocalVariableAnnotation, visitMaxs
-
-
-
-
Constructor Detail
-
AdviceAdapter
protected AdviceAdapter(int api, org.objectweb.asm.MethodVisitor methodVisitor, int access, java.lang.String name, java.lang.String descriptor)Constructs a newAdviceAdapter.- Parameters:
api- the ASM API version implemented by this visitor. Must be one ofOpcodes.ASM4,Opcodes.ASM5,Opcodes.ASM6orOpcodes.ASM7.methodVisitor- the method visitor to which this adapter delegates calls.access- the method's access flags (seeOpcodes).name- the method's name.descriptor- the method's descriptor (seeType).
-
-
Method Detail
-
visitCode
public void visitCode()
- Overrides:
visitCodein classorg.objectweb.asm.MethodVisitor
-
visitLabel
public void visitLabel(org.objectweb.asm.Label label)
- Overrides:
visitLabelin classorg.objectweb.asm.MethodVisitor
-
visitInsn
public void visitInsn(int opcode)
- Overrides:
visitInsnin classorg.objectweb.asm.MethodVisitor
-
visitVarInsn
public void visitVarInsn(int opcode, int var)- Overrides:
visitVarInsnin classLocalVariablesSorter
-
visitFieldInsn
public void visitFieldInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String descriptor)- Overrides:
visitFieldInsnin classorg.objectweb.asm.MethodVisitor
-
visitIntInsn
public void visitIntInsn(int opcode, int operand)- Overrides:
visitIntInsnin classorg.objectweb.asm.MethodVisitor
-
visitLdcInsn
public void visitLdcInsn(java.lang.Object value)
- Overrides:
visitLdcInsnin classorg.objectweb.asm.MethodVisitor
-
visitMultiANewArrayInsn
public void visitMultiANewArrayInsn(java.lang.String descriptor, int numDimensions)- Overrides:
visitMultiANewArrayInsnin classorg.objectweb.asm.MethodVisitor
-
visitTypeInsn
public void visitTypeInsn(int opcode, java.lang.String type)- Overrides:
visitTypeInsnin classorg.objectweb.asm.MethodVisitor
-
visitMethodInsn
@Deprecated public void visitMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String descriptor)Deprecated.Deprecated.- Overrides:
visitMethodInsnin classorg.objectweb.asm.MethodVisitor
-
visitMethodInsn
public void visitMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String descriptor, boolean isInterface)- Overrides:
visitMethodInsnin classorg.objectweb.asm.MethodVisitor
-
visitInvokeDynamicInsn
public void visitInvokeDynamicInsn(java.lang.String name, java.lang.String descriptor, org.objectweb.asm.Handle bootstrapMethodHandle, java.lang.Object... bootstrapMethodArguments)- Overrides:
visitInvokeDynamicInsnin classorg.objectweb.asm.MethodVisitor
-
visitJumpInsn
public void visitJumpInsn(int opcode, org.objectweb.asm.Label label)- Overrides:
visitJumpInsnin classorg.objectweb.asm.MethodVisitor
-
visitLookupSwitchInsn
public void visitLookupSwitchInsn(org.objectweb.asm.Label dflt, int[] keys, org.objectweb.asm.Label[] labels)- Overrides:
visitLookupSwitchInsnin classorg.objectweb.asm.MethodVisitor
-
visitTableSwitchInsn
public void visitTableSwitchInsn(int min, int max, org.objectweb.asm.Label dflt, org.objectweb.asm.Label... labels)- Overrides:
visitTableSwitchInsnin classorg.objectweb.asm.MethodVisitor
-
visitTryCatchBlock
public void visitTryCatchBlock(org.objectweb.asm.Label start, org.objectweb.asm.Label end, org.objectweb.asm.Label handler, java.lang.String type)- Overrides:
visitTryCatchBlockin classorg.objectweb.asm.MethodVisitor
-
onMethodEnter
protected void onMethodEnter()
Generates the "before" advice for the visited method. The default implementation of this method does nothing. Subclasses can use or change all the local variables, but should not change state of the stack. This method is called at the beginning of the method or after super class constructor has been called (in constructors).
-
onMethodExit
protected void onMethodExit(int opcode)
Generates the "after" advice for the visited method. The default implementation of this method does nothing. Subclasses can use or change all the local variables, but should not change state of the stack. This method is called at the end of the method, just before return and athrow instructions. The top element on the stack contains the return value or the exception instance. For example:public void onMethodExit(final int opcode) { if (opcode == RETURN) { visitInsn(ACONST_NULL); } else if (opcode == ARETURN || opcode == ATHROW) { dup(); } else { if (opcode == LRETURN || opcode == DRETURN) { dup2(); } else { dup(); } box(Type.getReturnType(this.methodDesc)); } visitIntInsn(SIPUSH, opcode); visitMethodInsn(INVOKESTATIC, owner, "onExit", "(Ljava/lang/Object;I)V"); } // An actual call back method. public static void onExit(final Object exitValue, final int opcode) { ... }- Parameters:
opcode- one ofOpcodes.RETURN,Opcodes.IRETURN,Opcodes.FRETURN,Opcodes.ARETURN,Opcodes.LRETURN,Opcodes.DRETURNorOpcodes.ATHROW.
-
-