Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] How to track a caller

Hi there. You can get information about the calling method using thisEnclosingJoinPointStaticPart. The docs don’t say much about it although it has been elaborated on in past on this mailing list.

 

 


From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Java guru
Sent: Friday, September 08, 2006 9:44 AM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] How to track a caller

 

Hi

 I have a situation where I need to get the information about the calling method.

 

By calling method I mean, the method from which a call to another method is made, which satisfies a pointcut def. I am providing an example below

 

pointcut interceptGetStament(): call(public String getTest(*));

 

 String around() : interceptGetStament(){
        MethodSignature sig = (MethodSignature) thisJoinPoint.getSignature();
        System.out.println(thisJoinPoint.getSignature().getName());
         return thisJoinPoint.getSignature ().getName();
    }

 

 

public class Test {
   
    public String getTest(String s)
    {
        return s;
    }
    
 }

 

public class Test1 {
    public static void main(String[] args) {
        Test t  = new Test();
        System.out.println(t.getTest("hellow"));
    }
}

 

Now when I run Test1, i need to printout the method which calls getTest(), in this case its "main".But what I am getting is "getTest" as it is the joinPoint. How do I go about it?

 

 


Back to the top