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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * An object used to collect partial results (of type [E]) where the partial
7 * results are contributed by plugins.
8 */
9 class ResultCollector<E> {
10 /**
11 * The id used as a plugin id for contributions from the server.
12 */
13 final String serverId;
14
15 /**
16 * A multi-keyed map, where the first key is the (normalized and absolute)
17 * path to the file associated with the results, and the second is the id of
18 * the plugin that provided the partial results. The value is the partial
19 * results contrinuted by the plugin for the file.
20 */
21 Map<String, Map<String, E>> resultMap = <String, Map<String, E>>{};
22
23 /**
24 * Initialize a newly created result manager.
25 */
26 ResultCollector(this.serverId);
27
28 /**
29 * Clear any results that have been contributed for the file with the given
30 * [filePath], but continue to collect results for the file. This is used when
31 * the results for the specified file are known to be invalid, typically
32 * because the content of the file has been modified.
33 */
34 void clearResultsForFile(String filePath) {
35 resultMap[filePath].clear();
36 }
37
38 /**
39 * Clear any results that have been contributed by the plugin with the given
40 * [pluginId].
41 */
42 void clearResultsFromPlugin(String pluginId) {
43 for (Map<String, E> partialResults in resultMap.values) {
44 partialResults.remove(pluginId);
45 }
46 }
47
48 /**
49 * Return an iterator producing the partial results that have been contributed
50 * 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.
51 */
52 Iterable<E> getResults(String filePath) {
53 Map<String, E> partialResultMap = resultMap[filePath];
54 if (partialResultMap == null) {
55 return <E>[];
56 }
57 List<E> values = partialResultMap.values.toList();
58 //
59 // Ensure that the server's contributions are always first in the list.
60 //
61 E serverContributions = partialResultMap[serverId];
62 if (serverContributions != null && values.remove(serverContributions)) {
63 values.insert(0, serverContributions);
64 }
65 return values;
66 }
67
68 /**
69 * Record the [partialResults] as having been contributed for the given
70 * [filePath] by the plugin with the given [pluginId].
71 */
72 void putResults(String filePath, String pluginId, E partialResults) {
73 Map<String, E> fileResults = resultMap[filePath];
74 if (fileResults != null) {
75 fileResults[pluginId] = partialResults;
76 }
77 }
78
79 /**
80 * Start collecting results contributed for the file with the given
81 * [filePath]. Unless the collector is told to collect results for a file, any
82 * results that are contributed for that file are discarded.
83 */
84 void startCollectingFor(String filePath) {
85 resultMap.putIfAbsent(filePath, () => <String, E>{});
86 }
87
88 /**
89 * Stop collecting results contributed for the file with the given [filePath].
90 * Until the collector is told to start collecting results for the file, any
91 * results that are contributed for the file are discarded.
92 */
93 void stopCollectingFor(String filePath) {
94 resultMap.remove(filePath);
95 }
96 }
OLDNEW
« 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