2

Is it possible to know which methods are covered with a pointcut in AspectJ?

The background for this question is that I have a pointcut which covers every method (except for its own):

pointcut traceMethods() : (execution(* *(..))&& !cflow(within(MethodTrace)));

I would like be able to created a list of method-signatures for every method covered by the pointcut once the application has started. Is that possible?

dreamcrash
  • 47,137
  • 25
  • 94
  • 117
c_uld
  • 81
  • 1
  • 9

1 Answers1

0

For what you want the following would:

pointcut traceMethods() : (execution(* *(..))&& !cflow(within(MethodTrace)));

before() : traceMethods()
{
     // Holds the signature the method intercepted by the pointcut traceMethods()
     String s = thisJoinPointStaticPart.getSignature().toString();  

     // do something with string 's'
}

More information about it here:

AspectJ provides a special reference variable, thisJoinPoint, that contains reflective information about the current join point for the advice to use. The thisJoinPoint variable can only be used in the context of advice, just like this can only be used in the context of non-static methods and variable initializers. In advice, thisJoinPoint is an object of type org.aspectj.lang.JoinPoint

dreamcrash
  • 47,137
  • 25
  • 94
  • 117