在我当前的Android应用程序中,我正在研究@AspectJ的使用。
我试图“捕获”所有对其签名类似的方法的执行:
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)))我做错了什么?
更新
我已经通过更正!within()修复了其中一个错误/警告消息,如下所示:-
1)忽略我的方面类:
@Pointcut("!within(com.example.aspect.TraceAspect)")
public void notAspect() { }发布于 2017-08-09 21:07:37
我不确定您的问题,但您可以尝试像这样更改POINTCUT。
@Pointcut("!within(com.example.aspect.TraceAspect)")
public void notAspect() { }
@Pointcut("execution(* com.example..*.*Clicked(com.example.CustomType)))
public void customClicked() { }看,我在这里删除了放在@Around注释中的args(custom)部分。当然,我已经删除了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;
}它应该可以正常工作,不会失败。
https://stackoverflow.com/questions/45586836
复制相似问题