]> source.dussan.org Git - aspectj.git/commitdiff
annotation tests for this and target
authoracolyer <acolyer>
Thu, 9 Dec 2004 14:02:47 +0000 (14:02 +0000)
committeracolyer <acolyer>
Thu, 9 Dec 2004 14:02:47 +0000 (14:02 +0000)
tests/java5/annotations/thisOrtarget/TestingAnnotations.jar [new file with mode: 0644]
tests/java5/annotations/thisOrtarget/TestingAnnotations.java [new file with mode: 0644]
tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj [new file with mode: 0644]

diff --git a/tests/java5/annotations/thisOrtarget/TestingAnnotations.jar b/tests/java5/annotations/thisOrtarget/TestingAnnotations.jar
new file mode 100644 (file)
index 0000000..d5dbd0b
Binary files /dev/null and b/tests/java5/annotations/thisOrtarget/TestingAnnotations.jar differ
diff --git a/tests/java5/annotations/thisOrtarget/TestingAnnotations.java b/tests/java5/annotations/thisOrtarget/TestingAnnotations.java
new file mode 100644 (file)
index 0000000..67ad612
--- /dev/null
@@ -0,0 +1,51 @@
+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
diff --git a/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj b/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj
new file mode 100644 (file)
index 0000000..c642da9
--- /dev/null
@@ -0,0 +1,50 @@
+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