Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(948)

Unified Diff: pkg/analyzer/lib/src/context/context.dart

Issue 1239863002: Add hook for listening to implicitly analyzed files (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/context/context.dart
diff --git a/pkg/analyzer/lib/src/context/context.dart b/pkg/analyzer/lib/src/context/context.dart
index 9c0c9808356e71d72075280b178eba1551f8733c..3199f85bf1e32f9d9a3c0821b9964c06e54fa6c0 100644
--- a/pkg/analyzer/lib/src/context/context.dart
+++ b/pkg/analyzer/lib/src/context/context.dart
@@ -167,6 +167,12 @@ class AnalysisContextImpl implements InternalAnalysisContext {
StreamController<SourcesChangedEvent> _onSourcesChangedController;
/**
+ * A subscription for a stream of events indicating when files are (and are
+ * not) being implicitly analyzed.
+ */
+ StreamController<AnalyzedSourcesEvent> _analyzedSourcesController;
Paul Berry 2015/07/15 19:50:01 How about naming this "_implicitlyAnalyzedSourcesC
+
+ /**
* The listeners that are to be notified when various analysis results are
* produced in this context.
*/
@@ -220,6 +226,8 @@ class AnalysisContextImpl implements InternalAnalysisContext {
_taskManager, <WorkManager>[dartWorkManager, htmlWorkManager], this);
_onSourcesChangedController =
new StreamController<SourcesChangedEvent>.broadcast();
+ _analyzedSourcesController =
+ new StreamController<AnalyzedSourcesEvent>.broadcast();
}
@override
@@ -281,6 +289,10 @@ class AnalysisContextImpl implements InternalAnalysisContext {
}
@override
+ Stream<AnalyzedSourcesEvent> get analyzedSources =>
+ _analyzedSourcesController.stream;
+
+ @override
set contentCache(ContentCache value) {
_contentCache = value;
}
@@ -728,6 +740,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
entry.modificationTime = getModificationStamp(target);
}
_cache.put(entry);
+ if (target is Source) {
+ _analyzedSourcesController.add(new AnalyzedSourcesEvent(target, true));
+ }
}
return entry;
}
@@ -1219,7 +1234,7 @@ class AnalysisContextImpl implements InternalAnalysisContext {
for (Source source in missingSources) {
if (getLibrariesContaining(source).isEmpty &&
getLibrariesDependingOn(source).isEmpty) {
- _cache.remove(source);
+ _removeFromCache(source);
removalCount++;
}
}
@@ -1427,6 +1442,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
entry.modificationTime = getModificationStamp(source);
entry.explicitlyAdded = explicitlyAdded;
_cache.put(entry);
+ if (!explicitlyAdded) {
+ _analyzedSourcesController.add(new AnalyzedSourcesEvent(source, true));
+ }
return entry;
}
@@ -1637,6 +1655,13 @@ class AnalysisContextImpl implements InternalAnalysisContext {
}
}
+ void _removeFromCache(Source source) {
+ CacheEntry entry = _cache.remove(source);
+ if (entry != null && entry.explicitlyAdded) {
+ _analyzedSourcesController.add(new AnalyzedSourcesEvent(source, false));
+ }
+ }
+
/**
* Remove the given [source] from the priority order if it is in the list.
*/
@@ -1769,7 +1794,7 @@ class AnalysisContextImpl implements InternalAnalysisContext {
* Record that the given [source] has been removed.
*/
void _sourceRemoved(Source source) {
- _cache.remove(source);
+ _removeFromCache(source);
_removeFromPriorityOrder(source);
}

Powered by Google App Engine
This is Rietveld 408576698