Revision: 10493
Author:   gwt.mirror...@gmail.com
Date:     Thu Aug  4 11:07:02 2011
Log:      Remove CompilationUnit.getSource().

No longer needed with GwtAstBuidler.

http://gwt-code-reviews.appspot.com/1462807/
Review by: zun...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=10493

Modified:
 /trunk/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java
/trunk/dev/core/src/com/google/gwt/dev/javac/CompilationProblemReporter.java
 /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
 /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
 /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnitBuilder.java
 /trunk/dev/core/src/com/google/gwt/dev/javac/SourceFileCompilationUnit.java
 /trunk/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java
/trunk/dev/core/test/com/google/gwt/dev/javac/CompilationUnitArchiveTest.java
 /trunk/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java Tue Jun 14 05:20:58 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java Thu Aug 4 11:07:02 2011
@@ -41,7 +41,6 @@
   private final CategorizedProblem[] problems;
   private final String resourceLocation;
   private final String resourcePath;
-  private final DiskCacheToken sourceToken;
   private final String typeName;

   /**
@@ -67,7 +66,6 @@
     this.problems = unit.problems;
     this.astToken = unit.astToken;
     this.astVersion = unit.astVersion;
-    this.sourceToken = unit.sourceToken;

     // Override these fields
     this.lastModified = lastModified;
@@ -85,7 +83,7 @@
    *          serialized AST types.
    */
   @SuppressWarnings("deprecation")
- CachedCompilationUnit(CompilationUnit unit, long sourceToken, long astToken) {
+  CachedCompilationUnit(CompilationUnit unit, long astToken) {
     assert unit != null;
     this.compiledClasses = unit.getCompiledClasses();
     this.contentId = unit.getContentId();
@@ -110,7 +108,6 @@
     }
     this.astToken = new DiskCacheToken(astToken);
     this.astVersion = GwtAstBuilder.getSerializationVersion();
-    this.sourceToken = new DiskCacheToken(sourceToken);
   }

   @Override
@@ -147,12 +144,6 @@
   public String getResourcePath() {
     return resourcePath;
   }
