Re-enable the gwt.typecreator.shard.size system property to fix RPC serializer code in legacy hosted mode.

Patch by: bobv
Review by: jat


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5057 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java b/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
index 19f311d..125bce6 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/TypeSerializerCreator.java
@@ -375,7 +375,18 @@
       }
     }
 
+    boolean shard = shardSize > 0 && filteredTypes.size() > shardSize;
+    int shardCount = 0;
+
+    if (shard) {
+      srcWriter.println("(function() {");
+    }
+
     for (JType type : filteredTypes) {
+      if (shard && ++shardCount % shardSize == 0) {
+        srcWriter.println("})();");
+        srcWriter.println("(function() {");
+      }
 
       srcWriter.println("@com.google.gwt.user.client.rpc.impl.SerializerBase"
           + "::registerMethods("
@@ -397,6 +408,10 @@
       srcWriter.println();
     }
 
+    if (shard) {
+      srcWriter.println("})();");
+    }
+
     srcWriter.outdent();
     srcWriter.println("}-*/;");
     srcWriter.println();
@@ -407,6 +422,12 @@
     srcWriter.indent();
 
     int index = 0;
+    boolean shard = shardSize > 0 && getSerializableTypes().length > shardSize;
+    int shardCount = 0;
+
+    if (shard) {
+      srcWriter.println("(function() {");
+    }
 
     for (JType type : getSerializableTypes()) {
 
@@ -429,6 +450,12 @@
         jsniTypeRef += "[]";
         type = type.isArray().getComponentType();
       }
+
+      if (shard && ++shardCount % shardSize == 0) {
+        srcWriter.println("})();");
+        srcWriter.println("(function() {");
+      }
+
       srcWriter.println("@com.google.gwt.user.client.rpc.impl.SerializerBase"
           + "::registerSignature("
           + "Lcom/google/gwt/core/client/JsArrayString;" + "Ljava/lang/Class;"
@@ -441,6 +468,10 @@
       srcWriter.println();
     }
 
+    if (shard) {
+      srcWriter.println("})();");
+    }
+
     srcWriter.outdent();
     srcWriter.println("}-*/;");
     srcWriter.println();