[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] execution pointcut and subclassing
|
Hi,
Recently I came across some issues regarding execution pointcut and subclassing, a sample code is as following:
class Shape {
public void moveBy(int x, int y) {...}
}
class Rectangle extends Shape {
}
class Square extends Rectangle {
public void moveBy(int x, int y) {...}
}
class Driver {
public void main(String[] args) {
System.out.println("[ Shape square = new Square(); square.moveBy(1,1); ]");
Shape square = new Square();
square.moveBy(1,1);
System.out.println("[ Shape rect = new Rectangle(); rect.moveBy(1,1); ]");
Shape rect = new Rectangle();
rect.moveBy(1,1);
}
}
aspect SomeAspect {
after():execution(* Rectangle.moveBy(..)) {
System.out.println("exec:Rectangle.moveBy");
}
after():execution(* Square.moveBy(..)) {
System.out.println("exec:Square.moveBy");
}
after():execution(* Shape.moveBy(..)) {
System.out.println("exec:Shape.moveBy");
}
}
If we run the above example, we will get the following output:
[ Shape square = new Square(); square.moveBy(1,1); ]
exec:Rectangle.moveBy
exec:Square.moveBy
exec:Shape.moveBy
[ Shape rect = new Rectangle(); rect.moveBy(1,1); ]
exec:Shape.moveBy
Notice that, when square.moveBy is called, even moveBy method is not defined in Rectangle class, the pointcut execution(* Rectangle.moveBy(..)) still matches it, however, when rect.moveBy is called, "exec:Rectangle.moveBy" doesn't show up because moveBy method is not overriden in Rectangle.
I searched on the bugzilla and tried the same program on both AspectJ and ABC compiler and got the same result, so I assume it's not a bug in AspectJ implementation.
The question is, what is the semantics of the method signature in execution pointcut? I checked the semantics appendix on eclipse.org and got the answer that "the signature is a method signature whose qualifying type is the declaring type of the method". However, this doesn't seem to explain much - the result is still contradictory.
Thanks,
Linton