[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Pointcut doubt

Thanks a lot... It works properly!

-----Mensaje original-----
De: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] En nombre de Walter Cazzola
Enviado el: jueves, 20 de mayo de 2010 10:04
Para: AspectJ ML
Asunto: Re: [aspectj-users] Pointcut doubt

On Thu, 20 May 2010, Exposito Aguilera, Francisco wrote:

> How can I create a pointcut in order to add a log in all methods but
getters
> or setters?

> I have tried execution(* !get*(..)), but it doesn't work.

This works as expected to me:

   public aspect AC {
     pointcut noget(): execution(* *(..)) && !execution(* get*(..)) ;

     after(): noget() {
       System.out.println("***AC*** "+thisJoinPoint);
     }
   }

   public class C {
     private int x;
     public C(int v) {x=v;}
     public void dummy() {System.out.println("I'm dummy, x value is
"+getx());}
     public int getx() {return x;}

     public static void main(String argv[]) {
       C c = new C(7);
       c.dummy();
       c.getx();
     }
   }

   >java C
   I'm dummy, x value is 7
   ***AC*** execution(void C.dummy())
   ***AC*** execution(void C.main(String[]))

I hope this helps.

Walter

-- 
Walter Cazzola, PhD - Assistant Professor, DICo, University of Milano
E-mail cazzola@xxxxxxxxxxxxx Ph.: +39 02 503 16300  Fax: +39 02 503 16253
* * * ---------------------------- * * * ---------------------------- * * *
                ... recursive: adjective, see recursive ...
* * * ---------------------------- * * * ---------------------------- * * *