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

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

Issue 497393002: Make more use of generated code in analysis server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library services.correction.change;
6
7 import 'package:analysis_server/src/constants.dart';
8 import 'package:analysis_server/src/protocol2.dart';
9 import 'package:analysis_server/src/services/json.dart';
10
11
12 /**
13 * A description of a single change to one or more files. 
14 */
15 class Change implements HasToJson {
16 /**
17 * A textual description of the change to be applied. 
18 */
19 final String message;
20
21 /**
22 * A list of the [FileEdit]s used to effect the change. 
23 */
24 final List<SourceFileEdit> fileEdits = <SourceFileEdit>[];
25
26 /**
27 * A list of the [LinkedEditGroup]s in the change. 
28 */
29 final List<LinkedEditGroup> linkedEditGroups = <LinkedEditGroup>[];
30
31 /**
32 * The position that should be selected after the edits have been applied.
33 */
34 Position selection;
35
36 Change(this.message);
37
38 /**
39 * Adds [edit] to the [FileEdit] for the given [file].
40 */
41 void addEdit(String file, SourceEdit edit) {
42 SourceFileEdit fileEdit = getFileEdit(file);
43 if (fileEdit == null) {
44 fileEdit = new SourceFileEdit(file);
45 addFileEdit(fileEdit);
46 }
47 fileEdit.add(edit);
48 }
49
50 /**
51 * Adds the given [FileEdit].
52 */
53 void addFileEdit(SourceFileEdit edit) {
54 fileEdits.add(edit);
55 }
56
57 /**
58 * Adds the given [LinkedEditGroup].
59 */
60 void addLinkedEditGroup(LinkedEditGroup linkedEditGroup) {
61 linkedEditGroups.add(linkedEditGroup);
62 }
63
64 /**
65 * Returns the [FileEdit] for the given [file], maybe `null`.
66 */
67 SourceFileEdit getFileEdit(String file) {
68 for (SourceFileEdit fileEdit in fileEdits) {
69 if (fileEdit.file == file) {
70 return fileEdit;
71 }
72 }
73 return null;
74 }
75
76 @override
77 Map<String, Object> toJson() {
78 Map<String, Object> json = {
79 MESSAGE: message,
80 EDITS: objectToJson(fileEdits),
81 LINKED_EDIT_GROUPS: objectToJson(linkedEditGroups)
82 };
83 if (selection != null) {
84 json[SELECTION] = selection.toJson();
85 }
86 return json;
87 }
88
89 @override
90 String toString() =>
91 'Change(message=$message, edits=$fileEdits, '
92 'linkedEditGroups=$linkedEditGroups, selection=$selection)';
93 }
94
95
96 /**
97 * A group of linked [Position]s in multiple files that are simultaneously
98 * modified - if one gets edited, all other positions in a group are edited the
99 * same way. All linked positions in a group have the same content.
100 */
101 class LinkedEditGroup implements HasToJson {
102 int length;
103 final List<Position> positions = <Position>[];
104 final List<LinkedEditSuggestion> suggestions = <LinkedEditSuggestion>[];
105
106 void addPosition(Position position, int length) {
107 positions.add(position);
108 this.length = length;
109 }
110
111 void addSuggestion(LinkedEditSuggestion suggestion) {
112 suggestions.add(suggestion);
113 }
114
115 @override
116 Map<String, Object> toJson() {
117 return {
118 LENGTH: length,
119 POSITIONS: objectToJson(positions),
120 SUGGESTIONS: objectToJson(suggestions)
121 };
122 }
123
124 @override
125 String toString() =>
126 'LinkedEditGroup(length=$length, positions=$positions, suggestions=$sugges tions)';
127 }
128
129
130 /**
131 * A suggestion of a value that could be used to replace all of the linked edit
132 * regions in a [LinkedEditGroup].
133 */
134 class LinkedEditSuggestion implements HasToJson {
135 final LinkedEditSuggestionKind kind;
136 final String value;
137
138 LinkedEditSuggestion(this.kind, this.value);
139
140 bool operator ==(other) {
141 if (other is LinkedEditSuggestion) {
142 return other.kind == kind && other.value == value;
143 }
144 return false;
145 }
146
147 @override
148 Map<String, Object> toJson() {
149 return {
150 KIND: kind.name,
151 VALUE: value
152 };
153 }
154
155 @override
156 String toString() => '(kind=$kind, value=$value)';
157 }
158
159
160 /**
161 * An enumeration of the kind of values that can be suggested for a linked edit.
162 */
163 class LinkedEditSuggestionKind {
164 static const METHOD = const LinkedEditSuggestionKind('METHOD');
165 static const PARAMETER = const LinkedEditSuggestionKind('PARAMETER');
166 static const TYPE = const LinkedEditSuggestionKind('TYPE');
167 static const VARIABLE = const LinkedEditSuggestionKind('VARIABLE');
168 final String name;
169
170 const LinkedEditSuggestionKind(this.name);
171
172 @override
173 String toString() => name;
174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698