diff options
author | aclement <aclement> | 2005-08-24 08:05:27 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-08-24 08:05:27 +0000 |
commit | 70ba7e28b6ed0b2026c1ed6e403e2d54afacebcf (patch) | |
tree | 142c9496374f0f07e3ad0b429488bdf4c5a9dde6 | |
parent | 2c91eb942998395a9824f51f35023dcbb765e2a2 (diff) | |
download | aspectj-70ba7e28b6ed0b2026c1ed6e403e2d54afacebcf.tar.gz aspectj-70ba7e28b6ed0b2026c1ed6e403e2d54afacebcf.zip |
genericitds: bridge method testcode.
8 files changed, 210 insertions, 0 deletions
diff --git a/tests/java5/generics/itds/bridgeMethods/Bridging1.aj b/tests/java5/generics/itds/bridgeMethods/Bridging1.aj new file mode 100644 index 000000000..6aefd137e --- /dev/null +++ b/tests/java5/generics/itds/bridgeMethods/Bridging1.aj @@ -0,0 +1,17 @@ +// this bridge stuff is handled by the compiler - because D is a subtype of C even though method1 is being overridden, +// a bridge method 'C method1() { method1();}' is generated in the subclass D +import java.lang.reflect.*; + +class C { + C method1() {return null;} +} + +class D extends C { + D method1() {return null;} +} + +public aspect Bridging1 { + public static void main(String []argv) { + Util.dumpMethods("D",new String[]{"C D.method1() [BridgeMethod]","D D.method1()"}); + } +} diff --git a/tests/java5/generics/itds/bridgeMethods/Bridging2.aj b/tests/java5/generics/itds/bridgeMethods/Bridging2.aj new file mode 100644 index 000000000..ecd270de3 --- /dev/null +++ b/tests/java5/generics/itds/bridgeMethods/Bridging2.aj @@ -0,0 +1,16 @@ +// this bridge stuff is handled by the compiler +import java.lang.reflect.*; + +abstract class C<A> { + abstract A next(); +} + +class D extends C<String> { + String next() {return "";} +} + +public aspect Bridging2 { + public static void main(String []argv) { + Util.dumpMethods("D"); + } +}
\ No newline at end of file diff --git a/tests/java5/generics/itds/bridgeMethods/Bridging3.aj b/tests/java5/generics/itds/bridgeMethods/Bridging3.aj new file mode 100644 index 000000000..13b70034a --- /dev/null +++ b/tests/java5/generics/itds/bridgeMethods/Bridging3.aj @@ -0,0 +1,16 @@ +// this bridge stuff is handled by the compiler +import java.lang.reflect.*; + +abstract class C<A> { + abstract A id(A x); +} + +class D extends C<String> { + String id(String s) {return s;} +} + +public aspect Bridging3 { + public static void main(String []argv) { + Util.dumpMethods("D"); + } +}
\ No newline at end of file diff --git a/tests/java5/generics/itds/bridgeMethods/BridgingITD1.aj b/tests/java5/generics/itds/bridgeMethods/BridgingITD1.aj new file mode 100644 index 000000000..8631df618 --- /dev/null +++ b/tests/java5/generics/itds/bridgeMethods/BridgingITD1.aj @@ -0,0 +1,17 @@ +// Now the implementation is introduced via an ITD, we should still get the bridge method in the class D +import java.lang.reflect.*; + +class C { + public C method1() {return null;} +} + +class D extends C { + // D method1() {return null;} +} + +public aspect BridgingITD1 { + public D D.method1() { return null; } + public static void main(String []argv) { + Util.dumpMethods("D",new String[]{"C D.method1() [BridgeMethod]","D D.method1()"}); + } +}
\ No newline at end of file diff --git a/tests/java5/generics/itds/bridgeMethods/BridgingITD2.aj b/tests/java5/generics/itds/bridgeMethods/BridgingITD2.aj new file mode 100644 index 000000000..4e1d7b8c9 --- /dev/null +++ b/tests/java5/generics/itds/bridgeMethods/BridgingITD2.aj @@ -0,0 +1,21 @@ +// this bridge stuff is handled by the compiler +import java.lang.reflect.*; + +abstract class C<A> { + public abstract A next(); +} + +class D extends C<String> { + //String next() {return "";} +} + +public aspect BridgingITD2 { + + public String D.next() { return ""; } + + public static void main(String []argv) { + Util.dumpMethods("D"); + C c = new D(); + String s = c.next(); + } +} diff --git a/tests/java5/generics/itds/bridgeMethods/C.java b/tests/java5/generics/itds/bridgeMethods/C.java new file mode 100644 index 000000000..ba1081cf4 --- /dev/null +++ b/tests/java5/generics/itds/bridgeMethods/C.java @@ -0,0 +1,35 @@ +public class C<O extends Number> { + + O m1() {return null;} + void m2(O o) {} + void m3(String s,O o) {} + void m4(O o,O o2) {} + O m5(O o,O o2) {return null;} + +} + +class D1<P extends Float> extends C<P> { + + @Override + P m1() {return null;} + + @Override + void m2(P s) {} + + @Override + void m3(String s,P o) {} + + @Override + void m4(P o,P o2) {} + + @Override + P m5(P o,P o2) {return null;} + +} + + +class D2 extends C { + + @Override + Float m1() { return null; } +} diff --git a/tests/java5/generics/itds/bridgeMethods/ProgramA.java b/tests/java5/generics/itds/bridgeMethods/ProgramA.java new file mode 100644 index 000000000..69a39890b --- /dev/null +++ b/tests/java5/generics/itds/bridgeMethods/ProgramA.java @@ -0,0 +1,22 @@ +// Bridge methods. + +interface I<N extends Number> { + public N methodOne(); + public N methodTwo(); +} + +class Impl<T extends Float> implements I<T> { + public T m() { return null;} +} + +public class ProgramA { + public static void main(String[]argv) { + Impl i = new Impl(); + i.methodOne(); + i.methodTwo(); + } +} + +aspect X { + public N Impl<N>.methodTwo() { return null;} +} diff --git a/tests/java5/generics/itds/bridgeMethods/Util.java b/tests/java5/generics/itds/bridgeMethods/Util.java new file mode 100644 index 000000000..2016f1d4d --- /dev/null +++ b/tests/java5/generics/itds/bridgeMethods/Util.java @@ -0,0 +1,66 @@ +import java.lang.reflect.*; +import java.util.*; + +public class Util { + + public static void dumpMethods(String clazzname,String[] expectedMethods) { + List methodsFound = new ArrayList(); + try { + java.lang.Class clz = Class.forName(clazzname); + Method m[] = clz.getDeclaredMethods(); + System.err.println("Number of methods defined for "+clazzname+" is "+(m==null?0:m.length)); + if (m!=null) { + for (int i =0;i<m.length;i++) { + String methodString = m[i].getReturnType().getName()+" "+m[i].getDeclaringClass().getName()+"."+ + m[i].getName()+"("+stringify(m[i].getParameterTypes())+")"+ + (m[i].isBridge()?" [BridgeMethod]":""); + methodsFound.add(methodString); + } + } + } catch (Throwable e) {e.printStackTrace();} + + StringBuffer diagnosticInfo = new StringBuffer(); + diagnosticInfo.append("\nExpected:\n").append(dumparray(expectedMethods)); + diagnosticInfo.append("\nFound:\n").append(dumplist(methodsFound)); + + for (int i = 0; i < expectedMethods.length; i++) { + String string = expectedMethods[i]; + if (!methodsFound.contains(string)) { + throw new RuntimeException("Expecting method '"+string+"' but didnt find it\n"+diagnosticInfo.toString()); + } + methodsFound.remove(string); + } + if (methodsFound.size()>0) { + throw new RuntimeException("Found more methods than expected: "+dumplist(methodsFound)); + } + } + + private static String dumparray(String[] arr) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < arr.length; i++) { + String string = arr[i]; + sb.append(string).append("\n"); + } + return sb.toString(); + } + + private static String dumplist(List l) { + StringBuffer sb = new StringBuffer(); + for (Iterator iter = l.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + sb.append(element).append("\n"); + } + return sb.toString(); + } + + private static String stringify(Class[] clazzes) { + if (clazzes==null) return ""; + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < clazzes.length; i++) { + Class class1 = clazzes[i]; + if (i>0) sb.append(","); + sb.append(clazzes[i].getName()); + } + return sb.toString(); + } +}
\ No newline at end of file |