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

Unified Diff: pkg/analysis_server/lib/src/domain_execution.dart

Issue 587783003: Replace AnalysisServerListener with Stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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/analysis_server/lib/src/domain_execution.dart
diff --git a/pkg/analysis_server/lib/src/domain_execution.dart b/pkg/analysis_server/lib/src/domain_execution.dart
index 9fb599fb5096562be9aa5752518540aff3acda70..351e7a98ee9a264f0533426e0416746f3121c7b6 100644
--- a/pkg/analysis_server/lib/src/domain_execution.dart
+++ b/pkg/analysis_server/lib/src/domain_execution.dart
@@ -4,10 +4,12 @@
library domain.execution;
+import 'dart:async';
+import 'dart:collection';
+
import 'package:analysis_server/src/analysis_server.dart';
import 'package:analysis_server/src/constants.dart';
import 'package:analysis_server/src/protocol.dart';
-import 'dart:collection';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/source.dart';
@@ -32,9 +34,10 @@ class ExecutionDomainHandler implements RequestHandler {
Map<String, String> contextMap = new HashMap<String, String>();
/**
- * The listener used to send notifications when
+ * The subscription to the 'onAnalysisComplete' events,
+ * used to send notifications when
*/
- LaunchDataNotificationListener launchDataListener;
+ StreamSubscription onAnalysisSubscription;
/**
* Initialize a newly created handler to handle requests for the given [server].
@@ -123,42 +126,20 @@ class ExecutionDomainHandler implements RequestHandler {
List<ExecutionService> subscriptions =
new ExecutionSetSubscriptionsParams.fromRequest(request).subscriptions;
if (subscriptions.contains(ExecutionService.LAUNCH_DATA)) {
- if (launchDataListener == null) {
- launchDataListener = new LaunchDataNotificationListener(server);
- server.addAnalysisServerListener(launchDataListener);
- if (server.isAnalysisComplete()) {
- launchDataListener.analysisComplete();
- }
+ if (onAnalysisSubscription == null) {
+ onAnalysisSubscription =
+ server.onAnalysisComplete.listen(_analysisComplete);
}
} else {
- if (launchDataListener != null) {
- server.removeAnalysisServerListener(launchDataListener);
- launchDataListener = null;
+ if (onAnalysisSubscription != null) {
+ onAnalysisSubscription.cancel();
+ onAnalysisSubscription = null;
}
}
return new ExecutionSetSubscriptionsResult().toResponse(request.id);
}
-}
-/**
- * Instances of the class [LaunchDataNotificationListener] listen for analysis
- * to be complete and then notify the client of the launch data that has been
- * computed.
- */
-class LaunchDataNotificationListener implements AnalysisServerListener {
- /**
- * The analysis server used to send notifications.
- */
- final AnalysisServer server;
-
- /**
- * Initialize a newly created listener to send notifications through the given
- * [server] when analysis is complete.
- */
- LaunchDataNotificationListener(this.server);
-
- @override
- void analysisComplete() {
+ void _analysisComplete(_) {
List<ExecutableFile> executables = [];
Map<String, List<String>> dartToHtml = new HashMap<String, List<String>>();
Map<String, List<String>> htmlToDart = new HashMap<String, List<String>>();
@@ -182,7 +163,7 @@ class LaunchDataNotificationListener implements AnalysisServerListener {
if (files.isNotEmpty) {
// TODO(brianwilkerson) Handle the case where the same library is
// being analyzed in multiple contexts.
- dartToHtml[librarySource.fullName] = getFullNames(files);
+ dartToHtml[librarySource.fullName] = _getFullNames(files);
}
}
@@ -192,7 +173,7 @@ class LaunchDataNotificationListener implements AnalysisServerListener {
if (libraries.isNotEmpty) {
// TODO(brianwilkerson) Handle the case where the same HTML file is
// being analyzed in multiple contexts.
- htmlToDart[htmlSource.fullName] = getFullNames(libraries);
+ htmlToDart[htmlSource.fullName] = _getFullNames(libraries);
}
}
}
@@ -203,7 +184,7 @@ class LaunchDataNotificationListener implements AnalysisServerListener {
htmlToDart).toNotification());
}
- List<String> getFullNames(List<Source> sources) {
+ static List<String> _getFullNames(List<Source> sources) {
return sources.map((Source source) => source.fullName).toList();
}
}

Powered by Google App Engine
This is Rietveld 408576698