[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Pointcuts for Multi-paramter Methods and for Method Control Flow
|
Hi,
> 1) Matching Method Signatures
I think this enhancement request talks to some of what you want to do:
Although not exactly the same, the discussion in there highlights some of the difficulties about getting things right for this language feature. Unfortunately whilst there is a (ugly) workaround we spend effort on other bugs that have no workaround. You can achieve what you want by not matching on the arguments and instead inspecting them all through the thisJoinPoint object in the advice, but I know it would be nicer to do it all in the pointcut declaration.
> 2) Method with Inter-related Objects Pointcut
pointcut whatIWant() : cflowbelow(execution(* *(..)) && read() && write();
Your pointcut says:
"I want to match a joinpoint that is below the control flow of any executing method which is a call to get and a call to set"
No joinpoint will be both a call to set and a call to get so it fails to match.
You can find methods executing within the cflow of a getter:
execution(* *(..)) && cflowbelow(read());
or setter:
execution(* *(..)) && cflowbelow(write());
But you can't describe quite what you want because when your setter is being called the getter has already finished (thinking about the program when it runs). You might write it:
A a = new A();
B b = new B();
a.setSomething(b.getSomethingElse());
but in the generated bytecode it just looks like:
A a = new A();
B b = new B();
Object tmp = b.getSomethingElse();
a.setSomething(tmp);
> In case it is not possible, is there a pattern for observing the call stack within the
> control flow of a certain method?
Either of the pointcuts above will get you some of the way but really even if you inspect the call stack manually (Thread.currentThread().getStackTrace()) whilst advising the setter, you won't see the getter on there.
cheers,
Andy