Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Re: aspectj-users Digest, Vol 13, Issue 63

Hi,
 
Suppose I have three classes A, B, and C (C is omitted here), where the static method call1 can access an instance field passed by a non-static method call2. Also suppose there is a pointcut that catches all method calls. Now when the call: c.call2(b) is intercepted, I can obtain the callee object which is referenced by c, also I can only get the caller's TYPE which is class A (since the method call is made within a static context). My question is the following:
 
given the argument b obtained in the advice associated with the above pointcut, how can I know whether the object referenced by b is actually the object that is referenced by a field in class A? In other words, I would like to know whether A's object is passing its field b into C's object or not.
 
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);
       }
}
 
I tried Java reflection to check if one of A's fields references b (by calling Field.get(Object obj) == b). This won't work if the field is an instance field because in this case the method requires an enclosing object as argument. But how can I get the caller's object?
 
Thanks a lot for any idea!
 
SunnyDay

Back to the top