+++ /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
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+
+@Retention(RetentionPolicy.RUNTIME) @interface One {}
+@Retention(RetentionPolicy.RUNTIME) @interface Two {}
+@Retention(RetentionPolicy.RUNTIME) @interface Three {}
+@Retention(RetentionPolicy.RUNTIME) @interface Four {}
+@Retention(RetentionPolicy.RUNTIME) @interface Five {}
+@Retention(RetentionPolicy.RUNTIME) @interface Six {}
+
+class Target {
+
+ public void m() {}
+
+ public Target(int i) {}
+
+ public int x;
+}
+
+aspect X {
+ declare @method: * Target.*(..): @One;
+ declare @method: * Target.*(..): @Two;
+
+
+ declare @constructor: Target.new(int): @Three;
+ declare @constructor: Target.new(int): @Four;
+
+
+ declare @field: int Target.*: @Five;
+ declare @field: int Target.*: @Six;
+}
+
+public class DecA {
+ public static void main(String []argv) {
+ // Let's do the method then the ctor, then the field
+ try {
+ Class c = Target.class;
+ Method m = c.getDeclaredMethod("m",null);
+ System.err.println("There are "+m.getAnnotations().length+" annotations on public void m():");
+ dumpAnnos(m.getAnnotations());
+ Constructor ctor = c.getDeclaredConstructor(new Class[]{Integer.TYPE});
+ System.err.println("There are "+ctor.getAnnotations().length+" annotations on public Target(int):");
+ dumpAnnos(ctor.getAnnotations());
+ Field f = c.getDeclaredField("x");
+ System.err.println("There are "+f.getAnnotations().length+" annotations on public int x:");
+ dumpAnnos(f.getAnnotations());
+ } catch (Exception e) { e.printStackTrace();}
+ }
+
+ public static void dumpAnnos(Annotation[] anns) {
+ List l = new ArrayList();
+ if (anns!=null) {
+ for (int i = 0; i < anns.length; i++) {
+ l.add(anns[i].annotationType().getName());
+ }
+ }
+ Collections.sort(l);
+ int i = 1;
+ for (Iterator iter = l.iterator(); iter.hasNext();) {
+ System.err.println((i++)+") "+iter.next());
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+
+@Retention(RetentionPolicy.RUNTIME) @interface One {}
+@Retention(RetentionPolicy.RUNTIME) @interface Two {}
+@Retention(RetentionPolicy.RUNTIME) @interface Three {}
+@Retention(RetentionPolicy.RUNTIME) @interface Four {}
+@Retention(RetentionPolicy.RUNTIME) @interface Five {}
+@Retention(RetentionPolicy.RUNTIME) @interface Six {}
+
+interface Target {
+ public void m();
+}
+
+class A implements Target {
+ public void m() {
+
+ }
+}
+
+aspect X {
+ declare @method: * Target+.*(..): @One;
+ declare @method: * Target+.*(..): @Two;
+}
+
+public class DecA2 {
+ public static void main(String []argv) {
+ try {
+ Class c = Target.class;
+ Method m = c.getDeclaredMethod("m",null);
+ System.err.println("There are "+m.getAnnotations().length+" annotations on public void Target.m():");
+ dumpAnnos(m.getAnnotations());
+ c = A.class;
+ m = c.getDeclaredMethod("m",null);
+ System.err.println("There are "+m.getAnnotations().length+" annotations on public void A.m():");
+ dumpAnnos(m.getAnnotations());
+ } catch (Exception e) { e.printStackTrace();}
+ }
+
+ public static void dumpAnnos(Annotation[] anns) {
+ List l = new ArrayList();
+ if (anns!=null) {
+ for (int i = 0; i < anns.length; i++) {
+ l.add(anns[i].annotationType().getName());
+ }
+ }
+ Collections.sort(l);
+ int i = 1;
+ for (Iterator iter = l.iterator(); iter.hasNext();) {
+ System.err.println((i++)+") "+iter.next());
+ }
+ }
+}
\ No newline at end of file
public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
- // reported on the list...
-// public void testDeca() { runTest("doubly annotating a method with declare");}
-
+// public void testDeca() { runTest("doubly annotating a method with declare");}
+// public void testDeca2() { runTest("doubly annotating a method with declare - 2");}
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");}
<run class="A"/>
</ajc-test>
- <ajc-test dir="bugs151/Deca" title="doubly annotating a method with declare">
+ <ajc-test dir="bugs151/pr133298" 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()"/>
+ <line text="1) One"/>
+ <line text="2) Two"/>
+ <line text="There are 2 annotations on public Target(int):"/>
+ <line text="1) Four"/>
+ <line text="2) Three"/>
+ <line text="There are 2 annotations on public int x:"/>
+ <line text="1) Five"/>
+ <line text="2) Six"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="bugs151/pr133298" title="doubly annotating a method with declare - 2">
+ <compile files="DecA2.java" options="-1.5"/>
+ <run class="DecA2">
+ <stderr>
+ <line text="There are 2 annotations on public void Target.m()"/>
+ <line text="1) One"/>
+ <line text="2) Two"/>
+ <line text="There are 2 annotations on public void A.m()"/>
+ <line text="1) One"/>
+ <line text="2) Two"/>
</stderr>
</run>
</ajc-test>