Skip to main content

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

Use @within if interested in joinpoints within an annotated type.
Although without a qualifying type of joinpoint, it will match a lot
of stuff (including the call):

===
Join point 'staticinitialization(void Test2.<clinit>())' in Type
'Test2' (Main.java:16) advised by before advice from 'Test1'
(Main.java:12)
	
Join point 'constructor-execution(void Test2.<init>())' in Type
'Test2' (Main.java:16) advised by before advice from 'Test1'
(Main.java:12)
	
Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'Test2' (Main.java:18) advised by before advice from 'Test1'
(Main.java:12)
	
Join point 'method-call(void
java.io.PrintStream.println(java.lang.String))' in Type 'Test2'
(Main.java:18) advised by before advice from 'Test1' (Main.java:12)
	
Join point 'adviceexecution(void Test2.ajc$before$Test2$1$33a682())'
in Type 'Test2' (Main.java:18) advised by before advice from 'Test1'
(Main.java:12)
	
Join point 'initialization(void Test2.<init>())' in Type 'Test2'
(Main.java:16) advised by before advice from 'Test1' (Main.java:12)
	
Join point 'preinitialization(void Test2.<init>())' in Type 'Test2'
(Main.java:16) advised by before advice from 'Test1' (Main.java:12)
===

> since Test2 is annoted with Annotation2 than the System.out.println
> call should be caught by Test1 / p8. Is this correct?

No, @annotation() matches on the subject of the joinpoint.  At the
call joinpoint to println, the subject is the method being called,
that method is not annotated with Annotation2.

cheers,
Andy





On 14 January 2012 09:33, Dénes Németh <mr.nemeth.denes@xxxxxxxxx> wrote:
> 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
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top