From 2fb86fe604b613774492df5185b1c5717c434d29 Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 24 Mar 2006 10:10:02 +0000 Subject: test and fix for 132926 --- tests/bugs151/Deca/DecA.java | 36 ++++++++++++++++++++ tests/bugs151/pr132926/AffectedType.java | 10 ++++++ tests/bugs151/pr132926/InputAnnotation.java | 5 +++ tests/bugs151/pr132926/InputAnnotation2.java | 5 +++ .../org/aspectj/systemtest/ajc151/Ajc151Tests.java | 6 ++++ tests/src/org/aspectj/systemtest/ajc151/ajc151.xml | 27 +++++++++++++++ weaver/src/org/aspectj/weaver/AnnotationX.java | 39 +++++++++++++++++----- 7 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 tests/bugs151/Deca/DecA.java create mode 100644 tests/bugs151/pr132926/AffectedType.java create mode 100644 tests/bugs151/pr132926/InputAnnotation.java create mode 100644 tests/bugs151/pr132926/InputAnnotation2.java 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 -- cgit v1.2.3