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

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

Issue 2894403003: Convert quick fix support to use AnalysisDriver (Closed)
Patch Set: Created 3 years, 7 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 import 'dart:async';
6
7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; 5 import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
8 import 'package:analysis_server/src/plugin/server_plugin.dart';
9 import 'package:analysis_server/src/services/correction/fix_internal.dart'; 6 import 'package:analysis_server/src/services/correction/fix_internal.dart';
10 import 'package:analyzer/error/error.dart'; 7 import 'package:analyzer/error/error.dart';
11 import 'package:analyzer/exception/exception.dart';
12 import 'package:analyzer/file_system/file_system.dart'; 8 import 'package:analyzer/file_system/file_system.dart';
9 import 'package:analyzer/src/dart/analysis/driver.dart';
13 import 'package:analyzer/src/error/codes.dart'; 10 import 'package:analyzer/src/error/codes.dart';
14 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/parser.dart'; 11 import 'package:analyzer/src/generated/parser.dart';
16 12
17 /** 13 /**
18 * Compute and return the fixes available for the given [error]. The error was
19 * reported after it's source was analyzed in the given [context]. The [plugin]
20 * is used to get the list of fix contributors.
21 */
22 Future<List<Fix>> computeFixes(
23 ServerPlugin plugin,
24 ResourceProvider resourceProvider,
25 AnalysisContext context,
26 AnalysisError error) async {
27 List<Fix> fixes = <Fix>[];
28 List<FixContributor> contributors = plugin.fixContributors;
29 FixContext fixContext = new FixContextImpl(resourceProvider, context, error);
30 for (FixContributor contributor in contributors) {
31 try {
32 List<Fix> contributedFixes = await contributor.computeFixes(fixContext);
33 if (contributedFixes != null) {
34 fixes.addAll(contributedFixes);
35 }
36 } catch (exception, stackTrace) {
37 AnalysisEngine.instance.logger.logError(
38 'Exception from fix contributor: ${contributor.runtimeType}',
39 new CaughtException(exception, stackTrace));
40 }
41 }
42 fixes.sort(Fix.SORT_BY_RELEVANCE);
43 return fixes;
44 }
45
46 /**
47 * Return true if this [errorCode] is likely to have a fix associated with it. 14 * Return true if this [errorCode] is likely to have a fix associated with it.
48 */ 15 */
49 bool hasFix(ErrorCode errorCode) => 16 bool hasFix(ErrorCode errorCode) =>
50 errorCode == StaticWarningCode.UNDEFINED_CLASS_BOOLEAN || 17 errorCode == StaticWarningCode.UNDEFINED_CLASS_BOOLEAN ||
51 errorCode == StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER || 18 errorCode == StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER ||
52 errorCode == StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS || 19 errorCode == StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS ||
53 errorCode == StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED || 20 errorCode == StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED ||
54 errorCode == StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR || 21 errorCode == StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR ||
55 errorCode == 22 errorCode ==
56 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE || 23 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE ||
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } 226 }
260 227
261 /** 228 /**
262 * The implementation of [FixContext]. 229 * The implementation of [FixContext].
263 */ 230 */
264 class FixContextImpl implements FixContext { 231 class FixContextImpl implements FixContext {
265 @override 232 @override
266 final ResourceProvider resourceProvider; 233 final ResourceProvider resourceProvider;
267 234
268 @override 235 @override
269 final AnalysisContext analysisContext; 236 final AnalysisDriver analysisDriver;
270 237
271 @override 238 @override
272 final AnalysisError error; 239 final AnalysisError error;
273 240
274 FixContextImpl(this.resourceProvider, this.analysisContext, this.error); 241 FixContextImpl(this.resourceProvider, this.analysisDriver, this.error);
275 242
276 FixContextImpl.from(FixContext other) 243 FixContextImpl.from(FixContext other)
277 : resourceProvider = other.resourceProvider, 244 : resourceProvider = other.resourceProvider,
278 analysisContext = other.analysisContext, 245 analysisDriver = other.analysisDriver,
279 error = other.error; 246 error = other.error;
280 } 247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698