Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home »  » AJDT » How to capture a caller in an aspect
How to capture a caller in an aspect [message #645412] Fri, 17 December 2010 07:55 Go to next message
Jingang Zhou is currently offline Jingang ZhouFriend
Messages: 57
Registered: December 2010
Member
I want to use an aspect to track methods invoke, e.g., on ClassA's foo() method, if any class invokes this method, I will print "Class XXXX invoked foo.", however, I don't know how to get the class XXXX 's infomation, how to do it?

Thanks.

[Updated on: Fri, 17 December 2010 07:58]

Report message to a moderator

Re: How to capture a caller in an aspect [message #645529 is a reply to message #645412] Fri, 17 December 2010 16:43 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
You could use the this() pointcut. for example:

before(Object o) : call(public void ClassA.foo()) && this (o) {
  System.out.println("Class " + o.getClass());
}


But, the only way this will work is if the call sites themselves are woven. This means that the classes that call foo() must be sent through the weaver.
Re: How to capture a caller in an aspect [message #645698 is a reply to message #645529] Mon, 20 December 2010 02:44 Go to previous messageGo to next message
Jingang Zhou is currently offline Jingang ZhouFriend
Messages: 57
Registered: December 2010
Member
Thank you Andrew.

Such a constrain is not feasible in our scenario, so do you have any better ideas?

Thanks.
Re: How to capture a caller in an aspect [message #645703 is a reply to message #645698] Mon, 20 December 2010 04:06 Go to previous message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
No. If you are not weaving call sites, then there is no way to determine the calling type. It's possible that you could use load time weaving for this, however. But, I would recommend against trying load time weaving on JDK classes (it may be possible in some situations, but is really, really tricky).
Previous Topic:Problem with "Eclipse-SupplementBundle: *"
Next Topic:64-Bit Installation Problem
Goto Forum:
  


Current Time: Sun Dec 17 00:35:01 GMT 2017

Powered by FUDForum. Page generated in 0.02051 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software