-
-  @Override
-  @Deprecated
-  public String getSource() {
-    return sourceToken.readString();
-  }

   @Override
   public String getTypeName() {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationProblemReporter.java Wed Jun 8 16:44:32 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationProblemReporter.java Thu Aug 4 11:07:02 2011
@@ -19,6 +19,7 @@
 import com.google.gwt.core.ext.TreeLogger.HelpInfo;
 import com.google.gwt.core.ext.TreeLogger.Type;
 import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.dev.javac.CompilationUnitBuilder.GeneratedCompilationUnit;
 import com.google.gwt.dev.jjs.InternalCompilerException;
 import com.google.gwt.dev.jjs.InternalCompilerException.NodeInfo;
 import com.google.gwt.dev.jjs.SourceInfo;
@@ -29,7 +30,6 @@

 import java.io.File;
 import java.io.IOException;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -43,13 +43,6 @@
  * console.
  */
 public class CompilationProblemReporter {
-
-  /**
-   * Used to lazily retrieve source if needed for reporting an error.
-   */
-  public interface SourceFetcher {
-    String getSource();
-  }

   /**
* Used as a convenience to catch all exceptions thrown by the compiler. For
@@ -144,40 +137,24 @@
   }

   /**
-   * Walk the compilation state and report errors if they exist.
+   * Logs errors to the console.
    *
    * @param logger logger for reporting errors to the console
-   * @param compilationState contains units that might contain errors
- * @param suppressErrors See {@link #reportErrors(TreeLogger, CompilationUnit, boolean)}
+   * @param unit Compilation unit that may have errors
+   * @param suppressErrors Controls he log level for logging errors. If
+ * <code>false</code> is passed, compilation errors are logged at
+   *          TreeLogger.ERROR and warnings logged at TreeLogger.WARN. If
+   *          <code>true</code> is passed, compilation errors are logged at
+   *          TreeLogger.TRACE and TreeLogger.DEBUG.
+   * @return <code>true</code> if an error was logged.
    */
- public static void reportAllErrors(TreeLogger logger, CompilationState compilationState,
-      boolean suppressErrors) {
-    for (CompilationUnit unit : compilationState.getCompilationUnits()) {
-      if (unit.isError()) {
-        reportErrors(logger, unit, suppressErrors);
-      }
-    }
-  }
-
-  /**
-   * Report an error in a compilation unit to the console.
-   *
-   * @param logger logger for reporting errors to the console
-   * @param problems problems to report on the console.
-   * @param fileName Name of the source file for the unit where the problem
-   *          originated.
- * @param isError <code>true</code> if this is considered a fatal compilation
-   *          error.
-   * @param suppressErrors Controls the log level for logging errors. See
-   *          {@link #reportErrors(TreeLogger, CompilationUnit, boolean)}.
-   * @return a branch of the logger parameter for logging further problems.
-   */
- public static TreeLogger reportErrors(TreeLogger logger, CategorizedProblem[] problems, - String fileName, boolean isError, SourceFetcher fetcher, String typeName,
-      boolean suppressErrors) {
+ public static boolean reportErrors(TreeLogger logger, CompilationUnit unit, boolean suppressErrors) {
+    CategorizedProblem[] problems = unit.getProblems();
     if (problems == null || problems.length == 0) {
-      return null;
-    }
+      return false;
+    }
+    String fileName = unit.getResourceLocation();
+    boolean isError = unit.isError();
     TreeLogger.Type warnLogLevel;
     TreeLogger.Type errorLogLevel;
     if (suppressErrors) {
@@ -225,42 +202,13 @@
       branch.log(logLevel, msgBuf.toString(), null, helpInfo);
     }

-    if (branch != null && fetcher != null) {
- CompilationProblemReporter.maybeDumpSource(branch, fileName, fetcher, typeName);
-    }
-
-    return branch;
-  }
-
-  /**
-   * Logs errors to the console.
-   *
-   * @param logger logger for reporting errors to the console
-   * @param unit Compilation unit that may have errors
-   * @param suppressErrors Controls he log level for logging errors. If
- * <code>false</code> is passed, compilation errors are logged at
-   *          TreeLogger.ERROR and warnings logged at TreeLogger.WARN. If
-   *          <code>true</code> is passed, compilation errors are logged at
-   *          TreeLogger.TRACE and TreeLogger.DEBUG.
-   * @return <code>true</code> if an error was logged.
-   */
-  @SuppressWarnings("deprecation")
- public static boolean reportErrors(TreeLogger logger, final CompilationUnit unit,
-      boolean suppressErrors) {
-    CategorizedProblem[] problems = unit.getProblems();
-    if (problems == null || problems.length == 0) {
-      return false;
-    }
-    TreeLogger branch =
- CompilationProblemReporter.reportErrors(logger, unit.getProblems(), unit
-            .getResourceLocation(), unit.isError(), new SourceFetcher() {
-
-          @Override
-          public String getSource() {
-            return unit.getSource();
-          }
-
-        }, unit.getTypeName(), suppressErrors);
+    if (branch != null && branch.isLoggable(TreeLogger.INFO)) {
+      if (unit instanceof GeneratedCompilationUnit) {
+ GeneratedCompilationUnit generatedUnit = (GeneratedCompilationUnit) unit; + CompilationProblemReporter.maybeDumpSource(branch, generatedUnit.getSource(), unit
+            .getTypeName());
+      }
+    }
     return branch != null;
   }

@@ -275,23 +223,6 @@
       }
     }
   }
-
-  private static boolean isCompilationUnitOnDisk(String loc) {
-    try {
-      if (new File(loc).exists()) {
-        return true;
-      }
-
-      URL url = new URL(loc);
-      String s = url.toExternalForm();
- if (s.startsWith("file:") || s.startsWith("jar:file:") || s.startsWith("zip:file:")) {
-        return true;
-      }
-    } catch (MalformedURLException e) {
-      // Probably not really on disk.
-    }
-    return false;
-  }

