Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AspectJ » Help: how to get calling class for static methods?
Help: how to get calling class for static methods? [message #63046] Sun, 19 March 2006 03:31
Sunfire is currently offline SunfireFriend
Messages: 71
Registered: July 2009
Member
Hello,

I am having trouble in obtaining the caller and callee's classes if a
method call is made within the caller's static method. For example:

public class A
{
public static void call1()
{
B.changeField();
}
}

public class B {
public static void changeField()
{
System.out.println("from B");
}
}

How can I know the caller is class A and the callee is class B? I tried
the following pointcut:

pointcut staticMethodCall() : call(static * *.*(..));

after() : staticMethodCall()
{
Class calleeClass = thisJoinPoint.getSignature().getDeclaringType();

Object caller = thisJoinPoint.getThis();

if (caller == null)

caller = thisJoinPoint.getSourceLocation().getWithinType();
}

Here I used thisJoinPoint.getSignature().getDeclaringType() to obtain the
callee's class. But I am not sure what's the exact meaning of "Signature"
in the context of a method call. Does it always give me the type of the
callee?

For the caller, I used thisJoinPoint.getSourceLocation().getWithinType();
But what if I test a program where no source code is available? Can I
still call thisJoinPoint.getSourceLocation()?

All these seem to work for now but I am really wondering if this is a good
solution. I appreciate any advice and code snippet!

Thank you,

SunnyDay
Previous Topic:How to catch the program termination event?
Next Topic:Help: how to get calling class for static methods?
Goto Forum:
  


Current Time: Fri Apr 26 14:32:00 GMT 2024

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

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

Back to the top