开发者

Define a pointcut on a member access and function call

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


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:

A a = b.a;
a.foo();

or even

public void fooA(A aToFoo) { aToFoo.foo(); }

public void whatever(B someB) { fooA(someB.a); }


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