| 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.fix.fix_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/error.dart'; |
| 10 |
| 11 /** |
| 12 * A description of a single proposed fix for some problem. |
| 13 */ |
| 14 class Fix { |
| 15 /** |
| 16 * An empty list of fixes. |
| 17 */ |
| 18 static const List<Fix> EMPTY_LIST = const <Fix>[]; |
| 19 |
| 20 /** |
| 21 * A comparator that can be used to sort fixes by their relevance. The most |
| 22 * relevant fixes will be sorted before fixes with a lower relevance. |
| 23 */ |
| 24 static final Comparator<Fix> SORT_BY_RELEVANCE = (Fix firstFix, |
| 25 Fix secondFix) => firstFix.kind.relevance - secondFix.kind.relevance; |
| 26 |
| 27 /** |
| 28 * A description of the fix being proposed. |
| 29 */ |
| 30 final FixKind kind; |
| 31 |
| 32 /** |
| 33 * The change to be made in order to apply the fix. |
| 34 */ |
| 35 final SourceChange change; |
| 36 |
| 37 /** |
| 38 * Initialize a newly created fix to have the given [kind] and [change]. |
| 39 */ |
| 40 Fix(this.kind, this.change); |
| 41 |
| 42 @override |
| 43 String toString() { |
| 44 return 'Fix(kind=$kind, change=$change)'; |
| 45 } |
| 46 } |
| 47 |
| 48 /** |
| 49 * An object used to produce fixes for a specific error. Fix contributors are |
| 50 * long-lived objects and must not retain any state between invocations of |
| 51 * [computeFixes]. |
| 52 */ |
| 53 abstract class FixContributor { |
| 54 /** |
| 55 * Return a list of fixes for the given [error]. The error was reported |
| 56 * after it's source was analyzed in the given [context]. |
| 57 */ |
| 58 List<Fix> computeFixes(AnalysisContext context, AnalysisError error); |
| 59 } |
| 60 |
| 61 /** |
| 62 * A description of a class of fixes. Instances are intended to hold the |
| 63 * information that is common across a number of fixes and to be shared by those |
| 64 * fixes. For example, if an unnecessary cast is found then one of the suggested |
| 65 * fixes will be to remove the cast. If there are multiple unnecessary casts in |
| 66 * a single file, then there will be multiple fixes, one per occurance, but they |
| 67 * will all share the same kind. |
| 68 */ |
| 69 class FixKind { |
| 70 /** |
| 71 * The name of this kind of fix, used for debugging. |
| 72 */ |
| 73 final String name; |
| 74 |
| 75 /** |
| 76 * The relevance of this kind of fix for the kind of error being addressed. |
| 77 */ |
| 78 final int relevance; |
| 79 |
| 80 /** |
| 81 * A human-readable description of the changes that will be applied by this |
| 82 * kind of fix. |
| 83 */ |
| 84 final String message; |
| 85 |
| 86 /** |
| 87 * Initialize a newly created kind of fix to have the given [name], |
| 88 * [relevance] and [message]. |
| 89 */ |
| 90 const FixKind(this.name, this.relevance, this.message); |
| 91 |
| 92 @override |
| 93 String toString() => name; |
| 94 } |
| OLD | NEW |