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