| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, 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 library analysis_server.edit.assist.assist_core; | |
| 6 | |
| 7 import 'package:analysis_server/src/protocol.dart' show SourceChange; | |
| 8 import 'package:analyzer/src/generated/engine.dart'; | |
| 9 import 'package:analyzer/src/generated/source.dart'; | |
| 10 | |
| 11 /** | |
| 12 * A description of a single proposed assist. | |
| 13 * | |
| 14 * Clients are not expected to subtype this class. | |
| 15 */ | |
| 16 class Assist { | |
| 17 /** | |
| 18 * An empty list of assists. | |
| 19 */ | |
| 20 static const List<Assist> EMPTY_LIST = const <Assist>[]; | |
| 21 | |
| 22 /** | |
| 23 * A comparator that can be used to sort assists by their relevance. The most | |
| 24 * relevant assists will be sorted before assists with a lower relevance. | |
| 25 */ | |
| 26 static final Comparator<Assist> SORT_BY_RELEVANCE = (Assist firstAssist, | |
| 27 Assist secondAssist) => | |
| 28 firstAssist.kind.relevance - secondAssist.kind.relevance; | |
| 29 | |
| 30 /** | |
| 31 * A description of the assist being proposed. | |
| 32 */ | |
| 33 final AssistKind kind; | |
| 34 | |
| 35 /** | |
| 36 * The change to be made in order to apply the assist. | |
| 37 */ | |
| 38 final SourceChange change; | |
| 39 | |
| 40 /** | |
| 41 * Initialize a newly created assist to have the given [kind] and [change]. | |
| 42 */ | |
| 43 Assist(this.kind, this.change); | |
| 44 | |
| 45 @override | |
| 46 String toString() { | |
| 47 return 'Assist(kind=$kind, change=$change)'; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 /** | |
| 52 * An object used to produce assists for a specific location. | |
| 53 * | |
| 54 * Clients are expected to subtype this class when implementing plugins. | |
| 55 */ | |
| 56 abstract class AssistContributor { | |
| 57 /** | |
| 58 * Return a list of assists for a location in the given [source]. The location | |
| 59 * is specified by the [offset] and [length] of the selected region. The | |
| 60 * [context] can be used to get additional information that is useful for | |
| 61 * computing assists. | |
| 62 */ | |
| 63 List<Assist> computeAssists( | |
| 64 AnalysisContext context, Source source, int offset, int length); | |
| 65 } | |
| 66 | |
| 67 /** | |
| 68 * A description of a class of assists. Instances are intended to hold the | |
| 69 * information that is common across a number of assists and to be shared by | |
| 70 * those assists. | |
| 71 * | |
| 72 * Clients are not expected to subtype this class. | |
| 73 */ | |
| 74 class AssistKind { | |
| 75 /** | |
| 76 * The name of this kind of assist, used for debugging. | |
| 77 */ | |
| 78 final String name; | |
| 79 | |
| 80 /** | |
| 81 * The relevance of this kind of assist for the kind of error being addressed. | |
| 82 */ | |
| 83 final int relevance; | |
| 84 | |
| 85 /** | |
| 86 * A human-readable description of the changes that will be applied by this | |
| 87 * kind of assist. | |
| 88 */ | |
| 89 final String message; | |
| 90 | |
| 91 /** | |
| 92 * Initialize a newly created kind of assist to have the given [name], | |
| 93 * [relevance] and [message]. | |
| 94 */ | |
| 95 const AssistKind(this.name, this.relevance, this.message); | |
| 96 | |
| 97 @override | |
| 98 String toString() => name; | |
| 99 } | |
| OLD | NEW |