Re: Distinguishing between different access modifiers for a method in the MethodVisitor

Aniket Panse <[email protected]> Mon, 26 Feb 2018 18:55:10 -0600
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
I think I've figured out a way, I'll reply on this mail thread if it works, in case someone is looking for this in the future.

⁣Sent from BlueMail ​

On Feb 26, 2018, 6:48 PM, at 6:48 PM, Aniket Panse <[email protected]> wrote:
>Ah, I did that. It seems that it's the MethodVisitor of the _calling_
>method that calls the visitMethodInsn().
>
>In the example above, the MethodVisitor for "main()" would be calling
>visitMethodInsn().
>
>On Mon, Feb 26, 2018 at 6:45 PM, Eugene Kuleshov <[email protected]>
>wrote:
>
>> You can pass access flags from class visitor to method visitor when
>> the latter is created.
>>
>>
>>
>> On Mon, Feb 26, 2018 at 7:43 PM, Aniket Panse <[email protected]>
>> wrote:
>> > 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
>> >
>>


-- 
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