| 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 'dart:async'; |
| 8 |
| 7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
| 8 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 10 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
| 9 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:analyzer/src/generated/error.dart'; | 13 import 'package:analyzer/src/generated/error.dart'; |
| 12 import 'package:analyzer/src/generated/java_engine.dart'; | 14 import 'package:analyzer/src/generated/java_engine.dart'; |
| 13 import 'package:analyzer/src/generated/parser.dart'; | 15 import 'package:analyzer/src/generated/parser.dart'; |
| 14 | 16 |
| 15 /** | 17 /** |
| 16 * Compute and return the fixes available for the given [error]. The error was | 18 * Compute and return the fixes available for the given [error]. The error was |
| 17 * reported after it's source was analyzed in the given [context]. The [plugin] | 19 * reported after it's source was analyzed in the given [context]. The [plugin] |
| 18 * is used to get the list of fix contributors. | 20 * is used to get the list of fix contributors. |
| 19 */ | 21 */ |
| 20 List<Fix> computeFixes(ServerPlugin plugin, ResourceProvider resourceProvider, | 22 Future<List<Fix>> computeFixes( |
| 21 AnalysisContext context, AnalysisError error) { | 23 ServerPlugin plugin, |
| 24 ResourceProvider resourceProvider, |
| 25 AnalysisContext context, |
| 26 AnalysisError error) async { |
| 22 List<Fix> fixes = <Fix>[]; | 27 List<Fix> fixes = <Fix>[]; |
| 23 List<FixContributor> contributors = plugin.fixContributors; | 28 List<FixContributor> contributors = plugin.fixContributors; |
| 29 FixContext fixContext = new FixContextImpl(resourceProvider, context, error); |
| 24 for (FixContributor contributor in contributors) { | 30 for (FixContributor contributor in contributors) { |
| 25 try { | 31 try { |
| 26 List<Fix> contributedFixes = | 32 List<Fix> contributedFixes = await contributor.computeFixes(fixContext); |
| 27 contributor.computeFixes(resourceProvider, context, error); | |
| 28 if (contributedFixes != null) { | 33 if (contributedFixes != null) { |
| 29 fixes.addAll(contributedFixes); | 34 fixes.addAll(contributedFixes); |
| 30 } | 35 } |
| 31 } catch (exception, stackTrace) { | 36 } catch (exception, stackTrace) { |
| 32 AnalysisEngine.instance.logger.logError( | 37 AnalysisEngine.instance.logger.logError( |
| 33 'Exception from fix contributor: ${contributor.runtimeType}', | 38 'Exception from fix contributor: ${contributor.runtimeType}', |
| 34 new CaughtException(exception, stackTrace)); | 39 new CaughtException(exception, stackTrace)); |
| 35 } | 40 } |
| 36 } | 41 } |
| 37 fixes.sort(Fix.SORT_BY_RELEVANCE); | 42 fixes.sort(Fix.SORT_BY_RELEVANCE); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 static const USE_CONST = const FixKind('USE_CONST', 50, "Change to constant"); | 200 static const USE_CONST = const FixKind('USE_CONST', 50, "Change to constant"); |
| 196 static const USE_EFFECTIVE_INTEGER_DIVISION = const FixKind( | 201 static const USE_EFFECTIVE_INTEGER_DIVISION = const FixKind( |
| 197 'USE_EFFECTIVE_INTEGER_DIVISION', | 202 'USE_EFFECTIVE_INTEGER_DIVISION', |
| 198 50, | 203 50, |
| 199 "Use effective integer division ~/"); | 204 "Use effective integer division ~/"); |
| 200 static const USE_EQ_EQ_NULL = | 205 static const USE_EQ_EQ_NULL = |
| 201 const FixKind('USE_EQ_EQ_NULL', 50, "Use == null instead of 'is Null'"); | 206 const FixKind('USE_EQ_EQ_NULL', 50, "Use == null instead of 'is Null'"); |
| 202 static const USE_NOT_EQ_NULL = | 207 static const USE_NOT_EQ_NULL = |
| 203 const FixKind('USE_NOT_EQ_NULL', 50, "Use != null instead of 'is! Null'"); | 208 const FixKind('USE_NOT_EQ_NULL', 50, "Use != null instead of 'is! Null'"); |
| 204 } | 209 } |
| 210 |
| 211 /** |
| 212 * The implementation of [FixContext]. |
| 213 */ |
| 214 class FixContextImpl implements FixContext { |
| 215 @override |
| 216 final ResourceProvider resourceProvider; |
| 217 |
| 218 @override |
| 219 final AnalysisContext analysisContext; |
| 220 |
| 221 @override |
| 222 final AnalysisError error; |
| 223 |
| 224 FixContextImpl(this.resourceProvider, this.analysisContext, this.error); |
| 225 |
| 226 FixContextImpl.from(FixContext other) |
| 227 : resourceProvider = other.resourceProvider, |
| 228 analysisContext = other.analysisContext, |
| 229 error = other.error; |
| 230 } |
| OLD | NEW |