Author: [email protected]
Date: Wed Apr 29 23:16:00 2009
New Revision: 5313

Modified:
    trunk/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java

Log:
Created a new class in the TestFile that implements Generated so that the  
cast later succeeds.

Patch by: amitmanjhi
Review by: scottb (TBR)



Modified:  
trunk/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java
==============================================================================
--- trunk/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java      
 
(original)
+++ trunk/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java      
 
Wed Apr 29 23:16:00 2009
@@ -22,6 +22,8 @@
  import com.google.gwt.dev.javac.impl.MockResourceOracle;
  import com.google.gwt.dev.javac.impl.SourceFileCompilationUnit;
  import com.google.gwt.dev.resource.Resource;
+import com.google.gwt.dev.shell.StandardGeneratorContext.Generated;
+import com.google.gwt.dev.util.Util;
  import com.google.gwt.dev.util.log.AbstractTreeLogger;
  import com.google.gwt.dev.util.log.PrintWriterTreeLogger;

@@ -41,6 +43,45 @@
   */
  public class CompilationStateTest extends TestCase {

+  private class GeneratedSourceFileCompilationUnit extends
+      SourceFileCompilationUnit implements Generated {
+
+    private final boolean modifySource;
+    private String strongHash;
+
+    public GeneratedSourceFileCompilationUnit(Resource sourceFile, boolean  
modifySource) {
+      super(sourceFile);
+      this.modifySource = modifySource;
+    }
+
+    public void abort() {
+    }
+
+    public void commit() {
+    }
+
+    @Override
+    public String getSource() {
+      String extraChars = "";
+      if (modifySource) {
+        extraChars = "\n";
+      }
+      return super.getSource() + extraChars;
+    }
+
+    public String getStrongHash() {
+      if (strongHash == null) {
+        strongHash = Util.computeStrongName(Util.getBytes(getSource()));
+      }
+      return strongHash;
+    }
+
+    @Override
+    public boolean isGenerated() {
+      return true;
+    }
+  }
+
    static void assertUnitsChecked(Collection<CompilationUnit> units) {
      for (CompilationUnit unit : units) {
        assertSame(State.CHECKED, unit.getState());
@@ -293,12 +334,8 @@
        MockJavaResource... sourceFiles) {
      Set<CompilationUnit> units = new HashSet<CompilationUnit>();
      for (MockJavaResource sourceFile : sourceFiles) {
-      units.add(new SourceFileCompilationUnit(sourceFile) {
-        @Override
-        public boolean isGenerated() {
-          return true;
-        }
-      });
+      // keep the same source
+      units.add(new GeneratedSourceFileCompilationUnit(sourceFile, false));
      }
      return units;
    }
@@ -307,18 +344,8 @@
        MockJavaResource... sourceFiles) {
      Set<CompilationUnit> units = new HashSet<CompilationUnit>();
      for (MockJavaResource sourceFile : sourceFiles) {
-      units.add(new SourceFileCompilationUnit(sourceFile) {
-        /* modified the source */
-        @Override
-        public String getSource() {
-          return super.getSource() + "\n";
-        }
-
-        @Override
-        public boolean isGenerated() {
-          return true;
-        }
-      });
+      // modify the source
+      units.add(new GeneratedSourceFileCompilationUnit(sourceFile, true));
      }
      return units;
    }
@@ -377,8 +404,8 @@
     * <ol>
     * <li>Check graveyardUnits before refresh. assert size is 0.</li>
     * <li>Refresh. assert size is 'graveyardUnitsSize'.</li>
-   * <li>Add generated cups. Confirm that the 'reusedTypes' and
-   * 'numInvalidated' match.</li>
+   * <li>Add generated cups. Confirm that the 'reusedTypes'  
and 'numInvalidated'
+   * match.</li>
     * </ol>
     *
     * @param generatedCups generated CompilationUnits to be added.

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

Reply via email to