Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] execution join points and overridden methods

This has been the behavior since (at least) AspectJ 1.0.

In this code

> public class A1 { public void f() {} }
> public class A2 extends A1 { public void f() {} }

the method-signature 'void f()' is defined in A1 and 
overridden in A2.  So 

   execution(void A1.f())

will pick out any f() implemented in A1 or any subclass of A1.
We did it this way to satisfy the Liskov substitution principle, 
so advice on a method also works for any implementation of it.
If A2 did not extend A1, then the pointcut would not match.

To define a pointcut for lexical per-class behavior, use
&& within(A1).

Wes

> ------------Original Message------------
> From: Doug Orleans <dougo@xxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Fri, Aug-13-2004 4:04 PM
> Subject: [aspectj-users] execution join points and overridden methods
>
> I'm a bit surprised by this behavior (from ajc 1.2):
> 
> public class A1 {
>   public void f() {
>     System.out.println("A1.f()");
>   }
> }
> 
> public class A2 extends A1 {
>   public void f() {
>     System.out.println("A2.f()");
>   }
> }
> 
> aspect A {
>   before(): execution(void A1.f()) {
>     System.out.println("before A1.f()");
>   }
>   before(): execution(void A2.f()) {
>     System.out.println("before A2.f()");
>   }
> }
> 
> public class Test {
>   public static void main(String[] args) {
>     A2 a2 = new A2();
>     a2.f();
>   }
> }
> 
> Output:
> 
> before A1.f()
> before A2.f()
> A2.f()
> 
> Why does the A1.f() execution pointcut match if that method is not 
> executed?
> 
> --dougo@xxxxxxxxx
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 




Back to the top