2016-09-28 111 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

相關問題