--- /dev/null
+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
--- /dev/null
+public class AffectedType {
+
+ public static void main(String[] args) {
+
+ }
+}
+
+aspect X {
+ declare @type: AffectedType: @InputAnnotation;
+}
\ No newline at end of file
--- /dev/null
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@interface InputAnnotation {}
--- /dev/null
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@interface InputAnnotation {}
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");}
<!-- 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>
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