定义成员访问和函数调用的切入点
这很难解释,但我想在 AspectJ 中定义一个像这样的函数调用的切入点:
public class B{
public A a;
}
public class A{
public void foo(){...}
}
并且切入点应该拦截以下调用:
B.a.foo();
我仍然没有弄清楚如何做到这一点(如果有的话) 。你们有什么想法吗?
提前致谢
it's quite hard to explain but I want to define in AspectJ a pointcut upon the call of a function like this:
public class B{
public A a;
}
public class A{
public void foo(){...}
}
and the pointcut should intercept the following call:
B.a.foo();
I still haven't figured out the way to do it (if there is any). Does any of you have any idea?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我自己也是 AspectJ 新手,但我感觉这是不可能的。即使您设计了一个与
Bafoo()
匹配的切入点,您仍然必须以某种方式处理以下情况:或者甚至
I'm an AspectJ newbie myself too, but I get the feeling this isn't possible. Even if you devised a pointcut that matched
B.a.foo()
, you'd still have to somehow handle the following case:or even
您可以定义一个切入点来捕获对公共字段的任何引用,但据我所知,您无法创建一个将字段引用与对该引用的方法调用相结合的切入点。
You can define a pointcut that traps any reference to the public field, but AFAIK you can't create one that combines a field reference with a method call on that reference.
正如其他人提到的,这在 AspectJ 中是不可能的。然而,AspectJ 的一些研究扩展引入了跟踪切入,这是一种新的切入点,能够完全满足您的要求。我不认为有任何实现可以用于生产,但您可能有兴趣阅读它。一篇好论文在这里:
http://lsmr.cpsc.ucalgary.ca /papers/walker-fse-2004.pdf
As others have mentioned, this is not possible in AspectJ. However, there are some research extensions of AspectJ that introduce tracecuts, which are a new kind of pointcut capable of doing exactly what you are asking. I do not believe that there are any implementations that are production ready, but you may be interested in reading up about it. A good paper is here:
http://lsmr.cpsc.ucalgary.ca/papers/walker-fse-2004.pdf