Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Newbie question: how to get caller method name

Title: Newbie question: how to get caller method name
In this case, you can try the special variable available in advice,
"thisEnclosingJoinPointStaticPart"; the signature has the name of the method
(for enclosing method-execution join points).  See the API documentation
for the StaticPart class, and the ProgrammingGuide and quick reference
for special variables available in advice.
 
Hope this helps -
Wes
 
 
------------Original Message------------
From: "Larry Zhou" <lzhou@xxxxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Date: Thu, Sep-9-2004 6:31 PM
Subject: [aspectj-users] Newbie question: how to get caller method name

Hi,

I have two java files A.java and B.java, there is a call from A:methodA to B:methodB.
Throught reflection, I can get the names of A, B and methodB.

Please see the source code below. I run them this way.
C> ajc *.java
C> java A


But how can I get the method name of caller in aspect code? In this case, it is methodA.

Thanks,

Larry

------------------------ A.java -------------------------------
public class A {

    void methodA()
    {
        B b = new B();
        b.methodB();
    }

    public static void main(String[] args)
    {
        A a = new A();
        a.methodA();
    }
}
-------------------------B.java ------------------------------
public class B {
    void methodB()
    {
        System.out.println("B:methodB");

    }
}
----------------------- MyAspect.java ---------------------------------
public aspect MyAspect {

    pointcut invokeB() : call(void *.methodB());

    before() : invokeB()
    {
        if ( thisJoinPoint.getThis() != null) {
            System.out.println("getThis()=" + thisJoinPoint.getThis());
        }
        if ( thisJoinPoint.getTarget() != null) {
            System.out.println("getTarget()=" + thisJoinPoint.getTarget());
        }
        System.out.println("toLongString()=" + thisJoinPoint.toLongString());
    }
}


Back to the top