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

Side by Side Diff: pkg/analyzer_plugin/lib/utilities/fixes/fix_contributor_mixin.dart

Issue 2962903002: Add support code to make fixes easier in plugins (Closed)
Patch Set: Created 3 years, 5 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
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5 import 'package:analyzer/error/error.dart';
6 import 'package:analyzer/src/generated/java_core.dart';
7 import 'package:analyzer_plugin/protocol/protocol_common.dart'
8 hide AnalysisError;
9 import 'package:analyzer_plugin/protocol/protocol_generated.dart';
10 import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dar t';
11 import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
12
13 /**
14 * A partial implementation of a [FixContributor] that iterates over the list of
15 * errors and provides a utility method to make it easier to add fixes.
16 *
17 * Clients may not extend or implement this class, but are allowed to use it as
18 * a mix-in when creating a subclass of [FixContributor].
19 */
20 abstract class FixContributorMixin implements FixContributor {
21 /**
22 * The request that specifies the fixes that are to be built.
23 */
24 DartFixesRequest request;
25
26 /**
27 * The collector to which fixes should be added.
28 */
29 FixCollector collector;
30
31 /**
32 * Add a fix for the given [error]. Use the [kind] of the fix to get the
33 * message and priority, and use the change [builder] to get the edits that
34 * comprise the fix. If the message has parameters, then use the list of
35 * [args] to populate the message.
36 */
37 void addFix(AnalysisError error, FixKind kind, ChangeBuilder builder,
38 {List<Object> args: null}) {
39 SourceChange change = builder.sourceChange;
40 if (change.edits.isEmpty) {
41 return;
42 }
43 change.message = formatList(kind.message, args);
44 collector.addFix(error,
45 new PrioritizedSourceChange(kind.priority, builder.sourceChange));
46 }
47
48 @override
49 void computeFixes(DartFixesRequest request, FixCollector collector) {
50 this.request = request;
51 this.collector = collector;
52 try {
53 for (AnalysisError error in request.errorsToFix) {
54 computeFixesForError(error);
55 }
56 } finally {
57 this.request = null;
58 this.collector = null;
59 }
60 }
61
62 /**
63 * Compute the fixes that are appropriate for the given [error] and add them
64 * to the fix [collector].
65 */
66 void computeFixesForError(AnalysisError error);
67 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/services/correction/fix_test.dart ('k') | pkg/analyzer_plugin/lib/utilities/fixes/fixes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698