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

Unified Diff: pkg/analysis_server/lib/src/plugin/result_collector.dart

Issue 2676593006: Initial support for managing partial results from plugins (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/src/plugin/result_collector_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/plugin/result_collector.dart
diff --git a/pkg/analysis_server/lib/src/plugin/result_collector.dart b/pkg/analysis_server/lib/src/plugin/result_collector.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6bd9d7742dcdb35630168653967e8aa1ea21b41b
--- /dev/null
+++ b/pkg/analysis_server/lib/src/plugin/result_collector.dart
@@ -0,0 +1,96 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/**
+ * An object used to collect partial results (of type [E]) where the partial
+ * results are contributed by plugins.
+ */
+class ResultCollector<E> {
+ /**
+ * The id used as a plugin id for contributions from the server.
+ */
+ final String serverId;
+
+ /**
+ * A multi-keyed map, where the first key is the (normalized and absolute)
+ * path to the file associated with the results, and the second is the id of
+ * the plugin that provided the partial results. The value is the partial
+ * results contrinuted by the plugin for the file.
+ */
+ Map<String, Map<String, E>> resultMap = <String, Map<String, E>>{};
+
+ /**
+ * Initialize a newly created result manager.
+ */
+ ResultCollector(this.serverId);
+
+ /**
+ * Clear any results that have been contributed for the file with the given
+ * [filePath], but continue to collect results for the file. This is used when
+ * the results for the specified file are known to be invalid, typically
+ * because the content of the file has been modified.
+ */
+ void clearResultsForFile(String filePath) {
+ resultMap[filePath].clear();
+ }
+
+ /**
+ * Clear any results that have been contributed by the plugin with the given
+ * [pluginId].
+ */
+ void clearResultsFromPlugin(String pluginId) {
+ for (Map<String, E> partialResults in resultMap.values) {
+ partialResults.remove(pluginId);
+ }
+ }
+
+ /**
+ * Return an iterator producing the partial results that have been contributed
+ * for the given [filePath],
scheglov 2017/02/04 03:05:16 Did you want to continue writing?
Brian Wilkerson 2017/02/04 17:45:38 No, just mistyped.
+ */
+ Iterable<E> getResults(String filePath) {
+ Map<String, E> partialResultMap = resultMap[filePath];
+ if (partialResultMap == null) {
+ return <E>[];
+ }
+ List<E> values = partialResultMap.values.toList();
+ //
+ // Ensure that the server's contributions are always first in the list.
+ //
+ E serverContributions = partialResultMap[serverId];
+ if (serverContributions != null && values.remove(serverContributions)) {
+ values.insert(0, serverContributions);
+ }
+ return values;
+ }
+
+ /**
+ * Record the [partialResults] as having been contributed for the given
+ * [filePath] by the plugin with the given [pluginId].
+ */
+ void putResults(String filePath, String pluginId, E partialResults) {
+ Map<String, E> fileResults = resultMap[filePath];
+ if (fileResults != null) {
+ fileResults[pluginId] = partialResults;
+ }
+ }
+
+ /**
+ * Start collecting results contributed for the file with the given
+ * [filePath]. Unless the collector is told to collect results for a file, any
+ * results that are contributed for that file are discarded.
+ */
+ void startCollectingFor(String filePath) {
+ resultMap.putIfAbsent(filePath, () => <String, E>{});
+ }
+
+ /**
+ * Stop collecting results contributed for the file with the given [filePath].
+ * Until the collector is told to start collecting results for the file, any
+ * results that are contributed for the file are discarded.
+ */
+ void stopCollectingFor(String filePath) {
+ resultMap.remove(filePath);
+ }
+}
« no previous file with comments | « no previous file | pkg/analysis_server/test/src/plugin/result_collector_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698