是否可以知道AspectJ中的切入点覆盖了哪些方法?
这个问题的背景是我有一个切入点,涵盖了每个方法(除了它自己的方法):
pointcut traceMethods() : (execution(* *(..))&& !cflow(within(MethodTrace)));
我希望能够在应用程序启动后为切入点所涵盖的每个方法创建一个方法签名列表。这可能吗?
答案 0 :(得分:0)
如果我正确理解了您的问题,您可以通过执行上述操作来完成此操作:
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'
}
有关它的更多信息here:
AspectJ提供了一个特殊的引用变量thisKoinPoint 包含有关当前连接点的反射信息 建议使用。 thisJoinPoint变量只能用于 建议的上下文,就像这样只能在上下文中使用 非静态方法和变量初始化器。在建议中,这个加入点 是org.aspectj.lang.JoinPoint
类型的对象