2017-08-09 33 views
0

在我目前的Android應用程序,我調查使用的@AspectJ的Android AspectJ的@Around與方法ARGS不工作

我試圖「捕捉」所有執行到的簽名方法類似: -

public void onMethodClicked(com.example.CustomType customType) {} 

我有以下POINTCUTS

1)忽略我的看點類:

@Pointcut("!within(com.example.aspect)") 
public void notAspect() { } 

2)選擇與customType參數

@Pointcut("execution(* com.example..*.*Clicked(com.example.CustomType)) && args(custom)";) 
public void customClicked(CustomType custom) { } 

3)我@Around所有 「點擊」 方法: -

@Around("notAspect() && customClicked()") 
public Object selectedClicked(final ProceedingJoinPoint joinPoint, CustomType custom) throws Throwable { 
    Log.d(TAG, "Found a clicked method " + custom); 
    Object result = joinPoint.proceed(); 

    return result; 
} 

當我建立我的Android應用程序,我得到這些消息

no match for this type name: CustomType [Xlint:invalidAbsoluteTypeName] 

bad parameter to pointcut reference 
formal unbound in pointcut 

no match for this type name: com.example.aspect [Xlint:invalidAbsoluteTypeName] 

the parameter custom is not bound in [all branches of] pointcut 
use of ProceedingJoinPoint is allowed only on around advice (arg 1 in (before(extraFlags: 2): (((!within(com.example.aspect+) && execution(* com.example..*.*Clicked(com.example.CustomType)) && args(custom)) && persingleton(com.example.aspect.TraceAspect))->void com.example.aspect.TraceAspect.selectedClicked(org.aspectj.lang.JoinPoint, com.example.CustomType))) 

我做錯了什麼?

UPDATE

我有固定的錯誤之一/通過糾正!within()如下警告信息: -

1)忽略我的看點類:

@Pointcut("!within(com.example.aspect.TraceAspect)") 
public void notAspect() { } 

回答

2

我不知道關於你的問題,但你可以嘗試改變這樣的POINTCUT

@Pointcut("!within(com.example.aspect.TraceAspect)") 
public void notAspect() { } 

@Pointcut("execution(* com.example..*.*Clicked(com.example.CustomType))) 
public void customClicked() { } 

看我已經刪除了args(custom)一部分這裏哪去了@Around註釋裏面。是的,當然我已經刪除了函數customClicked的函數參數參數,並且在語句結尾處刪除了分號。

現在通過從這裏傳遞參數來編寫你的selectedClicked函數。

@Around("notAspect() && customClicked() && args(custom)") 
public Object selectedClicked(final ProceedingJoinPoint joinPoint, CustomType custom) throws Throwable { 

    Log.d(TAG, "Found a clicked method " + custom); 
    Object result = joinPoint.proceed(); 

    return result; 
} 

它應該沒有失敗。

+1

不錯的工作!這固定我的問題,雖然我不得不刪除「pointcut =」fronte圍繞諮詢 – Hector

+0

很高興知道幫助! :) –

相關問題