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