Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
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




Back to the top