2016-09-28 58 views
0

如何解决一个“无法找到符号变量thisJoinPoint”,而试图在AndroidStudio中使用注释样式构建一个AspectJ项目?无法找到符号变量thisJoinPoint

平台详细信息:AspectJ的1.8.1,2.1.3 AndroidStudio

代码示例:

import org.aspectj.lang.JoinPoint.*;   // Not used! 
import org.aspectj.lang.ProceedingJoinPoint; // Not used! 
import org.aspectj.lang.annotation.After; 
import org.aspectj.lang.annotation.Pointcut; 

@Aspect 
public class MyAspect { 
    @Pointcut("execution(* *(..))") 
    public void methodExecution() {} 

    @After("methodExecution()") 
    public void accessThisJoinPointData() { 
     if (thisJointPoint != null) { // HERE the variable isn’t recognized! 
      // Do something with thisJoinPoint... 
     } 
    } 
} 

回答

0

一些试验和研究后,我刚发现,标注样式,我们需要声明thisJoinPoint作为建议的参数。所以,问题如下解决:

@After("methodExecution()") 
    public void accessThisJoinPointData(JoinPoint thisJoinPoint) { 
     if (thisJointPoint != null) { // Now the variable can be recognized! 
      // Do something with thisJoinPoint... 
     } 
} 

参考:

“如果咨询机构需要访问thisJoinPoint,thisJoinPointStaticPart,thisEnclosingJoinPointStaticPart那么这些需要使用注释风格时,被声明为额外的方法参数。 “

https://eclipse.org/aspectj/doc/released/adk15notebook/ataspectj-pcadvice.html

相关问题