Fixes http://code.google.com/p/google-web-toolkit/issues/detail?id=3611 -- refresh did not work correctly when -gen was used. 

Patch by: amitmanjhi
Review by: robertvawter (desk review)



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5297 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/javac/CompilationState.java b/dev/core/src/com/google/gwt/dev/javac/CompilationState.java
index d145d46..7f2ec5e 100644
--- a/dev/core/src/com/google/gwt/dev/javac/CompilationState.java
+++ b/dev/core/src/com/google/gwt/dev/javac/CompilationState.java
@@ -294,7 +294,7 @@
       CompilationUnit graveyardUnit = graveyardUnits.remove(typeName);
       if (graveyardUnit != null) {
         assert graveyardUnit.getState() == State.GRAVEYARD;
-        if (unit.getSource().equals(graveyardUnit.getSource())) {
+        if (unit.getStrongHash().equals(graveyardUnit.getStrongHash())) {
           usefulGraveyardUnits.put(typeName, graveyardUnit);
         } else {
           // The old unit is invalidated.
diff --git a/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java b/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
index cd296df..7d6fa5d 100644
--- a/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
+++ b/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java
@@ -378,6 +378,15 @@
   public abstract String getSource();
 
   /**
+   * Returns the strong hash of the source. The default implementation simply
+   * returns the source. Subclasses can override this implementation if source
+   * might be overwritten.
+   */
+  public String getStrongHash() {
+    return getSource();
+  }
+
+  /**
    * Returns the fully-qualified name of the top level public type.
    */
   public abstract String getTypeName();
diff --git a/dev/core/src/com/google/gwt/dev/shell/StandardGeneratorContext.java b/dev/core/src/com/google/gwt/dev/shell/StandardGeneratorContext.java
index 6037d6b..84a4d48 100644
--- a/dev/core/src/com/google/gwt/dev/shell/StandardGeneratorContext.java
+++ b/dev/core/src/com/google/gwt/dev/shell/StandardGeneratorContext.java
@@ -148,6 +148,7 @@
       implements Generated {
 
     private PrintWriter pw;
+    private String strongHash; // cache so that refreshes work correctly
 
     public GeneratedUnitWithFile(File file, PrintWriter pw, String packageName) {
       super(file, packageName);
@@ -162,6 +163,7 @@
     public void commit() {
       pw.close();
       pw = null;
+      strongHash = Util.computeStrongName(getSource().getBytes());
     }
 
     @Override
@@ -172,6 +174,15 @@
       return super.getSource();
     }
 
+    /**
+     * The old source is not preserved across refreshes. We use a strongHash to
+     * avoid the memory overhead of storing the source.
+     */
+    @Override
+    public String getStrongHash() {
+      return strongHash;
+    }
+
     @Override
     public boolean isGenerated() {
       return true;