[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Fwd: trigger all calls/sets from an annotated parameter within a method
|
Hi,
I'm afraid you can't do that (easily) - we don't know/preserve enough
about local variables. The slightly messy way to do it would be:
At the execution joinpoint for the method, remember which parameter
objects are annotated, some kind of sequence of these (for different
arg positions):
before(B b): execution(* *(@MyAnno (*),..)) && args(b) // arg in first
position
before(B b): execution(* *(*,@MyAnno (*),..)) && args(b) // arg in
second position
remember 'b'
Then, when call/set is made within that code, look at the object upon
which the method is being called (target) and check if it was an
annotated one.
before(B b): (call(* *(..)) || set(* *)) && target(b) {
if (b is in my list) {
System.out.println("triggered");
}
}
Using some kind of stack to push (on entry)/pop (on exit) the
contextual information you are keeping about the method.
cheers,
Andy
On 21 May 2012 08:50, Frederick Egli <frederick.egli@xxxxxxxxx> wrote:
> Hi all,
>
> I'm trying to trigger all calls/sets from an annotated parameter within a
> method. Consider the following example:
>
> public class A {
>
> public void foo(@MyAnno B b1, B b2){
> b1.bar(); //this should trigger
> b1.field = 42; //this should trigger
>
> b2.bar(); //should not trigger
> b2.field = 42; //should not trigger
> }
> }
>
> public class B {
> public int field;
> public void bar() { }
> }
>
> @Retention(RetentionPolicy.RUNTIME)
> @Target(ElementType.PARAMETER)
> public @interface MyAnno {
> }
>
>
> So far I have the following aspect. But of course this triggers all calls
> and sets from all method parameters.
>
> @Aspect
> public class MyAspect {
> @Before("cflowbelow(execution(* *.*(..,@MyAnno (*),..))) && (call(*
> *(..)) || set(* *)) && !within(MyAspect)")
> public void belowAdvice() {
> System.out.println("triggered");
> }
> }
>
> Is there any way to only trigger the calls and sets from the annotated (in
> my case b1) parameter within a method (foo())?
>
>
> Thanks in advance!
>
> Fred
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>