Chromium Code Reviews| 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_generated.dart'; | |
| 9 import 'package:analyzer_plugin/src/utilities/assist/assist.dart'; | |
| 10 import 'package:analyzer_plugin/utilities/generator.dart'; | |
| 11 | |
| 12 /** | |
| 13 * An object that [AssistContributor]s use to record assists. | |
| 14 * | |
| 15 * Clients may not extend, implement or mix-in this class. | |
| 16 */ | |
| 17 abstract class AssistCollector { | |
| 18 /** | |
| 19 * Record a new [assist]. | |
| 20 */ | |
| 21 void addAssist(PrioritizedSourceChange assist); | |
| 22 } | |
| 23 | |
| 24 /** | |
| 25 * An object used to produce assists. | |
| 26 * | |
| 27 * Clients may implement this class when implementing plugins. | |
| 28 */ | |
| 29 abstract class AssistContributor { | |
| 30 /** | |
| 31 * Contribute assists for the location in the file specified by the given | |
| 32 * [request] into the given [collector]. | |
| 33 */ | |
| 34 void computeFixes(AssistRequest request, AssistCollector collector); | |
|
scheglov
2017/06/07 16:09:19
computeAssists() ?
| |
| 35 } | |
| 36 | |
| 37 /** | |
| 38 * A generator that will generate an 'edit.getAssists' response. | |
| 39 * | |
| 40 * Clients may not extend, implement or mix-in this class. | |
| 41 */ | |
| 42 class AssistGenerator { | |
| 43 /** | |
| 44 * The contributors to be used to generate the assists. | |
| 45 */ | |
| 46 final List<AssistContributor> contributors; | |
| 47 | |
| 48 /** | |
| 49 * Initialize a newly created assists generator to use the given | |
| 50 * [contributors]. | |
| 51 */ | |
| 52 AssistGenerator(this.contributors); | |
| 53 | |
| 54 /** | |
| 55 * Create an 'edit.getAssists' response for the location in the file specified | |
| 56 * by the given [request]. If any of the contributors throws an exception, | |
| 57 * also create a non-fatal 'plugin.error' notification. | |
| 58 */ | |
| 59 GeneratorResult generateAssistsResponse(AssistRequest request) { | |
| 60 List<Notification> notifications = <Notification>[]; | |
| 61 AssistCollectorImpl collector = new AssistCollectorImpl(); | |
| 62 for (AssistContributor contributor in contributors) { | |
| 63 try { | |
| 64 contributor.computeFixes(request, collector); | |
| 65 } catch (exception, stackTrace) { | |
| 66 notifications.add(new PluginErrorParams( | |
| 67 false, exception.toString(), stackTrace.toString()) | |
| 68 .toNotification()); | |
| 69 } | |
| 70 } | |
| 71 EditGetAssistsResult result = new EditGetAssistsResult(collector.assists); | |
| 72 return new GeneratorResult(result, notifications); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 /** | |
| 77 * The information about a requested set of assists. | |
| 78 * | |
| 79 * Clients may not extend, implement or mix-in this class. | |
| 80 */ | |
| 81 abstract class AssistRequest { | |
| 82 /** | |
| 83 * Return the length of the selection within the source for which assists are | |
| 84 * being requested. | |
| 85 */ | |
| 86 int get length; | |
| 87 | |
| 88 /** | |
| 89 * Return the offset of the selection within the source for which assists are | |
| 90 * being requested. | |
| 91 */ | |
| 92 int get offset; | |
| 93 | |
| 94 /** | |
| 95 * Return the resource provider associated with this request. | |
| 96 */ | |
| 97 ResourceProvider get resourceProvider; | |
| 98 | |
| 99 /** | |
| 100 * The analysis result for the file in which the assists are being requested. | |
| 101 */ | |
| 102 ResolveResult get result; | |
| 103 } | |
| OLD | NEW |