Fixes issue 3357; using -validateOnly with I18N caused spurious validation errors because we were trying to rebind every visible class.

Review by: bruce (desk)


git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4823 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/Precompile.java b/dev/core/src/com/google/gwt/dev/Precompile.java
index cb86208..0b97f1e 100644
--- a/dev/core/src/com/google/gwt/dev/Precompile.java
+++ b/dev/core/src/com/google/gwt/dev/Precompile.java
@@ -246,8 +246,8 @@
         public boolean run(TreeLogger logger) throws UnableToCompleteException {
           FutureTask<UpdateResult> updater = null;
           if (!options.isUpdateCheckDisabled()) {
-            updater = PlatformSpecific.checkForUpdatesInBackgroundThread(logger,
-                CheckForUpdates.ONE_DAY);
+            updater = PlatformSpecific.checkForUpdatesInBackgroundThread(
+                logger, CheckForUpdates.ONE_DAY);
           }
           boolean success = new Precompile(options).run(logger);
           if (success) {
@@ -298,7 +298,8 @@
           compilationState, rpo);
       PerfLogger.start("Precompile");
       UnifiedAst unifiedAst = JavaToJavaScriptCompiler.precompile(logger,
-          frontEnd, declEntryPts, jjsOptions, rpo.getPermuationCount() == 1);
+          frontEnd, declEntryPts, null, jjsOptions,
+          rpo.getPermuationCount() == 1);
       PerfLogger.end();
 
       // Merge all identical permutations together.
@@ -340,13 +341,14 @@
       CompilationState compilationState = module.getCompilationState(logger);
 
       String[] declEntryPts = module.getEntryPointTypeNames();
+      String[] additionalRootTypes = null;
       if (declEntryPts.length == 0) {
-        // Pretend that every single compilation unit is an entry point.
+        // No declared entry points, just validate all visible classes.
         Set<CompilationUnit> compilationUnits = compilationState.getCompilationUnits();
-        declEntryPts = new String[compilationUnits.size()];
+        additionalRootTypes = new String[compilationUnits.size()];
         int i = 0;
         for (CompilationUnit unit : compilationUnits) {
-          declEntryPts[i++] = unit.getTypeName();
+          additionalRootTypes[i++] = unit.getTypeName();
         }
       }
 
@@ -359,7 +361,7 @@
       WebModeCompilerFrontEnd frontEnd = new WebModeCompilerFrontEnd(
           compilationState, rpo);
       JavaToJavaScriptCompiler.precompile(logger, frontEnd, declEntryPts,
-          jjsOptions, true);
+          additionalRootTypes, jjsOptions, true);
       return true;
     } catch (UnableToCompleteException e) {
       // Already logged.
diff --git a/dev/core/src/com/google/gwt/dev/jdt/WebModeCompilerFrontEnd.java b/dev/core/src/com/google/gwt/dev/jdt/WebModeCompilerFrontEnd.java
index 300a42b..a8261cd 100644
--- a/dev/core/src/com/google/gwt/dev/jdt/WebModeCompilerFrontEnd.java
+++ b/dev/core/src/com/google/gwt/dev/jdt/WebModeCompilerFrontEnd.java
@@ -23,7 +23,6 @@
 import com.google.gwt.dev.jdt.FindDeferredBindingSitesVisitor.DeferredBindingSite;
 import com.google.gwt.dev.util.Empty;
 import com.google.gwt.dev.util.JsniRef;
-import com.google.gwt.dev.util.Util;
 
 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
@@ -31,6 +30,7 @@
 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
 
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
@@ -176,7 +176,7 @@
           }
           dependentTypeNames.add(typeName);
         }
