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/analysis_services/lib/correction/change.dart

Issue 447613002: Make Change implementation consistent with the server spec. (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
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library services.correction.change; 8 library services.correction.change;
9 9
10 import 'package:analysis_services/constants.dart'; 10 import 'package:analysis_services/constants.dart';
11 import 'package:analysis_services/json.dart'; 11 import 'package:analysis_services/json.dart';
12 12
13 13
14 _fromJsonList(List target, List<Map<String, Object>> jsonList,
15 decoder(Map<String, Object> json)) {
16 target.addAll(jsonList.map(decoder));
17 }
18
19
20 /** 14 /**
21 * A description of a single change to one or more files.  15 * A description of a single change to one or more files. 
22 */ 16 */
23 class Change implements HasToJson { 17 class Change implements HasToJson {
24 /** 18 /**
25 * A textual description of the change to be applied.  19 * A textual description of the change to be applied. 
26 */ 20 */
27 final String message; 21 final String message;
28 22
29 /** 23 /**
30 * A list of the [FileEdit]s used to effect the change.  24 * A list of the [FileEdit]s used to effect the change. 
31 */ 25 */
32 final List<FileEdit> edits = <FileEdit>[]; 26 final List<FileEdit> edits = <FileEdit>[];
33 27
34 /** 28 /**
35 * A list of the [LinkedPositionGroup]s in the change.  29 * A list of the [LinkedEditGroup]s in the change. 
36 */ 30 */
37 final List<LinkedPositionGroup> linkedPositionGroups = <LinkedPositionGroup>[ 31 final List<LinkedEditGroup> linkedEditGroups = <LinkedEditGroup>[];
38 ];
39 32
40 /** 33 /**
41 * An optional position to move selection to after applying this change. 34 * An optional position to move selection to after applying this change.
42 */ 35 */
43 Position endPosition; 36 Position endPosition;
44 37
45 Change(this.message); 38 Change(this.message);
46 39
47 /** 40 /**
48 * Adds the given [FileEdit]. 41 * Adds the given [FileEdit].
49 */ 42 */
50 void add(FileEdit edit) { 43 void add(FileEdit edit) {
51 edits.add(edit); 44 edits.add(edit);
52 } 45 }
53 46
54 /** 47 /**
55 * Adds the given [LinkedPositionGroup]. 48 * Adds the given [LinkedEditGroup].
56 */ 49 */
57 void addLinkedPositionGroup(LinkedPositionGroup linkedPositionGroup) { 50 void addLinkedEditGroup(LinkedEditGroup linkedEditGroup) {
58 linkedPositionGroups.add(linkedPositionGroup); 51 linkedEditGroups.add(linkedEditGroup);
59 } 52 }
60 53
61 @override 54 @override
62 Map<String, Object> toJson() { 55 Map<String, Object> toJson() {
63 return { 56 return {
64 MESSAGE: message, 57 MESSAGE: message,
65 EDITS: objectToJson(edits), 58 EDITS: objectToJson(edits),
66 LINKED_POSITION_GROUPS: objectToJson(linkedPositionGroups) 59 LINKED_EDIT_GROUPS: objectToJson(linkedEditGroups)
67 }; 60 };
68 } 61 }
69 62
70 @override 63 @override
71 String toString() => 64 String toString() =>
72 'Change(message=$message, edits=$edits, ' 65 'Change(message=$message, edits=$edits, linkedEditGroups=$linkedEditGroups )';
73 'linkedPositionGroups=$linkedPositionGroups)';
74
75 static Change fromJson(Map<String, Object> json) {
76 String message = json[MESSAGE];
77 Change change = new Change(message);
78 _fromJsonList(change.edits, json[EDITS], FileEdit.fromJson);
79 _fromJsonList(
80 change.linkedPositionGroups,
81 json[LINKED_POSITION_GROUPS],
82 LinkedPositionGroup.fromJson);
83 return change;
84 }
85 } 66 }
86 67
87 68
88 /** 69 /**
89 * A description of a single change to a single file.  70 * A description of a single change to a single file. 
90 */ 71 */
91 class Edit implements HasToJson { 72 class Edit implements HasToJson {
92 /** 73 /**
93 * The offset of the region to be modified.  74 * The offset of the region to be modified. 
94 */ 75 */
(...skipping 30 matching lines...) Expand all
125 return { 106 return {
126 OFFSET: offset, 107 OFFSET: offset,
127 LENGTH: length, 108 LENGTH: length,
128 REPLACEMENT: replacement 109 REPLACEMENT: replacement
129 }; 110 };
130 } 111 }
131 112
132 @override 113 @override
133 String toString() => 114 String toString() =>
134 "Edit(offset=$offset, length=$length, replacement=:>$replacement<:)"; 115 "Edit(offset=$offset, length=$length, replacement=:>$replacement<:)";
135
136 static Edit fromJson(Map<String, Object> json) {
137 int offset = json[OFFSET];
138 int length = json[LENGTH];
139 String replacement = json[REPLACEMENT];
140 return new Edit(offset, length, replacement);
141 }
142 } 116 }
143 117
144 118
145 /** 119 /**
146 * A description of a set of changes to a single file.  120 * A description of a set of changes to a single file. 
147 */ 121 */
148 class FileEdit implements HasToJson { 122 class FileEdit implements HasToJson {
149 /** 123 /**
150 * The file to be modified. 124 * The file to be modified.
151 */ 125 */
(...skipping 16 matching lines...) Expand all
168 @override 142 @override
169 Map<String, Object> toJson() { 143 Map<String, Object> toJson() {
170 return { 144 return {
171 FILE: file, 145 FILE: file,
172 EDITS: objectToJson(edits) 146 EDITS: objectToJson(edits)
173 }; 147 };
174 } 148 }
175 149
176 @override 150 @override
177 String toString() => "FileEdit(file=$file, edits=$edits)"; 151 String toString() => "FileEdit(file=$file, edits=$edits)";
178
179 static FileEdit fromJson(Map<String, Object> json) {
180 String file = json[FILE];
181 FileEdit fileEdit = new FileEdit(file);
182 _fromJsonList(fileEdit.edits, json[EDITS], Edit.fromJson);
183 return fileEdit;
184 }
185 } 152 }
186 153
187 154
188 /** 155 /**
189 * A group of linked [Position]s in multiple files that are simultaneously 156 * A group of linked [Position]s in multiple files that are simultaneously
190 * modified - if one gets edited, all other positions in a group are edited the 157 * modified - if one gets edited, all other positions in a group are edited the
191 * same way. All linked positions in a group have the same content. 158 * same way. All linked positions in a group have the same content.
192 */ 159 */
193 class LinkedPositionGroup implements HasToJson { 160 class LinkedEditGroup implements HasToJson {
194 final String id; 161 final String id;
162 int length;
195 final List<Position> positions = <Position>[]; 163 final List<Position> positions = <Position>[];
196 final List<String> proposals = <String>[]; 164 final List<LinkedEditSuggestion> suggestions = <LinkedEditSuggestion>[];
197 165
198 LinkedPositionGroup(this.id); 166 LinkedEditGroup(this.id);
199 167
200 void addPosition(Position position) { 168 void addPosition(Position position, int length) {
201 if (positions.isNotEmpty && position.length != positions[0].length) {
202 throw new ArgumentError(
203 'All positions should have the same length. '
204 'Was: ${positions[0].length}. New: ${position.length}');
205 }
206 positions.add(position); 169 positions.add(position);
170 this.length = length;
207 } 171 }
208 172
209 void addProposal(String proposal) { 173 void addSuggestion(LinkedEditSuggestion suggestion) {
210 proposals.add(proposal); 174 suggestions.add(suggestion);
211 } 175 }
212 176
213 @override 177 @override
214 Map<String, Object> toJson() { 178 Map<String, Object> toJson() {
215 return { 179 return {
216 ID: id, 180 ID: id,
217 POSITIONS: objectToJson(positions) 181 LENGTH: length,
182 POSITIONS: objectToJson(positions),
183 SUGGESTIONS: objectToJson(suggestions)
218 }; 184 };
219 } 185 }
220 186
221 @override 187 @override
222 String toString() => 'LinkedPositionGroup(id=$id, positions=$positions)'; 188 String toString() =>
223 189 'LinkedEditGroup(id=$id, length=$length, '
224 static LinkedPositionGroup fromJson(Map<String, Object> json) { 190 'positions=$positions, suggestions=$suggestions)';
225 String id = json[ID];
226 LinkedPositionGroup group = new LinkedPositionGroup(id);
227 _fromJsonList(group.positions, json[POSITIONS], Position.fromJson);
228 return group;
229 }
230 } 191 }
231 192
232 193
194 /**
195 * A suggestion of a value that could be used to replace all of the linked edit
196 * regions in a [LinkedEditGroup].
197 */
198 class LinkedEditSuggestion implements HasToJson {
199 final LinkedEditSuggestionKind kind;
200 final String value;
201
202 LinkedEditSuggestion(this.kind, this.value);
203
204 bool operator ==(other) {
205 if (other is LinkedEditSuggestion) {
206 return other.kind == kind && other.value == value;
207 }
208 return false;
209 }
210
211 @override
212 Map<String, Object> toJson() {
213 return {
214 KIND: kind.name,
215 VALUE: value
216 };
217 }
218
219 @override
220 String toString() => '(kind=$kind, value=$value)';
221 }
222
223
224 /**
225 * An enumeration of the kind of values that can be suggested for a linked edit.
226 */
227 class LinkedEditSuggestionKind {
228 static const METHOD = const LinkedEditSuggestionKind('METHOD');
229 static const PARAMETER = const LinkedEditSuggestionKind('PARAMETER');
230 static const TYPE = const LinkedEditSuggestionKind('TYPE');
231 static const VARIABLE = const LinkedEditSuggestionKind('VARIABLE');
232 final String name;
233
234 const LinkedEditSuggestionKind(this.name);
235
236 @override
237 String toString() => name;
238 }
239
240
233 /** 241 /**
234 * A position in a file. 242 * A position in a file.
235 */ 243 */
236 class Position implements HasToJson { 244 class Position implements HasToJson {
237 final String file; 245 final String file;
238 final int offset; 246 final int offset;
239 final int length;
240 247
241 Position(this.file, this.offset, this.length); 248 Position(this.file, this.offset);
242 249
243 int get hashCode { 250 int get hashCode {
244 int hash = file.hashCode; 251 int hash = file.hashCode;
245 hash = hash * 31 + offset; 252 hash = hash * 31 + offset;
246 hash = hash * 31 + length;
247 return hash; 253 return hash;
248 } 254 }
249 255
250 bool operator ==(other) { 256 bool operator ==(other) {
251 if (other is Position) { 257 if (other is Position) {
252 return other.file == file && 258 return other.file == file && other.offset == offset;
253 other.offset == offset &&
254 other.length == length;
255 } 259 }
256 return false; 260 return false;
257 } 261 }
258 262
259 @override 263 @override
260 Map<String, Object> toJson() { 264 Map<String, Object> toJson() {
261 return { 265 return {
262 FILE: file, 266 FILE: file,
263 OFFSET: offset, 267 OFFSET: offset
264 LENGTH: length
265 }; 268 };
266 } 269 }
267 270
268 @override 271 @override
269 String toString() => 'Position(file=$file, offset=$offset, length=$length)'; 272 String toString() => 'Position(file=$file, offset=$offset)';
270
271 static Position fromJson(Map<String, Object> json) {
272 String file = json[FILE];
273 int offset = json[OFFSET];
274 int length = json[LENGTH];
275 return new Position(file, offset, length);
276 }
277 } 273 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/lib/constants.dart ('k') | pkg/analysis_services/lib/src/correction/assist.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698