tags:

views:

44

answers:

1

I have an aspect in my application that intercepts every advice execution on the system. I want to be able to identify which advice is being "intercepted" by my adviceexecution pointcut like this

//... some code in AdviceInspector.aj

    before(): adviceexecution() && !within(AdviceInspector) {
 System.out.println("advice execution being intercepted");
            // TODO : get a way to know which advice execution has been intercepted
}

//... further code

Thanks in advance

A: 

You can get the Signature of the advice from the joinPoint. Signature has various methods to describe it. If it is just for debugging the toString() method describes it nicely

before(): adviceexecution() && !within(AdviceInspector) {
    org.aspectj.lang.Signature sig = thisJoinPoint.getStaticPart().getSignature();
    //It is also valid to do 
    //Signature sig =  thisJoinPointStaticPart.getSignature();
    System.out.println(sig);
}
Rich Seller