| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, 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 services.correction.fix; | |
| 6 | |
| 7 import 'package:analysis_services/correction/change.dart'; | |
| 8 import 'package:analysis_services/search/search_engine.dart'; | |
| 9 import 'package:analysis_services/src/correction/fix.dart'; | |
| 10 import 'package:analyzer/src/generated/ast.dart'; | |
| 11 import 'package:analyzer/src/generated/error.dart'; | |
| 12 import 'package:analyzer/src/generated/source.dart'; | |
| 13 | |
| 14 | |
| 15 /** | |
| 16 * Computes [Fix]s for the given [AnalysisError]. | |
| 17 * | |
| 18 * Returns the computed [Fix]s, not `null`. | |
| 19 */ | |
| 20 List<Fix> computeFixes(SearchEngine searchEngine, CompilationUnit unit, | |
| 21 AnalysisError error) { | |
| 22 Source source = unit.element.source; | |
| 23 String file = source.fullName; | |
| 24 var processor = new FixProcessor(searchEngine, source, file, unit, error); | |
| 25 return processor.compute(); | |
| 26 } | |
| 27 | |
| 28 | |
| 29 /** | |
| 30 * A description of a single proposed fix for some problem. | |
| 31 */ | |
| 32 class Fix { | |
| 33 final FixKind kind; | |
| 34 final Change change; | |
| 35 | |
| 36 Fix(this.kind, this.change); | |
| 37 | |
| 38 @override | |
| 39 String toString() { | |
| 40 return '[kind=$kind, change=$change]'; | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 | |
| 45 /** | |
| 46 * An enumeration of possible quick fix kinds. | |
| 47 */ | |
| 48 class FixKind { | |
| 49 static const ADD_PACKAGE_DEPENDENCY = | |
| 50 const FixKind('ADD_PACKAGE_DEPENDENCY', 50, "Add dependency on package '{0
}'"); | |
| 51 static const ADD_SUPER_CONSTRUCTOR_INVOCATION = | |
| 52 const FixKind( | |
| 53 'ADD_SUPER_CONSTRUCTOR_INVOCATION', | |
| 54 50, | |
| 55 "Add super constructor {0} invocation"); | |
| 56 static const CHANGE_TO = const FixKind('CHANGE_TO', 51, "Change to '{0}'"); | |
| 57 static const CHANGE_TO_STATIC_ACCESS = | |
| 58 const FixKind( | |
| 59 'CHANGE_TO_STATIC_ACCESS', | |
| 60 50, | |
| 61 "Change access to static using '{0}'"); | |
| 62 static const CREATE_CLASS = | |
| 63 const FixKind('CREATE_CLASS', 50, "Create class '{0}'"); | |
| 64 static const CREATE_CONSTRUCTOR = | |
| 65 const FixKind('CREATE_CONSTRUCTOR', 50, "Create constructor '{0}'"); | |
| 66 static const CREATE_CONSTRUCTOR_SUPER = | |
| 67 const FixKind('CREATE_CONSTRUCTOR_SUPER', 50, "Create constructor to call
{0}"); | |
| 68 static const CREATE_FUNCTION = | |
| 69 const FixKind('CREATE_FUNCTION', 49, "Create function '{0}'"); | |
| 70 static const CREATE_METHOD = | |
| 71 const FixKind('CREATE_METHOD', 50, "Create method '{0}'"); | |
| 72 static const CREATE_MISSING_OVERRIDES = | |
| 73 const FixKind('CREATE_MISSING_OVERRIDES', 50, "Create %d missing override(
s)"); | |
| 74 static const CREATE_NO_SUCH_METHOD = | |
| 75 const FixKind('CREATE_NO_SUCH_METHOD', 49, "Create 'noSuchMethod' method")
; | |
| 76 static const CREATE_PART = | |
| 77 const FixKind('CREATE_PART', 50, "Create part '{0}'"); | |
| 78 static const IMPORT_LIBRARY_PREFIX = | |
| 79 const FixKind( | |
| 80 'IMPORT_LIBRARY_PREFIX', | |
| 81 51, | |
| 82 "Use imported library '{0}' with prefix '{1}'"); | |
| 83 static const IMPORT_LIBRARY_PROJECT = | |
| 84 const FixKind('IMPORT_LIBRARY_PROJECT', 51, "Import library '{0}'"); | |
| 85 static const IMPORT_LIBRARY_SDK = | |
| 86 const FixKind('IMPORT_LIBRARY_SDK', 51, "Import library '{0}'"); | |
| 87 static const IMPORT_LIBRARY_SHOW = | |
| 88 const FixKind('IMPORT_LIBRARY_SHOW', 51, "Update library '{0}' import"); | |
| 89 static const INSERT_SEMICOLON = | |
| 90 const FixKind('INSERT_SEMICOLON', 50, "Insert ';'"); | |
| 91 static const MAKE_CLASS_ABSTRACT = | |
| 92 const FixKind('MAKE_CLASS_ABSTRACT', 50, "Make class '{0}' abstract"); | |
| 93 static const REMOVE_PARAMETERS_IN_GETTER_DECLARATION = | |
| 94 const FixKind( | |
| 95 'REMOVE_PARAMETERS_IN_GETTER_DECLARATION', | |
| 96 50, | |
| 97 "Remove parameters in getter declaration"); | |
| 98 static const REMOVE_PARENTHESIS_IN_GETTER_INVOCATION = | |
| 99 const FixKind( | |
| 100 'REMOVE_PARENTHESIS_IN_GETTER_INVOCATION', | |
| 101 50, | |
| 102 "Remove parentheses in getter invocation"); | |
| 103 static const REMOVE_UNNECASSARY_CAST = | |
| 104 const FixKind('REMOVE_UNNECASSARY_CAST', 50, "Remove unnecessary cast"); | |
| 105 static const REMOVE_UNUSED_IMPORT = | |
| 106 const FixKind('REMOVE_UNUSED_IMPORT', 50, "Remove unused import"); | |
| 107 static const REPLACE_BOOLEAN_WITH_BOOL = | |
| 108 const FixKind('REPLACE_BOOLEAN_WITH_BOOL', 50, "Replace 'boolean' with 'bo
ol'"); | |
| 109 static const USE_CONST = const FixKind('USE_CONST', 50, "Change to constant"); | |
| 110 static const USE_EFFECTIVE_INTEGER_DIVISION = | |
| 111 const FixKind( | |
| 112 'USE_EFFECTIVE_INTEGER_DIVISION', | |
| 113 50, | |
| 114 "Use effective integer division ~/"); | |
| 115 static const USE_EQ_EQ_NULL = | |
| 116 const FixKind('USE_EQ_EQ_NULL', 50, "Use == null instead of 'is Null'"); | |
| 117 static const USE_NOT_EQ_NULL = | |
| 118 const FixKind('USE_NOT_EQ_NULL', 50, "Use != null instead of 'is! Null'"); | |
| 119 | |
| 120 final name; | |
| 121 final int relevance; | |
| 122 final String message; | |
| 123 | |
| 124 const FixKind(this.name, this.relevance, this.message); | |
| 125 | |
| 126 @override | |
| 127 String toString() => name; | |
| 128 } | |
| OLD | NEW |