-        Util.addAll(dependentTypeNames, resultTypes);
+        Collections.addAll(dependentTypeNames, resultTypes);
       } catch (UnableToCompleteException e) {
         FindDeferredBindingSitesVisitor.reportRebindProblem(site,
             "Failed to resolve '" + reqType + "' via deferred binding");
diff --git a/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java b/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
index 96f2f59..fa6aeca 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/JavaToJavaScriptCompiler.java
@@ -72,8 +72,8 @@
 import com.google.gwt.dev.js.JsVerboseNamer;
 import com.google.gwt.dev.js.ast.JsProgram;
 import com.google.gwt.dev.util.DefaultTextOutput;
+import com.google.gwt.dev.util.Empty;
 import com.google.gwt.dev.util.PerfLogger;
-import com.google.gwt.dev.util.Util;
 
 import org.eclipse.jdt.core.compiler.IProblem;
 import org.eclipse.jdt.internal.compiler.CompilationResult;
@@ -81,6 +81,7 @@
 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -212,7 +213,10 @@
    * 
    * @param logger the logger to use
    * @param compilerFrontEnd the compiler front ent
-   * @param declEntryPts the set of entry classes
+   * @param declEntryPts the set of entry classes declared in a GWT module;
+   *          these will be automatically rebound
+   * @param additionalRootTypes additional classes that should serve as code
+   *          roots; will not be rebound; may be <code>null</code>
    * @param options the compiler options
    * @param singlePermutation if true, do not pre-optimize the resulting AST or
    *          allow serialization of the result
@@ -222,28 +226,33 @@
    */
   public static UnifiedAst precompile(TreeLogger logger,
       WebModeCompilerFrontEnd compilerFrontEnd, String[] declEntryPts,
-      JJSOptions options, boolean singlePermutation)
-      throws UnableToCompleteException {
+      String[] additionalRootTypes, JJSOptions options,
+      boolean singlePermutation) throws UnableToCompleteException {
 
-    if (declEntryPts.length == 0) {
+    if (additionalRootTypes == null) {
+      additionalRootTypes = Empty.STRINGS;
+    }
+    if (declEntryPts.length + additionalRootTypes.length == 0) {
       throw new IllegalArgumentException("entry point(s) required");
     }
 
     RebindPermutationOracle rpo = compilerFrontEnd.getRebindPermutationOracle();
 
-    // Find all the possible rebound entry points.
-    Set<String> allEntryPoints = new TreeSet<String>();
+    Set<String> allRootTypes = new TreeSet<String>();
+
+    // Find all the possible rebinds for declared entry point types.
     for (String element : declEntryPts) {
       String[] all = rpo.getAllPossibleRebindAnswers(logger, element);
-      Util.addAll(allEntryPoints, all);
+      Collections.addAll(allRootTypes, all);
     }
-    allEntryPoints.addAll(JProgram.CODEGEN_TYPES_SET);
-    allEntryPoints.addAll(JProgram.INDEX_TYPES_SET);
+    Collections.addAll(allRootTypes, additionalRootTypes);
+    allRootTypes.addAll(JProgram.CODEGEN_TYPES_SET);
+    allRootTypes.addAll(JProgram.INDEX_TYPES_SET);
 
     // Compile the source and get the compiler so we can get the parse tree
     //
     CompilationUnitDeclaration[] goldenCuds = compilerFrontEnd.getCompilationUnitDeclarations(
-        logger, allEntryPoints.toArray(new String[0]));
+        logger, allRootTypes.toArray(new String[0]));
 
     // Check for compilation problems. We don't log here because any problems
     // found here will have already been logged by AbstractCompiler.
diff --git a/dev/core/src/com/google/gwt/dev/util/Util.java b/dev/core/src/com/google/gwt/dev/util/Util.java
index c3c4a4f..e0e3f75 100644
--- a/dev/core/src/com/google/gwt/dev/util/Util.java
+++ b/dev/core/src/com/google/gwt/dev/util/Util.java
@@ -83,12 +83,6 @@
       '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
       'E', 'F'};
 
-  public static <T> void addAll(Collection<T> c, T[] a) {
-    for (T val : a) {
-      c.add(val);
-    }
-  }
-
   public static byte[] append(byte[] xs, byte x) {
     int n = xs.length;
     byte[] t = new byte[n + 1];