[英]how to exclude field execution from method executions pointcut with Aspectj
I'd like to capture all method executions. 我想捕获所有方法执行。 So I defined below pointcut and tried to exclude the field access with get/set pointcut designators, but it doesn't work.
因此,我在切入点下面进行了定义,并尝试使用获取/设置切入点指示符排除对字段的访问,但这不起作用。
Any suggestions? 有什么建议么? Thanks a lot.
非常感谢。
pointcut funcExecutionPointcut():execution(* *.*(..)) && !get(* *.*) && !set(* *.*);
before():funcExecutionPointcut() {
//log some info.
Signature sig = thisJoinPointStaticPart.getSignature();
String className = "";
if (thisJoinPoint.getThis() != null)
className = thisJoinPoint.getThis().getClass().getName();
mylogger.log(Level.INFO,"Entering [(" + className + ")" + sig.toShortString() + "] @" + line + "@" +file);
}
The problem is that the output shows that the class's fields are also hit by the pointcut, log like below. 问题在于输出显示该类的字段也被切入点击中,日志如下所示。
2013-09-30 11:39:11:18 Thread-447 INFO AspectJFuncTracing - Entering [()ImageListManager.access$0(..)] @48@ImageListManager.java
2013-09-30 11:39:11:19 Thread-447 INFO AspectJFuncTracing - Entering [()ImageListManager.access$1(..)] @56@ImageListManager.java
The corresponding source code is as below. 相应的源代码如下。
....
public void run() {
while (mThreadBeing) {
try {
sleep(sleeptime);
} catch (Exception e) {
e.printStackTrace();
}
sleeptime = 200;
if (!mThreadBeing) {
break;
}
if (mScrolling) {
continue;
}
...
ImageListManager.access$0 points to the class field mThreadBeing, while ImageListManager.access$1 points to the class field mScrolling. ImageListManager.access $ 0指向类字段mThreadBeing,而ImageListManager.access $ 1指向类字段mScrolling。
Those are the synthetic methods executions, they are created by compiler because, I suppose from what you wrote down, the run() method is inside an inner class of your ImageListManager . 这些是合成方法的执行,它们是由编译器创建的,因为我想从您写下的内容来看 , run()方法位于ImageListManager的内部类内部。 They are in charge of retrieving the values for the first and the second defined field (supposing from the $0 and the $1 after the access).
他们负责检索第一个和第二个定义字段的值(假设从访问后的$ 0和$ 1开始)。
If you want to remove that executions put in you pointcut and and-clause with: 如果您想删除切入点和子句中的执行,请执行以下操作:
!execution(* *.access$*(..))
Hope it helps, 希望能帮助到你,
Dario. 达里奥
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.