Revision: 7436
Author: sp...@google.com
Date: Wed Jan 20 12:24:08 2010
Log: Merge r7343 from trunk.  Has arrays implement Serializable.

svn merge --ignore-ancestry -c 7343 https://google-web-toolkit.googlecode.com/svn/trunk .



http://code.google.com/p/google-web-toolkit/source/detail?r=7436

Modified:
 /releases/2.0/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
 /releases/2.0/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
 /releases/2.0/user/test/com/google/gwt/dev/jjs/test/ClassCastTest.java

=======================================
--- /releases/2.0/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java Tue Jul 28 09:27:08 2009 +++ /releases/2.0/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java Wed Jan 20 12:24:08 2010
@@ -71,10 +71,10 @@

public static final Set<String> INDEX_TYPES_SET = new LinkedHashSet<String>(
       Arrays.asList(new String[] {
-          "java.lang.Object", "java.lang.String", "java.lang.Class",
-          "java.lang.CharSequence", "java.lang.Comparable", "java.lang.Enum",
-          "java.lang.Iterable", "java.util.Iterator",
-          "com.google.gwt.core.client.GWT",
+          "java.io.Serializable", "java.lang.Object", "java.lang.String",
+          "java.lang.Class", "java.lang.CharSequence", "java.lang.Cloneable",
+          "java.lang.Comparable", "java.lang.Enum", "java.lang.Iterable",
+          "java.util.Iterator", "com.google.gwt.core.client.GWT",
           "com.google.gwt.core.client.JavaScriptObject",
           "com.google.gwt.lang.ClassLiteralHolder",
           "com.google.gwt.core.client.RunAsyncCallback",
@@ -310,6 +310,10 @@

private Map<JReferenceType, Integer> typeIdMap = new HashMap<JReferenceType, Integer>();

+  private JInterfaceType typeJavaIoSerializable;
+
+  private JInterfaceType typeJavaLangCloneable;
+
   private JClassType typeJavaLangEnum;

   private JClassType typeJavaLangObject;
@@ -329,10 +333,10 @@
   /**
    * Constructor.
    *
- * @param enableSourceInfoDescendants Controls whether or not SourceInfo nodes
-   *          created via the JProgram will record descendant information.
-   *          Enabling this feature will collect extra data during the
- * compilation cycle, but at a cost of memory and object allocations. + * @param correlator Controls whether or not SourceInfo nodes created via the + * JProgram will record descendant information. Enabling this feature + * will collect extra data during the compilation cycle, but at a
+   *          cost of memory and object allocations.
    */
   public JProgram(CorrelationFactory correlator) {
     super(correlator.makeSourceInfo(SourceOrigin.create(0,
@@ -461,6 +465,11 @@

     if (INDEX_TYPES_SET.contains(sname)) {
       indexedTypes.put(x.getShortName(), x);
+      if (sname.equals("java.lang.Cloneable")) {
+        typeJavaLangCloneable = x;
+      } else if (sname.equals("java.io.Serializable")) {
+        typeJavaIoSerializable = x;
+      }
     }

     return x;
@@ -691,6 +700,9 @@
         // unrelated
         return typeJavaLangObject;

+      } else if (greater == IS_ARRAY
+ && ((tLesser == typeJavaLangCloneable) || (tLesser == typeJavaIoSerializable))) {
+        return tLesser;
       } else {

// unrelated: the best commonality between an interface and array, or
=======================================
--- /releases/2.0/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java Fri Sep 25 11:27:03 2009 +++ /releases/2.0/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java Wed Jan 20 12:24:08 2010
@@ -286,6 +286,9 @@
    */
private final Map<JMethod, Map<JClassType, Set<JMethod>>> virtualUpRefMap = new IdentityHashMap<JMethod, Map<JClassType, Set<JMethod>>>();

+  private JDeclaredType javaIoSerializable;
+  private JDeclaredType javaLangCloneable;
+
   public JTypeOracle(JProgram program) {
     this.program = program;
   }
@@ -325,6 +328,12 @@
         }
       }

+      /*
+ * Warning: If this code is ever updated to consider casts of array types + * to interface types, then be sure to consider that casting an array to + * Serializable and Cloneable succeeds. Currently all casts of an array to + * an interface return true, which is overly conservative but is safe.
+       */
     } else if (type instanceof JClassType) {

       JClassType cType = (JClassType) type;
@@ -375,6 +384,10 @@
           }
         }
       }
+
+      if (qType == javaIoSerializable || qType == javaLangCloneable) {
+        return true;
+      }
     } else if (type instanceof JClassType) {

       JClassType cType = (JClassType) type;
@@ -408,6 +421,9 @@

   public void computeBeforeAST() {
     javaLangObject = program.getTypeJavaLangObject();
+ javaIoSerializable = program.getFromTypeMap(Serializable.class.getName());
+    javaLangCloneable = program.getFromTypeMap(Cloneable.class.getName());
+
     superClassMap.clear();
     subClassMap.clear();
     superInterfaceMap.clear();
=======================================
--- /releases/2.0/user/test/com/google/gwt/dev/jjs/test/ClassCastTest.java Wed Sep 3 13:46:24 2008 +++ /releases/2.0/user/test/com/google/gwt/dev/jjs/test/ClassCastTest.java Wed Jan 20 12:24:08 2010
@@ -16,9 +16,12 @@
 package com.google.gwt.dev.jjs.test;

 import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.user.client.ui.Widget;
+
+import java.io.Serializable;

 /**
- * TODO: document me.
+ * Test type casts and <code>instanceof</code>.
  */
 @SuppressWarnings("unused")
 public class ClassCastTest extends GWTTestCase {
@@ -32,13 +35,26 @@
   static abstract class Food {
   }

-  private final Food foodItem = new Apple();
-
-  private final CanEatRaw rawFoodItem = new Apple();
-
+  private volatile Object arrayOfInt = new int[3];
+  private volatile Object arrayOfWidget = new Widget[4];
+  private volatile Food foodItem = new Apple();
+  private volatile CanEatRaw rawFoodItem = new Apple();
+
+  @Override
   public String getModuleName() {
     return "com.google.gwt.dev.jjs.CompilerSuite";
   }
+
+  public void testArrayInterfaces() {
+    assertTrue(arrayOfInt instanceof Serializable);
+    assertTrue(arrayOfWidget instanceof Serializable);
+
+    assertTrue(arrayOfInt instanceof Cloneable);
+    assertTrue(arrayOfWidget instanceof Cloneable);
+
+    assertFalse(arrayOfInt instanceof Food);
+    assertFalse(arrayOfWidget instanceof Food);
+  }

   public void testBaseToInterface() {
     Apple apple = (Apple) foodItem;
-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to