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

Side by Side Diff: pkg/analysis_server/test/src/utilities/change_builder_dart_test.dart

Issue 1842063003: Start making server strong mode clean (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Remove unintended change Created 4 years, 8 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
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 library analysis_server.test.src.utilities.change_builder_dart_test; 5 library analysis_server.test.src.utilities.change_builder_dart_test;
6 6
7 import 'package:analysis_server/plugin/protocol/protocol.dart'; 7 import 'package:analysis_server/plugin/protocol/protocol.dart';
8 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_co re.dart';
8 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_da rt.dart'; 9 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_da rt.dart';
9 import 'package:analysis_server/src/utilities/change_builder_dart.dart'; 10 import 'package:analysis_server/src/utilities/change_builder_dart.dart';
10 import 'package:analyzer/dart/ast/ast.dart'; 11 import 'package:analyzer/dart/ast/ast.dart';
12 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
12 import 'package:test_reflective_loader/test_reflective_loader.dart'; 14 import 'package:test_reflective_loader/test_reflective_loader.dart';
13 import 'package:unittest/unittest.dart'; 15 import 'package:unittest/unittest.dart';
14 16
15 import '../../abstract_context.dart'; 17 import '../../abstract_context.dart';
16 import '../../utils.dart'; 18 import '../../utils.dart';
17 19
18 main() { 20 main() {
19 initializeTestEnvironment(); 21 initializeTestEnvironment();
20 defineReflectiveTests(DartChangeBuilderImplTest); 22 defineReflectiveTests(DartChangeBuilderImplTest);
(...skipping 30 matching lines...) Expand all
51 expect(edits, hasLength(1)); 53 expect(edits, hasLength(1));
52 return edits[0]; 54 return edits[0];
53 } 55 }
54 56
55 void test_writeClassDeclaration_interfaces() { 57 void test_writeClassDeclaration_interfaces() {
56 Source source = addSource('/test.dart', 'class A {}'); 58 Source source = addSource('/test.dart', 'class A {}');
57 CompilationUnit unit = resolveLibraryUnit(source); 59 CompilationUnit unit = resolveLibraryUnit(source);
58 ClassDeclaration declaration = unit.declarations[0]; 60 ClassDeclaration declaration = unit.declarations[0];
59 61
60 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 62 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
61 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 63 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
62 builder.addInsertion(0, (DartEditBuilder builder) { 64 builder.addInsertion(0, (EditBuilder builder) {
63 builder 65 (builder as DartEditBuilder)
64 .writeClassDeclaration('C', interfaces: [declaration.element.type]); 66 .writeClassDeclaration('C', interfaces: [declaration.element.type]);
65 }); 67 });
66 }); 68 });
67 SourceEdit edit = getEdit(builder); 69 SourceEdit edit = getEdit(builder);
68 expect( 70 expect(
69 edit.replacement, equalsIgnoringWhitespace('class C implements A { }')); 71 edit.replacement, equalsIgnoringWhitespace('class C implements A { }'));
70 } 72 }
71 73
72 void test_writeClassDeclaration_isAbstract() { 74 void test_writeClassDeclaration_isAbstract() {
73 Source source = addSource('/test.dart', ''); 75 Source source = addSource('/test.dart', '');
74 resolveLibraryUnit(source); 76 resolveLibraryUnit(source);
75 77
76 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 78 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
77 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 79 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
78 builder.addInsertion(0, (DartEditBuilder builder) { 80 builder.addInsertion(0, (EditBuilder builder) {
79 builder.writeClassDeclaration('C', isAbstract: true); 81 (builder as DartEditBuilder)
82 .writeClassDeclaration('C', isAbstract: true);
80 }); 83 });
81 }); 84 });
82 SourceEdit edit = getEdit(builder); 85 SourceEdit edit = getEdit(builder);
83 expect(edit.replacement, equalsIgnoringWhitespace('abstract class C { }')); 86 expect(edit.replacement, equalsIgnoringWhitespace('abstract class C { }'));
84 } 87 }
85 88
86 void test_writeClassDeclaration_memberWriter() { 89 void test_writeClassDeclaration_memberWriter() {
87 Source source = addSource('/test.dart', ''); 90 Source source = addSource('/test.dart', '');
88 resolveLibraryUnit(source); 91 resolveLibraryUnit(source);
89 92
90 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 93 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
91 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 94 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
92 builder.addInsertion(0, (DartEditBuilder builder) { 95 builder.addInsertion(0, (EditBuilder builder) {
93 builder.writeClassDeclaration('C', memberWriter: () { 96 (builder as DartEditBuilder).writeClassDeclaration('C',
97 memberWriter: () {
94 builder.write('/**/'); 98 builder.write('/**/');
95 }); 99 });
96 }); 100 });
97 }); 101 });
98 SourceEdit edit = getEdit(builder); 102 SourceEdit edit = getEdit(builder);
99 expect(edit.replacement, equalsIgnoringWhitespace('class C { /**/ }')); 103 expect(edit.replacement, equalsIgnoringWhitespace('class C { /**/ }'));
100 } 104 }
101 105
102 void test_writeClassDeclaration_mixins_noSuperclass() { 106 void test_writeClassDeclaration_mixins_noSuperclass() {
103 Source source = addSource('/test.dart', 'class A {}'); 107 Source source = addSource('/test.dart', 'class A {}');
104 CompilationUnit unit = resolveLibraryUnit(source); 108 CompilationUnit unit = resolveLibraryUnit(source);
105 ClassDeclaration classA = unit.declarations[0]; 109 ClassDeclaration classA = unit.declarations[0];
106 110
107 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 111 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
108 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 112 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
109 builder.addInsertion(0, (DartEditBuilder builder) { 113 builder.addInsertion(0, (EditBuilder builder) {
110 builder.writeClassDeclaration('C', mixins: [classA.element.type]); 114 (builder as DartEditBuilder)
115 .writeClassDeclaration('C', mixins: [classA.element.type]);
111 }); 116 });
112 }); 117 });
113 SourceEdit edit = getEdit(builder); 118 SourceEdit edit = getEdit(builder);
114 expect(edit.replacement, 119 expect(edit.replacement,
115 equalsIgnoringWhitespace('class C extends Object with A { }')); 120 equalsIgnoringWhitespace('class C extends Object with A { }'));
116 } 121 }
117 122
118 void test_writeClassDeclaration_mixins_superclass() { 123 void test_writeClassDeclaration_mixins_superclass() {
119 Source source = addSource('/test.dart', 'class A {} class B {}'); 124 Source source = addSource('/test.dart', 'class A {} class B {}');
120 CompilationUnit unit = resolveLibraryUnit(source); 125 CompilationUnit unit = resolveLibraryUnit(source);
121 ClassDeclaration classA = unit.declarations[0]; 126 ClassDeclaration classA = unit.declarations[0];
122 ClassDeclaration classB = unit.declarations[1]; 127 ClassDeclaration classB = unit.declarations[1];
123 128
124 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 129 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
125 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 130 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
126 builder.addInsertion(0, (DartEditBuilder builder) { 131 builder.addInsertion(0, (EditBuilder builder) {
127 builder.writeClassDeclaration('C', 132 (builder as DartEditBuilder).writeClassDeclaration('C',
128 mixins: [classB.element.type], superclass: classA.element.type); 133 mixins: [classB.element.type], superclass: classA.element.type);
129 }); 134 });
130 }); 135 });
131 SourceEdit edit = getEdit(builder); 136 SourceEdit edit = getEdit(builder);
132 expect(edit.replacement, 137 expect(edit.replacement,
133 equalsIgnoringWhitespace('class C extends A with B { }')); 138 equalsIgnoringWhitespace('class C extends A with B { }'));
134 } 139 }
135 140
136 void test_writeClassDeclaration_nameGroupName() { 141 void test_writeClassDeclaration_nameGroupName() {
137 Source source = addSource('/test.dart', ''); 142 Source source = addSource('/test.dart', '');
138 resolveLibraryUnit(source); 143 resolveLibraryUnit(source);
139 144
140 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 145 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
141 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 146 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
142 builder.addInsertion(0, (DartEditBuilder builder) { 147 builder.addInsertion(0, (EditBuilder builder) {
143 builder.writeClassDeclaration('C', nameGroupName: 'name'); 148 (builder as DartEditBuilder)
149 .writeClassDeclaration('C', nameGroupName: 'name');
144 }); 150 });
145 }); 151 });
146 SourceEdit edit = getEdit(builder); 152 SourceEdit edit = getEdit(builder);
147 expect(edit.replacement, equalsIgnoringWhitespace('class C { }')); 153 expect(edit.replacement, equalsIgnoringWhitespace('class C { }'));
148 154
149 List<LinkedEditGroup> linkedEditGroups = 155 List<LinkedEditGroup> linkedEditGroups =
150 builder.sourceChange.linkedEditGroups; 156 builder.sourceChange.linkedEditGroups;
151 expect(linkedEditGroups, hasLength(1)); 157 expect(linkedEditGroups, hasLength(1));
152 LinkedEditGroup group = linkedEditGroups[0]; 158 LinkedEditGroup group = linkedEditGroups[0];
153 expect(group.length, 1); 159 expect(group.length, 1);
154 expect(group.positions, hasLength(1)); 160 expect(group.positions, hasLength(1));
155 } 161 }
156 162
157 void test_writeClassDeclaration_superclass() { 163 void test_writeClassDeclaration_superclass() {
158 Source source = addSource('/test.dart', 'class B {}'); 164 Source source = addSource('/test.dart', 'class B {}');
159 CompilationUnit unit = resolveLibraryUnit(source); 165 CompilationUnit unit = resolveLibraryUnit(source);
160 ClassDeclaration declaration = unit.declarations[0]; 166 ClassDeclaration declaration = unit.declarations[0];
161 167
162 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 168 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
163 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 169 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
164 builder.addInsertion(0, (DartEditBuilder builder) { 170 builder.addInsertion(0, (EditBuilder builder) {
165 builder.writeClassDeclaration('C', 171 (builder as DartEditBuilder)
166 superclass: declaration.element.type); 172 .writeClassDeclaration('C', superclass: declaration.element.type);
167 }); 173 });
168 }); 174 });
169 SourceEdit edit = getEdit(builder); 175 SourceEdit edit = getEdit(builder);
170 expect(edit.replacement, equalsIgnoringWhitespace('class C extends B { }')); 176 expect(edit.replacement, equalsIgnoringWhitespace('class C extends B { }'));
171 } 177 }
172 178
173 void test_writeFieldDeclaration_initializerWriter() { 179 void test_writeFieldDeclaration_initializerWriter() {
174 String content = 'class A {}'; 180 String content = 'class A {}';
175 Source source = addSource('/test.dart', content); 181 Source source = addSource('/test.dart', content);
176 resolveLibraryUnit(source); 182 resolveLibraryUnit(source);
177 183
178 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 184 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
179 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 185 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
180 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 186 builder.addInsertion(content.length - 1, (EditBuilder builder) {
181 builder.writeFieldDeclaration('f', initializerWriter: () { 187 (builder as DartEditBuilder).writeFieldDeclaration('f',
188 initializerWriter: () {
182 builder.write('e'); 189 builder.write('e');
183 }); 190 });
184 }); 191 });
185 }); 192 });
186 SourceEdit edit = getEdit(builder); 193 SourceEdit edit = getEdit(builder);
187 expect(edit.replacement, equalsIgnoringWhitespace('var f = e;')); 194 expect(edit.replacement, equalsIgnoringWhitespace('var f = e;'));
188 } 195 }
189 196
190 void test_writeFieldDeclaration_isConst() { 197 void test_writeFieldDeclaration_isConst() {
191 String content = 'class A {}'; 198 String content = 'class A {}';
192 Source source = addSource('/test.dart', content); 199 Source source = addSource('/test.dart', content);
193 resolveLibraryUnit(source); 200 resolveLibraryUnit(source);
194 201
195 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 202 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
196 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 203 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
197 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 204 builder.addInsertion(content.length - 1, (EditBuilder builder) {
198 builder.writeFieldDeclaration('f', isConst: true); 205 (builder as DartEditBuilder).writeFieldDeclaration('f', isConst: true);
199 }); 206 });
200 }); 207 });
201 SourceEdit edit = getEdit(builder); 208 SourceEdit edit = getEdit(builder);
202 expect(edit.replacement, equalsIgnoringWhitespace('const f;')); 209 expect(edit.replacement, equalsIgnoringWhitespace('const f;'));
203 } 210 }
204 211
205 void test_writeFieldDeclaration_isConst_isFinal() { 212 void test_writeFieldDeclaration_isConst_isFinal() {
206 String content = 'class A {}'; 213 String content = 'class A {}';
207 Source source = addSource('/test.dart', content); 214 Source source = addSource('/test.dart', content);
208 resolveLibraryUnit(source); 215 resolveLibraryUnit(source);
209 216
210 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 217 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
211 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 218 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
212 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 219 builder.addInsertion(content.length - 1, (EditBuilder builder) {
213 builder.writeFieldDeclaration('f', isConst: true, isFinal: true); 220 (builder as DartEditBuilder)
221 .writeFieldDeclaration('f', isConst: true, isFinal: true);
214 }); 222 });
215 }); 223 });
216 SourceEdit edit = getEdit(builder); 224 SourceEdit edit = getEdit(builder);
217 expect(edit.replacement, equalsIgnoringWhitespace('const f;')); 225 expect(edit.replacement, equalsIgnoringWhitespace('const f;'));
218 } 226 }
219 227
220 void test_writeFieldDeclaration_isFinal() { 228 void test_writeFieldDeclaration_isFinal() {
221 String content = 'class A {}'; 229 String content = 'class A {}';
222 Source source = addSource('/test.dart', content); 230 Source source = addSource('/test.dart', content);
223 resolveLibraryUnit(source); 231 resolveLibraryUnit(source);
224 232
225 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 233 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
226 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 234 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
227 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 235 builder.addInsertion(content.length - 1, (EditBuilder builder) {
228 builder.writeFieldDeclaration('f', isFinal: true); 236 (builder as DartEditBuilder).writeFieldDeclaration('f', isFinal: true);
229 }); 237 });
230 }); 238 });
231 SourceEdit edit = getEdit(builder); 239 SourceEdit edit = getEdit(builder);
232 expect(edit.replacement, equalsIgnoringWhitespace('final f;')); 240 expect(edit.replacement, equalsIgnoringWhitespace('final f;'));
233 } 241 }
234 242
235 void test_writeFieldDeclaration_isStatic() { 243 void test_writeFieldDeclaration_isStatic() {
236 String content = 'class A {}'; 244 String content = 'class A {}';
237 Source source = addSource('/test.dart', content); 245 Source source = addSource('/test.dart', content);
238 resolveLibraryUnit(source); 246 resolveLibraryUnit(source);
239 247
240 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 248 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
241 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 249 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
242 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 250 builder.addInsertion(content.length - 1, (EditBuilder builder) {
243 builder.writeFieldDeclaration('f', isStatic: true); 251 (builder as DartEditBuilder).writeFieldDeclaration('f', isStatic: true);
244 }); 252 });
245 }); 253 });
246 SourceEdit edit = getEdit(builder); 254 SourceEdit edit = getEdit(builder);
247 expect(edit.replacement, equalsIgnoringWhitespace('static var f;')); 255 expect(edit.replacement, equalsIgnoringWhitespace('static var f;'));
248 } 256 }
249 257
250 void test_writeFieldDeclaration_nameGroupName() { 258 void test_writeFieldDeclaration_nameGroupName() {
251 String content = 'class A {}'; 259 String content = 'class A {}';
252 Source source = addSource('/test.dart', content); 260 Source source = addSource('/test.dart', content);
253 resolveLibraryUnit(source); 261 resolveLibraryUnit(source);
254 262
255 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 263 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
256 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 264 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
257 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 265 builder.addInsertion(content.length - 1, (EditBuilder builder) {
258 builder.writeFieldDeclaration('f', nameGroupName: 'name'); 266 (builder as DartEditBuilder)
267 .writeFieldDeclaration('f', nameGroupName: 'name');
259 }); 268 });
260 }); 269 });
261 SourceEdit edit = getEdit(builder); 270 SourceEdit edit = getEdit(builder);
262 expect(edit.replacement, equalsIgnoringWhitespace('var f;')); 271 expect(edit.replacement, equalsIgnoringWhitespace('var f;'));
263 272
264 List<LinkedEditGroup> linkedEditGroups = 273 List<LinkedEditGroup> linkedEditGroups =
265 builder.sourceChange.linkedEditGroups; 274 builder.sourceChange.linkedEditGroups;
266 expect(linkedEditGroups, hasLength(1)); 275 expect(linkedEditGroups, hasLength(1));
267 LinkedEditGroup group = linkedEditGroups[0]; 276 LinkedEditGroup group = linkedEditGroups[0];
268 expect(group.length, 1); 277 expect(group.length, 1);
269 expect(group.positions, hasLength(1)); 278 expect(group.positions, hasLength(1));
270 Position position = group.positions[0]; 279 Position position = group.positions[0];
271 expect(position.offset, equals(13)); 280 expect(position.offset, equals(13));
272 } 281 }
273 282
274 void test_writeFieldDeclaration_type_typeGroupName() { 283 void test_writeFieldDeclaration_type_typeGroupName() {
275 String content = 'class A {} class B {}'; 284 String content = 'class A {} class B {}';
276 Source source = addSource('/test.dart', content); 285 Source source = addSource('/test.dart', content);
277 CompilationUnit unit = resolveLibraryUnit(source); 286 CompilationUnit unit = resolveLibraryUnit(source);
278 ClassDeclaration declaration = unit.declarations[0]; 287 ClassDeclaration declaration = unit.declarations[0];
279 288
280 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 289 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
281 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 290 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
282 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 291 builder.addInsertion(content.length - 1, (EditBuilder builder) {
283 builder.writeFieldDeclaration('f', 292 (builder as DartEditBuilder).writeFieldDeclaration('f',
284 type: declaration.element.type, typeGroupName: 'type'); 293 type: declaration.element.type, typeGroupName: 'type');
285 }); 294 });
286 }); 295 });
287 SourceEdit edit = getEdit(builder); 296 SourceEdit edit = getEdit(builder);
288 expect(edit.replacement, equalsIgnoringWhitespace('A f;')); 297 expect(edit.replacement, equalsIgnoringWhitespace('A f;'));
289 298
290 List<LinkedEditGroup> linkedEditGroups = 299 List<LinkedEditGroup> linkedEditGroups =
291 builder.sourceChange.linkedEditGroups; 300 builder.sourceChange.linkedEditGroups;
292 expect(linkedEditGroups, hasLength(1)); 301 expect(linkedEditGroups, hasLength(1));
293 LinkedEditGroup group = linkedEditGroups[0]; 302 LinkedEditGroup group = linkedEditGroups[0];
294 expect(group.length, 1); 303 expect(group.length, 1);
295 expect(group.positions, hasLength(1)); 304 expect(group.positions, hasLength(1));
296 Position position = group.positions[0]; 305 Position position = group.positions[0];
297 expect(position.offset, equals(20)); 306 expect(position.offset, equals(20));
298 } 307 }
299 308
300 void test_writeGetterDeclaration_bodyWriter() { 309 void test_writeGetterDeclaration_bodyWriter() {
301 String content = 'class A {}'; 310 String content = 'class A {}';
302 Source source = addSource('/test.dart', content); 311 Source source = addSource('/test.dart', content);
303 resolveLibraryUnit(source); 312 resolveLibraryUnit(source);
304 313
305 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 314 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
306 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 315 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
307 builder.addInsertion(content.length - 1, (DartEditBuilderImpl builder) { 316 builder.addInsertion(content.length - 1, (EditBuilder builder) {
308 builder.writeGetterDeclaration('g', bodyWriter: () { 317 (builder as DartEditBuilder).writeGetterDeclaration('g',
318 bodyWriter: () {
309 builder.write('{}'); 319 builder.write('{}');
310 }); 320 });
311 }); 321 });
312 }); 322 });
313 SourceEdit edit = getEdit(builder); 323 SourceEdit edit = getEdit(builder);
314 expect(edit.replacement, equalsIgnoringWhitespace('get g {}')); 324 expect(edit.replacement, equalsIgnoringWhitespace('get g {}'));
315 } 325 }
316 326
317 void test_writeGetterDeclaration_isStatic() { 327 void test_writeGetterDeclaration_isStatic() {
318 String content = 'class A {}'; 328 String content = 'class A {}';
319 Source source = addSource('/test.dart', content); 329 Source source = addSource('/test.dart', content);
320 resolveLibraryUnit(source); 330 resolveLibraryUnit(source);
321 331
322 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 332 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
323 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 333 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
324 builder.addInsertion(content.length - 1, (DartEditBuilderImpl builder) { 334 builder.addInsertion(content.length - 1, (EditBuilder builder) {
325 builder.writeGetterDeclaration('g', isStatic: true); 335 (builder as DartEditBuilder)
336 .writeGetterDeclaration('g', isStatic: true);
326 }); 337 });
327 }); 338 });
328 SourceEdit edit = getEdit(builder); 339 SourceEdit edit = getEdit(builder);
329 expect(edit.replacement, equalsIgnoringWhitespace('static get g => null;')); 340 expect(edit.replacement, equalsIgnoringWhitespace('static get g => null;'));
330 } 341 }
331 342
332 void test_writeGetterDeclaration_nameGroupName() { 343 void test_writeGetterDeclaration_nameGroupName() {
333 String content = 'class A {}'; 344 String content = 'class A {}';
334 Source source = addSource('/test.dart', content); 345 Source source = addSource('/test.dart', content);
335 resolveLibraryUnit(source); 346 resolveLibraryUnit(source);
336 347
337 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 348 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
338 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 349 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
339 builder.addInsertion(content.length - 1, (DartEditBuilderImpl builder) { 350 builder.addInsertion(content.length - 1, (EditBuilder builder) {
340 builder.writeGetterDeclaration('g', nameGroupName: 'name'); 351 (builder as DartEditBuilder)
352 .writeGetterDeclaration('g', nameGroupName: 'name');
341 }); 353 });
342 }); 354 });
343 SourceEdit edit = getEdit(builder); 355 SourceEdit edit = getEdit(builder);
344 expect(edit.replacement, equalsIgnoringWhitespace('get g => null;')); 356 expect(edit.replacement, equalsIgnoringWhitespace('get g => null;'));
345 357
346 List<LinkedEditGroup> linkedEditGroups = 358 List<LinkedEditGroup> linkedEditGroups =
347 builder.sourceChange.linkedEditGroups; 359 builder.sourceChange.linkedEditGroups;
348 expect(linkedEditGroups, hasLength(1)); 360 expect(linkedEditGroups, hasLength(1));
349 LinkedEditGroup group = linkedEditGroups[0]; 361 LinkedEditGroup group = linkedEditGroups[0];
350 expect(group.length, 1); 362 expect(group.length, 1);
351 expect(group.positions, hasLength(1)); 363 expect(group.positions, hasLength(1));
352 Position position = group.positions[0]; 364 Position position = group.positions[0];
353 expect(position.offset, equals(13)); 365 expect(position.offset, equals(13));
354 } 366 }
355 367
356 void test_writeGetterDeclaration_returnType() { 368 void test_writeGetterDeclaration_returnType() {
357 String content = 'class A {} class B {}'; 369 String content = 'class A {} class B {}';
358 Source source = addSource('/test.dart', content); 370 Source source = addSource('/test.dart', content);
359 CompilationUnit unit = resolveLibraryUnit(source); 371 CompilationUnit unit = resolveLibraryUnit(source);
360 ClassDeclaration classA = unit.declarations[0]; 372 ClassDeclaration classA = unit.declarations[0];
361 373
362 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 374 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
363 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 375 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
364 builder.addInsertion(content.length - 1, (DartEditBuilderImpl builder) { 376 builder.addInsertion(content.length - 1, (EditBuilder builder) {
365 builder.writeGetterDeclaration('g', 377 (builder as DartEditBuilder).writeGetterDeclaration('g',
366 returnType: classA.element.type, returnTypeGroupName: 'returnType'); 378 returnType: classA.element.type, returnTypeGroupName: 'returnType');
367 }); 379 });
368 }); 380 });
369 SourceEdit edit = getEdit(builder); 381 SourceEdit edit = getEdit(builder);
370 expect(edit.replacement, equalsIgnoringWhitespace('A get g => null;')); 382 expect(edit.replacement, equalsIgnoringWhitespace('A get g => null;'));
371 383
372 List<LinkedEditGroup> linkedEditGroups = 384 List<LinkedEditGroup> linkedEditGroups =
373 builder.sourceChange.linkedEditGroups; 385 builder.sourceChange.linkedEditGroups;
374 expect(linkedEditGroups, hasLength(1)); 386 expect(linkedEditGroups, hasLength(1));
375 LinkedEditGroup group = linkedEditGroups[0]; 387 LinkedEditGroup group = linkedEditGroups[0];
376 expect(group.length, 1); 388 expect(group.length, 1);
377 expect(group.positions, hasLength(1)); 389 expect(group.positions, hasLength(1));
378 Position position = group.positions[0]; 390 Position position = group.positions[0];
379 expect(position.offset, equals(20)); 391 expect(position.offset, equals(20));
380 } 392 }
381 393
382 void test_writeOverrideOfInheritedMember() { 394 void test_writeOverrideOfInheritedMember() {
383 String content = ''' 395 String content = '''
384 class A { 396 class A {
385 A add(A a) => null; 397 A add(A a) => null;
386 } 398 }
387 class B extends A { 399 class B extends A {
388 }'''; 400 }''';
389 Source source = addSource('/test.dart', content); 401 Source source = addSource('/test.dart', content);
390 CompilationUnit unit = resolveLibraryUnit(source); 402 CompilationUnit unit = resolveLibraryUnit(source);
391 ClassDeclaration declaration = unit.declarations[0]; 403 ClassDeclaration declaration = unit.declarations[0];
392 404
393 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 405 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
394 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 406 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
395 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 407 builder.addInsertion(content.length - 1, (EditBuilder builder) {
396 builder.writeOverrideOfInheritedMember(declaration.element.methods[0]); 408 (builder as DartEditBuilder)
409 .writeOverrideOfInheritedMember(declaration.element.methods[0]);
397 }); 410 });
398 }); 411 });
399 SourceEdit edit = getEdit(builder); 412 SourceEdit edit = getEdit(builder);
400 expect(edit.replacement, equalsIgnoringWhitespace(''' 413 expect(edit.replacement, equalsIgnoringWhitespace('''
401 @override 414 @override
402 A add(A a) { 415 A add(A a) {
403 // TODO: implement add 416 // TODO: implement add
404 return null; 417 return null;
405 }''')); 418 }'''));
406 } 419 }
407 420
408 void test_writeParameters_named() { 421 void test_writeParameters_named() {
409 String content = 'f(int i, {String s}) {}'; 422 String content = 'f(int i, {String s}) {}';
410 Source source = addSource('/test.dart', content); 423 Source source = addSource('/test.dart', content);
411 CompilationUnit unit = resolveLibraryUnit(source); 424 CompilationUnit unit = resolveLibraryUnit(source);
412 FunctionDeclaration f = unit.declarations[0]; 425 FunctionDeclaration f = unit.declarations[0];
413 FormalParameterList parameters = f.functionExpression.parameters; 426 FormalParameterList parameters = f.functionExpression.parameters;
414 Iterable elements = parameters.parameters 427 Iterable<ParameterElement> elements = parameters.parameters
415 .map((FormalParameter parameter) => parameter.element); 428 .map((FormalParameter parameter) => parameter.element);
416 429
417 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 430 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
418 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 431 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
419 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 432 builder.addInsertion(content.length - 1, (EditBuilder builder) {
420 builder.writeParameters(elements); 433 (builder as DartEditBuilder).writeParameters(elements);
421 }); 434 });
422 }); 435 });
423 SourceEdit edit = getEdit(builder); 436 SourceEdit edit = getEdit(builder);
424 expect(edit.replacement, equalsIgnoringWhitespace('(int i, {String s})')); 437 expect(edit.replacement, equalsIgnoringWhitespace('(int i, {String s})'));
425 } 438 }
426 439
427 void test_writeParameters_positional() { 440 void test_writeParameters_positional() {
428 String content = 'f(int i, [String s]) {}'; 441 String content = 'f(int i, [String s]) {}';
429 Source source = addSource('/test.dart', content); 442 Source source = addSource('/test.dart', content);
430 CompilationUnit unit = resolveLibraryUnit(source); 443 CompilationUnit unit = resolveLibraryUnit(source);
431 FunctionDeclaration f = unit.declarations[0]; 444 FunctionDeclaration f = unit.declarations[0];
432 FormalParameterList parameters = f.functionExpression.parameters; 445 FormalParameterList parameters = f.functionExpression.parameters;
433 Iterable elements = parameters.parameters 446 Iterable<ParameterElement> elements = parameters.parameters
434 .map((FormalParameter parameter) => parameter.element); 447 .map((FormalParameter parameter) => parameter.element);
435 448
436 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 449 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
437 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 450 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
438 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 451 builder.addInsertion(content.length - 1, (EditBuilder builder) {
439 builder.writeParameters(elements); 452 (builder as DartEditBuilder).writeParameters(elements);
440 }); 453 });
441 }); 454 });
442 SourceEdit edit = getEdit(builder); 455 SourceEdit edit = getEdit(builder);
443 expect(edit.replacement, equalsIgnoringWhitespace('(int i, [String s])')); 456 expect(edit.replacement, equalsIgnoringWhitespace('(int i, [String s])'));
444 } 457 }
445 458
446 void test_writeParameters_required() { 459 void test_writeParameters_required() {
447 String content = 'f(int i, String s) {}'; 460 String content = 'f(int i, String s) {}';
448 Source source = addSource('/test.dart', content); 461 Source source = addSource('/test.dart', content);
449 CompilationUnit unit = resolveLibraryUnit(source); 462 CompilationUnit unit = resolveLibraryUnit(source);
450 FunctionDeclaration f = unit.declarations[0]; 463 FunctionDeclaration f = unit.declarations[0];
451 FormalParameterList parameters = f.functionExpression.parameters; 464 FormalParameterList parameters = f.functionExpression.parameters;
452 Iterable elements = parameters.parameters 465 Iterable<ParameterElement> elements = parameters.parameters
453 .map((FormalParameter parameter) => parameter.element); 466 .map((FormalParameter parameter) => parameter.element);
454 467
455 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 468 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
456 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 469 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
457 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 470 builder.addInsertion(content.length - 1, (EditBuilder builder) {
458 builder.writeParameters(elements); 471 (builder as DartEditBuilder).writeParameters(elements);
459 }); 472 });
460 }); 473 });
461 SourceEdit edit = getEdit(builder); 474 SourceEdit edit = getEdit(builder);
462 expect(edit.replacement, equalsIgnoringWhitespace('(int i, String s)')); 475 expect(edit.replacement, equalsIgnoringWhitespace('(int i, String s)'));
463 } 476 }
464 477
465 void test_writeParametersMatchingArguments_named() { 478 void test_writeParametersMatchingArguments_named() {
466 String content = ''' 479 String content = '''
467 f(int i, String s) { 480 f(int i, String s) {
468 g(s, index: i); 481 g(s, index: i);
469 }'''; 482 }''';
470 Source source = addSource('/test.dart', content); 483 Source source = addSource('/test.dart', content);
471 CompilationUnit unit = resolveLibraryUnit(source); 484 CompilationUnit unit = resolveLibraryUnit(source);
472 FunctionDeclaration f = unit.declarations[0]; 485 FunctionDeclaration f = unit.declarations[0];
473 BlockFunctionBody body = f.functionExpression.body; 486 BlockFunctionBody body = f.functionExpression.body;
474 ExpressionStatement statement = body.block.statements[0]; 487 ExpressionStatement statement = body.block.statements[0];
475 MethodInvocation invocation = statement.expression; 488 MethodInvocation invocation = statement.expression;
476 489
477 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 490 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
478 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 491 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
479 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 492 builder.addInsertion(content.length - 1, (EditBuilder builder) {
480 builder.writeParametersMatchingArguments(invocation.argumentList); 493 (builder as DartEditBuilder)
494 .writeParametersMatchingArguments(invocation.argumentList);
481 }); 495 });
482 }); 496 });
483 SourceEdit edit = getEdit(builder); 497 SourceEdit edit = getEdit(builder);
484 expect( 498 expect(
485 edit.replacement, equalsIgnoringWhitespace('(String s, [int index])')); 499 edit.replacement, equalsIgnoringWhitespace('(String s, [int index])'));
486 } 500 }
487 501
488 void test_writeParametersMatchingArguments_required() { 502 void test_writeParametersMatchingArguments_required() {
489 String content = ''' 503 String content = '''
490 f(int i, String s) { 504 f(int i, String s) {
491 g(s, i); 505 g(s, i);
492 }'''; 506 }''';
493 Source source = addSource('/test.dart', content); 507 Source source = addSource('/test.dart', content);
494 CompilationUnit unit = resolveLibraryUnit(source); 508 CompilationUnit unit = resolveLibraryUnit(source);
495 FunctionDeclaration f = unit.declarations[0]; 509 FunctionDeclaration f = unit.declarations[0];
496 BlockFunctionBody body = f.functionExpression.body; 510 BlockFunctionBody body = f.functionExpression.body;
497 ExpressionStatement statement = body.block.statements[0]; 511 ExpressionStatement statement = body.block.statements[0];
498 MethodInvocation invocation = statement.expression; 512 MethodInvocation invocation = statement.expression;
499 513
500 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 514 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
501 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 515 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
502 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 516 builder.addInsertion(content.length - 1, (EditBuilder builder) {
503 builder.writeParametersMatchingArguments(invocation.argumentList); 517 (builder as DartEditBuilder)
518 .writeParametersMatchingArguments(invocation.argumentList);
504 }); 519 });
505 }); 520 });
506 SourceEdit edit = getEdit(builder); 521 SourceEdit edit = getEdit(builder);
507 expect(edit.replacement, equalsIgnoringWhitespace('(String s, int i)')); 522 expect(edit.replacement, equalsIgnoringWhitespace('(String s, int i)'));
508 } 523 }
509 524
510 void test_writeParameterSource() { 525 void test_writeParameterSource() {
511 String content = 'class A {}'; 526 String content = 'class A {}';
512 Source source = addSource('/test.dart', content); 527 Source source = addSource('/test.dart', content);
513 CompilationUnit unit = resolveLibraryUnit(source); 528 CompilationUnit unit = resolveLibraryUnit(source);
514 ClassDeclaration classA = unit.declarations[0]; 529 ClassDeclaration classA = unit.declarations[0];
515 530
516 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 531 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
517 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 532 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
518 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 533 builder.addInsertion(content.length - 1, (EditBuilder builder) {
519 builder.writeParameterSource(classA.element.type, 'a'); 534 (builder as DartEditBuilder)
535 .writeParameterSource(classA.element.type, 'a');
520 }); 536 });
521 }); 537 });
522 SourceEdit edit = getEdit(builder); 538 SourceEdit edit = getEdit(builder);
523 expect(edit.replacement, equalsIgnoringWhitespace('A a')); 539 expect(edit.replacement, equalsIgnoringWhitespace('A a'));
524 } 540 }
525 541
526 void test_writeType_dymanic() { 542 void test_writeType_dymanic() {
527 String content = 'class A {}'; 543 String content = 'class A {}';
528 Source source = addSource('/test.dart', content); 544 Source source = addSource('/test.dart', content);
529 CompilationUnit unit = resolveLibraryUnit(source); 545 CompilationUnit unit = resolveLibraryUnit(source);
530 546
531 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 547 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
532 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 548 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
533 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 549 builder.addInsertion(content.length - 1, (EditBuilder builder) {
534 builder.writeType(unit.element.context.typeProvider.dynamicType); 550 (builder as DartEditBuilder)
551 .writeType(unit.element.context.typeProvider.dynamicType);
535 }); 552 });
536 }); 553 });
537 SourceEdit edit = getEdit(builder); 554 SourceEdit edit = getEdit(builder);
538 expect(edit.replacement, equalsIgnoringWhitespace('')); 555 expect(edit.replacement, equalsIgnoringWhitespace(''));
539 } 556 }
540 557
541 void test_writeType_genericType() { 558 void test_writeType_genericType() {
542 String content = 'class A {} class B<E> {}'; 559 String content = 'class A {} class B<E> {}';
543 Source source = addSource('/test.dart', content); 560 Source source = addSource('/test.dart', content);
544 CompilationUnit unit = resolveLibraryUnit(source); 561 CompilationUnit unit = resolveLibraryUnit(source);
545 ClassDeclaration classA = unit.declarations[0]; 562 ClassDeclaration classA = unit.declarations[0];
546 ClassDeclaration classB = unit.declarations[1]; 563 ClassDeclaration classB = unit.declarations[1];
547 564
548 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 565 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
549 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 566 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
550 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 567 builder.addInsertion(content.length - 1, (EditBuilder builder) {
551 builder 568 (builder as DartEditBuilder)
552 .writeType(classB.element.type.instantiate([classA.element.type])); 569 .writeType(classB.element.type.instantiate([classA.element.type]));
553 }); 570 });
554 }); 571 });
555 SourceEdit edit = getEdit(builder); 572 SourceEdit edit = getEdit(builder);
556 expect(edit.replacement, equalsIgnoringWhitespace('B<A>')); 573 expect(edit.replacement, equalsIgnoringWhitespace('B<A>'));
557 } 574 }
558 575
559 void test_writeType_groupName() { 576 void test_writeType_groupName() {
560 String content = 'class A {} class B extends A {} class C extends B {}'; 577 String content = 'class A {} class B extends A {} class C extends B {}';
561 Source source = addSource('/test.dart', content); 578 Source source = addSource('/test.dart', content);
562 CompilationUnit unit = resolveLibraryUnit(source); 579 CompilationUnit unit = resolveLibraryUnit(source);
563 ClassDeclaration classC = unit.declarations[2]; 580 ClassDeclaration classC = unit.declarations[2];
564 581
565 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 582 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
566 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 583 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
567 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 584 builder.addInsertion(content.length - 1, (EditBuilder builder) {
568 builder.writeType(classC.element.type, groupName: 'type'); 585 (builder as DartEditBuilder)
586 .writeType(classC.element.type, groupName: 'type');
569 }); 587 });
570 }); 588 });
571 SourceEdit edit = getEdit(builder); 589 SourceEdit edit = getEdit(builder);
572 expect(edit.replacement, equalsIgnoringWhitespace('C')); 590 expect(edit.replacement, equalsIgnoringWhitespace('C'));
573 591
574 List<LinkedEditGroup> linkedEditGroups = 592 List<LinkedEditGroup> linkedEditGroups =
575 builder.sourceChange.linkedEditGroups; 593 builder.sourceChange.linkedEditGroups;
576 expect(linkedEditGroups, hasLength(1)); 594 expect(linkedEditGroups, hasLength(1));
577 LinkedEditGroup group = linkedEditGroups[0]; 595 LinkedEditGroup group = linkedEditGroups[0];
578 expect(group, isNotNull); 596 expect(group, isNotNull);
579 } 597 }
580 598
581 void test_writeType_groupName_addSupertypeProposals() { 599 void test_writeType_groupName_addSupertypeProposals() {
582 String content = 'class A {} class B extends A {} class C extends B {}'; 600 String content = 'class A {} class B extends A {} class C extends B {}';
583 Source source = addSource('/test.dart', content); 601 Source source = addSource('/test.dart', content);
584 CompilationUnit unit = resolveLibraryUnit(source); 602 CompilationUnit unit = resolveLibraryUnit(source);
585 ClassDeclaration classC = unit.declarations[2]; 603 ClassDeclaration classC = unit.declarations[2];
586 604
587 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 605 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
588 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 606 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
589 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 607 builder.addInsertion(content.length - 1, (EditBuilder builder) {
590 builder.writeType(classC.element.type, 608 (builder as DartEditBuilder).writeType(classC.element.type,
591 addSupertypeProposals: true, groupName: 'type'); 609 addSupertypeProposals: true, groupName: 'type');
592 }); 610 });
593 }); 611 });
594 SourceEdit edit = getEdit(builder); 612 SourceEdit edit = getEdit(builder);
595 expect(edit.replacement, equalsIgnoringWhitespace('C')); 613 expect(edit.replacement, equalsIgnoringWhitespace('C'));
596 614
597 List<LinkedEditGroup> linkedEditGroups = 615 List<LinkedEditGroup> linkedEditGroups =
598 builder.sourceChange.linkedEditGroups; 616 builder.sourceChange.linkedEditGroups;
599 expect(linkedEditGroups, hasLength(1)); 617 expect(linkedEditGroups, hasLength(1));
600 LinkedEditGroup group = linkedEditGroups[0]; 618 LinkedEditGroup group = linkedEditGroups[0];
601 List<LinkedEditSuggestion> suggestions = group.suggestions; 619 List<LinkedEditSuggestion> suggestions = group.suggestions;
602 expect(suggestions, hasLength(4)); 620 expect(suggestions, hasLength(4));
603 Iterable<String> values = 621 Iterable<String> values =
604 suggestions.map((LinkedEditSuggestion suggestion) { 622 suggestions.map((LinkedEditSuggestion suggestion) {
605 expect(suggestion.kind, LinkedEditSuggestionKind.TYPE); 623 expect(suggestion.kind, LinkedEditSuggestionKind.TYPE);
606 return suggestion.value; 624 return suggestion.value;
607 }); 625 });
608 expect(values, contains('Object')); 626 expect(values, contains('Object'));
609 expect(values, contains('A')); 627 expect(values, contains('A'));
610 expect(values, contains('B')); 628 expect(values, contains('B'));
611 expect(values, contains('C')); 629 expect(values, contains('C'));
612 } 630 }
613 631
614 void test_writeType_null() { 632 void test_writeType_null() {
615 String content = 'class A {}'; 633 String content = 'class A {}';
616 Source source = addSource('/test.dart', content); 634 Source source = addSource('/test.dart', content);
617 resolveLibraryUnit(source); 635 resolveLibraryUnit(source);
618 636
619 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 637 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
620 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 638 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
621 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 639 builder.addInsertion(content.length - 1, (EditBuilder builder) {
622 builder.writeType(null); 640 (builder as DartEditBuilder).writeType(null);
623 }); 641 });
624 }); 642 });
625 SourceEdit edit = getEdit(builder); 643 SourceEdit edit = getEdit(builder);
626 expect(edit.replacement, equalsIgnoringWhitespace('')); 644 expect(edit.replacement, equalsIgnoringWhitespace(''));
627 } 645 }
628 646
629 void test_writeType_required_dymanic() { 647 void test_writeType_required_dymanic() {
630 String content = 'class A {}'; 648 String content = 'class A {}';
631 Source source = addSource('/test.dart', content); 649 Source source = addSource('/test.dart', content);
632 CompilationUnit unit = resolveLibraryUnit(source); 650 CompilationUnit unit = resolveLibraryUnit(source);
633 651
634 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 652 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
635 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 653 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
636 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 654 builder.addInsertion(content.length - 1, (EditBuilder builder) {
637 builder.writeType(unit.element.context.typeProvider.dynamicType, 655 (builder as DartEditBuilder).writeType(
656 unit.element.context.typeProvider.dynamicType,
638 required: true); 657 required: true);
639 }); 658 });
640 }); 659 });
641 SourceEdit edit = getEdit(builder); 660 SourceEdit edit = getEdit(builder);
642 expect(edit.replacement, equalsIgnoringWhitespace('var')); 661 expect(edit.replacement, equalsIgnoringWhitespace('var'));
643 } 662 }
644 663
645 void test_writeType_required_notNull() { 664 void test_writeType_required_notNull() {
646 String content = 'class A {}'; 665 String content = 'class A {}';
647 Source source = addSource('/test.dart', content); 666 Source source = addSource('/test.dart', content);
648 CompilationUnit unit = resolveLibraryUnit(source); 667 CompilationUnit unit = resolveLibraryUnit(source);
649 ClassDeclaration classA = unit.declarations[0]; 668 ClassDeclaration classA = unit.declarations[0];
650 669
651 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 670 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
652 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 671 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
653 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 672 builder.addInsertion(content.length - 1, (EditBuilder builder) {
654 builder.writeType(classA.element.type, required: true); 673 (builder as DartEditBuilder)
674 .writeType(classA.element.type, required: true);
655 }); 675 });
656 }); 676 });
657 SourceEdit edit = getEdit(builder); 677 SourceEdit edit = getEdit(builder);
658 expect(edit.replacement, equalsIgnoringWhitespace('A')); 678 expect(edit.replacement, equalsIgnoringWhitespace('A'));
659 } 679 }
660 680
661 void test_writeType_required_null() { 681 void test_writeType_required_null() {
662 String content = 'class A {}'; 682 String content = 'class A {}';
663 Source source = addSource('/test.dart', content); 683 Source source = addSource('/test.dart', content);
664 resolveLibraryUnit(source); 684 resolveLibraryUnit(source);
665 685
666 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 686 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
667 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 687 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
668 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 688 builder.addInsertion(content.length - 1, (EditBuilder builder) {
669 builder.writeType(null, required: true); 689 (builder as DartEditBuilder).writeType(null, required: true);
670 }); 690 });
671 }); 691 });
672 SourceEdit edit = getEdit(builder); 692 SourceEdit edit = getEdit(builder);
673 expect(edit.replacement, equalsIgnoringWhitespace('var')); 693 expect(edit.replacement, equalsIgnoringWhitespace('var'));
674 } 694 }
675 695
676 void test_writeType_simpleType() { 696 void test_writeType_simpleType() {
677 String content = 'class A {}'; 697 String content = 'class A {}';
678 Source source = addSource('/test.dart', content); 698 Source source = addSource('/test.dart', content);
679 CompilationUnit unit = resolveLibraryUnit(source); 699 CompilationUnit unit = resolveLibraryUnit(source);
680 ClassDeclaration classA = unit.declarations[0]; 700 ClassDeclaration classA = unit.declarations[0];
681 701
682 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 702 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
683 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 703 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
684 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 704 builder.addInsertion(content.length - 1, (EditBuilder builder) {
685 builder.writeType(classA.element.type); 705 (builder as DartEditBuilder).writeType(classA.element.type);
686 }); 706 });
687 }); 707 });
688 SourceEdit edit = getEdit(builder); 708 SourceEdit edit = getEdit(builder);
689 expect(edit.replacement, equalsIgnoringWhitespace('A')); 709 expect(edit.replacement, equalsIgnoringWhitespace('A'));
690 } 710 }
691 711
692 void test_writeTypes_empty() { 712 void test_writeTypes_empty() {
693 String content = 'class A {}'; 713 String content = 'class A {}';
694 Source source = addSource('/test.dart', content); 714 Source source = addSource('/test.dart', content);
695 resolveLibraryUnit(source); 715 resolveLibraryUnit(source);
696 716
697 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 717 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
698 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 718 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
699 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 719 builder.addInsertion(content.length - 1, (EditBuilder builder) {
700 (builder as DartEditBuilderImpl).writeTypes([]); 720 (builder as DartEditBuilderImpl).writeTypes([]);
701 }); 721 });
702 }); 722 });
703 SourceEdit edit = getEdit(builder); 723 SourceEdit edit = getEdit(builder);
704 expect(edit.replacement, isEmpty); 724 expect(edit.replacement, isEmpty);
705 } 725 }
706 726
707 void test_writeTypes_noPrefix() { 727 void test_writeTypes_noPrefix() {
708 String content = 'class A {} class B {}'; 728 String content = 'class A {} class B {}';
709 Source source = addSource('/test.dart', content); 729 Source source = addSource('/test.dart', content);
710 CompilationUnit unit = resolveLibraryUnit(source); 730 CompilationUnit unit = resolveLibraryUnit(source);
711 ClassDeclaration classA = unit.declarations[0]; 731 ClassDeclaration classA = unit.declarations[0];
712 ClassDeclaration classB = unit.declarations[1]; 732 ClassDeclaration classB = unit.declarations[1];
713 733
714 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 734 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
715 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 735 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
716 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 736 builder.addInsertion(content.length - 1, (EditBuilder builder) {
717 (builder as DartEditBuilderImpl) 737 (builder as DartEditBuilderImpl)
718 .writeTypes([classA.element.type, classB.element.type]); 738 .writeTypes([classA.element.type, classB.element.type]);
719 }); 739 });
720 }); 740 });
721 SourceEdit edit = getEdit(builder); 741 SourceEdit edit = getEdit(builder);
722 expect(edit.replacement, equalsIgnoringWhitespace('A, B')); 742 expect(edit.replacement, equalsIgnoringWhitespace('A, B'));
723 } 743 }
724 744
725 void test_writeTypes_null() { 745 void test_writeTypes_null() {
726 String content = 'class A {}'; 746 String content = 'class A {}';
727 Source source = addSource('/test.dart', content); 747 Source source = addSource('/test.dart', content);
728 resolveLibraryUnit(source); 748 resolveLibraryUnit(source);
729 749
730 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 750 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
731 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 751 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
732 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 752 builder.addInsertion(content.length - 1, (EditBuilder builder) {
733 (builder as DartEditBuilderImpl).writeTypes(null); 753 (builder as DartEditBuilderImpl).writeTypes(null);
734 }); 754 });
735 }); 755 });
736 SourceEdit edit = getEdit(builder); 756 SourceEdit edit = getEdit(builder);
737 expect(edit.replacement, isEmpty); 757 expect(edit.replacement, isEmpty);
738 } 758 }
739 759
740 void test_writeTypes_prefix() { 760 void test_writeTypes_prefix() {
741 String content = 'class A {} class B {}'; 761 String content = 'class A {} class B {}';
742 Source source = addSource('/test.dart', content); 762 Source source = addSource('/test.dart', content);
743 CompilationUnit unit = resolveLibraryUnit(source); 763 CompilationUnit unit = resolveLibraryUnit(source);
744 ClassDeclaration classA = unit.declarations[0]; 764 ClassDeclaration classA = unit.declarations[0];
745 ClassDeclaration classB = unit.declarations[1]; 765 ClassDeclaration classB = unit.declarations[1];
746 766
747 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 767 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
748 builder.addFileEdit(source, 1, (DartFileEditBuilderImpl builder) { 768 builder.addFileEdit(source, 1, (FileEditBuilder builder) {
749 builder.addInsertion(content.length - 1, (DartEditBuilder builder) { 769 builder.addInsertion(content.length - 1, (EditBuilder builder) {
750 (builder as DartEditBuilderImpl).writeTypes( 770 (builder as DartEditBuilderImpl).writeTypes(
751 [classA.element.type, classB.element.type], 771 [classA.element.type, classB.element.type],
752 prefix: 'implements '); 772 prefix: 'implements ');
753 }); 773 });
754 }); 774 });
755 SourceEdit edit = getEdit(builder); 775 SourceEdit edit = getEdit(builder);
756 expect(edit.replacement, equalsIgnoringWhitespace('implements A, B')); 776 expect(edit.replacement, equalsIgnoringWhitespace('implements A, B'));
757 } 777 }
758 } 778 }
759 779
760 @reflectiveTest 780 @reflectiveTest
761 class DartFileEditBuilderImplTest extends AbstractContextTest { 781 class DartFileEditBuilderImplTest extends AbstractContextTest {
762 void test_createEditBuilder() { 782 void test_createEditBuilder() {
763 Source source = addSource('/test.dart', 'library test;'); 783 Source source = addSource('/test.dart', 'library test;');
764 resolveLibraryUnit(source); 784 resolveLibraryUnit(source);
765 int timeStamp = 65; 785 int timeStamp = 65;
766 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context); 786 DartChangeBuilderImpl builder = new DartChangeBuilderImpl(context);
767 builder.addFileEdit(source, timeStamp, (DartFileEditBuilderImpl builder) { 787 builder.addFileEdit(source, timeStamp, (FileEditBuilder builder) {
768 int offset = 4; 788 int offset = 4;
769 int length = 5; 789 int length = 5;
770 DartEditBuilderImpl editBuilder = 790 DartEditBuilderImpl editBuilder = (builder as DartFileEditBuilderImpl)
771 builder.createEditBuilder(offset, length); 791 .createEditBuilder(offset, length);
772 expect(editBuilder, new isInstanceOf<DartEditBuilder>()); 792 expect(editBuilder, new isInstanceOf<DartEditBuilder>());
773 SourceEdit sourceEdit = editBuilder.sourceEdit; 793 SourceEdit sourceEdit = editBuilder.sourceEdit;
774 expect(sourceEdit.length, length); 794 expect(sourceEdit.length, length);
775 expect(sourceEdit.offset, offset); 795 expect(sourceEdit.offset, offset);
776 expect(sourceEdit.replacement, isEmpty); 796 expect(sourceEdit.replacement, isEmpty);
777 }); 797 });
778 } 798 }
779 } 799 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698