Author: sco...@google.com Date: Thu Apr 2 13:44:20 2009 New Revision: 5166
Removed: trunk/dev/core/src/com/google/gwt/dev/javac/JavaSourceFile.java trunk/dev/core/src/com/google/gwt/dev/javac/JavaSourceOracle.java trunk/dev/core/src/com/google/gwt/dev/javac/impl/JavaSourceOracleImpl.java trunk/dev/core/test/com/google/gwt/dev/javac/JavaSourceCodeBase.java trunk/dev/core/test/com/google/gwt/dev/javac/MockJavaSourceOracle.java trunk/dev/core/test/com/google/gwt/dev/javac/impl/JavaSourceOracleImplTest.java trunk/dev/core/test/com/google/gwt/dev/javac/impl/MockJavaSourceFile.java Modified: trunk/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java trunk/dev/core/src/com/google/gwt/dev/javac/CompilationState.java trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java trunk/dev/core/src/com/google/gwt/dev/javac/impl/SourceFileCompilationUnit.java trunk/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java trunk/dev/core/test/com/google/gwt/dev/javac/CompilationUnitFileReferenceTest.java trunk/dev/core/test/com/google/gwt/dev/javac/JavaCompilationSuite.java trunk/dev/core/test/com/google/gwt/dev/javac/JdtCompilerTest.java trunk/dev/core/test/com/google/gwt/dev/javac/TypeOracleTestingUtils.java trunk/dev/core/test/com/google/gwt/dev/javac/impl/JavaResourceBase.java trunk/dev/core/test/com/google/gwt/dev/javac/impl/JdtBehaviorTest.java trunk/dev/core/test/com/google/gwt/dev/javac/impl/MockResourceOracle.java trunk/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java trunk/user/test/com/google/gwt/dev/cfg/TestSuperAndSourceTags.java trunk/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java trunk/user/test/com/google/gwt/user/rebind/rpc/TypeHierarchyUtilsTest.java Log: Removed the highly unnecessary JavaSourceFile abstraction, which served no real purpose. Review by: jat Modified: trunk/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java ============================================================================== --- trunk/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java (original) +++ trunk/dev/core/src/com/google/gwt/dev/cfg/ModuleDef.java Thu Apr 2 13:44:20 2009 @@ -22,9 +22,6 @@ import com.google.gwt.core.ext.linker.LinkerOrder.Order; import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.google.gwt.dev.javac.CompilationState; -import com.google.gwt.dev.javac.JavaSourceFile; -import com.google.gwt.dev.javac.JavaSourceOracle; -import com.google.gwt.dev.javac.impl.JavaSourceOracleImpl; import com.google.gwt.dev.resource.Resource; import com.google.gwt.dev.resource.impl.DefaultFilters; import com.google.gwt.dev.resource.impl.PathPrefix; @@ -83,8 +80,6 @@ private CompilationState lazyCompilationState; - private JavaSourceOracle lazyJavaSourceOracle; - private ResourceOracleImpl lazyPublicOracle; private ResourceOracleImpl lazySourceOracle; @@ -233,7 +228,7 @@ public CompilationState getCompilationState(TreeLogger logger) throws UnableToCompleteException { if (lazyCompilationState == null) { - lazyCompilationState = new CompilationState(logger, lazyJavaSourceOracle); + lazyCompilationState = new CompilationState(logger, lazySourceOracle); checkForSeedTypes(logger); } return lazyCompilationState; @@ -358,8 +353,8 @@ * @param partialPath * @return */ - synchronized JavaSourceFile findSourceFile(String partialPath) { - return lazyJavaSourceOracle.getSourceMap().get(partialPath); + synchronized Resource findSourceFile(String partialPath) { + return lazySourceOracle.getResourceMap().get(partialPath); } /** @@ -409,7 +404,6 @@ branch.log(TreeLogger.WARN, "No source path entries; expect subsequent failures", null); } - lazyJavaSourceOracle = new JavaSourceOracleImpl(lazySourceOracle); PerfLogger.end(); } Modified: trunk/dev/core/src/com/google/gwt/dev/javac/CompilationState.java ============================================================================== --- trunk/dev/core/src/com/google/gwt/dev/javac/CompilationState.java (original) +++ trunk/dev/core/src/com/google/gwt/dev/javac/CompilationState.java Thu Apr 2 13:44:20 2009 @@ -20,6 +20,8 @@ import com.google.gwt.dev.javac.CompilationUnit.State; import com.google.gwt.dev.javac.impl.SourceFileCompilationUnit; import com.google.gwt.dev.js.ast.JsProgram; +import com.google.gwt.dev.resource.Resource; +import com.google.gwt.dev.resource.ResourceOracle; import com.google.gwt.dev.util.PerfLogger; import java.util.Collection; @@ -62,7 +64,8 @@ * protected for testing. */ Map<String, CompilationUnit> graveyardUnits; - private Set<JavaSourceFile> cachedSourceFiles = Collections.emptySet(); + + private Set<Resource> cachedSourceFiles = Collections.emptySet(); /** * Classes mapped by binary name. @@ -99,7 +102,7 @@ /** * Our source file inputs. */ - private final JavaSourceOracle sourceOracle; + private final ResourceOracle sourceOracle; /** * Construct a new {...@link CompilationState}. @@ -107,7 +110,7 @@ * @param sourceOracle an oracle used to retrieve source code and check for * changes in the underlying source code base */ - public CompilationState(TreeLogger logger, JavaSourceOracle sourceOracle) { + public CompilationState(TreeLogger logger, ResourceOracle sourceOracle) { this.sourceOracle = sourceOracle; refresh(logger); } @@ -127,7 +130,8 @@ } /** - * Reset all units to FRESH and clear TypeOracle to free up memory. + * Clear up all internal state to free up memory. Resets all units to FRESH + * and clears TypeOracle. */ public void clear() { // Always remove all generated compilation units. @@ -372,17 +376,17 @@ private void refreshFromSourceOracle() { // See if the source oracle has changed. - Set<JavaSourceFile> newSourceFiles = sourceOracle.getSourceFiles(); + Set<Resource> newSourceFiles = sourceOracle.getResources(); if (cachedSourceFiles == newSourceFiles) { return; } // Divide resources into changed and unchanged. - Set<JavaSourceFile> unchanged = new HashSet<JavaSourceFile>( + Set<Resource> unchanged = new HashSet<Resource>( cachedSourceFiles); unchanged.retainAll(newSourceFiles); - Set<JavaSourceFile> changed = new HashSet<JavaSourceFile>(newSourceFiles); + Set<Resource> changed = new HashSet<Resource>(newSourceFiles); changed.removeAll(unchanged); // First remove any stale units. @@ -396,8 +400,8 @@ } // Then add any new source files. - for (JavaSourceFile newSourceFile : changed) { - String typeName = newSourceFile.getTypeName(); + for (Resource newSourceFile : changed) { + String typeName = SourceFileCompilationUnit.getTypeName(newSourceFile); assert (!unitMap.containsKey(typeName)); unitMap.put(typeName, new SourceFileCompilationUnit(newSourceFile)); // invalid a graveyard unit, if a new unit has the same type. Modified: trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java ============================================================================== --- trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java (original) +++ trunk/dev/core/src/com/google/gwt/dev/javac/CompilationUnit.java Thu Apr 2 13:44:20 2009 @@ -21,6 +21,7 @@ import com.google.gwt.dev.asm.commons.EmptyVisitor; import com.google.gwt.dev.jdt.TypeRefVisitor; import com.google.gwt.dev.shell.CompilingClassLoader; +import com.google.gwt.dev.util.DiskCache; import com.google.gwt.dev.util.Util; import com.google.gwt.dev.util.collect.HashMap; import com.google.gwt.dev.util.collect.HashSet; @@ -54,6 +55,8 @@ * module and may be invalidated at certain times and recomputed. */ public abstract class CompilationUnit { + + protected static final DiskCache diskCache = new DiskCache(); /** * Encapsulates the functionality to find all nested classes of this class Modified: trunk/dev/core/src/com/google/gwt/dev/javac/impl/SourceFileCompilationUnit.java ============================================================================== --- trunk/dev/core/src/com/google/gwt/dev/javac/impl/SourceFileCompilationUnit.java (original) +++ trunk/dev/core/src/com/google/gwt/dev/javac/impl/SourceFileCompilationUnit.java Thu Apr 2 13:44:20 2009 @@ -16,16 +16,38 @@ package com.google.gwt.dev.javac.impl; import com.google.gwt.dev.javac.CompilationUnit; -import com.google.gwt.dev.javac.JavaSourceFile; +import com.google.gwt.dev.resource.Resource; +import com.google.gwt.dev.util.Util; + +import java.io.InputStream; /** * A compilation unit that was generated. */ public class SourceFileCompilationUnit extends CompilationUnit { - private JavaSourceFile sourceFile; + public static String getTypeName(Resource sourceFile) { + String path = sourceFile.getPath(); + assert (path.endsWith(".java")); + path = path.substring(0, path.lastIndexOf('.')); + return path.replace('/', '.'); + } + + public static String readSource(Resource sourceFile) { + InputStream contents = sourceFile.openContents(); + return Util.readStreamAsString(contents); + } + + /** + * 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 cacheToken = -1; + + private Resource sourceFile; - public SourceFileCompilationUnit(JavaSourceFile sourceFile) { + public SourceFileCompilationUnit(Resource sourceFile) { this.sourceFile = sourceFile; } @@ -41,16 +63,22 @@ @Override public String getSource() { - return sourceFile.readSource(); + if (cacheToken < 0) { + String sourceCode = readSource(sourceFile); + cacheToken = diskCache.writeString(sourceCode); + return sourceCode; + } else { + return diskCache.readString(cacheToken); + } } - public JavaSourceFile getSourceFile() { + public Resource getSourceFile() { return sourceFile; } @Override public String getTypeName() { - return sourceFile.getTypeName(); + return getTypeName(sourceFile); } @Override @@ -60,6 +88,6 @@ @Override public boolean isSuperSource() { - return sourceFile.isSuperSource(); + return sourceFile.wasRerooted(); } } 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 Thu Apr 2 13:44:20 2009 @@ -18,8 +18,10 @@ import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.dev.javac.CompilationUnit.State; import com.google.gwt.dev.javac.impl.JavaResourceBase; -import com.google.gwt.dev.javac.impl.MockJavaSourceFile; +import com.google.gwt.dev.javac.impl.MockJavaResource; +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.util.log.AbstractTreeLogger; import com.google.gwt.dev.util.log.PrintWriterTreeLogger; @@ -60,8 +62,8 @@ return TreeLogger.NULL; } - private MockJavaSourceOracle oracle = new MockJavaSourceOracle( - JavaSourceCodeBase.getStandardResources()); + private MockResourceOracle oracle = new MockResourceOracle( + JavaResourceBase.getStandardResources()); private CompilationState state = new CompilationState(createTreeLogger(), oracle); @@ -70,9 +72,8 @@ validateCompilationState(); // Add a unit and ensure it shows up. - state.addGeneratedCompilationUnits(createTreeLogger(), - getCompilationUnits(JavaSourceCodeBase.FOO)); - validateCompilationState(JavaSourceCodeBase.FOO.getTypeName()); + addGeneratedUnits(JavaResourceBase.FOO); + validateCompilationState(SourceFileCompilationUnit.getTypeName(JavaResourceBase.FOO)); // Ensure it disappears after a refresh. state.refresh(createTreeLogger()); @@ -81,20 +82,20 @@ /* test that a generated unit, if unchanged, is reused */ public void testCaching() { - testCaching(JavaSourceCodeBase.FOO); + testCaching(JavaResourceBase.FOO); } /* test that mutiple generated units, if unchanged, are reused */ public void testCachingOfMultipleUnits() { - testCaching(JavaSourceCodeBase.BAR, JavaSourceCodeBase.FOO); + testCaching(JavaResourceBase.BAR, JavaResourceBase.FOO); } public void testCompileError() { - oracle.add(JavaSourceCodeBase.BAR); + oracle.add(JavaResourceBase.BAR); state.refresh(createTreeLogger()); CompilationUnit badUnit = state.getCompilationUnitMap().get( - JavaSourceCodeBase.BAR.getTypeName()); + SourceFileCompilationUnit.getTypeName(JavaResourceBase.BAR)); assertSame(State.ERROR, badUnit.getState()); Set<CompilationUnit> goodUnits = new HashSet<CompilationUnit>( @@ -105,18 +106,16 @@ public void testCompileWithGeneratedUnits() { assertUnitsChecked(state.getCompilationUnits()); - state.addGeneratedCompilationUnits(createTreeLogger(), - getCompilationUnits(JavaSourceCodeBase.FOO)); + addGeneratedUnits(JavaResourceBase.FOO); assertUnitsChecked(state.getCompilationUnits()); } public void testCompileWithGeneratedUnitsError() { assertUnitsChecked(state.getCompilationUnits()); - state.addGeneratedCompilationUnits(createTreeLogger(), - getCompilationUnits(JavaSourceCodeBase.BAR)); + addGeneratedUnits(JavaResourceBase.BAR); CompilationUnit badUnit = state.getCompilationUnitMap().get( - JavaSourceCodeBase.BAR.getTypeName()); + SourceFileCompilationUnit.getTypeName(JavaResourceBase.BAR)); assertSame(State.ERROR, badUnit.getState()); Set<CompilationUnit> goodUnits = new HashSet<CompilationUnit>( @@ -127,20 +126,22 @@ public void testCompileWithGeneratedUnitsErrorAndDepedentGeneratedUnit() { assertUnitsChecked(state.getCompilationUnits()); - MockJavaSourceFile badFoo = new MockJavaSourceFile(JavaResourceBase.FOO) { + MockJavaResource badFoo = new MockJavaResource( + SourceFileCompilationUnit.getTypeName(JavaResourceBase.FOO)) { @Override - public String readSource() { - return super.readSource() + "\ncompilation error LOL!"; + protected CharSequence getContent() { + return SourceFileCompilationUnit.readSource(JavaResourceBase.FOO) + + "\ncompilation error LOL!"; } }; state.addGeneratedCompilationUnits(createTreeLogger(), getCompilationUnits( - badFoo, JavaSourceCodeBase.BAR)); + badFoo, JavaResourceBase.BAR)); CompilationUnit badUnit = state.getCompilationUnitMap().get( - badFoo.getTypeName()); + SourceFileCompilationUnit.getTypeName(badFoo)); assertSame(State.ERROR, badUnit.getState()); CompilationUnit invalidUnit = state.getCompilationUnitMap().get( - JavaSourceCodeBase.BAR.getTypeName()); + SourceFileCompilationUnit.getTypeName(JavaResourceBase.BAR)); assertSame(State.FRESH, invalidUnit.getState()); Set<CompilationUnit> goodUnits = new HashSet<CompilationUnit>( @@ -155,13 +156,12 @@ * another generated unit it depends on can be reused */ public void testComplexCacheInvalidation() { - Set<CompilationUnit> modifiedUnits = getCompilationUnits(JavaSourceCodeBase.FOO); - modifiedUnits.addAll(getModifiedCompilationUnits(JavaSourceCodeBase.BAR)); + Set<CompilationUnit> modifiedUnits = getCompilationUnits(JavaResourceBase.FOO); + modifiedUnits.addAll(getModifiedCompilationUnits(JavaResourceBase.BAR)); Set<String> reusedTypes = new HashSet<String>(); - reusedTypes.add(JavaSourceCodeBase.FOO.getTypeName()); - testCachingOverMultipleRefreshes(getCompilationUnits( - JavaSourceCodeBase.FOO, JavaSourceCodeBase.BAR), modifiedUnits, - reusedTypes, 1); + reusedTypes.add(SourceFileCompilationUnit.getTypeName(JavaResourceBase.FOO)); + testCachingOverMultipleRefreshes(getCompilationUnits(JavaResourceBase.FOO, + JavaResourceBase.BAR), modifiedUnits, reusedTypes, 1); } public void testInitialization() { @@ -169,17 +169,16 @@ } public void testInvalidation() { - testCachingOverMultipleRefreshes( - getCompilationUnits(JavaSourceCodeBase.FOO), - getModifiedCompilationUnits(JavaSourceCodeBase.FOO), + testCachingOverMultipleRefreshes(getCompilationUnits(JavaResourceBase.FOO), + getModifiedCompilationUnits(JavaResourceBase.FOO), Collections.<String> emptySet(), 1); } public void testInvalidationOfMultipleUnits() { - testCachingOverMultipleRefreshes(getCompilationUnits( - JavaSourceCodeBase.BAR, JavaSourceCodeBase.FOO), - getModifiedCompilationUnits(JavaSourceCodeBase.BAR, - JavaSourceCodeBase.FOO), Collections.<String> emptySet(), 2); + testCachingOverMultipleRefreshes(getCompilationUnits(JavaResourceBase.BAR, + JavaResourceBase.FOO), getModifiedCompilationUnits( + JavaResourceBase.BAR, JavaResourceBase.FOO), + Collections.<String> emptySet(), 2); } /* @@ -189,11 +188,11 @@ */ public void testInvalidationWhenSourceUnitsChange() { validateCompilationState(); - oracle.add(JavaSourceCodeBase.FOO); + oracle.add(JavaResourceBase.FOO); state.refresh(createTreeLogger()); // add generated units - Set<CompilationUnit> generatedCups = getCompilationUnits(JavaSourceCodeBase.BAR); + Set<CompilationUnit> generatedCups = getCompilationUnits(JavaResourceBase.BAR); Map<String, CompilationUnit> usefulUnits = state.getUsefulGraveyardUnits(generatedCups); assertEquals(0, usefulUnits.size()); state.addGeneratedCompilationUnits(createTreeLogger(), generatedCups, @@ -201,10 +200,12 @@ assertUnitsChecked(state.getCompilationUnits()); // change unit in source oracle - oracle.replace(new MockJavaSourceFile(JavaSourceCodeBase.FOO) { + oracle.replace(new MockJavaResource( + SourceFileCompilationUnit.getTypeName(JavaResourceBase.FOO)) { @Override - public String readSource() { - return JavaSourceCodeBase.FOO.readSource() + "\n"; + protected CharSequence getContent() { + return SourceFileCompilationUnit.readSource(JavaResourceBase.FOO) + + "\n"; } }); state.refresh(createTreeLogger()); @@ -223,7 +224,7 @@ validateCompilationState(); int size = state.getCompilationUnits().size(); - oracle.add(JavaSourceCodeBase.FOO); + oracle.add(JavaResourceBase.FOO); state.refresh(createTreeLogger()); assertEquals(size + 1, state.getCompilationUnits().size()); validateCompilationState(); @@ -234,7 +235,7 @@ } public void testSourceOracleEmpty() { - oracle = new MockJavaSourceOracle(); + oracle = new MockResourceOracle(); state = new CompilationState(createTreeLogger(), oracle); validateCompilationState(); } @@ -243,7 +244,7 @@ validateCompilationState(); int size = state.getCompilationUnits().size(); - oracle.remove(JavaSourceCodeBase.OBJECT.getTypeName()); + oracle.remove(JavaResourceBase.OBJECT.getPath()); state.refresh(createTreeLogger()); assertEquals(size - 1, state.getCompilationUnits().size()); validateCompilationState(); @@ -253,7 +254,12 @@ validateCompilationState(); int size = state.getCompilationUnits().size(); - oracle.replace(new MockJavaSourceFile(JavaSourceCodeBase.OBJECT)); + oracle.replace(new MockJavaResource("java.lang.Object") { + @Override + protected CharSequence getContent() { + return SourceFileCompilationUnit.readSource(JavaResourceBase.OBJECT); + } + }); state.refresh(createTreeLogger()); assertEquals(size, state.getCompilationUnits().size()); validateCompilationState(); @@ -263,7 +269,7 @@ validateCompilationState(); int size = state.getCompilationUnits().size(); - oracle.replace(JavaSourceCodeBase.OBJECT); + oracle.replace(JavaResourceBase.OBJECT); state.refresh(createTreeLogger()); assertEquals(size, state.getCompilationUnits().size()); validateCompilationState(); @@ -271,17 +277,22 @@ /* test if generatedUnits that depend on stale generatedUnits are invalidated */ public void testTransitiveInvalidation() { - Set<CompilationUnit> modifiedUnits = getModifiedCompilationUnits(JavaSourceCodeBase.FOO); - modifiedUnits.addAll(getCompilationUnits(JavaSourceCodeBase.BAR)); - testCachingOverMultipleRefreshes(getCompilationUnits( - JavaSourceCodeBase.BAR, JavaSourceCodeBase.FOO), modifiedUnits, - Collections.<String> emptySet(), 2); + Set<CompilationUnit> modifiedUnits = getModifiedCompilationUnits(JavaResourceBase.FOO); + modifiedUnits.addAll(getCompilationUnits(JavaResourceBase.BAR)); + testCachingOverMultipleRefreshes(getCompilationUnits(JavaResourceBase.BAR, + JavaResourceBase.FOO), modifiedUnits, Collections.<String> emptySet(), + 2); + } + + private void addGeneratedUnits(MockJavaResource... sourceFiles) { + Set<CompilationUnit> units = getCompilationUnits(sourceFiles); + state.addGeneratedCompilationUnits(createTreeLogger(), units); } private Set<CompilationUnit> getCompilationUnits( - JavaSourceFile... sourceFiles) { + MockJavaResource... sourceFiles) { Set<CompilationUnit> units = new HashSet<CompilationUnit>(); - for (JavaSourceFile sourceFile : sourceFiles) { + for (MockJavaResource sourceFile : sourceFiles) { units.add(new SourceFileCompilationUnit(sourceFile) { @Override public boolean isGenerated() { @@ -293,9 +304,9 @@ } private Set<CompilationUnit> getModifiedCompilationUnits( - JavaSourceFile... sourceFiles) { + MockJavaResource... sourceFiles) { Set<CompilationUnit> units = new HashSet<CompilationUnit>(); - for (JavaSourceFile sourceFile : sourceFiles) { + for (MockJavaResource sourceFile : sourceFiles) { units.add(new SourceFileCompilationUnit(sourceFile) { /* modified the source */ @Override @@ -312,10 +323,10 @@ return units; } - private void testCaching(JavaSourceFile... files) { + private void testCaching(MockJavaResource... files) { Set<String> reusedTypes = new HashSet<String>(); - for (JavaSourceFile file : files) { - reusedTypes.add(file.getTypeName()); + for (MockJavaResource file : files) { + reusedTypes.add(SourceFileCompilationUnit.getTypeName(file)); } testCachingOverMultipleRefreshes(getCompilationUnits(files), getCompilationUnits(files), reusedTypes, 0); @@ -406,8 +417,8 @@ assertEquals(new HashSet<CompilationUnit>(unitMap.values()), units); // Save off a mutable copy of the source map and generated types to compare. - Map<String, JavaSourceFile> sourceMap = new HashMap<String, JavaSourceFile>( - oracle.getSourceMap()); + Map<String, Resource> sourceMap = new HashMap<String, Resource>( + oracle.getResourceMap()); Set<String> generatedTypes = new HashSet<String>( Arrays.asList(generatedTypeNames)); assertEquals(sourceMap.size() + generatedTypes.size(), units.size()); @@ -422,9 +433,10 @@ assertTrue(generatedTypes.contains(className)); assertNotNull(generatedTypes.remove(className)); } else { - assertTrue(sourceMap.containsKey(className)); + String partialPath = className.replace('.', '/') + ".java"; + assertTrue(sourceMap.containsKey(partialPath)); // TODO: Validate the source file matches the resource. - assertNotNull(sourceMap.remove(className)); + assertNotNull(sourceMap.remove(partialPath)); } } // The mutable sets should be empty now. Modified: trunk/dev/core/test/com/google/gwt/dev/javac/CompilationUnitFileReferenceTest.java ============================================================================== --- trunk/dev/core/test/com/google/gwt/dev/javac/CompilationUnitFileReferenceTest.java (original) +++ trunk/dev/core/test/com/google/gwt/dev/javac/CompilationUnitFileReferenceTest.java Thu Apr 2 13:44:20 2009 @@ -18,7 +18,7 @@ import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.dev.javac.impl.JavaResourceBase; import com.google.gwt.dev.javac.impl.MockJavaResource; -import com.google.gwt.dev.javac.impl.MockJavaSourceFile; +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.util.log.AbstractTreeLogger; @@ -159,8 +159,8 @@ EXPECTED_DEPENDENCIES.put(source.getLocation(), targetSet); } - private MockJavaSourceOracle oracle = new MockJavaSourceOracle( - JavaSourceCodeBase.getStandardResources()); + private MockResourceOracle oracle = new MockResourceOracle( + JavaResourceBase.getStandardResources()); private CompilationState state = new CompilationState(createTreeLogger(), oracle); @@ -174,7 +174,7 @@ } public void testBinaryBindingsWithSimpleUnits() { - testBinaryBindings(JavaSourceCodeBase.FOO, JavaSourceCodeBase.BAR); + testBinaryBindings(JavaResourceBase.FOO, JavaResourceBase.BAR); } public void testBinaryBindingsWithStaticInnerClass() { @@ -190,7 +190,7 @@ } public void testSourceBindingsWithSimpleUnits() { - testSourceBindings(JavaSourceCodeBase.FOO, JavaSourceCodeBase.BAR); + testSourceBindings(JavaResourceBase.FOO, JavaResourceBase.BAR); } public void testSourceBindingsWithStaticInnerClass() { @@ -199,22 +199,22 @@ public void testWithGeneratedUnits() { state.addGeneratedCompilationUnits(createTreeLogger(), - copyAsGeneratedUnits(JavaSourceCodeBase.BAR, JavaSourceCodeBase.FOO)); - assertRefsMatchExpectedRefs(JavaSourceCodeBase.BAR, JavaSourceCodeBase.FOO); + copyAsGeneratedUnits(JavaResourceBase.BAR, JavaResourceBase.FOO)); + assertRefsMatchExpectedRefs(JavaResourceBase.BAR, JavaResourceBase.FOO); } public void testWithMixedUnits() { - oracle.add(JavaSourceCodeBase.FOO); + oracle.add(JavaResourceBase.FOO); state.refresh(createTreeLogger()); state.addGeneratedCompilationUnits(createTreeLogger(), - copyAsGeneratedUnits(JavaSourceCodeBase.BAR)); - assertRefsMatchExpectedRefs(JavaSourceCodeBase.BAR, JavaSourceCodeBase.FOO); + copyAsGeneratedUnits(JavaResourceBase.BAR)); + assertRefsMatchExpectedRefs(JavaResourceBase.BAR, JavaResourceBase.FOO); } - private void assertRefsMatchExpectedRefs(JavaSourceFile... files) { - for (JavaSourceFile sourceFile : files) { + private void assertRefsMatchExpectedRefs(Resource... files) { + for (Resource sourceFile : files) { Set<String> sourceFileRefs = state.getCompilationUnitMap().get( - sourceFile.getTypeName()).getFileNameRefs(); + SourceFileCompilationUnit.getTypeName(sourceFile)).getFileNameRefs(); Set<String> expectedSourceFileRefs = EXPECTED_DEPENDENCIES.get(sourceFile.getLocation()); assertEquals(expectedSourceFileRefs, sourceFileRefs); } @@ -224,10 +224,9 @@ * Returns copies of units as generated units for testing interactions with * generated units. */ - private Set<CompilationUnit> copyAsGeneratedUnits( - JavaSourceFile... sourceFiles) { + private Set<CompilationUnit> copyAsGeneratedUnits(Resource... sourceFiles) { Set<CompilationUnit> units = new HashSet<CompilationUnit>(); - for (JavaSourceFile sourceFile : sourceFiles) { + for (Resource sourceFile : sourceFiles) { units.add(new SourceFileCompilationUnit(sourceFile) { @Override public boolean isGenerated() { @@ -243,40 +242,24 @@ * have only binary references to the previous unit(s). This tests the binary * reference matching in {...@link CompilationState}. */ - private void testBinaryBindings(JavaSourceFile... files) { - for (JavaSourceFile sourceFile : files) { + private void testBinaryBindings(Resource... files) { + for (Resource sourceFile : files) { oracle.add(sourceFile); state.refresh(createTreeLogger()); } assertRefsMatchExpectedRefs(files); } - private void testBinaryBindings(MockJavaResource... resources) { - JavaSourceFile[] files = new JavaSourceFile[resources.length]; - for (int i = 0; i < resources.length; ++i) { - files[i] = new MockJavaSourceFile(resources[i]); - } - testBinaryBindings(files); - } - /** * Compiles all files together so that all units will have source references * to each other. This tests the source reference matching in * {...@link CompilationState}. */ - private void testSourceBindings(JavaSourceFile... files) { - for (JavaSourceFile sourceFile : files) { + private void testSourceBindings(Resource... files) { + for (Resource sourceFile : files) { oracle.add(sourceFile); } state.refresh(createTreeLogger()); assertRefsMatchExpectedRefs(files); - } - - private void testSourceBindings(MockJavaResource... resources) { - JavaSourceFile[] files = new JavaSourceFile[resources.length]; - for (int i = 0; i < resources.length; ++i) { - files[i] = new MockJavaSourceFile(resources[i]); - } - testSourceBindings(files); } } Modified: trunk/dev/core/test/com/google/gwt/dev/javac/JavaCompilationSuite.java ============================================================================== --- trunk/dev/core/test/com/google/gwt/dev/javac/JavaCompilationSuite.java (original) +++ trunk/dev/core/test/com/google/gwt/dev/javac/JavaCompilationSuite.java Thu Apr 2 13:44:20 2009 @@ -15,7 +15,6 @@ */ package com.google.gwt.dev.javac; -import com.google.gwt.dev.javac.impl.JavaSourceOracleImplTest; import com.google.gwt.dev.javac.impl.JdtBehaviorTest; import junit.framework.Test; @@ -35,7 +34,6 @@ suite.addTestSuite(JdtBehaviorTest.class); suite.addTestSuite(JdtCompilerTest.class); suite.addTestSuite(JSORestrictionsTest.class); - suite.addTestSuite(JavaSourceOracleImplTest.class); suite.addTestSuite(JsniCheckerTest.class); suite.addTestSuite(TypeOracleMediatorTest.class); Modified: trunk/dev/core/test/com/google/gwt/dev/javac/JdtCompilerTest.java ============================================================================== --- trunk/dev/core/test/com/google/gwt/dev/javac/JdtCompilerTest.java (original) +++ trunk/dev/core/test/com/google/gwt/dev/javac/JdtCompilerTest.java Thu Apr 2 13:44:20 2009 @@ -15,7 +15,9 @@ */ package com.google.gwt.dev.javac; +import com.google.gwt.dev.javac.impl.JavaResourceBase; import com.google.gwt.dev.javac.impl.SourceFileCompilationUnit; +import com.google.gwt.dev.resource.Resource; import junit.framework.TestCase; @@ -31,6 +33,14 @@ */ public class JdtCompilerTest extends TestCase { + static void assertUnitHasErrors(CompilationUnit unit, int numErrors) { + CompilationUnitDeclaration cud = unit.getJdtCud(); + CompilationResult result = cud.compilationResult(); + assertTrue(result.hasErrors()); + assertEquals(numErrors, result.getErrors().length); + assertTrue(result.getClassFiles().length > 0); + } + static void assertUnitsCompiled(Collection<CompilationUnit> units) { for (CompilationUnit unit : units) { CompilationUnitDeclaration cud = unit.getJdtCud(); @@ -41,26 +51,18 @@ } } - static void assertUnitHasErrors(CompilationUnit unit, int numErrors) { - CompilationUnitDeclaration cud = unit.getJdtCud(); - CompilationResult result = cud.compilationResult(); - assertTrue(result.hasErrors()); - assertEquals(numErrors, result.getErrors().length); - assertTrue(result.getClassFiles().length > 0); - } - public void testCompile() { List<CompilationUnit> units = new ArrayList<CompilationUnit>(); - addAll(units, JavaSourceCodeBase.getStandardResources()); - addAll(units, JavaSourceCodeBase.FOO, JavaSourceCodeBase.BAR); + addAll(units, JavaResourceBase.getStandardResources()); + addAll(units, JavaResourceBase.FOO, JavaResourceBase.BAR); JdtCompiler.compile(units); assertUnitsCompiled(units); } public void testCompileError() { List<CompilationUnit> units = new ArrayList<CompilationUnit>(); - addAll(units, JavaSourceCodeBase.getStandardResources()); - addAll(units, JavaSourceCodeBase.BAR); + addAll(units, JavaResourceBase.getStandardResources()); + addAll(units, JavaResourceBase.BAR); JdtCompiler.compile(units); assertUnitsCompiled(units.subList(0, units.size() - 1)); assertUnitHasErrors(units.get(units.size() - 1), 1); @@ -68,17 +70,17 @@ public void testCompileIncremental() { List<CompilationUnit> units = new ArrayList<CompilationUnit>(); - addAll(units, JavaSourceCodeBase.getStandardResources()); + addAll(units, JavaResourceBase.getStandardResources()); JdtCompiler.compile(units); assertUnitsCompiled(units); - addAll(units, JavaSourceCodeBase.FOO, JavaSourceCodeBase.BAR); + addAll(units, JavaResourceBase.FOO, JavaResourceBase.BAR); JdtCompiler.compile(units); assertUnitsCompiled(units); } private void addAll(Collection<CompilationUnit> units, - JavaSourceFile... sourceFiles) { - for (JavaSourceFile sourceFile : sourceFiles) { + Resource... sourceFiles) { + for (Resource sourceFile : sourceFiles) { units.add(new SourceFileCompilationUnit(sourceFile)); } } Modified: trunk/dev/core/test/com/google/gwt/dev/javac/TypeOracleTestingUtils.java ============================================================================== --- trunk/dev/core/test/com/google/gwt/dev/javac/TypeOracleTestingUtils.java (original) +++ trunk/dev/core/test/com/google/gwt/dev/javac/TypeOracleTestingUtils.java Thu Apr 2 13:44:20 2009 @@ -17,6 +17,8 @@ import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.core.ext.typeinfo.TypeOracle; +import com.google.gwt.dev.javac.impl.JavaResourceBase; +import com.google.gwt.dev.javac.impl.MockJavaResource; import com.google.gwt.dev.javac.impl.SourceFileCompilationUnit; import java.util.Collections; @@ -73,7 +75,7 @@ * Add compilation units for basic classes like Object and String. */ private static void addStandardCups(Set<CompilationUnit> units) { - for (JavaSourceFile resource : JavaSourceCodeBase.getStandardResources()) { + for (MockJavaResource resource : JavaResourceBase.getStandardResources()) { units.add(new SourceFileCompilationUnit(resource)); } } Modified: trunk/dev/core/test/com/google/gwt/dev/javac/impl/JavaResourceBase.java ============================================================================== --- trunk/dev/core/test/com/google/gwt/dev/javac/impl/JavaResourceBase.java (original) +++ trunk/dev/core/test/com/google/gwt/dev/javac/impl/JavaResourceBase.java Thu Apr 2 13:44:20 2009 @@ -20,7 +20,7 @@ */ public class JavaResourceBase { - public static final MockResource ANNOTATION = new MockJavaResource( + public static final MockJavaResource ANNOTATION = new MockJavaResource( "java.lang.annotation.Annotation") { @Override protected CharSequence getContent() { @@ -42,7 +42,7 @@ return code; } }; - public static final MockResource CLASS = new MockJavaResource( + public static final MockJavaResource CLASS = new MockJavaResource( "java.lang.Class") { @Override protected CharSequence getContent() { @@ -64,7 +64,7 @@ return code; } }; - public static final MockResource JAVASCRIPTOBJECT = new MockJavaResource( + public static final MockJavaResource JAVASCRIPTOBJECT = new MockJavaResource( "com.google.gwt.core.client.JavaScriptObject") { @Override protected CharSequence getContent() { @@ -76,7 +76,8 @@ return code; } }; - public static final MockResource MAP = new MockJavaResource("java.util.Map") { + public static final MockJavaResource MAP = new MockJavaResource( + "java.util.Map") { @Override protected CharSequence getContent() { StringBuffer code = new StringBuffer(); @@ -85,7 +86,7 @@ return code; } }; - public static final MockResource OBJECT = new MockJavaResource( + public static final MockJavaResource OBJECT = new MockJavaResource( "java.lang.Object") { @Override protected CharSequence getContent() { @@ -98,7 +99,7 @@ return code; } }; - public static final MockResource SERIALIZABLE = new MockJavaResource( + public static final MockJavaResource SERIALIZABLE = new MockJavaResource( "java.io.Serializable") { @Override protected CharSequence getContent() { @@ -108,7 +109,7 @@ return code; } }; - public static final MockResource STRING = new MockJavaResource( + public static final MockJavaResource STRING = new MockJavaResource( "java.lang.String") { @Override protected CharSequence getContent() { @@ -122,7 +123,7 @@ return code; } }; - public static final MockResource SUPPRESS_WARNINGS = new MockJavaResource( + public static final MockJavaResource SUPPRESS_WARNINGS = new MockJavaResource( "java.lang.SuppressWarnings") { @Override protected CharSequence getContent() { @@ -135,8 +136,8 @@ } }; - public static MockResource[] getStandardResources() { - return new MockResource[] { + public static MockJavaResource[] getStandardResources() { + return new MockJavaResource[] { ANNOTATION, CLASS, JAVASCRIPTOBJECT, MAP, OBJECT, SERIALIZABLE, STRING, SUPPRESS_WARNINGS}; } Modified: trunk/dev/core/test/com/google/gwt/dev/javac/impl/JdtBehaviorTest.java ============================================================================== --- trunk/dev/core/test/com/google/gwt/dev/javac/impl/JdtBehaviorTest.java (original) +++ trunk/dev/core/test/com/google/gwt/dev/javac/impl/JdtBehaviorTest.java Thu Apr 2 13:44:20 2009 @@ -142,14 +142,14 @@ private class ResourceAdapter implements ICompilationUnit { - private final MockJavaSourceFile sourceFile; + private final MockResource sourceFile; public ResourceAdapter(MockResource resource) { - sourceFile = new MockJavaSourceFile(resource); + sourceFile = resource; } public char[] getContents() { - return sourceFile.readSource().toCharArray(); + return SourceFileCompilationUnit.readSource(sourceFile).toCharArray(); } public char[] getFileName() { @@ -157,12 +157,13 @@ } public char[] getMainTypeName() { - return sourceFile.getShortName().toCharArray(); + return Shared.getShortName( + SourceFileCompilationUnit.getTypeName(sourceFile)).toCharArray(); } public char[][] getPackageName() { - return CharOperation.splitOn('.', - sourceFile.getPackageName().toCharArray()); + return CharOperation.splitOn('.', Shared.getPackageName( + SourceFileCompilationUnit.getTypeName(sourceFile)).toCharArray()); } @Override Modified: trunk/dev/core/test/com/google/gwt/dev/javac/impl/MockResourceOracle.java ============================================================================== --- trunk/dev/core/test/com/google/gwt/dev/javac/impl/MockResourceOracle.java (original) +++ trunk/dev/core/test/com/google/gwt/dev/javac/impl/MockResourceOracle.java Thu Apr 2 13:44:20 2009 @@ -38,6 +38,16 @@ add(resources); } + public void add(Resource... resources) { + Map<String, Resource> newMap = new HashMap<String, Resource>(exportedMap); + for (Resource resource : resources) { + String path = resource.getPath(); + Assert.assertFalse(newMap.containsKey(path)); + newMap.put(path, resource); + } + export(newMap); + } + public void clear() { } @@ -53,17 +63,7 @@ return exportedValues; } - void add(Resource... resources) { - Map<String, Resource> newMap = new HashMap<String, Resource>(exportedMap); - for (Resource resource : resources) { - String path = resource.getPath(); - Assert.assertFalse(newMap.containsKey(path)); - newMap.put(path, resource); - } - export(newMap); - } - - void remove(String... paths) { + public void remove(String... paths) { Map<String, Resource> newMap = new HashMap<String, Resource>(exportedMap); for (String path : paths) { Resource oldValue = newMap.remove(path); @@ -72,7 +72,7 @@ export(newMap); } - void replace(Resource... resources) { + public void replace(Resource... resources) { Map<String, Resource> newMap = new HashMap<String, Resource>(exportedMap); for (Resource resource : resources) { String path = resource.getPath(); Modified: trunk/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java ============================================================================== --- trunk/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java (original) +++ trunk/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java Thu Apr 2 13:44:20 2009 @@ -26,8 +26,7 @@ import com.google.gwt.core.ext.linker.GeneratedResource; import com.google.gwt.dev.cfg.PublicOracle; import com.google.gwt.dev.javac.CompilationState; -import com.google.gwt.dev.javac.JavaSourceFile; -import com.google.gwt.dev.javac.JavaSourceOracle; +import com.google.gwt.dev.javac.impl.MockResourceOracle; import com.google.gwt.dev.resource.Resource; import com.google.gwt.dev.util.Util; @@ -43,10 +42,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.Set; /** * A wide variety of tests on {...@link StandardGeneratorContext}. @@ -56,22 +52,7 @@ public static class MockCompilationState extends CompilationState { public MockCompilationState() { - super(TreeLogger.NULL, new JavaSourceOracle() { - public void clear() { - } - - public Set<String> getClassNames() { - return Collections.emptySet(); - } - - public Set<JavaSourceFile> getSourceFiles() { - return Collections.emptySet(); - } - - public Map<String, JavaSourceFile> getSourceMap() { - return Collections.emptyMap(); - } - }); + super(TreeLogger.NULL, new MockResourceOracle()); } } Modified: trunk/user/test/com/google/gwt/dev/cfg/TestSuperAndSourceTags.java ============================================================================== --- trunk/user/test/com/google/gwt/dev/cfg/TestSuperAndSourceTags.java (original) +++ trunk/user/test/com/google/gwt/dev/cfg/TestSuperAndSourceTags.java Thu Apr 2 13:44:20 2009 @@ -119,10 +119,14 @@ } private void validateExcluded(Class<?> clazz) { - assertNull(moduleDef.findSourceFile(getLogicalPath(clazz))); + assertNull(moduleDef.findSourceFile(toPath(clazz))); } private void validateIncluded(Class<?> clazz) { - assertNotNull(moduleDef.findSourceFile(getLogicalPath(clazz))); + assertNotNull(moduleDef.findSourceFile(toPath(clazz))); + } + + private String toPath(Class<?> clazz) { + return getLogicalPath(clazz).replace('.', '/') + ".java"; } } Modified: trunk/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java ============================================================================== --- trunk/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java (original) +++ trunk/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java Thu Apr 2 13:44:20 2009 @@ -34,9 +34,9 @@ import com.google.gwt.dev.cfg.ModuleDefLoader; import com.google.gwt.dev.cfg.StaticPropertyOracle; import com.google.gwt.dev.javac.CompilationUnit; -import com.google.gwt.dev.javac.JavaSourceCodeBase; import com.google.gwt.dev.javac.MockCompilationUnit; import com.google.gwt.dev.javac.TypeOracleTestingUtils; +import com.google.gwt.dev.javac.impl.JavaResourceBase; import com.google.gwt.dev.javac.impl.SourceFileCompilationUnit; import com.google.gwt.dev.util.UnitTestTreeLogger; import com.google.gwt.dev.util.log.PrintWriterTreeLogger; @@ -141,7 +141,7 @@ } private static void addJavaIoSerializable(Set<CompilationUnit> units) { - units.add(new SourceFileCompilationUnit(JavaSourceCodeBase.SERIALIZABLE)); + units.add(new SourceFileCompilationUnit(JavaResourceBase.SERIALIZABLE)); } private static void addJavaLangException(Set<CompilationUnit> units) { @@ -154,11 +154,11 @@ } private static void addJavaLangObject(Set<CompilationUnit> units) { - units.add(new SourceFileCompilationUnit(JavaSourceCodeBase.OBJECT)); + units.add(new SourceFileCompilationUnit(JavaResourceBase.OBJECT)); } private static void addJavaLangString(Set<CompilationUnit> units) { - units.add(new SourceFileCompilationUnit(JavaSourceCodeBase.STRING)); + units.add(new SourceFileCompilationUnit(JavaResourceBase.STRING)); } private static void addJavaLangThrowable(Set<CompilationUnit> units) { @@ -179,7 +179,7 @@ } private static void addJavaUtilMap(Set<CompilationUnit> units) { - units.add(new SourceFileCompilationUnit(JavaSourceCodeBase.MAP)); + units.add(new SourceFileCompilationUnit(JavaResourceBase.MAP)); } private static void addSerializationStreamReader(Set<CompilationUnit> units) { @@ -2170,8 +2170,7 @@ * @throws UnableToCompleteException * @throws NotFoundException */ - public void testTypeConstrainer() throws UnableToCompleteException, - NotFoundException { + public void testTypeConstrainer() throws NotFoundException { Set<CompilationUnit> units = new HashSet<CompilationUnit>(); addStandardClasses(units); @@ -2326,8 +2325,8 @@ JTypeParameter syntheticTypeParam = new JTypeParameter("U", 0); // Force the type parameter to have a declaring class - JClassType mockType = new JGenericType(to, a.getPackage(), null, false, - "C", false, new JTypeParameter[] {syntheticTypeParam}); + new JGenericType(to, a.getPackage(), null, false, "C", false, + new JTypeParameter[] {syntheticTypeParam}); syntheticTypeParam.setBounds(makeArray(b)); JParameterizedType parameterizedType = to.getParameterizedType(a, Modified: trunk/user/test/com/google/gwt/user/rebind/rpc/TypeHierarchyUtilsTest.java ============================================================================== --- trunk/user/test/com/google/gwt/user/rebind/rpc/TypeHierarchyUtilsTest.java (original) +++ trunk/user/test/com/google/gwt/user/rebind/rpc/TypeHierarchyUtilsTest.java Thu Apr 2 13:44:20 2009 @@ -16,7 +16,6 @@ package com.google.gwt.user.rebind.rpc; import com.google.gwt.core.ext.TreeLogger; -import com.google.gwt.core.ext.UnableToCompleteException; import com.google.gwt.core.ext.typeinfo.JClassType; import com.google.gwt.core.ext.typeinfo.NotFoundException; import com.google.gwt.core.ext.typeinfo.TypeOracle; @@ -43,8 +42,7 @@ return logger; } - public void testParameterizedInterface() throws UnableToCompleteException, - NotFoundException { + public void testParameterizedInterface() throws NotFoundException { Set<CompilationUnit> units = new HashSet<CompilationUnit>(); { StringBuilder code = new StringBuilder(); --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---