Author: b...@google.com Date: Tue Feb 10 13:36:30 2009 New Revision: 4687 Modified: changes/bobv/jso_single_impl_r4642/dev/core/src/com/google/gwt/dev/javac/CompilationState.java changes/bobv/jso_single_impl_r4642/dev/core/src/com/google/gwt/dev/javac/CompilationUnitInvalidator.java changes/bobv/jso_single_impl_r4642/dev/core/src/com/google/gwt/dev/javac/JSORestrictionsChecker.java
Log: Allow the JSORestrictionChecker's interntal state to be pruned between refreshes. Suggested by: scottb Modified: changes/bobv/jso_single_impl_r4642/dev/core/src/com/google/gwt/dev/javac/CompilationState.java ============================================================================== --- changes/bobv/jso_single_impl_r4642/dev/core/src/com/google/gwt/dev/javac/CompilationState.java (original) +++ changes/bobv/jso_single_impl_r4642/dev/core/src/com/google/gwt/dev/javac/CompilationState.java Tue Feb 10 13:36:30 2009 @@ -168,17 +168,22 @@ refreshFromSourceOracle(); updateExposedUnits(); - /* - * TODO(bobv): something like the code below. Basically, you probably want - * to only retain state for units marked as CHECKED; because CHECKED units - * won't be revalidated, so you basically need to retain the state as if - * they were revalidated. Anything other than CHECKED will be revalidated so - * that state needn't be retained. - */ - // invalidatorState.retainAll(exposedUnitMap); // Don't log about invalidated units via refresh. CompilationUnitInvalidator.invalidateUnitsWithInvalidRefs(TreeLogger.NULL, getCompilationUnits()); + + /* + * Only retain state for units marked as CHECKED; because CHECKED units + * won't be revalidated. + */ + Set<CompilationUnit> toRetain = new HashSet<CompilationUnit>(exposedUnits); + for (Iterator<CompilationUnit> it = toRetain.iterator(); it.hasNext();) { + CompilationUnit unit = it.next(); + if (unit.getState() != State.CHECKED) { + it.remove(); + } + } + invalidatorState.retainAll(toRetain); jdtCompiler = new JdtCompiler(); compile(logger, getCompilationUnits()); Modified: changes/bobv/jso_single_impl_r4642/dev/core/src/com/google/gwt/dev/javac/CompilationUnitInvalidator.java ============================================================================== --- changes/bobv/jso_single_impl_r4642/dev/core/src/com/google/gwt/dev/javac/CompilationUnitInvalidator.java (original) +++ changes/bobv/jso_single_impl_r4642/dev/core/src/com/google/gwt/dev/javac/CompilationUnitInvalidator.java Tue Feb 10 13:36:30 2009 @@ -24,6 +24,7 @@ import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -32,8 +33,8 @@ * Helper class to invalidate units in a set based on errors or references to * other invalidate units. * - * TODO: {...@link ClassFileReader#hasStructuralChanges(byte[])} could help us - * optimize this process! + * TODO: ClassFileReader#hasStructuralChanges(byte[]) could help us optimize + * this process! */ public class CompilationUnitInvalidator { @@ -42,6 +43,10 @@ */ public static class InvalidatorState { private final JSORestrictionsChecker.CheckerState jsoState = new JSORestrictionsChecker.CheckerState(); + + public void retainAll(Collection<CompilationUnit> toRetain) { + jsoState.retainAll(toRetain); + } } /** Modified: changes/bobv/jso_single_impl_r4642/dev/core/src/com/google/gwt/dev/javac/JSORestrictionsChecker.java ============================================================================== --- changes/bobv/jso_single_impl_r4642/dev/core/src/com/google/gwt/dev/javac/JSORestrictionsChecker.java (original) +++ changes/bobv/jso_single_impl_r4642/dev/core/src/com/google/gwt/dev/javac/JSORestrictionsChecker.java Tue Feb 10 13:36:30 2009 @@ -36,10 +36,12 @@ import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.IdentityHashMap; +import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.Stack; @@ -186,6 +188,58 @@ } } + public void retainAll(Collection<CompilationUnit> units) { + // Fast-path for removing everything + if (units.isEmpty()) { + interfacesToSuperInterfaces.clear(); + trivialToSuperInterfaces.clear(); + jsoImplsToInterfaces.clear(); + nodesToCuds.clear(); + singleJsoImplInterfaceNames.clear(); + trivialInterfaceNames.clear(); + if (regularInterfaceNames != null) { + regularInterfaceNames.clear(); + } + return; + } + + // Build up a list of the types that should be retained + Set<String> retainedTypeNames = new HashSet<String>(); + + for (CompilationUnit u : units) { + for (CompiledClass c : u.getCompiledClasses()) { + // Can't rely on getJdtCud() because those are pruned + retainedTypeNames.add(c.getSourceName()); + } + } + + // Loop over all TypeDeclarations that we have + for (Iterator<TypeDeclaration> it = nodesToCuds.keySet().iterator(); it.hasNext();) { + TypeDeclaration decl = it.next(); + + // Remove the TypeDeclaration if it's not in the list of retained types + if (!retainedTypeNames.contains(CharOperation.toString(decl.binding.compoundName))) { + it.remove(); + + assert interfacesToSuperInterfaces.containsKey(decl) + || trivialToSuperInterfaces.containsKey(decl) + || jsoImplsToInterfaces.containsKey(decl) : "TypeDeclaration " + + CharOperation.toString(decl.binding.compoundName) + + " in nodesToCuds, but not in any of the maps"; + + interfacesToSuperInterfaces.remove(decl); + trivialToSuperInterfaces.remove(decl); + jsoImplsToInterfaces.remove(decl); + } + } + + singleJsoImplInterfaceNames.retainAll(retainedTypeNames); + trivialInterfaceNames.retainAll(retainedTypeNames); + if (regularInterfaceNames != null) { + regularInterfaceNames.retainAll(retainedTypeNames); + } + } + private void add(Map<TypeDeclaration, Set<String>> map, TypeDeclaration key, String value) { Set<String> set = map.get(key); @@ -231,8 +285,6 @@ private void regularInterface(TypeDeclaration intfType, CompilationUnitDeclaration cud, String superInterfaceName) { - nodesToCuds.put(intfType, cud); - // Just used for sanity checking if (getClass().desiredAssertionStatus()) { regularInterfaceNames.add(CharOperation.toString(intfType.binding.compoundName)); --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---