OLD | NEW |
(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 import 'package:analyzer/dart/analysis/results.dart'; |
| 6 import 'package:analyzer/file_system/file_system.dart'; |
| 7 import 'package:analyzer_plugin/protocol/protocol.dart'; |
| 8 import 'package:analyzer_plugin/protocol/protocol_common.dart' |
| 9 hide AnalysisError; |
| 10 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; |
| 11 import 'package:analyzer_plugin/src/utilities/occurrences/occurrences.dart'; |
| 12 import 'package:analyzer_plugin/utilities/generator.dart'; |
| 13 |
| 14 /** |
| 15 * The information about a requested set of occurrences information when |
| 16 * computing occurrences information in a `.dart` file. |
| 17 * |
| 18 * Clients may not extend, implement or mix-in this class. |
| 19 */ |
| 20 abstract class DartOccurrencesRequest implements OccurrencesRequest { |
| 21 /** |
| 22 * The analysis result for the file for which the occurrences information is |
| 23 * being requested. |
| 24 */ |
| 25 ResolveResult get result; |
| 26 } |
| 27 |
| 28 /** |
| 29 * An object that [OccurrencesContributor]s use to record occurrences. |
| 30 * |
| 31 * Clients may not extend, implement or mix-in this class. |
| 32 */ |
| 33 abstract class OccurrencesCollector { |
| 34 /** |
| 35 * Add an occurrence of the given [element] at the given [offset]. |
| 36 */ |
| 37 void addOccurrence(Element element, int offset); |
| 38 } |
| 39 |
| 40 /** |
| 41 * An object used to produce occurrences information. |
| 42 * |
| 43 * Clients may implement this class when implementing plugins. |
| 44 */ |
| 45 abstract class OccurrencesContributor { |
| 46 /** |
| 47 * Contribute occurrences information into the given [collector]. |
| 48 */ |
| 49 void computeOccurrences( |
| 50 OccurrencesRequest request, OccurrencesCollector collector); |
| 51 } |
| 52 |
| 53 /** |
| 54 * A generator that will generate an 'analysis.occurrences' notification. |
| 55 * |
| 56 * Clients may not extend, implement or mix-in this class. |
| 57 */ |
| 58 class OccurrencesGenerator { |
| 59 /** |
| 60 * The contributors to be used to generate the occurrences information. |
| 61 */ |
| 62 final List<OccurrencesContributor> contributors; |
| 63 |
| 64 /** |
| 65 * Initialize a newly created occurrences generator to use the given |
| 66 * [contributors]. |
| 67 */ |
| 68 OccurrencesGenerator(this.contributors); |
| 69 |
| 70 /** |
| 71 * Create an 'analysis.occurrences' notification. If any of the contributors |
| 72 * throws an exception, also create a non-fatal 'plugin.error' notification. |
| 73 */ |
| 74 GeneratorResult generateOccurrencesNotification(OccurrencesRequest request) { |
| 75 List<Notification> notifications = <Notification>[]; |
| 76 OccurrencesCollectorImpl collector = new OccurrencesCollectorImpl(); |
| 77 for (OccurrencesContributor contributor in contributors) { |
| 78 try { |
| 79 contributor.computeOccurrences(request, collector); |
| 80 } catch (exception, stackTrace) { |
| 81 notifications.add(new PluginErrorParams( |
| 82 false, exception.toString(), stackTrace.toString()) |
| 83 .toNotification()); |
| 84 } |
| 85 } |
| 86 notifications.add( |
| 87 new AnalysisOccurrencesParams(request.path, collector.occurrences) |
| 88 .toNotification()); |
| 89 return new GeneratorResult(null, notifications); |
| 90 } |
| 91 } |
| 92 |
| 93 /** |
| 94 * The information about a requested set of occurrences information. |
| 95 * |
| 96 * Clients may not extend, implement or mix-in this class. |
| 97 */ |
| 98 abstract class OccurrencesRequest { |
| 99 /** |
| 100 * Return the path of the file for which occurrences information is being |
| 101 * requested. |
| 102 */ |
| 103 String get path; |
| 104 |
| 105 /** |
| 106 * Return the resource provider associated with this request. |
| 107 */ |
| 108 ResourceProvider get resourceProvider; |
| 109 } |
OLD | NEW |