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

Side by Side Diff: pkg/analysis_server/lib/plugin/edit/fix/fix_core.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
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/correction/fix.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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'; 5 import 'dart:async';
6 6
7 import 'package:analyzer/error/error.dart'; 7 import 'package:analyzer/error/error.dart';
8 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'; 9 import 'package:analyzer/src/dart/analysis/driver.dart';
10 import 'package:analyzer_plugin/protocol/protocol_common.dart' 10 import 'package:analyzer_plugin/protocol/protocol_common.dart'
11 show SourceChange; 11 show SourceChange;
12 import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
12 13
13 /** 14 /**
14 * A description of a single proposed fix for some problem. 15 * A description of a single proposed fix for some problem.
15 * 16 *
16 * Clients may not extend, implement or mix-in this class. 17 * Clients may not extend, implement or mix-in this class.
17 */ 18 */
18 class Fix { 19 class Fix {
19 /** 20 /**
20 * An empty list of fixes. 21 * An empty list of fixes.
21 */ 22 */
22 static const List<Fix> EMPTY_LIST = const <Fix>[]; 23 static const List<Fix> EMPTY_LIST = const <Fix>[];
23 24
24 /** 25 /**
25 * A comparator that can be used to sort fixes by their relevance. The most 26 * A comparator that can be used to sort fixes by their relevance. The most
26 * relevant fixes will be sorted before fixes with a lower relevance. 27 * relevant fixes will be sorted before fixes with a lower relevance.
27 */ 28 */
28 static final Comparator<Fix> SORT_BY_RELEVANCE = 29 static final Comparator<Fix> SORT_BY_RELEVANCE =
29 (Fix firstFix, Fix secondFix) => 30 (Fix firstFix, Fix secondFix) =>
30 firstFix.kind.relevance - secondFix.kind.relevance; 31 firstFix.kind.priority - secondFix.kind.priority;
31 32
32 /** 33 /**
33 * A description of the fix being proposed. 34 * A description of the fix being proposed.
34 */ 35 */
35 final FixKind kind; 36 final FixKind kind;
36 37
37 /** 38 /**
38 * The change to be made in order to apply the fix. 39 * The change to be made in order to apply the fix.
39 */ 40 */
40 final SourceChange change; 41 final SourceChange change;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 * [computeFixes]. 79 * [computeFixes].
79 * 80 *
80 * Clients may implement this class when implementing plugins. 81 * Clients may implement this class when implementing plugins.
81 */ 82 */
82 abstract class FixContributor { 83 abstract class FixContributor {
83 /** 84 /**
84 * Return a list of fixes for the given [context]. 85 * Return a list of fixes for the given [context].
85 */ 86 */
86 Future<List<Fix>> computeFixes(FixContext context); 87 Future<List<Fix>> computeFixes(FixContext context);
87 } 88 }
88
89 /**
90 * A description of a class of fixes. Instances are intended to hold the
91 * information that is common across a number of fixes and to be shared by those
92 * fixes. For example, if an unnecessary cast is found then one of the suggested
93 * fixes will be to remove the cast. If there are multiple unnecessary casts in
94 * a single file, then there will be multiple fixes, one per occurrence, but
95 * they will all share the same kind.
96 *
97 * Clients may not extend, implement or mix-in this class.
98 */
99 class FixKind {
100 /**
101 * The name of this kind of fix, used for debugging.
102 */
103 final String name;
104
105 /**
106 * The relevance of this kind of fix for the kind of error being addressed.
107 */
108 final int relevance;
109
110 /**
111 * A human-readable description of the changes that will be applied by this
112 * kind of fix.
113 */
114 final String message;
115
116 /**
117 * Initialize a newly created kind of fix to have the given [name],
118 * [relevance] and [message].
119 */
120 const FixKind(this.name, this.relevance, this.message);
121
122 @override
123 String toString() => name;
124 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/correction/fix.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698