| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library services.correction.fix; | 5 library services.correction.fix; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol.dart' show SourceChange; | 7 import 'package:analysis_server/src/protocol.dart' show SourceChange; |
| 8 import 'package:analysis_server/src/services/correction/fix_internal.dart'; |
| 8 import 'package:analysis_server/src/services/search/search_engine.dart'; | 9 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 9 import 'package:analysis_server/src/services/correction/fix_internal.dart'; | |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| 11 import 'package:analyzer/src/generated/error.dart'; | 11 import 'package:analyzer/src/generated/error.dart'; |
| 12 import 'package:analyzer/src/generated/source.dart'; | 12 import 'package:analyzer/src/generated/source.dart'; |
| 13 | 13 |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Computes [Fix]s for the given [AnalysisError]. | 16 * Computes [Fix]s for the given [AnalysisError]. |
| 17 * | 17 * |
| 18 * Returns the computed [Fix]s, not `null`. | 18 * Returns the computed [Fix]s, not `null`. |
| 19 */ | 19 */ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 | 44 |
| 45 /** | 45 /** |
| 46 * An enumeration of possible quick fix kinds. | 46 * An enumeration of possible quick fix kinds. |
| 47 */ | 47 */ |
| 48 class FixKind { | 48 class FixKind { |
| 49 static const ADD_PACKAGE_DEPENDENCY = | 49 static const ADD_PACKAGE_DEPENDENCY = |
| 50 const FixKind('ADD_PACKAGE_DEPENDENCY', 50, "Add dependency on package '{0
}'"); | 50 const FixKind('ADD_PACKAGE_DEPENDENCY', 50, "Add dependency on package '{0
}'"); |
| 51 static const ADD_SUPER_CONSTRUCTOR_INVOCATION = | 51 static const ADD_SUPER_CONSTRUCTOR_INVOCATION = const FixKind( |
| 52 const FixKind( | 52 'ADD_SUPER_CONSTRUCTOR_INVOCATION', |
| 53 'ADD_SUPER_CONSTRUCTOR_INVOCATION', | 53 50, |
| 54 50, | 54 "Add super constructor {0} invocation"); |
| 55 "Add super constructor {0} invocation"); | |
| 56 static const CHANGE_TO = const FixKind('CHANGE_TO', 51, "Change to '{0}'"); | 55 static const CHANGE_TO = const FixKind('CHANGE_TO', 51, "Change to '{0}'"); |
| 57 static const CHANGE_TO_STATIC_ACCESS = | 56 static const CHANGE_TO_STATIC_ACCESS = const FixKind( |
| 58 const FixKind( | 57 'CHANGE_TO_STATIC_ACCESS', |
| 59 'CHANGE_TO_STATIC_ACCESS', | 58 50, |
| 60 50, | 59 "Change access to static using '{0}'"); |
| 61 "Change access to static using '{0}'"); | |
| 62 static const CREATE_CLASS = | 60 static const CREATE_CLASS = |
| 63 const FixKind('CREATE_CLASS', 50, "Create class '{0}'"); | 61 const FixKind('CREATE_CLASS', 50, "Create class '{0}'"); |
| 64 static const CREATE_CONSTRUCTOR = | 62 static const CREATE_CONSTRUCTOR = |
| 65 const FixKind('CREATE_CONSTRUCTOR', 50, "Create constructor '{0}'"); | 63 const FixKind('CREATE_CONSTRUCTOR', 50, "Create constructor '{0}'"); |
| 66 static const CREATE_CONSTRUCTOR_SUPER = | 64 static const CREATE_CONSTRUCTOR_SUPER = const FixKind( |
| 67 const FixKind('CREATE_CONSTRUCTOR_SUPER', 50, "Create constructor to call
{0}"); | 65 'CREATE_CONSTRUCTOR_SUPER', |
| 66 50, |
| 67 "Create constructor to call {0}"); |
| 68 static const CREATE_FILE = |
| 69 const FixKind('CREATE_FILE', 50, "Create file '{0}'"); |
| 68 static const CREATE_FUNCTION = | 70 static const CREATE_FUNCTION = |
| 69 const FixKind('CREATE_FUNCTION', 49, "Create function '{0}'"); | 71 const FixKind('CREATE_FUNCTION', 49, "Create function '{0}'"); |
| 70 static const CREATE_METHOD = | 72 static const CREATE_METHOD = |
| 71 const FixKind('CREATE_METHOD', 50, "Create method '{0}'"); | 73 const FixKind('CREATE_METHOD', 50, "Create method '{0}'"); |
| 72 static const CREATE_MISSING_OVERRIDES = | 74 static const CREATE_MISSING_OVERRIDES = const FixKind( |
| 73 const FixKind('CREATE_MISSING_OVERRIDES', 50, "Create {0} missing override
(s)"); | 75 'CREATE_MISSING_OVERRIDES', |
| 76 50, |
| 77 "Create {0} missing override(s)"); |
| 74 static const CREATE_NO_SUCH_METHOD = | 78 static const CREATE_NO_SUCH_METHOD = |
| 75 const FixKind('CREATE_NO_SUCH_METHOD', 49, "Create 'noSuchMethod' method")
; | 79 const FixKind('CREATE_NO_SUCH_METHOD', 49, "Create 'noSuchMethod' method")
; |
| 76 static const CREATE_PART = | 80 static const IMPORT_LIBRARY_PREFIX = const FixKind( |
| 77 const FixKind('CREATE_PART', 50, "Create part '{0}'"); | 81 'IMPORT_LIBRARY_PREFIX', |
| 78 static const IMPORT_LIBRARY_PREFIX = | 82 51, |
| 79 const FixKind( | 83 "Use imported library '{0}' with prefix '{1}'"); |
| 80 'IMPORT_LIBRARY_PREFIX', | |
| 81 51, | |
| 82 "Use imported library '{0}' with prefix '{1}'"); | |
| 83 static const IMPORT_LIBRARY_PROJECT = | 84 static const IMPORT_LIBRARY_PROJECT = |
| 84 const FixKind('IMPORT_LIBRARY_PROJECT', 51, "Import library '{0}'"); | 85 const FixKind('IMPORT_LIBRARY_PROJECT', 51, "Import library '{0}'"); |
| 85 static const IMPORT_LIBRARY_SDK = | 86 static const IMPORT_LIBRARY_SDK = |
| 86 const FixKind('IMPORT_LIBRARY_SDK', 51, "Import library '{0}'"); | 87 const FixKind('IMPORT_LIBRARY_SDK', 51, "Import library '{0}'"); |
| 87 static const IMPORT_LIBRARY_SHOW = | 88 static const IMPORT_LIBRARY_SHOW = |
| 88 const FixKind('IMPORT_LIBRARY_SHOW', 51, "Update library '{0}' import"); | 89 const FixKind('IMPORT_LIBRARY_SHOW', 51, "Update library '{0}' import"); |
| 89 static const INSERT_SEMICOLON = | 90 static const INSERT_SEMICOLON = |
| 90 const FixKind('INSERT_SEMICOLON', 50, "Insert ';'"); | 91 const FixKind('INSERT_SEMICOLON', 50, "Insert ';'"); |
| 91 static const MAKE_CLASS_ABSTRACT = | 92 static const MAKE_CLASS_ABSTRACT = |
| 92 const FixKind('MAKE_CLASS_ABSTRACT', 50, "Make class '{0}' abstract"); | 93 const FixKind('MAKE_CLASS_ABSTRACT', 50, "Make class '{0}' abstract"); |
| 93 static const REMOVE_PARAMETERS_IN_GETTER_DECLARATION = | 94 static const REMOVE_PARAMETERS_IN_GETTER_DECLARATION = const FixKind( |
| 94 const FixKind( | 95 'REMOVE_PARAMETERS_IN_GETTER_DECLARATION', |
| 95 'REMOVE_PARAMETERS_IN_GETTER_DECLARATION', | 96 50, |
| 96 50, | 97 "Remove parameters in getter declaration"); |
| 97 "Remove parameters in getter declaration"); | 98 static const REMOVE_PARENTHESIS_IN_GETTER_INVOCATION = const FixKind( |
| 98 static const REMOVE_PARENTHESIS_IN_GETTER_INVOCATION = | 99 'REMOVE_PARENTHESIS_IN_GETTER_INVOCATION', |
| 99 const FixKind( | 100 50, |
| 100 'REMOVE_PARENTHESIS_IN_GETTER_INVOCATION', | 101 "Remove parentheses in getter invocation"); |
| 101 50, | |
| 102 "Remove parentheses in getter invocation"); | |
| 103 static const REMOVE_UNNECASSARY_CAST = | 102 static const REMOVE_UNNECASSARY_CAST = |
| 104 const FixKind('REMOVE_UNNECASSARY_CAST', 50, "Remove unnecessary cast"); | 103 const FixKind('REMOVE_UNNECASSARY_CAST', 50, "Remove unnecessary cast"); |
| 105 static const REMOVE_UNUSED_IMPORT = | 104 static const REMOVE_UNUSED_IMPORT = |
| 106 const FixKind('REMOVE_UNUSED_IMPORT', 50, "Remove unused import"); | 105 const FixKind('REMOVE_UNUSED_IMPORT', 50, "Remove unused import"); |
| 107 static const REPLACE_BOOLEAN_WITH_BOOL = | 106 static const REPLACE_BOOLEAN_WITH_BOOL = const FixKind( |
| 108 const FixKind('REPLACE_BOOLEAN_WITH_BOOL', 50, "Replace 'boolean' with 'bo
ol'"); | 107 'REPLACE_BOOLEAN_WITH_BOOL', |
| 108 50, |
| 109 "Replace 'boolean' with 'bool'"); |
| 109 static const REPLACE_IMPORT_URI = | 110 static const REPLACE_IMPORT_URI = |
| 110 const FixKind('REPLACE_IMPORT_URI', 50, "Replace with '{0}'"); | 111 const FixKind('REPLACE_IMPORT_URI', 50, "Replace with '{0}'"); |
| 111 static const REPLACE_VAR_WITH_DYNAMIC = | 112 static const REPLACE_VAR_WITH_DYNAMIC = |
| 112 const FixKind('REPLACE_VAR_WITH_DYNAMIC', 50, "Replace 'var' with 'dynamic
'"); | 113 const FixKind('REPLACE_VAR_WITH_DYNAMIC', 50, "Replace 'var' with 'dynamic
'"); |
| 113 static const USE_CONST = const FixKind('USE_CONST', 50, "Change to constant"); | 114 static const USE_CONST = const FixKind('USE_CONST', 50, "Change to constant"); |
| 114 static const USE_EFFECTIVE_INTEGER_DIVISION = | 115 static const USE_EFFECTIVE_INTEGER_DIVISION = const FixKind( |
| 115 const FixKind( | 116 'USE_EFFECTIVE_INTEGER_DIVISION', |
| 116 'USE_EFFECTIVE_INTEGER_DIVISION', | 117 50, |
| 117 50, | 118 "Use effective integer division ~/"); |
| 118 "Use effective integer division ~/"); | |
| 119 static const USE_EQ_EQ_NULL = | 119 static const USE_EQ_EQ_NULL = |
| 120 const FixKind('USE_EQ_EQ_NULL', 50, "Use == null instead of 'is Null'"); | 120 const FixKind('USE_EQ_EQ_NULL', 50, "Use == null instead of 'is Null'"); |
| 121 static const USE_NOT_EQ_NULL = | 121 static const USE_NOT_EQ_NULL = |
| 122 const FixKind('USE_NOT_EQ_NULL', 50, "Use != null instead of 'is! Null'"); | 122 const FixKind('USE_NOT_EQ_NULL', 50, "Use != null instead of 'is! Null'"); |
| 123 | 123 |
| 124 final name; | 124 final name; |
| 125 final int relevance; | 125 final int relevance; |
| 126 final String message; | 126 final String message; |
| 127 | 127 |
| 128 const FixKind(this.name, this.relevance, this.message); | 128 const FixKind(this.name, this.relevance, this.message); |
| 129 | 129 |
| 130 @override | 130 @override |
| 131 String toString() => name; | 131 String toString() => name; |
| 132 } | 132 } |
| OLD | NEW |