[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] using @annotation to select annotated aspects

Hi

Does @annotation work on aspects too? I could not come up with a
working example.
Logically I assume that the call of simple2.foo is caught by the p1
pointcut in Test2, and
since Test2 is annoted with Annotation2 than the System.out.println
call should be
caught by Test1 / p8. Is this correct?

@Retention(RetentionPolicy.RUNTIME)
public @interface Annotation2 { }

public class Simple {
	public void foo2(){ System.err.print("foo2"); }
}

aspect Test1{
     pointcut p8() : @annotation(Annotation2);
     before () : p8() { System.out.println("p8");
}

@Annotation2
aspect Test2{
	pointcut p1() : call(void Simple.foo2());
	before () : p1(){ System.err.println("lexical2"); }
}

public class Main{
   public static void main(String[]args){
       Simple s = new Simple();
       s.foo2();
   }
}


Many thanks,
Denes