Chromium Code Reviews| Index: pkg/analyzer/lib/src/task/dart_work_manager.dart |
| diff --git a/pkg/analyzer/lib/src/task/dart_work_manager.dart b/pkg/analyzer/lib/src/task/dart_work_manager.dart |
| index 66f73924fecb83ce530fc67f74e54ad81708670d..f50659e8bcf1f8301037d3c7dd5158c896cde9c4 100644 |
| --- a/pkg/analyzer/lib/src/task/dart_work_manager.dart |
| +++ b/pkg/analyzer/lib/src/task/dart_work_manager.dart |
| @@ -67,6 +67,18 @@ class DartWorkManager implements WorkManager { |
| final LinkedHashSet<Source> librarySourceQueue = new LinkedHashSet<Source>(); |
| /** |
| + * A table mapping library sources to the part sources they include. |
| + */ |
| + final HashMap<Source, List<Source>> libraryPartsMap = |
|
Brian Wilkerson
2015/05/22 16:05:42
Aren't we already keeping this in the cache? Why w
|
| + new HashMap<Source, List<Source>>(); |
| + |
| + /** |
| + * A table mapping part sources to the library sources that include them. |
| + */ |
| + final HashMap<Source, List<Source>> partLibrariesMap = |
| + new HashMap<Source, List<Source>>(); |
| + |
| + /** |
| * Initialize a newly created manager. |
| */ |
| DartWorkManager(this.context); |
| @@ -99,6 +111,15 @@ class DartWorkManager implements WorkManager { |
| // library queue |
| librarySourceQueue.removeAll(changedSources); |
| librarySourceQueue.removeAll(removedSources); |
| + // parts in libraries |
| + for (Source changedSource in changedSources) { |
| + _onLibrarySourceChangedOrRemoved(changedSource); |
| + _onPartSourceChangedOrRemoved(changedSource); |
| + } |
| + for (Source removedSource in removedSources) { |
| + _onLibrarySourceChangedOrRemoved(removedSource); |
| + _onPartSourceChangedOrRemoved(removedSource); |
| + } |
| // Some of the libraries might have been invalidated, reschedule them. |
| { |
| MapIterator<AnalysisTarget, CacheEntry> iterator = |
| @@ -163,6 +184,15 @@ class DartWorkManager implements WorkManager { |
| return new AnalysisErrorInfoImpl(errors, lineInfo); |
| } |
| + /** |
| + * Returns libraries containing the given [part]. |
| + * Maybe empty, but not null. |
| + */ |
| + List<Source> getLibrariesContainingPart(Source part) { |
| + List<Source> libraries = partLibrariesMap[part]; |
| + return libraries != null ? libraries : Source.EMPTY_LIST; |
| + } |
| + |
| @override |
| TargetedResult getNextResult() { |
| // Try to find a priority result to compute. |
| @@ -226,6 +256,21 @@ class DartWorkManager implements WorkManager { |
| } |
| } |
| } |
| + // Update parts in libraries. |
| + if (_isDartSource(target)) { |
| + Source library = target; |
| + List<Source> includedParts = outputs[INCLUDED_PARTS]; |
| + if (includedParts != null) { |
| + libraryPartsMap[library] = includedParts.toList(); |
|
Brian Wilkerson
2015/05/22 16:05:42
"includedParts" is declared to be a List. Is the d
|
| + for (Source part in includedParts) { |
| + List<Source> libraries = |
| + partLibrariesMap.putIfAbsent(part, () => <Source>[]); |
| + if (!libraries.contains(library)) { |
| + libraries.add(library); |
| + } |
| + } |
| + } |
| + } |
| // Update notice. |
| if (_isDartSource(target)) { |
| bool shouldSetErrors = false; |
| @@ -271,6 +316,38 @@ class DartWorkManager implements WorkManager { |
| return state != CacheState.VALID && state != CacheState.ERROR; |
| } |
| + /** |
| + * The given [library] source was changed or removed. |
| + * Update [libraryPartsMap] and [partLibrariesMap]. |
| + */ |
| + void _onLibrarySourceChangedOrRemoved(Source library) { |
| + List<Source> parts = libraryPartsMap.remove(library); |
| + if (parts != null) { |
| + for (Source part in parts) { |
| + List<Source> libraries = partLibrariesMap[part]; |
| + if (libraries != null) { |
| + libraries.remove(library); |
| + } |
| + } |
| + } |
| + } |
| + |
| + /** |
| + * The given [part] source was changed or removed. |
| + * Update [libraryPartsMap] and [partLibrariesMap]. |
| + */ |
| + void _onPartSourceChangedOrRemoved(Source part) { |
| + List<Source> libraries = partLibrariesMap.remove(part); |
| + if (libraries != null) { |
| + for (Source library in libraries) { |
| + List<Source> parts = libraryPartsMap[library]; |
| + if (parts != null) { |
| + parts.remove(part); |
| + } |
| + } |
| + } |
| + } |
| + |
| static bool _isDartSource(AnalysisTarget target) { |
| return target is Source && AnalysisEngine.isDartFileName(target.fullName); |
| } |