private static void logDependentErrors(TreeLogger logger, String missingType,
       CompilationState compilationState) {
@@ -321,24 +252,7 @@
   /**
    * Give the developer a chance to see the in-memory source that failed.
    */
- private static void maybeDumpSource(TreeLogger logger, String location, SourceFetcher fetcher,
-      String typeName) {
-
-    if (location.startsWith("/mock/")) {
-      // Unit test mocks, don't dump to disk.
-      return;
-    }
-
-    if (CompilationProblemReporter.isCompilationUnitOnDisk(location)) {
-      // Don't write another copy.
-      return;
-    }
-
-    if (!logger.isLoggable(TreeLogger.INFO)) {
-      // Don't bother dumping source if they can't see the related message.
-      return;
-    }
-
+ private static void maybeDumpSource(TreeLogger logger, String source, String typeName) {
     File tmpSrc;
     Throwable caught = null;
     try {
@@ -347,7 +261,7 @@
         typeName = "_" + typeName;
       }
       tmpSrc = File.createTempFile(typeName, ".java");
-      Util.writeStringAsFile(tmpSrc, fetcher.getSource());
+      Util.writeStringAsFile(tmpSrc, source);
       String dumpPath = tmpSrc.getAbsolutePath();
       if (logger.isLoggable(TreeLogger.INFO)) {
         logger.log(TreeLogger.INFO, "See snapshot: " + dumpPath, null);
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java Wed Aug 3 10:33:49 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java Thu Aug 4 11:07:02 2011
@@ -473,9 +473,12 @@
       // Look for units previously compiled
       CompilationUnit cachedUnit = unitCache.find(builder.getContentId());
       if (cachedUnit != null) {
-        cachedUnits.put(builder, cachedUnit);
-        compileMoreLater.addValidUnit(cachedUnit);
-        continue;
+        // Recompile generated units with errors so source can be dumped.
+        if (!cachedUnit.isError()) {
+          cachedUnits.put(builder, cachedUnit);
+          compileMoreLater.addValidUnit(cachedUnit);
+          continue;
+        }
       }
       builders.add(builder);
     }
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java Wed Jun 8 16:44:32 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java Thu Aug 4 11:07:02 2011
@@ -307,12 +307,6 @@
    */
   public abstract String getResourcePath();

-  /**
-   * Returns the source code for this unit.
-   */
-  @Deprecated
-  public abstract String getSource();
-
   /**
    * Returns the fully-qualified name of the top level public type.
    */
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnitBuilder.java Tue Jun 28 01:02:19 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnitBuilder.java Thu Aug 4 11:07:02 2011
@@ -1,12 +1,12 @@
 /*
  * Copyright 2009 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of
  * the License at
- *
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
  * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -151,7 +151,7 @@
     }
   }

- private static final class GeneratedCompilationUnit extends CompilationUnitImpl {
+  static final class GeneratedCompilationUnit extends CompilationUnitImpl {
     private final GeneratedUnit generatedUnit;

     public GeneratedCompilationUnit(GeneratedUnit generatedUnit,
@@ -164,9 +164,7 @@

     @Override
     public CachedCompilationUnit asCachedCompilationUnit() {
-      long sourceToken = generatedUnit.getSourceToken();
-      assert sourceToken >= 0;
-      return new CachedCompilationUnit(this, sourceToken, astToken);
+      return new CachedCompilationUnit(this, astToken);
     }

     @Override
@@ -184,12 +182,6 @@
       return Shared.toPath(generatedUnit.getTypeName());
     }

-    @Deprecated
-    @Override
-    public String getSource() {
-      return generatedUnit.getSource();
-    }
-
     @Override
     public String getTypeName() {
       return generatedUnit.getTypeName();
@@ -211,6 +203,10 @@
     ContentId getContentId() {
       return new ContentId(getTypeName(), generatedUnit.getStrongHash());
     }
+
+    String getSource() {
+      return generatedUnit.getSource();
+    }
   }

public static CompilationUnitBuilder create(GeneratedUnit generatedUnit) {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/SourceFileCompilationUnit.java Mon Jun 27 09:39:39 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/javac/SourceFileCompilationUnit.java Thu Aug 4 11:07:02 2011
@@ -17,12 +17,9 @@

 import com.google.gwt.dev.jjs.ast.JDeclaredType;
 import com.google.gwt.dev.resource.Resource;
-import com.google.gwt.util.tools.Utility;

 import org.eclipse.jdt.core.compiler.CategorizedProblem;

-import java.io.IOException;
-import java.io.InputStream;
 import java.util.Collection;
 import java.util.List;

@@ -31,13 +28,6 @@
  */
 class SourceFileCompilationUnit extends CompilationUnitImpl {

-  /**
- * A token to retrieve this object's bytes from the disk cache. It's generally
-   * much faster to read from the disk cache than to reread individual
-   * resources.
-   */
-  private long sourceToken = -1;
-
   private final Resource sourceFile;

   private final ContentId contentId;
@@ -58,18 +48,7 @@

   @Override
   public CachedCompilationUnit asCachedCompilationUnit() {
-    if (sourceToken < 0) {
-      InputStream in = null;
-      try {
-        in = sourceFile.openContents();
-        sourceToken = diskCache.transferFromStream(in);
-      } catch (IOException ex) {
- throw new RuntimeException("Can't read resource:" + sourceFile.getLocation(), ex);
-      } finally {
-        Utility.close(in);
-      }
-    }
-    return new CachedCompilationUnit(this, sourceToken, astToken);
+    return new CachedCompilationUnit(this, astToken);
   }

   @Override
@@ -86,26 +65,6 @@
   public String getResourcePath() {
     return sourceFile.getPathPrefix() + sourceFile.getPath();
   }
-
-  @Deprecated
-  @Override
-  public String getSource() {
-    try {
-      if (sourceToken < 0) {
-        String sourceCode = Shared.readSource(sourceFile);
-        sourceToken = diskCache.writeString(sourceCode);
-        return sourceCode;
-      } else {
-        return diskCache.readString(sourceToken);
-      }
-    } catch (IOException ex) {
-      throw new RuntimeException("Can't read resource:" + sourceFile, ex);
-    }
-  }
-
-  public Resource getSourceFile() {
-    return sourceFile;
-  }

   @Override
   public String getTypeName() {
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java Thu Apr 21 07:48:58 2011 +++ /trunk/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java Thu Aug 4 11:07:02 2011
@@ -480,7 +480,6 @@
       CompilationUnit unit) throws Exception {
     assertNotNull(unit);
     assertEquals(resource.getLastModified(), unit.getLastModified());
-    assertEquals(resource.getString(), unit.getSource());

     // dependencies
     Dependencies deps = unit.getDependencies();
@@ -563,9 +562,6 @@
assertEquals(origRef.getSignatureHash(), newRef.getSignatureHash());
       }
     }
-
-    // Compare the source
-    assertEquals(originalUnit.getSource(), newUnit.getSource());

     // Compare JSNI Methods
     List<JsniMethod> origJsniMethods = originalUnit.getJsniMethods();
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/javac/CompilationUnitArchiveTest.java Wed Jun 8 16:44:32 2011 +++ /trunk/dev/core/test/com/google/gwt/dev/javac/CompilationUnitArchiveTest.java Thu Aug 4 11:07:02 2011
@@ -93,7 +93,6 @@
     CompilationUnit found = archive.findUnit(unit.getResourcePath());
     assertEquals(found.getTypeName(), lookupType);
     assertEquals(found.getResourceLocation(), unit.getResourceLocation());
-    assertEquals(found.getSource(), unit.getSource());
   }

   private void scrambleArray(Object[] array) {
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java Wed Jun 8 16:44:32 2011 +++ /trunk/dev/core/test/com/google/gwt/dev/javac/MockCompilationUnit.java Thu Aug 4 11:07:02 2011
@@ -33,7 +33,6 @@
   private final ContentId contentId;
   private final long lastModified;
   private final String resourceLocation;
-  private final String source;
   private final String typeName;

   public MockCompilationUnit(String typeName, String source) {
@@ -42,7 +41,6 @@

public MockCompilationUnit(String typeName, String source, String resourceLocation) {
     this.typeName = typeName;
-    this.source = source;
     this.resourceLocation = resourceLocation;
     contentId = new ContentId(typeName, source);
     lastModified = nextTimestamp.getAndIncrement();
@@ -51,9 +49,8 @@
   @Override
   public CachedCompilationUnit asCachedCompilationUnit() {
     DiskCache diskCache = DiskCache.INSTANCE;
-    long sourceToken = diskCache.writeByteArray(Util.getBytes(source));
long astToken = diskCache.writeByteArray(Util.getBytes("Dummy AST data"));
-    return new CachedCompilationUnit(this, sourceToken, astToken);
+    return new CachedCompilationUnit(this, astToken);
   }

   @Override
@@ -85,11 +82,6 @@
   public String getResourcePath() {
     return Shared.toPath(typeName);
   }
-
-  @Override
-  public String getSource() {
-    return source;
-  }

   @Override
   public String getTypeName() {

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to