Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Need advice

Title: RE: [aspectj-users] Need advice

cflowbelow is fine if you have dynamic control concerns such as Foo.m1(String, String) calling a method in some other class which could end up calling Foo.m1(String,String,String). If you don't have to worry about that kind of pattern, a static guard !(within Foo) will also work.

Elizabeth

-----Original Message-----
From: Stefan Hanenberg [mailto:shanenbe@xxxxxxxxxxxxxxxxxxxxxxx]
Sent: January 15, 2004 10:45 AM
To: aspectj-users@xxxxxxxxxxx; ABuistov@xxxxxxxxxxx
Subject: Re: [aspectj-users] Need advice


Hi,

you can add a cflowbelow to the aspect:

  aspect MyProblemAspect{
    pointcut operationTracker(Foo foo): call ( * Foo.m1(..)) && target
(foo) && !cflowbelow(call ( * Foo.m1(String,String))) &&
!cflowbelow(call ( * Foo.m1(String,String,String)));

    before(Foo foo): operationTracker(foo) {
         System.out.println(foo.getXXX());
    }
  }

(the 2nd cflow below is just for preventing recursive calls in
m1(String,String,String))

- Stefan

Alexey Buistov wrote:

> Hello!
> I'm having the following:
>
> class Foo {
>    public void m1(String a, String b){ m1(a,b,null); }
>    public void m1(String a, String b, String c){
>      System.out.println("123");
>    }
>    public String getXXX() {return "XXX";}
>  }
>
>  aspect MyProblemAspect{
>    pointcut operationTracker(Foo foo): call ( * Foo.m1(..)) && target
> (foo);
>
>    before(Foo foo): operationTracker(foo) {
>      System.out.println(foo.getXXX());
>    }
>  }
>
> The output is:
> XXX
> XXX
> 123
>
> The question is:
> How do I modify MyProblemAspect in order to acheive the following behaviour:
>
> 1) 'before' advice executes ONLY ONCE when Foo.m1(String, String) is invoked
> 2) 'before' advice executes [once] when Foo.m1(String, String, String)
> is invoked
> 3) 'before' advice doesn't execute when Foo.m1(String, String, String)
> is invoked from Foo.m1(String, String)
>
> Thanks in advance
> Alexey

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top