I have compiled an example of quick code here: gist.github.com/VijayKrishna/1ca807c952187a7d8c4d , which shows how to use the method adapter through the corresponding visitor / adapter class.
So, you first βcallβ the class adapter (say, from the main method) as follows:
ClassReader cr = new ClassReader(in); ClassWriter cw = new ClassWriter(ClassReader.EXPAND_FRAMES); ReturnAdapter returnAdapter = new ReturnAdapter(cw, className); cr.accept(returnAdapter, 0);
Then follow this by adapting the methods as follows in the class-adapter visitMethod :
public MethodVisitor visitMethod(int access ... ... ... ) { MethodVisitor mv; mv = cv.visitMethod(access, name, desc, signature, exceptions); mv = new MethodReturnAdapter(Opcodes.ASM4, className, access, name, desc, mv); return mv; }
Here is the whole code snippet in case the essence is not available:
public class ReturnAdapter extends ClassVisitor { private String className; public ReturnAdapter(ClassVisitor cv, String className) { super(Opcodes.ASM4, cv); } @Override public MethodVisitor visitMethod( int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv; mv = cv.visitMethod(access, name, desc, signature, exceptions); mv = new MethodReturnAdapter(Opcodes.ASM4, className, access, name, desc, mv); return mv; } public static void main(String[] args) throws IOException { String classFile = args[0];