【发布时间】:2017-08-09 09:33:03
【问题描述】:
在我当前的 Android 应用程序中,我正在调查 @AspectJ 的使用情况
我正在尝试将所有执行“捕获”到签名类似的方法:-
public void onMethodClicked(com.example.CustomType customType) {}
我有以下POINTCUTS
1) 忽略我的 Aspect 类:
@Pointcut("!within(com.example.aspect)")
public void notAspect() { }
2) 选择所有带有 customType 参数的“Clicked”方法
@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)))
我做错了什么?
更新
我已通过更正!within() 修复了其中一条错误/警告消息,如下所示:-
1) 忽略我的 Aspect 类:
@Pointcut("!within(com.example.aspect.TraceAspect)")
public void notAspect() { }
【问题讨论】: