[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [aspectj-users] Restricting a pointcut
|
execution(void Figure.printPosition()) && within(Figure)
will get execution of only the method defined in Figure
similarly,
execution(void Figure.printPosition()) && !within(Figure)
will get only the overriding methods
> -----Original Message-----
> From: aspectj-users-admin@xxxxxxxxxxx
> [mailto:aspectj-users-admin@xxxxxxxxxxx] On Behalf Of Fabiano listas
> Sent: Monday, February 21, 2005 5:48 AM
> To: aspectj-users@xxxxxxxxxxx
> Subject: [aspectj-users] Restricting a pointcut
>
> Hello!
>
> In the example shown below, I'd like to restrict a pointcut to affect
> only the superclass, not the subclasses that extend it. Is there a
> generic way to do this? Do I need to especify all subclasses that my
> pointcut can't affect?
>
>
> public class Figure {
> public String printPosition() { return ""; };
> }
>
> public class Point extends Figure {
> private int x, y;
> public Point(int x, int y) { this.x = x; this.y = y; }
> public void setX(int x) { this.x = x; }
> public void setY(int y) { this.y = y; }
> public int getX() { return x; }
> public int getY() { return y; }
>
> public String printPosition() {
> return "Point at (" + this.x + "," + this.y + ")";
> }
> }
>
> public aspect TestingPointcut {
> pointcut p1(): call(public * Figure.printPosition());
> before(): p1() {
> System.out.println("TestingPointcut: " + thisJoinPoint);
> }
> }
>
>
> When I run the following main class,
>
> public class Teste {
> public static void main(String[] args) {
> Point p1 = new Point(3,3);
> Point p2 = new Point(-1,-1);
> System.out.println(p1.printPosition());
> System.out.println(p2.printPosition());
> }
> }
>
> I get this result:
> > TestingPointcut: call(String
> javaFonts.figure.Point.printPosition())
> > Point at (3,3)
> > TestingPointcut: call(String
> javaFonts.figure.Point.printPosition())
> > Point at (-1,-1)
>
> As you can observe, I'm not using the wildcard + in the pointcut
> definition, but the subtypes of Figure are also being affected.
> According to the AspectJ Programming Guide, hosted in
> eclipse.org, if I
> intend to affect exactly a type, I should define a pointcut
> like this:
>
> call(Foo.new());
>
> If I want to affect also the subtypes of Foo, I should
> define a pointcut
> like this:
>
> call(Foo+.new());
>
> Does it work only for constructors?
>
>
> Thanks,
> Fabiano Cutigi Ferrari.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
>