Crude AST versioning.

http://gwt-code-reviews.appspot.com/1450816/

Review by: zundel@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10331 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java b/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java
index 6cb542b..4bf3535 100644
--- a/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java
+++ b/dev/core/src/com/google/gwt/dev/javac/CachedCompilationUnit.java
@@ -15,6 +15,7 @@
  */
 package com.google.gwt.dev.javac;
 
+import com.google.gwt.dev.jjs.impl.GwtAstBuilder;
 import com.google.gwt.dev.util.DiskCacheToken;
 
 import org.eclipse.jdt.core.compiler.CategorizedProblem;
@@ -27,6 +28,7 @@
  */
 public class CachedCompilationUnit extends CompilationUnit {
   private final DiskCacheToken astToken;
+  private final long astVersion;
   private final Collection<CompiledClass> compiledClasses;
   private final ContentId contentId;
   private final Dependencies dependencies;
@@ -64,6 +66,7 @@
     this.isSuperSource = unit.isSuperSource();
     this.problems = unit.problems;
     this.astToken = unit.astToken;
+    this.astVersion = unit.astVersion;
     this.sourceToken = unit.sourceToken;
 
     // Override these fields
@@ -106,6 +109,7 @@
       }
     }
     this.astToken = new DiskCacheToken(astToken);
+    this.astVersion = GwtAstBuilder.getSerializationVersion();
     this.sourceToken = new DiskCacheToken(sourceToken);
   }
 
@@ -191,4 +195,8 @@
   CategorizedProblem[] getProblems() {
     return problems;
   }
+
+  long getTypesSerializedVersion() {
+    return astVersion;
+  }
 }
diff --git a/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java b/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
index 39bfe9c..80abe73 100644
--- a/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
+++ b/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
@@ -17,6 +17,7 @@
 
 import com.google.gwt.core.ext.TreeLogger;
 import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.dev.jjs.impl.GwtAstBuilder;
 import com.google.gwt.dev.util.log.speedtracer.DevModeEventType;
 import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger;
 import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger.Event;
@@ -489,10 +490,15 @@
              */
             inputStream = new ObjectInputStream(bis);
             while (true) {
-              CompilationUnit unit = (CompilationUnit) inputStream.readObject();
+              CachedCompilationUnit unit = (CachedCompilationUnit) inputStream.readObject();
               if (unit == null) {
                 break;
               }
+              if (GwtAstBuilder.ENABLED) {
+                if (unit.getTypesSerializedVersion() != GwtAstBuilder.getSerializationVersion()) {
+                  continue;
+                }
+              }
               UnitCacheEntry entry = new UnitCacheEntry(unit, UnitOrigin.PERSISTENT);
               UnitCacheEntry oldEntry = unitMap.get(unit.getResourcePath());
               if (oldEntry != null && unit.getLastModified() > oldEntry.getUnit().getLastModified()) {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
index 120e4ed..3297187 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
@@ -2752,6 +2752,13 @@
 
   public static boolean ENABLED = System.getProperties().containsKey("x.gwt.astBuilder");
 
+  /**
+   * Manually tracked version count.
+   * 
+   * TODO(zundel): something much more awesome?
+   */
+  private static final long AST_VERSION = 1;
+
   private static final char[] _STRING = "_String".toCharArray();
   private static final String ARRAY_LENGTH_FIELD = "length";
 
@@ -2782,6 +2789,16 @@
     }
   }
 
+  /**
+   * Returns a serialization version number. Used to determine if the AST
+   * contained within cached compilation units is compatible with the current
+   * version of GWT.
+   */
+  public static long getSerializationVersion() {
+    // TODO(zundel): something much awesomer.
+    return ENABLED ? AST_VERSION : 0L;
+  }
+
   static String dotify(char[][] name) {
     StringBuffer result = new StringBuffer();
     for (int i = 0; i < name.length; ++i) {