Chromium Code Reviews| Index: pkg/analyzer/lib/src/context/cache.dart |
| diff --git a/pkg/analyzer/lib/src/context/cache.dart b/pkg/analyzer/lib/src/context/cache.dart |
| index 5e50de4f1c246947e96c0343a23d9855ea899481..51dcb8d2ec71b93822f8c103bdce8dd93e6f4fed 100644 |
| --- a/pkg/analyzer/lib/src/context/cache.dart |
| +++ b/pkg/analyzer/lib/src/context/cache.dart |
| @@ -60,6 +60,15 @@ class AnalysisCache { |
| // } |
| /** |
| + * Return an iterator returning all of the [Source] targets. |
| + */ |
| + Iterable<Source> get sources { |
| + return _partitions |
| + .map((CachePartition partition) => partition._sources) |
| + .expand((Iterable<Source> sources) => sources); |
| + } |
| + |
| + /** |
| * Return the entry associated with the given [target]. |
| */ |
| CacheEntry get(AnalysisTarget target) { |
| @@ -455,6 +464,7 @@ class CacheEntry { |
| // If empty, remove the entry altogether. |
| if (_resultMap.isEmpty) { |
| _partition._targetMap.remove(target); |
| + _partition._removeSource(target); |
| } |
| } |
| @@ -707,6 +717,11 @@ abstract class CachePartition { |
| new HashMap<AnalysisTarget, CacheEntry>(); |
| /** |
| + * A set of the [Source] targets. |
| + */ |
| + final HashSet<Source> _sources = new HashSet<Source>(); |
| + |
| + /** |
| * Initialize a newly created cache partition, belonging to the given |
| * [context]. |
| */ |
| @@ -750,6 +765,7 @@ abstract class CachePartition { |
| entry._partition = this; |
| entry.fixExceptionState(); |
| _targetMap[target] = entry; |
| + _addSource(target); |
| } |
| /** |
| @@ -763,6 +779,7 @@ abstract class CachePartition { |
| if (entry != null) { |
| entry._invalidateAll(); |
| } |
| + _removeSource(target); |
| } |
| /** |
| @@ -798,6 +815,15 @@ abstract class CachePartition { |
| */ |
| int size() => _targetMap.length; |
| + /** |
| + * If the given [target] is a [Source], adds it to [_sources]. |
| + */ |
| + void _addSource(AnalysisTarget target) { |
|
Brian Wilkerson
2015/05/21 13:52:31
I was confused when I first saw this method being
|
| + if (target is Source) { |
| + _sources.add(target); |
| + } |
| + } |
| + |
| ResultData _getDataFor(TargetedResult result, {bool orNull: false}) { |
| CacheEntry entry = context.analysisCache.get(result.target); |
| if (orNull) { |
| @@ -819,6 +845,15 @@ abstract class CachePartition { |
| bool _isPriorityAnalysisTarget(AnalysisTarget target) { |
| return context.priorityTargets.contains(target); |
| } |
| + |
| + /** |
| + * If the given [target] is a [Source], removes it from [_sources]. |
| + */ |
| + void _removeSource(AnalysisTarget target) { |
| + if (target is Source) { |
| + _sources.remove(target); |
| + } |
| + } |
| } |
| /** |