]> source.dussan.org Git - aspectj.git/commitdiff
@within, @withincode tests
authoracolyer <acolyer>
Fri, 10 Dec 2004 13:21:26 +0000 (13:21 +0000)
committeracolyer <acolyer>
Fri, 10 Dec 2004 13:21:26 +0000 (13:21 +0000)
tests/java5/annotations/thisOrtarget/DeclareEoW.java [new file with mode: 0644]
tests/java5/annotations/within_code/TestingAnnotations.jar [new file with mode: 0644]
tests/java5/annotations/within_code/TestingAnnotations.java [new file with mode: 0644]
tests/java5/annotations/within_code/WithinAndWithinCodeTests.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java

diff --git a/tests/java5/annotations/thisOrtarget/DeclareEoW.java b/tests/java5/annotations/thisOrtarget/DeclareEoW.java
new file mode 100644 (file)
index 0000000..491e540
--- /dev/null
@@ -0,0 +1,7 @@
+public aspect DeclareEoW {
+       
+       declare warning : @this(@MyAnnotation) : "should give compilation error";
+       
+       declare error : @target(@MyAnnotation) : "should give compilation error";
+       
+}
\ No newline at end of file
diff --git a/tests/java5/annotations/within_code/TestingAnnotations.jar b/tests/java5/annotations/within_code/TestingAnnotations.jar
new file mode 100644 (file)
index 0000000..769d7ec
Binary files /dev/null and b/tests/java5/annotations/within_code/TestingAnnotations.jar differ
diff --git a/tests/java5/annotations/within_code/TestingAnnotations.java b/tests/java5/annotations/within_code/TestingAnnotations.java
new file mode 100644 (file)
index 0000000..35eb49e
--- /dev/null
@@ -0,0 +1,54 @@
+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 {
+  
+  @MyClassRetentionAnnotation public void doSomething(C c) {
+       c.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/within_code/WithinAndWithinCodeTests.java b/tests/java5/annotations/within_code/WithinAndWithinCodeTests.java
new file mode 100644 (file)
index 0000000..96ed018
--- /dev/null
@@ -0,0 +1,14 @@
+public aspect WithinAndWithinCodeTests {
+       
+       // should be two matches, L32 and L39
+       declare warning : execution(* doSomething(..)) && @within(@MyAnnotation)
+                       : "@within match on non-inherited annotation";
+       
+       // one match on L39
+       declare warning : execution(* doSomething(..)) && @within(@MyInheritableAnnotation)
+                       : "@within match on inheritable annotation";
+       
+       // one match on L32
+       declare warning : call(* doSomething(..)) && @withincode(@MyClassRetentionAnnotation)
+                       : "@withincode match";  
+}
\ No newline at end of file
index 966bf884a262657f1add43e0ac02253da570d7bf..0d607b905aab8553a10a1f90bb365f291dcaf7db 100644 (file)
@@ -45,15 +45,37 @@ public class AnnotationRuntimeTests extends TestUtils {
     public void test003_InheritableOrNot() {
         CompilationResult cR = binaryWeave("TestingAnnotations.jar","ThisOrTargetTests.aj",0,0);   
     }
-    
+
+    public void test004_CantUseinDecEoW() {
+        CompilationResult cR = binaryWeave("TestingAnnotations.jar","DeclareEoW.java",4,0);
+        List errors = new ArrayList();
+        errors.add(new Message(3,"this() pointcut designator cannot be used in declare statement"));
+        errors.add(new Message(5,"target() pointcut designator cannot be used in declare statement"));
+        MessageSpec messageSpec = new MessageSpec(new ArrayList(), errors);
+        assertMessages(cR, messageSpec);
+    }
+
     // TODO extra tests
     // run the result of test003 and validate matches (needs 1.5 runtime)
     // test inheritable annotation not present on type [should generate runtime test]
     
-    public void test004_ArgsSuite() {
+    public void test005_ArgsSuite() {
        baseDir = new File("../tests/java5/annotations/args");
         CompilationResult cR = binaryWeave("TestingArgsAnnotations.jar","AtArgsAspect.java",0,0);  
         // TODO need to RUN the result of these tests...
         System.out.println(cR);
     }
+    
+    public void test006_Within_Code() {
+       baseDir = new File("../tests/java5/annotations/within_code");
+        CompilationResult cR = binaryWeave("TestingAnnotations.jar","WithinAndWithinCodeTests.java",0,5);
+        List warnings = new ArrayList();
+        warnings.add(new Message(32,"@within match on non-inherited annotation"));
+        warnings.add(new Message(39,"@within match on non-inherited annotation"));
+        warnings.add(new Message(39,"@within match on inheritable annotation"));
+        warnings.add(new Message(43,"@within match on inheritable annotation"));
+        warnings.add(new Message(32,"@withincode match"));
+        MessageSpec mSpec = new MessageSpec(warnings,new ArrayList());
+        assertMessages(cR,mSpec);      
+    }
 }