]> source.dussan.org Git - aspectj.git/commitdiff
genericitds: bridge method testcode.
authoraclement <aclement>
Wed, 24 Aug 2005 08:05:27 +0000 (08:05 +0000)
committeraclement <aclement>
Wed, 24 Aug 2005 08:05:27 +0000 (08:05 +0000)
tests/java5/generics/itds/bridgeMethods/Bridging1.aj [new file with mode: 0644]
tests/java5/generics/itds/bridgeMethods/Bridging2.aj [new file with mode: 0644]
tests/java5/generics/itds/bridgeMethods/Bridging3.aj [new file with mode: 0644]
tests/java5/generics/itds/bridgeMethods/BridgingITD1.aj [new file with mode: 0644]
tests/java5/generics/itds/bridgeMethods/BridgingITD2.aj [new file with mode: 0644]
tests/java5/generics/itds/bridgeMethods/C.java [new file with mode: 0644]
tests/java5/generics/itds/bridgeMethods/ProgramA.java [new file with mode: 0644]
tests/java5/generics/itds/bridgeMethods/Util.java [new file with mode: 0644]

diff --git a/tests/java5/generics/itds/bridgeMethods/Bridging1.aj b/tests/java5/generics/itds/bridgeMethods/Bridging1.aj
new file mode 100644 (file)
index 0000000..6aefd13
--- /dev/null
@@ -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 (file)
index 0000000..ecd270d
--- /dev/null
@@ -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 (file)
index 0000000..13b7003
--- /dev/null
@@ -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 (file)
index 0000000..8631df6
--- /dev/null
@@ -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 (file)
index 0000000..4e1d7b8
--- /dev/null
@@ -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 (file)
index 0000000..ba1081c
--- /dev/null
@@ -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 (file)
index 0000000..69a3989
--- /dev/null
@@ -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 (file)
index 0000000..2016f1d
--- /dev/null
@@ -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