Removing non-determinism by putting golden CUDs into a well-defined order based on fully-qualified main type name.  Change also includes miscellaneous warning removal.

Review by: spoon (desk check)


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2209 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jdt/AbstractCompiler.java b/dev/core/src/com/google/gwt/dev/jdt/AbstractCompiler.java
index a8caf35..c95e9b5 100644
--- a/dev/core/src/com/google/gwt/dev/jdt/AbstractCompiler.java
+++ b/dev/core/src/com/google/gwt/dev/jdt/AbstractCompiler.java
@@ -18,6 +18,7 @@
 import com.google.gwt.core.ext.TreeLogger;
 import com.google.gwt.core.ext.UnableToCompleteException;
 import com.google.gwt.core.ext.typeinfo.CompilationUnitProvider;
+import com.google.gwt.dev.util.CharArrayComparator;
 import com.google.gwt.dev.util.Empty;
 import com.google.gwt.dev.util.PerfLogger;
 import com.google.gwt.dev.util.Util;
@@ -42,11 +43,13 @@
 import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
 
 import java.net.URL;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeSet;
 
 /**
  * A facade around the JDT compiler to manage on-demand compilation, caching
@@ -436,6 +439,30 @@
     }
   }
 
+  private static final Comparator<CompilationUnitDeclaration> CUD_COMPARATOR = new Comparator<CompilationUnitDeclaration>() {
+
+    public int compare(CompilationUnitDeclaration cud1,
+        CompilationUnitDeclaration cud2) {
+      ICompilationUnit cu1 = cud1.compilationResult().getCompilationUnit();
+      ICompilationUnit cu2 = cud2.compilationResult().getCompilationUnit();
+      char[][] package1 = cu1.getPackageName();
+      char[][] package2 = cu2.getPackageName();
+      for (int i = 0, c = Math.min(package1.length, package2.length); i < c; ++i) {
+        int result = CharArrayComparator.INSTANCE.compare(package1[i],
+            package2[i]);
+        if (result != 0) {
+          return result;
+        }
+      }
+      int result = package2.length - package1.length;
+      if (result != 0) {
+        return result;
+      }
+      return CharArrayComparator.INSTANCE.compare(cu1.getMainTypeName(),
+          cu2.getMainTypeName());
+    }
+  };
+
   private static final CachePolicy DEFAULT_POLICY = new CachePolicy() {
     public boolean shouldProcess(CompilationUnitDeclaration cud) {
       return true;
@@ -500,8 +527,7 @@
     return cachePolicy;
   }
 
-  public void invalidateUnitsInFiles(Set<String> fileNames,
-      Set<String> typeNames) {
+  public final void invalidateUnitsInFiles(Set<String> typeNames) {
     // StandardSourceOracle has its own cache that needs to be cleared
     // out. Short of modifying the interface SourceOracle to have an
     // invalidateCups, this check is needed.
@@ -526,7 +552,8 @@
     //
     TreeLogger oldLogger = threadLogger.push(logger);
     try {
-      Set<CompilationUnitDeclaration> cuds = new HashSet<CompilationUnitDeclaration>();
+      Set<CompilationUnitDeclaration> cuds = new TreeSet<CompilationUnitDeclaration>(
+          CUD_COMPARATOR);
       compiler.compile(units, cuds);
       int size = cuds.size();
       CompilationUnitDeclaration[] cudArray = new CompilationUnitDeclaration[size];
@@ -536,22 +563,30 @@
     }
   }
 
+  @SuppressWarnings("unused")
+  // overrider may use unused parameter
   protected void doAcceptResult(CompilationResult result) {
     // Do nothing by default.
     //
   }
 
+  @SuppressWarnings("unused")
+  // overrider may use unused parameter
   protected void doCompilationUnitDeclarationValidation(
       CompilationUnitDeclaration cud) {
     // Do nothing by default.
     //
   }
 
+  @SuppressWarnings("unused")
+  // overrider may use unused parameter
   protected String[] doFindAdditionalTypesUsingJsni(TreeLogger logger,
       CompilationUnitDeclaration cud) {
     return Empty.STRINGS;
   }
 
+  @SuppressWarnings("unused")
+  // overrider may use unused parameter
   protected String[] doFindAdditionalTypesUsingRebinds(TreeLogger logger,
       CompilationUnitDeclaration cud) {
     return Empty.STRINGS;
@@ -562,6 +597,8 @@
    * type. By default we compile everything from source, so we never have it
    * unless a subclass overrides this method.
    */
+  @SuppressWarnings("unused")
+  // overrider may use unused parameter
   protected ByteCode doGetByteCodeFromCache(TreeLogger logger,
       String binaryTypeName) {
     return null;
diff --git a/dev/core/src/com/google/gwt/dev/jdt/AstCompiler.java b/dev/core/src/com/google/gwt/dev/jdt/AstCompiler.java
index 4c7edb9..4a00d50 100644
--- a/dev/core/src/com/google/gwt/dev/jdt/AstCompiler.java
+++ b/dev/core/src/com/google/gwt/dev/jdt/AstCompiler.java
@@ -115,7 +115,7 @@
   public void invalidateChangedFiles(Set<String> changedFiles,
       Set<String> typeNames) {
     cachedResults.removeAll(changedFiles);
-    invalidateUnitsInFiles(changedFiles, typeNames);
+    invalidateUnitsInFiles(typeNames);
   }
 
   @Override
diff --git a/dev/core/src/com/google/gwt/dev/jdt/CacheManager.java b/dev/core/src/com/google/gwt/dev/jdt/CacheManager.java
index b36573c..20d8986 100644
--- a/dev/core/src/com/google/gwt/dev/jdt/CacheManager.java
+++ b/dev/core/src/com/google/gwt/dev/jdt/CacheManager.java
@@ -388,10 +388,13 @@
       Set<Entry<String, Object>> out = new HashSet<Entry<String, Object>>() {
         @Override
         public boolean remove(Object o) {
-          Entry<String, Object> entry = (Entry<String, Object>) o;
-          boolean removed = (DiskCache.this.remove(entry.getKey())) != null;
-          super.remove(o);
-          return removed;
+          if (o instanceof Entry) {
+            Entry<?, ?> entry = (Entry<?, ?>) o;
+            boolean removed = (DiskCache.this.remove(entry.getKey())) != null;
+            super.remove(o);
+            return removed;
+          }
+          return false;
         }
       };
       out.addAll(cache.entrySet());
@@ -997,7 +1000,7 @@
         }
       }
     }
-    compiler.invalidateUnitsInFiles(changedFiles, invalidTypes);
+    compiler.invalidateUnitsInFiles(invalidTypes);
     changedFiles.clear();
   }