12345678910111213141516171819202122232425262728293031 |
- import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
- import java.lang.annotation.*;
-
- @Retention(RUNTIME)
- @Inherited
- @interface MyAnnotation {}
-
- public aspect A perthis(annotatedClasses()) {
-
- pointcut annotatedClasses() : @this(MyAnnotation);
-
- before(): initialization(*.new(..)) {System.err.println(thisJoinPoint.getSignature().getDeclaringType()); }
-
- public static void main(String []argv) {
- new Foo();
- new Goo();
- new Boo();
- new Soo();
- }
- }
-
- // yes/no indicates if runtime match expected for staticinitialization
-
- @MyAnnotation class Foo { } // YES
-
- class Goo { } // NO
-
- @MyAnnotation class Boo { } // YES
-
- class Soo extends Boo { } // YES
|