OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; | 5 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; |
6 | 6 |
7 /** | 7 /** |
8 * An object that manages the subscriptions for analysis results. | 8 * An object that manages the subscriptions for analysis results. |
9 * | 9 * |
10 * Clients may not extend, implement or mix-in this class. | 10 * Clients may not extend, implement or mix-in this class. |
11 */ | 11 */ |
12 class SubscriptionManager { | 12 class SubscriptionManager { |
13 /** | 13 /** |
14 * The current set of subscriptions. | 14 * The current set of subscriptions. |
15 */ | 15 */ |
16 Map<AnalysisService, List<String>> _subscriptions; | 16 Map<AnalysisService, List<String>> _subscriptions; |
17 | 17 |
18 /** | 18 /** |
19 * Initialize a newly created subscription manager to have no subscriptions. | 19 * Initialize a newly created subscription manager to have no subscriptions. |
20 */ | 20 */ |
21 SubscriptionManager(); | 21 SubscriptionManager(); |
22 | 22 |
23 /** | 23 /** |
| 24 * Return `true` if the file with the given [filePath] has a subscription for |
| 25 * the given [service]. |
| 26 */ |
| 27 bool hasSubscriptionForFile(String filePath, AnalysisService service) { |
| 28 if (_subscriptions == null) { |
| 29 return false; |
| 30 } |
| 31 List<String> files = _subscriptions[service]; |
| 32 return files != null && files.contains(filePath); |
| 33 } |
| 34 |
| 35 /** |
24 * Return a list of the services for which the file with the given [filePath] | 36 * Return a list of the services for which the file with the given [filePath] |
25 * has been subscribed. | 37 * has been subscribed. |
26 */ | 38 */ |
27 List<AnalysisService> servicesForFile(String filePath) { | 39 List<AnalysisService> servicesForFile(String filePath) { |
28 List<AnalysisService> services = <AnalysisService>[]; | 40 List<AnalysisService> services = <AnalysisService>[]; |
29 if (_subscriptions != null) { | 41 if (_subscriptions != null) { |
30 _subscriptions.forEach((AnalysisService service, List<String> files) { | 42 _subscriptions.forEach((AnalysisService service, List<String> files) { |
31 if (files.contains(filePath)) { | 43 if (files.contains(filePath)) { |
32 services.add(service); | 44 services.add(service); |
33 } | 45 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 .putIfAbsent(path, () => <AnalysisService>[]) | 81 .putIfAbsent(path, () => <AnalysisService>[]) |
70 .add(service); | 82 .add(service); |
71 } | 83 } |
72 } | 84 } |
73 }); | 85 }); |
74 } | 86 } |
75 _subscriptions = subscriptions; | 87 _subscriptions = subscriptions; |
76 return newSubscriptions; | 88 return newSubscriptions; |
77 } | 89 } |
78 } | 90 } |
OLD | NEW |