Skip to main content

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

Is the following what you want?

  /**
   * calls to the public methods of foo, these are the possible calls
   * at which control enters Foo
   */
  pointcut possibleEntries(Foo foo): call(public * Foo.*(..)) && target(foo);

  /**
   * external calls to possibleEntries, these are the true external calls
   * into Foo.
   */
  pointcut trueExternalEntries(Foo foo): possibleEntries(foo) && !within(Foo);


Comments:

  - I'm giving names to these pointcuts that describe the points
    they match, not what the advice will do to them. I find that
    this helps a lot for me to gradually build up the pointcut I
    want. One reason for this is because then when I read things like

       entryPoints(foo) && !within(Foo)

    both parts are in the same form -- they both describe properties
    of the points, so composing them in my mind is easier.

  - Within and withincode are different things than cflow and cflowbelow,
    being about lexical and dynamic inclusion respectively. So in some
    sense they are apples and organges. But its often the case that
    when you reach for cflow(below), within or withincode would do just
    as well, and in fact be better, because its easier to reason about
    exactly what they mean.



> -----Original Message-----
> From: aspectj-users-admin@xxxxxxxxxxx 
> [mailto:aspectj-users-admin@xxxxxxxxxxx] On Behalf Of Alexey Buistov
> Sent: Thursday, January 15, 2004 7:51 AM
> To: aspectj-users@xxxxxxxxxxx
> Subject: RE: [aspectj-users] Need advice
> 
> 
> This is mostly ok, but I need the solution which will not 
> know anything about 
> Foo.m1(String,String) or Foo.m1(String,String,String) etc. I 
> have about 400 classes with 
> about 20 methods in each, so mentioning all those methods in 
> poincut would be a nightmare.
> 
> I've just come up with the following workaround solution:
> 
>  aspect MyProblemAspect{
>    pointcut  operationTracker(Foo foo): call ( * Foo.m1(..)) 
> && target(foo);
> 
>     public pointcut solution(Foo foo): !withincode( * Foo.m1(..))
>                                 && operationTracker(foo);
> 
>    before(Foo foo): solution(foo) {
>      System.out.println(foo.getXXX());
>    }
>  }
> 
> Is it flexible enough? Are there any hidden pitfalls in my solution?
> 
> -----Original Message-----
> From: Stefan Hanenberg [mailto:shanenbe@xxxxxxxxxxxxxxxxxxxxxxx]
> Sent: Thursday, January 15, 2004 5:45 PM
> To: aspectj-users@xxxxxxxxxxx; Alexey Buistov
> 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
> 
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 




Back to the top