Reviewers: jbrosenberg,

Message:
tiny review

Description:
Fixes a compile error that occurs with code like this:

interface SubIterator<E> extends Iterator<E> {
}

class Foo implements Iterable<String> {
  @Override
  public SubIterator<String> iterator() {
    return null;
  }
}

We were trying to find 'SubIterator.next()' which isn't modeled in JDT.
It turns out JDT has the right answer in a private field.

Please review this at http://gwt-code-reviews.appspot.com/1450814/

Affected files:
  M dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java


Index: dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java index 7d0957b5786563400524faeaa6031e27d78023b8..67ab81194733729b44c6dde5b953ca91c96b8c69 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
@@ -199,6 +199,7 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
 import org.eclipse.jdt.internal.compiler.lookup.VariableBinding;
 import org.eclipse.jdt.internal.compiler.util.Util;

+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -979,16 +980,8 @@ public class GwtAstBuilder {
           // Perform any implicit reference type casts (due to generics).
           // Note this occurs before potential unboxing.
           if (elementVar.getType() != javaLangObject) {
-            /*
- * Compute the collection element type by walking the iterator()
-             * method, which may be parameterized.
-             */
- ReferenceBinding collectionType = (ReferenceBinding) x.collection.resolvedType;
-            MethodBinding iteratorMethod =
- collectionType.getExactMethod(ITERATOR, NO_TYPES, cudScope); - ReferenceBinding iteratorType = (ReferenceBinding) iteratorMethod.returnType;
-            MethodBinding nextMethod = iteratorType.getMethods(NEXT)[0];
-            TypeBinding collectionElementType = nextMethod.returnType;
+            TypeBinding collectionElementType =
+                (ReferenceBinding) collectionElementTypeField.get(x);
             JType toType = typeMap.get(collectionElementType);
             assert (toType instanceof JReferenceType);
elementDecl.initializer = maybeCast(toType, elementDecl.initializer);
@@ -2762,6 +2755,12 @@ public class GwtAstBuilder {

   private static final char[] _STRING = "_String".toCharArray();
   private static final String ARRAY_LENGTH_FIELD = "length";
+
+  /**
+   * Reflective access to {@link ForeachStatement#collectionElementType}.
+   */
+  private static final Field collectionElementTypeField;
+
private static final char[] CREATE_VALUE_OF_MAP = "createValueOfMap".toCharArray();
   private static final char[] HAS_NEXT = "hasNext".toCharArray();
   private static final char[] ITERATOR = "iterator".toCharArray();
@@ -2775,6 +2774,13 @@ public class GwtAstBuilder {

   static {
     InternalCompilerException.preload();
+    try {
+ collectionElementTypeField = ForeachStatement.class.getDeclaredField("collectionElementType");
+      collectionElementTypeField.setAccessible(true);
+    } catch (Exception e) {
+      throw new RuntimeException(
+ "Unexpectedly unable to access ForeachStatement.collectionElementType via reflection", e);
+    }
   }

   static String dotify(char[][] name) {


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to