Don't attempt generator result caching for deRPC

Review at http://gwt-code-reviews.appspot.com/1462809


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10390 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/rebind/rpc/CachedRpcTypeInformation.java b/user/src/com/google/gwt/user/rebind/rpc/CachedRpcTypeInformation.java
index 24b2fa7..864f8f5 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/CachedRpcTypeInformation.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/CachedRpcTypeInformation.java
@@ -48,26 +48,17 @@
     recordTypes(serializableFromBrowser, instantiableFromBrowser, typesFromBrowser);
     recordTypes(serializableToBrowser, instantiableToBrowser, typesToBrowser);
 
+    assert (customSerializersUsed != null);
     for (JType type : customSerializersUsed) {
       addCustomSerializerType(type);
     }
 
+    assert (typesNotUsingCustomSerializers != null);
     for (JType type : typesNotUsingCustomSerializers) {
       addTypeNotUsingCustomSerializer(type);
     }
   }
 
-  public void addCustomSerializerType(JType type) {
-    String sourceName = type.getQualifiedSourceName();
-    lastModifiedTimes.put(sourceName, getLastModifiedTime(type));
-    customSerializerTypes.add(sourceName);
-  }
-
-  public void addTypeNotUsingCustomSerializer(JType type) {
-    String sourceName = type.getQualifiedSourceName();
-    typesNotUsingCustomSerializer.add(sourceName);
-  }
-
   public boolean checkLastModifiedTime(JType type) {
     Long cachedTime = lastModifiedTimes.get(type.getQualifiedSourceName());
     if (cachedTime == null) {
@@ -134,10 +125,35 @@
     return typesNotUsingCustomSerializer.contains(type.getQualifiedSourceName());
   }
 
+  private void addCustomSerializerType(JType type) {
+    String sourceName = type.getQualifiedSourceName();
+    lastModifiedTimes.put(sourceName, getLastModifiedTime(type));
+    customSerializerTypes.add(sourceName);
+  }
+
+  private void addTypeNotUsingCustomSerializer(JType type) {
+    String sourceName = type.getQualifiedSourceName();
+    typesNotUsingCustomSerializer.add(sourceName);
+  }
+
+  private boolean checkTypes(TreeLogger logger, Set<String> serializable, Set<String> instantiable,
+      SerializableTypeOracle sto) {
+    for (JType type : sto.getSerializableTypes()) {
+      String sourceName = type.getQualifiedSourceName();
+      if (sto.isSerializable(type) != serializable.contains(sourceName)
+          || sto.maybeInstantiated(type) != instantiable.contains(sourceName)
+          || !checkLastModifiedTime(type)) {
+        logger.log(TreeLogger.TRACE, "A change was detected in type " + sourceName);
+        return false;
+      }
+    }
+    return true;
+  }
+
   /*
    * Finds a last modified time for a type, for testing cacheability.
    */
-  public long getLastModifiedTime(JType type) {
+  private long getLastModifiedTime(JType type) {
     JType typeToCheck;
     if (type instanceof JArrayType) {
       typeToCheck = type.getLeafType();
@@ -158,20 +174,6 @@
     }
   }
 
-  private boolean checkTypes(TreeLogger logger, Set<String> serializable, Set<String> instantiable,
-      SerializableTypeOracle sto) {
-    for (JType type : sto.getSerializableTypes()) {
-      String sourceName = type.getQualifiedSourceName();
-      if (sto.isSerializable(type) != serializable.contains(sourceName)
-          || sto.maybeInstantiated(type) != instantiable.contains(sourceName)
-          || !checkLastModifiedTime(type)) {
-        logger.log(TreeLogger.TRACE, "A change was detected in type " + sourceName);
-        return false;
-      }
-    }
-    return true;
-  }
-
   private void logDifferencesBetweenCurrentAndCachedTypes(TreeLogger logger, JType[] currentTypes,
       Set<String> cachedTypes) {
 
@@ -190,6 +192,7 @@
 
   private void recordTypes(Set<String> serializable, Set<String> instantiable,
       SerializableTypeOracle sto) {
+    assert (sto != null);
     for (JType type : sto.getSerializableTypes()) {
       String sourceName = type.getQualifiedSourceName();
       lastModifiedTimes.put(sourceName, getLastModifiedTime(type));
diff --git a/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java b/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
index 71acaee..0596841 100644
--- a/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
+++ b/user/src/com/google/gwt/user/rebind/rpc/ProxyCreator.java
@@ -325,8 +325,8 @@
       event.end();
     }
 
-    // Check generator result cacheability, to see if we can return now
-    if (checkGeneratorResultCacheability(logger, context, typesSentFromBrowser, typesSentToBrowser)) {
+    // Check previous cached result, to see if we can return now
+    if (checkCachedGeneratorResultValid(logger, context, typesSentFromBrowser, typesSentToBrowser)) {
       logger.log(TreeLogger.TRACE, "Reusing all cached artifacts for " + getProxyQualifiedName());
       return new RebindResult(RebindStatus.USE_ALL_CACHED, getProxyQualifiedName());
     }
@@ -378,7 +378,7 @@
           serializationPolicyStrongName, rpcLog));
     }
 
-    if (context.isGeneratorResultCachingEnabled()) {
+    if (checkGeneratorResultCacheability(context)) {
       // Remember the type info that we care about for cacheability testing.
       CachedClientDataMap clientData = new CachedClientDataMap();
       CachedRpcTypeInformation cti =
@@ -392,8 +392,8 @@
 
       /*
        * Return with RebindStatus.USE_PARTIAL_CACHED, since we are allowing
-       * generator result caching for field serializers, but other generated
-       * types cannot be cached effectively.
+       * reuse of cached results for field serializers, when available, but
+       * all other types have been newly generated.
        */
       return new RebindResult(RebindStatus.USE_PARTIAL_CACHED, getProxyQualifiedName(), clientData);
     } else {
@@ -832,7 +832,7 @@
     return typeOracle.findType(packageName, getProxySimpleName()) != null;
   }
 
-  private boolean checkGeneratorResultCacheability(TreeLogger logger, GeneratorContextExt ctx,
+  private boolean checkCachedGeneratorResultValid(TreeLogger logger, GeneratorContextExt ctx,
       SerializableTypeOracle typesSentFromBrowser, SerializableTypeOracle typesSentToBrowser) {
 
     CachedRebindResult lastResult = ctx.getCachedGeneratorResult();
@@ -864,6 +864,18 @@
     return true;
   }
 
+  private boolean checkGeneratorResultCacheability(GeneratorContextExt context) {
+    /*
+     * Currently not supporting caching for implementations which sub-class this
+     * class, such as {@link RpcProxyCreator}, which implements deRPC.
+     */
+    if (!this.getClass().equals(ProxyCreator.class)) {
+      return false;
+    }
+
+    return context.isGeneratorResultCachingEnabled();
+  }
+
   private void emitPolicyFileArtifact(TreeLogger logger, GeneratorContextExt context,
       String partialPath) throws UnableToCompleteException {
     try {