[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Why is this call also matched?
|
Hi,
Today I got a chance to try the solution provided by Adrian on Mar. 24. This solution worked fine. Then I changed it a little bit to monitor all calls with such patterns. Here I am listing the code and aspect.
public class A
{
B b = new B();
public static void call1(B b)
{
C c = new C();
c.call2(b);
}
public void call2()
{
call1(b);
}
}
public class C
{
public void call3(B b)
{
b.changeField();
}
public static void main(String[] args)
{
A a1 = new A();
a1.call2();
}
}
pointcut staticCalledFromInstance(Object caller) :
call(static * *.*(..)) && this(caller);
pointcut calledFromWithinStaticInCflowOfInstance(Object caller) :
call(* *.* (..)) && cflow(staticCalledFromInstance(caller));
before(Object caller) : calledFromWithinStaticInCflowOfInstance(caller)
{
System.out.println(caller.getClass().getName());
}
What confuses me is that the call a1.call2() in main is also advised by the pointcut calledFromWithinStaticInCflowOfInstance (there is an advice marker next to this statement). I did not expect this call to be advised since it is not in the control flow of call1(b);
which is matched by staticCalledFromInstance pointcut. Could someone explain why this is the case?
Thank you very much!
Sunny