Distinguishing between different access modifiers for a method in the MethodVisitor

Aniket Panse <[email protected]> Mon, 26 Feb 2018 18:43:18 -0600
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <CAKpTao9DGAsojT3kkzxrYPbFea9Wx_-6nMCbUYb_pFNDMYGCeg@mail.gmail.com>
Hello List!

I'm trying to call a function before every "synchronized" method, but I'm
having trouble with it.

Say I have a class like so:

public class HelloWorld {
  public static void main() {
    myMethod();
  }
  public synchronized myMethod() {
    System.out.println("Hello World!");
  }
}

I'd like to print something out every time a synchronized method is called.
So I write a MethodAdaptor:

public class MethodAdapter extends MethodVisitor {
  @Override
  public void visitMethodInsn(int opcode, String owner, String name, String
desc, boolean itf) {
    // I'll add a call to System.out.println() here
    // but how do I know whether this method is synchronized??
  }
}

I realize that the class visitor does have access to the method's
modifiers, but how do I make that information available to the
MethodAdapter?

Thanks!
-- Aniket


-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws