Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: pkg/analysis_server/lib/src/services/correction/fix.dart

Issue 1385523002: AnalysisError `hasFix` attr (Implements #23874). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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) {
45 switch (errorCode) {
46 case StaticWarningCode.UNDEFINED_CLASS_BOOLEAN:
47 case StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER:
48 case StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS:
49 case StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR:
50 case StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE:
51 case StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO:
52 case StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE:
53 case StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR:
54 case StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS :
55 case StaticWarningCode.CAST_TO_NON_TYPE:
56 case StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME:
57 case StaticWarningCode.UNDEFINED_CLASS:
58 case StaticWarningCode.FINAL_NOT_INITIALIZED:
59 case StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1:
60 case StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2:
61 case StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS:
62 case StaticWarningCode.UNDEFINED_IDENTIFIER:
63 return true;
64 }
65
66 switch (errorCode) {
67 case CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE:
68 case CompileTimeErrorCode.INVALID_ANNOTATION:
69 case CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT:
70 case CompileTimeErrorCode.PART_OF_NON_PART:
71 case CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT:
72 case CompileTimeErrorCode.URI_DOES_NOT_EXIST:
73 return true;
74 }
75
76 switch (errorCode) {
77 case HintCode.DEAD_CODE:
78 case HintCode.DIVISION_OPTIMIZATION:
79 case HintCode.TYPE_CHECK_IS_NOT_NULL:
80 case HintCode.TYPE_CHECK_IS_NULL:
81 case HintCode.UNDEFINED_GETTER:
82 case HintCode.UNDEFINED_SETTER:
83 case HintCode.UNNECESSARY_CAST:
84 case HintCode.UNUSED_CATCH_CLAUSE:
85 case HintCode.UNUSED_CATCH_STACK:
86 case HintCode.UNUSED_IMPORT:
87 case HintCode.UNDEFINED_METHOD:
88 return true;
89 }
90
91 switch (errorCode) {
92 case ParserErrorCode.EXPECTED_TOKEN:
93 case ParserErrorCode.GETTER_WITH_PARAMETERS:
94 case ParserErrorCode.VAR_AS_TYPE_NAME:
95 return true;
96 }
97
98 switch (errorCode) {
99 case StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE:
100 case StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER:
101 case StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION:
102 case StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT:
103 case StaticTypeWarningCode.UNDEFINED_FUNCTION:
104 case StaticTypeWarningCode.UNDEFINED_GETTER:
105 case StaticTypeWarningCode.UNDEFINED_METHOD:
106 case StaticTypeWarningCode.UNDEFINED_SETTER:
107 return true;
108 }
109 return false;
110 }
111
112 /**
41 * An enumeration of possible quick fix kinds. 113 * An enumeration of possible quick fix kinds.
42 */ 114 */
43 class DartFixKind { 115 class DartFixKind {
44 static const ADD_ASYNC = 116 static const ADD_ASYNC =
45 const FixKind('ADD_ASYNC', 50, "Add 'async' modifier"); 117 const FixKind('ADD_ASYNC', 50, "Add 'async' modifier");
46 static const ADD_FIELD_FORMAL_PARAMETERS = const FixKind( 118 static const ADD_FIELD_FORMAL_PARAMETERS = const FixKind(
47 'ADD_FIELD_FORMAL_PARAMETERS', 30, "Add final field formal parameters"); 119 'ADD_FIELD_FORMAL_PARAMETERS', 30, "Add final field formal parameters");
48 static const ADD_MISSING_PARAMETER_POSITIONAL = const FixKind( 120 static const ADD_MISSING_PARAMETER_POSITIONAL = const FixKind(
49 'ADD_MISSING_PARAMETER_POSITIONAL', 121 'ADD_MISSING_PARAMETER_POSITIONAL',
50 31, 122 31,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 static const USE_CONST = const FixKind('USE_CONST', 50, "Change to constant"); 203 static const USE_CONST = const FixKind('USE_CONST', 50, "Change to constant");
132 static const USE_EFFECTIVE_INTEGER_DIVISION = const FixKind( 204 static const USE_EFFECTIVE_INTEGER_DIVISION = const FixKind(
133 'USE_EFFECTIVE_INTEGER_DIVISION', 205 'USE_EFFECTIVE_INTEGER_DIVISION',
134 50, 206 50,
135 "Use effective integer division ~/"); 207 "Use effective integer division ~/");
136 static const USE_EQ_EQ_NULL = 208 static const USE_EQ_EQ_NULL =
137 const FixKind('USE_EQ_EQ_NULL', 50, "Use == null instead of 'is Null'"); 209 const FixKind('USE_EQ_EQ_NULL', 50, "Use == null instead of 'is Null'");
138 static const USE_NOT_EQ_NULL = 210 static const USE_NOT_EQ_NULL =
139 const FixKind('USE_NOT_EQ_NULL', 50, "Use != null instead of 'is! Null'"); 211 const FixKind('USE_NOT_EQ_NULL', 50, "Use != null instead of 'is! Null'");
140 } 212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698