aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraclement <aclement>2006-03-24 10:10:02 +0000
committeraclement <aclement>2006-03-24 10:10:02 +0000
commit2fb86fe604b613774492df5185b1c5717c434d29 (patch)
tree9812ad9e7ec63083f5d73e703cc26e9e9d8067d8
parent6aef2d916321e2a37837bc1cd3fa255b153bdfa0 (diff)
downloadaspectj-2fb86fe604b613774492df5185b1c5717c434d29.tar.gz
aspectj-2fb86fe604b613774492df5185b1c5717c434d29.zip
test and fix for 132926
-rw-r--r--tests/bugs151/Deca/DecA.java36
-rw-r--r--tests/bugs151/pr132926/AffectedType.java10
-rw-r--r--tests/bugs151/pr132926/InputAnnotation.java5
-rw-r--r--tests/bugs151/pr132926/InputAnnotation2.java5
-rw-r--r--tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java6
-rw-r--r--tests/src/org/aspectj/systemtest/ajc151/ajc151.xml27
-rw-r--r--weaver/src/org/aspectj/weaver/AnnotationX.java39
7 files changed, 119 insertions, 9 deletions
diff --git a/tests/bugs151/Deca/DecA.java b/tests/bugs151/Deca/DecA.java
new file mode 100644
index 000000000..c668c740c
--- /dev/null
+++ b/tests/bugs151/Deca/DecA.java
@@ -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
index 000000000..41551645f
--- /dev/null
+++ b/tests/bugs151/pr132926/AffectedType.java
@@ -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
index 000000000..db4ebd9a4
--- /dev/null
+++ b/tests/bugs151/pr132926/InputAnnotation.java
@@ -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
index 000000000..7fb2afe9a
--- /dev/null
+++ b/tests/bugs151/pr132926/InputAnnotation2.java
@@ -0,0 +1,5 @@
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@interface InputAnnotation {}
diff --git a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
index 2c33e7bb6..81f495b89 100644
--- a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
+++ b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
@@ -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");}
diff --git a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml
index 5d83c75f5..c627cf8ff 100644
--- a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml
+++ b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml
@@ -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>
diff --git a/weaver/src/org/aspectj/weaver/AnnotationX.java b/weaver/src/org/aspectj/weaver/AnnotationX.java
index 17e06aa61..23d924ab5 100644
--- a/weaver/src/org/aspectj/weaver/AnnotationX.java
+++ b/weaver/src/org/aspectj/weaver/AnnotationX.java
@@ -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