--- /dev/null
+public class TestingAnnotations {
+
+ public static void main(String[] args) {
+
+ A a = new A();
+ B b = new B();
+ C c = new C();
+ D d = new D();
+ A reallyB = new B();
+ C reallyD = new D();
+
+ a.doSomething();
+ b.doSomething();
+ c.doSomething();
+ d.doSomething();
+ reallyB.doSomething();
+ reallyD.doSomething();
+ }
+
+}
+
+@MyClassRetentionAnnotation
+class A {
+ public void doSomething() {}
+}
+
+
+@MyAnnotation
+class B extends A {
+ public void doSomething() {}
+}
+
+@MyInheritableAnnotation
+@MyAnnotation
+class C {
+ public void doSomething() {}
+}
+
+class D extends C {
+ public void doSomething() {}
+}
+
+
+@interface MyClassRetentionAnnotation {}
+
+@java.lang.annotation.Retention(value=java.lang.annotation.RetentionPolicy.RUNTIME)
+@interface MyAnnotation {}
+
+@java.lang.annotation.Retention(value=java.lang.annotation.RetentionPolicy.RUNTIME)
+@java.lang.annotation.Inherited
+@interface MyInheritableAnnotation {}
\ No newline at end of file
--- /dev/null
+import java.util.List;\r
+\r
+public aspect ThisOrTargetTests {\r
+ \r
+ pointcut doSomethingExecution() : execution(* doSomething());\r
+ pointcut doSomethingCall() : call(* doSomething());\r
+ \r
+ before() : doSomethingExecution() && @this(@MyAnnotation) {\r
+ // should match:\r
+ // b.doSomething(), reallyB.doSomething() [with test],\r
+ // c.doSomething()\r
+ System.out.println("@this(@MyAnnotation): " + thisJoinPointStaticPart);\r
+ }\r
+ \r
+ before() : doSomethingExecution() && @this(@MyClassRetentionAnnotation) {\r
+ // should be compile-time error!\r
+ }\r
+ \r
+ before() : doSomethingExecution() && @this(@MyInheritableAnnotation) {\r
+ // should match:\r
+ // c.doSomething()\r
+ // d.doSomething()\r
+ // reallyD.doSomething()\r
+ System.out.println("@this(@MyInheritableAnnotation): " + thisJoinPointStaticPart);\r
+ }\r
+ \r
+ after() returning : doSomthingCall() && @target(@MyAnnotation) {\r
+ // should match:\r
+ // b.doSomething(), reallyB.doSomething() [with test],\r
+ // c.doSomething()\r
+ System.out.println("@target(@MyAnnotation): " + thisJoinPointStaticPart);\r
+ }\r
+ \r
+ after() returning : doSomethingCall() && @target(@MyClassRetentionAnnotation) {\r
+ // should be compile-time error!\r
+ }\r
+ \r
+ after() returning : doSomethingCall() && @target(@MyInheritableAnnotation) {\r
+ // should match:\r
+ // c.doSomething()\r
+ // d.doSomething()\r
+ // reallyD.doSomething()\r
+ System.out.println("@target(@MyInheritableAnnotation): " + thisJoinPointStaticPart);\r
+ }\r
+ \r
+ after(MyAnnotation ann) returning : @target(ann) {\r
+ // should be compile time error (limitation)\r
+ }\r
+ \r
+}
\ No newline at end of file