]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 132926
authoraclement <aclement>
Fri, 24 Mar 2006 10:10:02 +0000 (10:10 +0000)
committeraclement <aclement>
Fri, 24 Mar 2006 10:10:02 +0000 (10:10 +0000)
tests/bugs151/Deca/DecA.java [new file with mode: 0644]
tests/bugs151/pr132926/AffectedType.java [new file with mode: 0644]
tests/bugs151/pr132926/InputAnnotation.java [new file with mode: 0644]
tests/bugs151/pr132926/InputAnnotation2.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
tests/src/org/aspectj/systemtest/ajc151/ajc151.xml
weaver/src/org/aspectj/weaver/AnnotationX.java

diff --git a/tests/bugs151/Deca/DecA.java b/tests/bugs151/Deca/DecA.java
new file mode 100644 (file)
index 0000000..c668c74
--- /dev/null
@@ -0,0 +1,36 @@
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface One {}
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Two {}
+
+class Target {
+  public void m() {}
+}
+
+aspect X {
+  declare @method: * Target.*(..): @One;
+  declare @method: * Target.*(..): @Two;
+}
+
+public class DecA {
+  public static void main(String []argv) {
+         try {
+                 Class c = Target.class;
+                 Method m = c.getDeclaredMethod("m",null);
+                 Annotation[] anns =  m.getAnnotations();
+                 System.err.println("There are "+anns.length+" annotations on public void m():");
+                 for (int i = 0; i < anns.length; i++) {
+                       System.err.println((i+1)+") "+anns[i]);
+                 }
+         } catch (Exception e) {
+                 e.printStackTrace();
+         }
+  }
+}
\ No newline at end of file
diff --git a/tests/bugs151/pr132926/AffectedType.java b/tests/bugs151/pr132926/AffectedType.java
new file mode 100644 (file)
index 0000000..4155164
--- /dev/null
@@ -0,0 +1,10 @@
+public class AffectedType {
+
+       public static void main(String[] args) {
+               
+       }
+}
+
+aspect X {
+       declare @type: AffectedType: @InputAnnotation;
+}
\ No newline at end of file
diff --git a/tests/bugs151/pr132926/InputAnnotation.java b/tests/bugs151/pr132926/InputAnnotation.java
new file mode 100644 (file)
index 0000000..db4ebd9
--- /dev/null
@@ -0,0 +1,5 @@
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@interface InputAnnotation {}
diff --git a/tests/bugs151/pr132926/InputAnnotation2.java b/tests/bugs151/pr132926/InputAnnotation2.java
new file mode 100644 (file)
index 0000000..7fb2afe
--- /dev/null
@@ -0,0 +1,5 @@
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@interface InputAnnotation {}
index 2c33e7bb674d71c44bbbf4bc8792122c85df84a8..81f495b8936b5024aa3db7bb58cab7316b90814f 100644 (file)
@@ -25,6 +25,12 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
 
 public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
     
+       // reported on the list...
+//  public void testDeca() { runTest("doubly annotating a method with declare");}
+       
+  public void testCrashingWithASM_pr132926_1() { runTest("crashing on annotation type resolving with asm - 1");}
+  public void testCrashingWithASM_pr132926_2() { runTest("crashing on annotation type resolving with asm - 2");}
+  public void testCrashingWithASM_pr132926_3() { runTest("crashing on annotation type resolving with asm - 3");}
   public void testGenericAdviceParameters_pr123553()    { runTest("generic advice parameters");}
   public void testMemberTypesInGenericTypes_pr122458()    { runTest("member types in generic types");}
   public void testMemberTypesInGenericTypes_pr122458_2()  { runTest("member types in generic types - 2");}
index 5d83c75f5bfd57730591a5d7583b3be51f60b365..c627cf8ff41141a7c8f48ae9fa019b7918f4e111 100644 (file)
@@ -2,12 +2,39 @@
 
 <!-- AspectJ v1.5.1 Tests -->
 <suite>
