From f963fc4dcd3f0391e6eb234c3346d16eb5bdb891 Mon Sep 17 00:00:00 2001 From: aclement Date: Sun, 26 Mar 2006 18:15:39 +0000 Subject: [PATCH] better tests for 133298 - yucky bug. --- tests/bugs151/Deca/DecA.java | 36 ---------- tests/bugs151/pr133298/DecA.java | 72 +++++++++++++++++++ tests/bugs151/pr133298/DecA2.java | 62 ++++++++++++++++ .../systemtest/ajc151/Ajc151Tests.java | 5 +- .../org/aspectj/systemtest/ajc151/ajc151.xml | 26 ++++++- 5 files changed, 159 insertions(+), 42 deletions(-) delete mode 100644 tests/bugs151/Deca/DecA.java create mode 100644 tests/bugs151/pr133298/DecA.java create mode 100644 tests/bugs151/pr133298/DecA2.java diff --git a/tests/bugs151/Deca/DecA.java b/tests/bugs151/Deca/DecA.java deleted file mode 100644 index c668c740c..000000000 --- a/tests/bugs151/Deca/DecA.java +++ /dev/null @@ -1,36 +0,0 @@ -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/pr133298/DecA.java b/tests/bugs151/pr133298/DecA.java new file mode 100644 index 000000000..7be6a7b45 --- /dev/null +++ b/tests/bugs151/pr133298/DecA.java @@ -0,0 +1,72 @@ +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 diff --git a/tests/bugs151/pr133298/DecA2.java b/tests/bugs151/pr133298/DecA2.java new file mode 100644 index 000000000..bb8728906 --- /dev/null +++ b/tests/bugs151/pr133298/DecA2.java @@ -0,0 +1,62 @@ +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 diff --git a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java index 81f495b89..fce100bd4 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java @@ -25,9 +25,8 @@ 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 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");} diff --git a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml index c627cf8ff..2373c27ec 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml +++ b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml @@ -24,13 +24,33 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5