| 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/correction/fix_internal.dart'; |
| 9 import 'package:analysis_server/src/services/search/search_engine.dart'; | 9 import 'package:analysis_server/src/services/search/search_engine.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 | 12 |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * Computes [Fix]s for the given [AnalysisError]. | 15 * Computes [Fix]s for the given [AnalysisError]. |
| 16 * | 16 * |
| 17 * Returns the computed [Fix]s, not `null`. | 17 * Returns the computed [Fix]s, not `null`. |
| 18 */ | 18 */ |
| 19 List<Fix> computeFixes(SearchEngine searchEngine, CompilationUnit unit, | 19 List<Fix> computeFixes(SearchEngine searchEngine, CompilationUnit unit, |
| 20 AnalysisError error) { | 20 AnalysisError error) { |
| 21 var processor = new FixProcessor(searchEngine, unit, error); | 21 var processor = new FixProcessor(searchEngine, unit, error); |
| 22 return processor.compute(); | 22 List<Fix> fixes = processor.compute(); |
| 23 fixes.sort((Fix a, Fix b) { |
| 24 return a.kind.relevance - b.kind.relevance; |
| 25 }); |
| 26 return fixes; |
| 23 } | 27 } |
| 24 | 28 |
| 25 | 29 |
| 26 /** | 30 /** |
| 27 * A description of a single proposed fix for some problem. | 31 * A description of a single proposed fix for some problem. |
| 28 */ | 32 */ |
| 29 class Fix { | 33 class Fix { |
| 30 final FixKind kind; | 34 final FixKind kind; |
| 31 final SourceChange change; | 35 final SourceChange change; |
| 32 | 36 |
| 33 Fix(this.kind, this.change); | 37 Fix(this.kind, this.change); |
| 34 | 38 |
| 35 @override | 39 @override |
| 36 String toString() { | 40 String toString() { |
| 37 return '[kind=$kind, change=$change]'; | 41 return '[kind=$kind, change=$change]'; |
| 38 } | 42 } |
| 39 } | 43 } |
| 40 | 44 |
| 41 | 45 |
| 42 /** | 46 /** |
| 43 * An enumeration of possible quick fix kinds. | 47 * An enumeration of possible quick fix kinds. |
| 44 */ | 48 */ |
| 45 class FixKind { | 49 class FixKind { |
| 46 static const ADD_PACKAGE_DEPENDENCY = | 50 static const ADD_PACKAGE_DEPENDENCY = |
| 47 const FixKind('ADD_PACKAGE_DEPENDENCY', 50, "Add dependency on package '{0
}'"); | 51 const FixKind('ADD_PACKAGE_DEPENDENCY', 50, "Add dependency on package '{0
}'"); |
| 48 static const ADD_SUPER_CONSTRUCTOR_INVOCATION = const FixKind( | 52 static const ADD_SUPER_CONSTRUCTOR_INVOCATION = const FixKind( |
| 49 'ADD_SUPER_CONSTRUCTOR_INVOCATION', | 53 'ADD_SUPER_CONSTRUCTOR_INVOCATION', |
| 50 50, | 54 50, |
| 51 "Add super constructor {0} invocation"); | 55 "Add super constructor {0} invocation"); |
| 52 static const CHANGE_TO = const FixKind('CHANGE_TO', 51, "Change to '{0}'"); | 56 static const CHANGE_TO = const FixKind('CHANGE_TO', 49, "Change to '{0}'"); |
| 53 static const CHANGE_TO_STATIC_ACCESS = const FixKind( | 57 static const CHANGE_TO_STATIC_ACCESS = const FixKind( |
| 54 'CHANGE_TO_STATIC_ACCESS', | 58 'CHANGE_TO_STATIC_ACCESS', |
| 55 50, | 59 50, |
| 56 "Change access to static using '{0}'"); | 60 "Change access to static using '{0}'"); |
| 57 static const CREATE_CLASS = | 61 static const CREATE_CLASS = |
| 58 const FixKind('CREATE_CLASS', 50, "Create class '{0}'"); | 62 const FixKind('CREATE_CLASS', 50, "Create class '{0}'"); |
| 59 static const CREATE_CONSTRUCTOR = | 63 static const CREATE_CONSTRUCTOR = |
| 60 const FixKind('CREATE_CONSTRUCTOR', 50, "Create constructor '{0}'"); | 64 const FixKind('CREATE_CONSTRUCTOR', 50, "Create constructor '{0}'"); |
| 61 static const CREATE_CONSTRUCTOR_SUPER = const FixKind( | 65 static const CREATE_CONSTRUCTOR_SUPER = const FixKind( |
| 62 'CREATE_CONSTRUCTOR_SUPER', | 66 'CREATE_CONSTRUCTOR_SUPER', |
| 63 50, | 67 50, |
| 64 "Create constructor to call {0}"); | 68 "Create constructor to call {0}"); |
| 65 static const CREATE_FIELD = | 69 static const CREATE_FIELD = |
| 66 const FixKind('CREATE_FIELD', 50, "Create field '{0}'"); | 70 const FixKind('CREATE_FIELD', 50, "Create field '{0}'"); |
| 67 static const CREATE_FILE = | 71 static const CREATE_FILE = |
| 68 const FixKind('CREATE_FILE', 50, "Create file '{0}'"); | 72 const FixKind('CREATE_FILE', 50, "Create file '{0}'"); |
| 69 static const CREATE_FUNCTION = | 73 static const CREATE_FUNCTION = |
| 70 const FixKind('CREATE_FUNCTION', 49, "Create function '{0}'"); | 74 const FixKind('CREATE_FUNCTION', 51, "Create function '{0}'"); |
| 71 static const CREATE_LOCAL_VARIABLE = | 75 static const CREATE_LOCAL_VARIABLE = |
| 72 const FixKind('CREATE_LOCAL_VARIABLE', 50, "Create local variable '{0}'"); | 76 const FixKind('CREATE_LOCAL_VARIABLE', 50, "Create local variable '{0}'"); |
| 73 static const CREATE_METHOD = | 77 static const CREATE_METHOD = |
| 74 const FixKind('CREATE_METHOD', 50, "Create method '{0}'"); | 78 const FixKind('CREATE_METHOD', 50, "Create method '{0}'"); |
| 75 static const CREATE_MISSING_OVERRIDES = const FixKind( | 79 static const CREATE_MISSING_OVERRIDES = const FixKind( |
| 76 'CREATE_MISSING_OVERRIDES', | 80 'CREATE_MISSING_OVERRIDES', |
| 77 50, | 81 50, |
| 78 "Create {0} missing override(s)"); | 82 "Create {0} missing override(s)"); |
| 79 static const CREATE_NO_SUCH_METHOD = | 83 static const CREATE_NO_SUCH_METHOD = |
| 80 const FixKind('CREATE_NO_SUCH_METHOD', 49, "Create 'noSuchMethod' method")
; | 84 const FixKind('CREATE_NO_SUCH_METHOD', 51, "Create 'noSuchMethod' method")
; |
| 81 static const IMPORT_LIBRARY_PREFIX = const FixKind( | 85 static const IMPORT_LIBRARY_PREFIX = const FixKind( |
| 82 'IMPORT_LIBRARY_PREFIX', | 86 'IMPORT_LIBRARY_PREFIX', |
| 83 51, | 87 51, |
| 84 "Use imported library '{0}' with prefix '{1}'"); | 88 "Use imported library '{0}' with prefix '{1}'"); |
| 85 static const IMPORT_LIBRARY_PROJECT = | 89 static const IMPORT_LIBRARY_PROJECT = |
| 86 const FixKind('IMPORT_LIBRARY_PROJECT', 51, "Import library '{0}'"); | 90 const FixKind('IMPORT_LIBRARY_PROJECT', 49, "Import library '{0}'"); |
| 87 static const IMPORT_LIBRARY_SDK = | 91 static const IMPORT_LIBRARY_SDK = |
| 88 const FixKind('IMPORT_LIBRARY_SDK', 51, "Import library '{0}'"); | 92 const FixKind('IMPORT_LIBRARY_SDK', 49, "Import library '{0}'"); |
| 89 static const IMPORT_LIBRARY_SHOW = | 93 static const IMPORT_LIBRARY_SHOW = |
| 90 const FixKind('IMPORT_LIBRARY_SHOW', 51, "Update library '{0}' import"); | 94 const FixKind('IMPORT_LIBRARY_SHOW', 49, "Update library '{0}' import"); |
| 91 static const INSERT_SEMICOLON = | 95 static const INSERT_SEMICOLON = |
| 92 const FixKind('INSERT_SEMICOLON', 50, "Insert ';'"); | 96 const FixKind('INSERT_SEMICOLON', 50, "Insert ';'"); |
| 93 static const MAKE_CLASS_ABSTRACT = | 97 static const MAKE_CLASS_ABSTRACT = |
| 94 const FixKind('MAKE_CLASS_ABSTRACT', 50, "Make class '{0}' abstract"); | 98 const FixKind('MAKE_CLASS_ABSTRACT', 50, "Make class '{0}' abstract"); |
| 95 static const REMOVE_PARAMETERS_IN_GETTER_DECLARATION = const FixKind( | 99 static const REMOVE_PARAMETERS_IN_GETTER_DECLARATION = const FixKind( |
| 96 'REMOVE_PARAMETERS_IN_GETTER_DECLARATION', | 100 'REMOVE_PARAMETERS_IN_GETTER_DECLARATION', |
| 97 50, | 101 50, |
| 98 "Remove parameters in getter declaration"); | 102 "Remove parameters in getter declaration"); |
| 99 static const REMOVE_PARENTHESIS_IN_GETTER_INVOCATION = const FixKind( | 103 static const REMOVE_PARENTHESIS_IN_GETTER_INVOCATION = const FixKind( |
| 100 'REMOVE_PARENTHESIS_IN_GETTER_INVOCATION', | 104 'REMOVE_PARENTHESIS_IN_GETTER_INVOCATION', |
| (...skipping 23 matching lines...) Expand all Loading... |
| 124 | 128 |
| 125 final name; | 129 final name; |
| 126 final int relevance; | 130 final int relevance; |
| 127 final String message; | 131 final String message; |
| 128 | 132 |
| 129 const FixKind(this.name, this.relevance, this.message); | 133 const FixKind(this.name, this.relevance, this.message); |
| 130 | 134 |
| 131 @override | 135 @override |
| 132 String toString() => name; | 136 String toString() => name; |
| 133 } | 137 } |
| OLD | NEW |