+
+    <ajc-test dir="bugs151/pr132926" pr="132926" title="crashing on annotation type resolving with asm - 1">
+     <compile files="InputAnnotation.java,AffectedType.java" options="-1.5"/>
+    </ajc-test>
+    
+    <ajc-test dir="bugs151/pr132926" pr="132926" title="crashing on annotation type resolving with asm - 2">
+     <compile files="InputAnnotation.java" outjar="foo.jar" options="-1.5"/>
+     <compile files="AffectedType.java" classpath="foo.jar" options="-1.5"/>
+    </ajc-test>
+    
+    <ajc-test dir="bugs151/pr132926" pr="132926" title="crashing on annotation type resolving with asm - 3">
+     <compile files="InputAnnotation2.java" outjar="foo.jar" options="-1.5"/>
+     <compile files="AffectedType.java" classpath="foo.jar" options="-1.5">
+       <message kind="error" line="9" text="AffectedType is not a valid target for annotation InputAnnotation, this annotation can only be applied to these element types {METHOD}"/>
+     </compile>
+    </ajc-test>
     
     <ajc-test dir="bugs151/pr123553" title="generic advice parameters">
         <compile files="A.java" options="-1.5"/>
         <run class="A"/>
     </ajc-test>  
     
+    <ajc-test dir="bugs151/Deca" title="doubly annotating a method with declare">
+      <compile files="DecA.java" options="-1.5"/>
+      <run class="DecA">
+        <stderr>
+          <line text="There are 2 annotations on public void m()"/>
+          <line text="1) @One()"/>
+          <line text="2) @Two()"/>
+        </stderr>
+      </run>
+    </ajc-test>
+    
      <ajc-test dir="bugs151/pr129566" title="arrayindexoutofbounds">
         <compile files="SkipList.java" options="-1.5"/>
     </ajc-test>  
index 17e06aa61a896f14cabdb2477f3c9d377ee3bfa1..23d924ab56d5bd1f342ac1d20edf26fd7e721a8f 100644 (file)
@@ -154,18 +154,39 @@ public class AnnotationX {
                lookedForAtTargetAnnotation = true;
                atTargetAnnotation = retrieveAnnotationOnAnnotation(UnresolvedType.AT_TARGET);
                if (atTargetAnnotation != null) {
-                       supportedTargets = new HashSet();
-                       List values = atTargetAnnotation.getBcelAnnotation().getValues();
-                       ElementNameValuePair envp = (ElementNameValuePair)values.get(0);
-                       ArrayElementValue aev = (ArrayElementValue)envp.getValue();
-                       ElementValue[] evs = aev.getElementValuesArray();
-                       for (int i = 0; i < evs.length; i++) {
-                               EnumElementValue ev = (EnumElementValue)evs[i];
-                               supportedTargets.add(ev.getEnumValueString());
-                       }
+                       supportedTargets = atTargetAnnotation.getTargets();
                }
        }
   }
+  
+  /**
+   * For the @Target annotation, this will return a set of the elementtypes it can be applied to.
+   * For non @Target annotations, it returns null.
+   */
+  public Set /* of String */ getTargets() {
+         if (!signature.equals(UnresolvedType.AT_TARGET)) return null;
+         Set supportedTargets = new HashSet();
+         if (mode==MODE_BCEL) {
+           List values = getBcelAnnotation().getValues();
+               ElementNameValuePair envp = (ElementNameValuePair)values.get(0);
+               ArrayElementValue aev = (ArrayElementValue)envp.getValue();
+               ElementValue[] evs = aev.getElementValuesArray();
+               for (int i = 0; i < evs.length; i++) {
+                       EnumElementValue ev = (EnumElementValue)evs[i];
+                       supportedTargets.add(ev.getEnumValueString());
+               }
+         } else {
+                 List values = theRealASMAnnotation.getNameValuePairs();
+                 AnnotationNameValuePair nvp = (AnnotationNameValuePair)values.get(0);
+                 ArrayAnnotationValue aav = (ArrayAnnotationValue)nvp.getValue();
+                 AnnotationValue[] avs = aav.getValues();
+                 for (int i = 0; i < avs.length; i++) {
+                       AnnotationValue value = avs[i];
+                       supportedTargets.add(value.stringify());
+                 }
+         }
+         return supportedTargets;
+  }
 
   /**
    * @return true if this annotation can be put on a field