| 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 analysis_server.src.services.correction.fix; | 5 library analysis_server.src.services.correction.fix; |
| 6 | 6 |
| 7 import 'package:analysis_server/edit/fix/fix_core.dart'; | 7 import 'package:analysis_server/edit/fix/fix_core.dart'; |
| 8 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 8 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
| 9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:analyzer/src/generated/error.dart'; | 11 import 'package:analyzer/src/generated/error.dart'; |
| 12 import 'package:analyzer/src/generated/java_engine.dart'; | 12 import 'package:analyzer/src/generated/java_engine.dart'; |
| 13 import 'package:analyzer/src/generated/parser.dart'; |
| 13 | 14 |
| 14 /** | 15 /** |
| 15 * Compute and return the fixes available for the given [error]. The error was | 16 * Compute and return the fixes available for the given [error]. The error was |
| 16 * reported after it's source was analyzed in the given [context]. The [plugin] | 17 * reported after it's source was analyzed in the given [context]. The [plugin] |
| 17 * is used to get the list of fix contributors. | 18 * is used to get the list of fix contributors. |
| 18 */ | 19 */ |
| 19 List<Fix> computeFixes(ServerPlugin plugin, ResourceProvider resourceProvider, | 20 List<Fix> computeFixes(ServerPlugin plugin, ResourceProvider resourceProvider, |
| 20 AnalysisContext context, AnalysisError error) { | 21 AnalysisContext context, AnalysisError error) { |
| 21 List<Fix> fixes = <Fix>[]; | 22 List<Fix> fixes = <Fix>[]; |
| 22 List<FixContributor> contributors = plugin.fixContributors; | 23 List<FixContributor> contributors = plugin.fixContributors; |
| 23 for (FixContributor contributor in contributors) { | 24 for (FixContributor contributor in contributors) { |
| 24 try { | 25 try { |
| 25 List<Fix> contributedFixes = | 26 List<Fix> contributedFixes = |
| 26 contributor.computeFixes(resourceProvider, context, error); | 27 contributor.computeFixes(resourceProvider, context, error); |
| 27 if (contributedFixes != null) { | 28 if (contributedFixes != null) { |
| 28 fixes.addAll(contributedFixes); | 29 fixes.addAll(contributedFixes); |
| 29 } | 30 } |
| 30 } catch (exception, stackTrace) { | 31 } catch (exception, stackTrace) { |
| 31 AnalysisEngine.instance.logger.logError( | 32 AnalysisEngine.instance.logger.logError( |
| 32 'Exception from fix contributor: ${contributor.runtimeType}', | 33 'Exception from fix contributor: ${contributor.runtimeType}', |
| 33 new CaughtException(exception, stackTrace)); | 34 new CaughtException(exception, stackTrace)); |
| 34 } | 35 } |
| 35 } | 36 } |
| 36 fixes.sort(Fix.SORT_BY_RELEVANCE); | 37 fixes.sort(Fix.SORT_BY_RELEVANCE); |
| 37 return fixes; | 38 return fixes; |
| 38 } | 39 } |
| 39 | 40 |
| 40 /** | 41 /** |
| 42 * Return true if this [errorCode] is likely to have a fix associated with it. |
| 43 */ |
| 44 bool hasFix(ErrorCode errorCode) => errorCode == |
| 45 StaticWarningCode.UNDEFINED_CLASS_BOOLEAN || |
| 46 errorCode == StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER || |
| 47 errorCode == StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS || |
| 48 errorCode == StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR || |
| 49 errorCode == |
| 50 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE || |
| 51 errorCode == |
| 52 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO || |
| 53 errorCode == |
| 54 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE || |
| 55 errorCode == |
| 56 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR || |
| 57 errorCode == |
| 58 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS
|| |
| 59 errorCode == StaticWarningCode.CAST_TO_NON_TYPE || |
| 60 errorCode == StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME || |
| 61 errorCode == StaticWarningCode.UNDEFINED_CLASS || |
| 62 errorCode == StaticWarningCode.FINAL_NOT_INITIALIZED || |
| 63 errorCode == StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1 || |
| 64 errorCode == StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2 || |
| 65 errorCode == StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS || |
| 66 errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER || |
| 67 errorCode == |
| 68 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE || |
| 69 errorCode == CompileTimeErrorCode.INVALID_ANNOTATION || |
| 70 errorCode == CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT || |
| 71 errorCode == CompileTimeErrorCode.PART_OF_NON_PART || |
| 72 errorCode == |
| 73 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT || |
| 74 errorCode == CompileTimeErrorCode.URI_DOES_NOT_EXIST || |
| 75 errorCode == HintCode.DEAD_CODE || |
| 76 errorCode == HintCode.DIVISION_OPTIMIZATION || |
| 77 errorCode == HintCode.TYPE_CHECK_IS_NOT_NULL || |
| 78 errorCode == HintCode.TYPE_CHECK_IS_NULL || |
| 79 errorCode == HintCode.UNDEFINED_GETTER || |
| 80 errorCode == HintCode.UNDEFINED_SETTER || |
| 81 errorCode == HintCode.UNNECESSARY_CAST || |
| 82 errorCode == HintCode.UNUSED_CATCH_CLAUSE || |
| 83 errorCode == HintCode.UNUSED_CATCH_STACK || |
| 84 errorCode == HintCode.UNUSED_IMPORT || |
| 85 errorCode == HintCode.UNDEFINED_METHOD || |
| 86 errorCode == ParserErrorCode.EXPECTED_TOKEN || |
| 87 errorCode == ParserErrorCode.GETTER_WITH_PARAMETERS || |
| 88 errorCode == ParserErrorCode.VAR_AS_TYPE_NAME || |
| 89 errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE || |
| 90 errorCode == StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER || |
| 91 errorCode == StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION || |
| 92 errorCode == StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT || |
| 93 errorCode == StaticTypeWarningCode.UNDEFINED_FUNCTION || |
| 94 errorCode == StaticTypeWarningCode.UNDEFINED_GETTER || |
| 95 errorCode == StaticTypeWarningCode.UNDEFINED_METHOD || |
| 96 errorCode == StaticTypeWarningCode.UNDEFINED_SETTER; |
| 97 |
| 98 /** |
| 41 * An enumeration of possible quick fix kinds. | 99 * An enumeration of possible quick fix kinds. |
| 42 */ | 100 */ |
| 43 class DartFixKind { | 101 class DartFixKind { |
| 44 static const ADD_ASYNC = | 102 static const ADD_ASYNC = |
| 45 const FixKind('ADD_ASYNC', 50, "Add 'async' modifier"); | 103 const FixKind('ADD_ASYNC', 50, "Add 'async' modifier"); |
| 46 static const ADD_FIELD_FORMAL_PARAMETERS = const FixKind( | 104 static const ADD_FIELD_FORMAL_PARAMETERS = const FixKind( |
| 47 'ADD_FIELD_FORMAL_PARAMETERS', 30, "Add final field formal parameters"); | 105 'ADD_FIELD_FORMAL_PARAMETERS', 30, "Add final field formal parameters"); |
| 48 static const ADD_MISSING_PARAMETER_POSITIONAL = const FixKind( | 106 static const ADD_MISSING_PARAMETER_POSITIONAL = const FixKind( |
| 49 'ADD_MISSING_PARAMETER_POSITIONAL', | 107 'ADD_MISSING_PARAMETER_POSITIONAL', |
| 50 31, | 108 31, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 static const USE_CONST = const FixKind('USE_CONST', 50, "Change to constant"); | 189 static const USE_CONST = const FixKind('USE_CONST', 50, "Change to constant"); |
| 132 static const USE_EFFECTIVE_INTEGER_DIVISION = const FixKind( | 190 static const USE_EFFECTIVE_INTEGER_DIVISION = const FixKind( |
| 133 'USE_EFFECTIVE_INTEGER_DIVISION', | 191 'USE_EFFECTIVE_INTEGER_DIVISION', |
| 134 50, | 192 50, |
| 135 "Use effective integer division ~/"); | 193 "Use effective integer division ~/"); |
| 136 static const USE_EQ_EQ_NULL = | 194 static const USE_EQ_EQ_NULL = |
| 137 const FixKind('USE_EQ_EQ_NULL', 50, "Use == null instead of 'is Null'"); | 195 const FixKind('USE_EQ_EQ_NULL', 50, "Use == null instead of 'is Null'"); |
| 138 static const USE_NOT_EQ_NULL = | 196 static const USE_NOT_EQ_NULL = |
| 139 const FixKind('USE_NOT_EQ_NULL', 50, "Use != null instead of 'is! Null'"); | 197 const FixKind('USE_NOT_EQ_NULL', 50, "Use != null instead of 'is! Null'"); |
| 140 } | 198 } |
| OLD | NEW |