for special variables available in advice.
------------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());
}
}