org.objectweb.asm.commons

Class AdviceAdapter

public abstract class AdviceAdapter extends GeneratorAdapter implements Opcodes

A MethodAdapter to insert before, after and around advices in methods and constructors.

The behavior for constructors is like this:

  1. as long as the INVOKESPECIAL for the object initialization has not been reached, every bytecode instruction is dispatched in the ctor code visitor
  2. when this one is reached, it is only added in the ctor code visitor and a JP invoke is added
  3. after that, only the other code visitor receives the instructions

Author: Eugene Kuleshov Eric Bruneton

Field Summary
protected intmethodAccess
protected StringmethodDesc
Constructor Summary
protected AdviceAdapter(MethodVisitor mv, int access, String name, String desc)
Creates a new AdviceAdapter.
Method Summary
protected voidonMethodEnter()
Called at the beginning of the method or after super class class call in the constructor.
protected voidonMethodExit(int opcode)
Called before explicit exit from the method using either return or throw.
voidvisitCode()
voidvisitFieldInsn(int opcode, String owner, String name, String desc)
voidvisitInsn(int opcode)
voidvisitIntInsn(int opcode, int operand)
voidvisitJumpInsn(int opcode, Label label)
voidvisitLabel(Label label)
voidvisitLdcInsn(Object cst)
voidvisitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels)
voidvisitMethodInsn(int opcode, String owner, String name, String desc)
voidvisitMultiANewArrayInsn(String desc, int dims)
voidvisitTableSwitchInsn(int min, int max, Label dflt, Label[] labels)
voidvisitTypeInsn(int opcode, String type)
voidvisitVarInsn(int opcode, int var)

Field Detail

methodAccess

protected int methodAccess

methodDesc

protected String methodDesc

Constructor Detail

AdviceAdapter

protected AdviceAdapter(MethodVisitor mv, int access, String name, String desc)
Creates a new AdviceAdapter.

Parameters: mv the method visitor to which this adapter delegates calls. access the method's access flags (see Opcodes). name the method's name. desc the method's descriptor (see Type).

Method Detail

onMethodEnter

protected void onMethodEnter()
Called at the beginning of the method or after super class class call in the constructor.

Custom code can use or change all the local variables, but should not change state of the stack.

onMethodExit

protected void onMethodExit(int opcode)
Called before explicit exit from the method using either return or throw. Top element on the stack contains the return value or exception instance. For example:
   public void onMethodExit(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(int opcode, Object param) {
     ...
 


Custom code can use or change all the local variables, but should not change state of the stack.

Parameters: opcode one of the RETURN, IRETURN, FRETURN, ARETURN, LRETURN, DRETURN or ATHROW

visitCode

public void visitCode()

visitFieldInsn

public void visitFieldInsn(int opcode, String owner, String name, String desc)

visitInsn

public void visitInsn(int opcode)

visitIntInsn

public void visitIntInsn(int opcode, int operand)

visitJumpInsn

public void visitJumpInsn(int opcode, Label label)

visitLabel

public void visitLabel(Label label)

visitLdcInsn

public void visitLdcInsn(Object cst)

visitLookupSwitchInsn

public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels)

visitMethodInsn

public void visitMethodInsn(int opcode, String owner, String name, String desc)

visitMultiANewArrayInsn

public void visitMultiANewArrayInsn(String desc, int dims)

visitTableSwitchInsn

public void visitTableSwitchInsn(int min, int max, Label dflt, Label[] labels)

visitTypeInsn

public void visitTypeInsn(int opcode, String type)

visitVarInsn

public void visitVarInsn(int opcode, int var)