Skip to main content

[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: 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=233718

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



On 13 December 2012 05:21, Helge <ropf@xxxxxx> wrote:
Dear all,

I am Helge and I am new to this list. I have two questions on the pointcut
language or better on how to formulate two specific pointcuts in case they
can be formulated at all.

1) Matching Method Signatures

I would like to describe all method execution join points where the method's
signature contains arbitrary parameters of which at least two are of certain
types. The order of the parameters of this type is not important. For
example:

m1(A a, B b), m2(B b, A a), m3(A a, B b, A aa), m4(T1 t1, T2 t2, T3 t3, A a,
T4 t4, B b, T5 t5), m5(T1 t1, B b, T2 t2, A a, T3 t3, B bb, T4 t4)

should all be matched by the pointcut, but

m6(A a), m7(B b, B bb), m8(T1 t1, B b, T2 t2), ...

should not be matched.

For the case of exactly two parameters of the corresponding types I can
formulate a pointcut such as:

     pointcut findMethod(A a, B b) : execution(* *(.., A, .., B, ..)) &&
args(a,b,..);

But obviously this pointcut considers the order of the parameters of type A
and B. I would have to 'or' another execution(* *(.., B, .., A, ..)) to make
it order independent. My problem is now how to incorporate more than two
parameters of corresponding types? I am imagining something like:

     pointcut findMethod(Collection  a, Collection b) : execution(* *(any(A,
B)+) && args(a,b,..);

Where the collection is ordered to the appearance of the parameters in the
signature.

Is there something similar in AspectJ's pointcut language?

Unfortunately, I could not find anything that comes close to it neither in
the 'AspectJ in Action' book nor on the internet. I found the following
http://aspectj.2085585.n4.nabble.com/Matching-on-parameter-annotations-td2080015.html#a2080018
and the corresponding bug entry on eclipse.org. It seems to be a similar
question but related to annotation matching. And it seems for this case
there is currently appropriate pointcut language _expression_.


2) Method with Inter-related Objects Pointcut

I would like to describe all method executions where in the control flow
setters of on object of type A are called and getters of another object of
type B are called. Currently, I am experimenting and stated the following...

        pointcut read() : target(B) && call(* get*(..));
        pointcut write() : target(A) && call(* set*(..));
        pointcut whatIWant() : cflowbelow(execution(* *(..)) && read() && write();

...to describe the method m() by a pointcut...

        public void m() {

                A a = new A();
                B b = new B();
                a.setSomething(b.getSomethingElse());
        }



I find the matches for read() and I find those for write() but not for
whatIWant(). Likely, since readA() and writeB() appear at different places
in the control flow, I do not find a match for whatIWant().

I am wondering if it is possible at all to describe this joinpoint in a
pointcut. I have the feeling that it is not. Is my feeling right? In case it
is not possible, is there a pattern for observing the call stack within the
control flow of a certain method?



Thank you very much in advance for your help.

Best regards,
Helge




--
View this message in context: http://aspectj.2085585.n4.nabble.com/Pointcuts-for-Multi-paramter-Methods-and-for-Method-Control-Flow-tp4650677.html
Sent from the AspectJ - users mailing list archive at Nabble.com.
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top