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

Side by Side Diff: pkg/analysis_server/lib/edit/fix/fix_core.dart

Issue 1392253002: Restructure the public API for server (Closed) Base URL: https://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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analysis_server.edit.fix.fix_core;
6
7 import 'package:analysis_server/src/protocol.dart' show SourceChange;
8 import 'package:analyzer/file_system/file_system.dart';
9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/error.dart';
11
12 /**
13 * A description of a single proposed fix for some problem.
14 *
15 * Clients are not expected to subtype this class.
16 */
17 class Fix {
18 /**
19 * An empty list of fixes.
20 */
21 static const List<Fix> EMPTY_LIST = const <Fix>[];
22
23 /**
24 * A comparator that can be used to sort fixes by their relevance. The most
25 * relevant fixes will be sorted before fixes with a lower relevance.
26 */
27 static final Comparator<Fix> SORT_BY_RELEVANCE = (Fix firstFix,
28 Fix secondFix) =>
29 firstFix.kind.relevance - secondFix.kind.relevance;
30
31 /**
32 * A description of the fix being proposed.
33 */
34 final FixKind kind;
35
36 /**
37 * The change to be made in order to apply the fix.
38 */
39 final SourceChange change;
40
41 /**
42 * Initialize a newly created fix to have the given [kind] and [change].
43 */
44 Fix(this.kind, this.change);
45
46 @override
47 String toString() {
48 return 'Fix(kind=$kind, change=$change)';
49 }
50 }
51
52 /**
53 * An object used to produce fixes for a specific error. Fix contributors are
54 * long-lived objects and must not retain any state between invocations of
55 * [computeFixes].
56 *
57 * Clients are expected to subtype this class when implementing plugins.
58 */
59 abstract class FixContributor {
60 /**
61 * Return a list of fixes for the given [error]. The error was reported
62 * after it's source was analyzed in the given [context].
63 */
64 List<Fix> computeFixes(ResourceProvider resourceProvider,
65 AnalysisContext context, AnalysisError error);
66 }
67
68 /**
69 * A description of a class of fixes. Instances are intended to hold the
70 * information that is common across a number of fixes and to be shared by those
71 * fixes. For example, if an unnecessary cast is found then one of the suggested
72 * fixes will be to remove the cast. If there are multiple unnecessary casts in
73 * a single file, then there will be multiple fixes, one per occurance, but they
74 * will all share the same kind.
75 *
76 * Clients are not expected to subtype this class.
77 */
78 class FixKind {
79 /**
80 * The name of this kind of fix, used for debugging.
81 */
82 final String name;
83
84 /**
85 * The relevance of this kind of fix for the kind of error being addressed.
86 */
87 final int relevance;
88
89 /**
90 * A human-readable description of the changes that will be applied by this
91 * kind of fix.
92 */
93 final String message;
94
95 /**
96 * Initialize a newly created kind of fix to have the given [name],
97 * [relevance] and [message].
98 */
99 const FixKind(this.name, this.relevance, this.message);
100
101 @override
102 String toString() => name;
103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698