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

Side by Side Diff: pkg/analysis_server/test/services/correction/fix_test.dart

Issue 1269043003: 'Import library' and 'Create class' Quick Fixes for unresolved class-like name in list literals. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | 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) 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 library test.services.correction.fix; 5 library test.services.correction.fix;
6 6
7 import 'package:analysis_server/edit/fix/fix_core.dart'; 7 import 'package:analysis_server/edit/fix/fix_core.dart';
8 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; 8 import 'package:analysis_server/src/protocol.dart' hide AnalysisError;
9 import 'package:analysis_server/src/services/correction/fix.dart'; 9 import 'package:analysis_server/src/services/correction/fix.dart';
10 import 'package:analysis_server/src/services/correction/fix_internal.dart'; 10 import 'package:analysis_server/src/services/correction/fix_internal.dart';
(...skipping 29 matching lines...) Expand all
40 SourceChange change; 40 SourceChange change;
41 String resultCode; 41 String resultCode;
42 42
43 void assert_undefinedFunction_create_returnType_bool(String lineWithTest) { 43 void assert_undefinedFunction_create_returnType_bool(String lineWithTest) {
44 resolveTestUnit(''' 44 resolveTestUnit('''
45 main() { 45 main() {
46 bool b = true; 46 bool b = true;
47 $lineWithTest 47 $lineWithTest
48 } 48 }
49 '''); 49 ''');
50 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 50 assertHasFix(
51 DartFixKind.CREATE_FUNCTION,
52 '''
51 main() { 53 main() {
52 bool b = true; 54 bool b = true;
53 $lineWithTest 55 $lineWithTest
54 } 56 }
55 57
56 bool test() { 58 bool test() {
57 } 59 }
58 '''); 60 ''');
59 } 61 }
60 62
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 109
108 void test_addFieldFormalParameters_hasRequiredParameter() { 110 void test_addFieldFormalParameters_hasRequiredParameter() {
109 resolveTestUnit(''' 111 resolveTestUnit('''
110 class Test { 112 class Test {
111 final int a; 113 final int a;
112 final int b; 114 final int b;
113 final int c; 115 final int c;
114 Test(this.a); 116 Test(this.a);
115 } 117 }
116 '''); 118 ''');
117 assertHasFix(DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, ''' 119 assertHasFix(
120 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS,
121 '''
118 class Test { 122 class Test {
119 final int a; 123 final int a;
120 final int b; 124 final int b;
121 final int c; 125 final int c;
122 Test(this.a, this.b, this.c); 126 Test(this.a, this.b, this.c);
123 } 127 }
124 '''); 128 ''');
125 } 129 }
126 130
127 void test_addFieldFormalParameters_noParameters() { 131 void test_addFieldFormalParameters_noParameters() {
128 resolveTestUnit(''' 132 resolveTestUnit('''
129 class Test { 133 class Test {
130 final int a; 134 final int a;
131 final int b; 135 final int b;
132 final int c; 136 final int c;
133 Test(); 137 Test();
134 } 138 }
135 '''); 139 ''');
136 assertHasFix(DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, ''' 140 assertHasFix(
141 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS,
142 '''
137 class Test { 143 class Test {
138 final int a; 144 final int a;
139 final int b; 145 final int b;
140 final int c; 146 final int c;
141 Test(this.a, this.b, this.c); 147 Test(this.a, this.b, this.c);
142 } 148 }
143 '''); 149 ''');
144 } 150 }
145 151
146 void test_addFieldFormalParameters_noRequiredParameter() { 152 void test_addFieldFormalParameters_noRequiredParameter() {
147 resolveTestUnit(''' 153 resolveTestUnit('''
148 class Test { 154 class Test {
149 final int a; 155 final int a;
150 final int b; 156 final int b;
151 final int c; 157 final int c;
152 Test([this.c]); 158 Test([this.c]);
153 } 159 }
154 '''); 160 ''');
155 assertHasFix(DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, ''' 161 assertHasFix(
162 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS,
163 '''
156 class Test { 164 class Test {
157 final int a; 165 final int a;
158 final int b; 166 final int b;
159 final int c; 167 final int c;
160 Test(this.a, this.b, [this.c]); 168 Test(this.a, this.b, [this.c]);
161 } 169 }
162 '''); 170 ''');
163 } 171 }
164 172
165 void test_addMissingParameter_function_positional_hasZero() { 173 void test_addMissingParameter_function_positional_hasZero() {
166 resolveTestUnit(''' 174 resolveTestUnit('''
167 test() {} 175 test() {}
168 main() { 176 main() {
169 test(1); 177 test(1);
170 } 178 }
171 '''); 179 ''');
172 assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, ''' 180 assertHasFix(
181 DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL,
182 '''
173 test([int i]) {} 183 test([int i]) {}
174 main() { 184 main() {
175 test(1); 185 test(1);
176 } 186 }
177 '''); 187 ''');
178 } 188 }
179 189
180 void test_addMissingParameter_function_required_hasOne() { 190 void test_addMissingParameter_function_required_hasOne() {
181 resolveTestUnit(''' 191 resolveTestUnit('''
182 test(int a) {} 192 test(int a) {}
183 main() { 193 main() {
184 test(1, 2.0); 194 test(1, 2.0);
185 } 195 }
186 '''); 196 ''');
187 assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' 197 assertHasFix(
198 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED,
199 '''
188 test(int a, double d) {} 200 test(int a, double d) {}
189 main() { 201 main() {
190 test(1, 2.0); 202 test(1, 2.0);
191 } 203 }
192 '''); 204 ''');
193 } 205 }
194 206
195 void test_addMissingParameter_function_required_hasZero() { 207 void test_addMissingParameter_function_required_hasZero() {
196 resolveTestUnit(''' 208 resolveTestUnit('''
197 test() {} 209 test() {}
198 main() { 210 main() {
199 test(1); 211 test(1);
200 } 212 }
201 '''); 213 ''');
202 assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' 214 assertHasFix(
215 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED,
216 '''
203 test(int i) {} 217 test(int i) {}
204 main() { 218 main() {
205 test(1); 219 test(1);
206 } 220 }
207 '''); 221 ''');
208 } 222 }
209 223
210 void test_addMissingParameter_method_positional_hasOne() { 224 void test_addMissingParameter_method_positional_hasOne() {
211 resolveTestUnit(''' 225 resolveTestUnit('''
212 class A { 226 class A {
213 test(int a) {} 227 test(int a) {}
214 main() { 228 main() {
215 test(1, 2.0); 229 test(1, 2.0);
216 } 230 }
217 } 231 }
218 '''); 232 ''');
219 assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, ''' 233 assertHasFix(
234 DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL,
235 '''
220 class A { 236 class A {
221 test(int a, [double d]) {} 237 test(int a, [double d]) {}
222 main() { 238 main() {
223 test(1, 2.0); 239 test(1, 2.0);
224 } 240 }
225 } 241 }
226 '''); 242 ''');
227 } 243 }
228 244
229 void test_addMissingParameter_method_required_hasOne() { 245 void test_addMissingParameter_method_required_hasOne() {
230 resolveTestUnit(''' 246 resolveTestUnit('''
231 class A { 247 class A {
232 test(int a) {} 248 test(int a) {}
233 main() { 249 main() {
234 test(1, 2.0); 250 test(1, 2.0);
235 } 251 }
236 } 252 }
237 '''); 253 ''');
238 assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' 254 assertHasFix(
255 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED,
256 '''
239 class A { 257 class A {
240 test(int a, double d) {} 258 test(int a, double d) {}
241 main() { 259 main() {
242 test(1, 2.0); 260 test(1, 2.0);
243 } 261 }
244 } 262 }
245 '''); 263 ''');
246 } 264 }
247 265
248 void test_addMissingParameter_method_required_hasZero() { 266 void test_addMissingParameter_method_required_hasZero() {
249 resolveTestUnit(''' 267 resolveTestUnit('''
250 class A { 268 class A {
251 test() {} 269 test() {}
252 main() { 270 main() {
253 test(1); 271 test(1);
254 } 272 }
255 } 273 }
256 '''); 274 ''');
257 assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' 275 assertHasFix(
276 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED,
277 '''
258 class A { 278 class A {
259 test(int i) {} 279 test(int i) {}
260 main() { 280 main() {
261 test(1); 281 test(1);
262 } 282 }
263 } 283 }
264 '''); 284 ''');
265 } 285 }
266 286
267 void test_addPartOfDirective() { 287 void test_addPartOfDirective() {
(...skipping 10 matching lines...) Expand all
278 '''); 298 ''');
279 _performAnalysis(); 299 _performAnalysis();
280 AnalysisError error = _findErrorToFix(); 300 AnalysisError error = _findErrorToFix();
281 fix = _assertHasFix(DartFixKind.ADD_PART_OF, error); 301 fix = _assertHasFix(DartFixKind.ADD_PART_OF, error);
282 change = fix.change; 302 change = fix.change;
283 // apply to "file" 303 // apply to "file"
284 List<SourceFileEdit> fileEdits = change.edits; 304 List<SourceFileEdit> fileEdits = change.edits;
285 expect(fileEdits, hasLength(1)); 305 expect(fileEdits, hasLength(1));
286 SourceFileEdit fileEdit = change.edits[0]; 306 SourceFileEdit fileEdit = change.edits[0];
287 expect(fileEdit.file, '/part.dart'); 307 expect(fileEdit.file, '/part.dart');
288 expect(SourceEdit.applySequence(partCode, fileEdit.edits), r''' 308 expect(
309 SourceEdit.applySequence(partCode, fileEdit.edits),
310 r'''
289 // Comment first. 311 // Comment first.
290 // Comment second. 312 // Comment second.
291 313
292 part of my.lib; 314 part of my.lib;
293 315
294 class A {} 316 class A {}
295 '''); 317 ''');
296 } 318 }
297 319
298 void test_addSync_BAD_nullFunctionBody() { 320 void test_addSync_BAD_nullFunctionBody() {
(...skipping 26 matching lines...) Expand all
325 List<Fix> fixes = _computeFixes(error); 347 List<Fix> fixes = _computeFixes(error);
326 // has exactly one fix 348 // has exactly one fix
327 expect(fixes, hasLength(1)); 349 expect(fixes, hasLength(1));
328 Fix fix = fixes[0]; 350 Fix fix = fixes[0];
329 expect(fix.kind, DartFixKind.ADD_ASYNC); 351 expect(fix.kind, DartFixKind.ADD_ASYNC);
330 // apply to "file" 352 // apply to "file"
331 List<SourceFileEdit> fileEdits = fix.change.edits; 353 List<SourceFileEdit> fileEdits = fix.change.edits;
332 expect(fileEdits, hasLength(1)); 354 expect(fileEdits, hasLength(1));
333 resultCode = SourceEdit.applySequence(testCode, fileEdits[0].edits); 355 resultCode = SourceEdit.applySequence(testCode, fileEdits[0].edits);
334 // verify 356 // verify
335 expect(resultCode, ''' 357 expect(
358 resultCode,
359 '''
336 foo() {} 360 foo() {}
337 main() async { 361 main() async {
338 await foo(); 362 await foo();
339 } 363 }
340 '''); 364 ''');
341 } 365 }
342 } 366 }
343 367
344 void test_addSync_expressionFunctionBody() { 368 void test_addSync_expressionFunctionBody() {
345 errorFilter = (AnalysisError error) { 369 errorFilter = (AnalysisError error) {
346 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; 370 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER;
347 }; 371 };
348 resolveTestUnit(''' 372 resolveTestUnit('''
349 foo() {} 373 foo() {}
350 main() => await foo(); 374 main() => await foo();
351 '''); 375 ''');
352 assertHasFix(DartFixKind.ADD_ASYNC, ''' 376 assertHasFix(
377 DartFixKind.ADD_ASYNC,
378 '''
353 foo() {} 379 foo() {}
354 main() async => await foo(); 380 main() async => await foo();
355 '''); 381 ''');
356 } 382 }
357 383
358 void test_boolean() { 384 void test_boolean() {
359 resolveTestUnit(''' 385 resolveTestUnit('''
360 main() { 386 main() {
361 boolean v; 387 boolean v;
362 } 388 }
363 '''); 389 ''');
364 assertHasFix(DartFixKind.REPLACE_BOOLEAN_WITH_BOOL, ''' 390 assertHasFix(
391 DartFixKind.REPLACE_BOOLEAN_WITH_BOOL,
392 '''
365 main() { 393 main() {
366 bool v; 394 bool v;
367 } 395 }
368 '''); 396 ''');
369 } 397 }
370 398
371 void test_changeToStaticAccess_method() { 399 void test_changeToStaticAccess_method() {
372 resolveTestUnit(''' 400 resolveTestUnit('''
373 class A { 401 class A {
374 static foo() {} 402 static foo() {}
375 } 403 }
376 main(A a) { 404 main(A a) {
377 a.foo(); 405 a.foo();
378 } 406 }
379 '''); 407 ''');
380 assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, ''' 408 assertHasFix(
409 DartFixKind.CHANGE_TO_STATIC_ACCESS,
410 '''
381 class A { 411 class A {
382 static foo() {} 412 static foo() {}
383 } 413 }
384 main(A a) { 414 main(A a) {
385 A.foo(); 415 A.foo();
386 } 416 }
387 '''); 417 ''');
388 } 418 }
389 419
390 void test_changeToStaticAccess_method_importType() { 420 void test_changeToStaticAccess_method_importType() {
391 addSource('/libA.dart', r''' 421 addSource(
422 '/libA.dart',
423 r'''
392 library libA; 424 library libA;
393 class A { 425 class A {
394 static foo() {} 426 static foo() {}
395 } 427 }
396 '''); 428 ''');
397 addSource('/libB.dart', r''' 429 addSource(
430 '/libB.dart',
431 r'''
398 library libB; 432 library libB;
399 import 'libA.dart'; 433 import 'libA.dart';
400 class B extends A {} 434 class B extends A {}
401 '''); 435 ''');
402 resolveTestUnit(''' 436 resolveTestUnit('''
403 import 'libB.dart'; 437 import 'libB.dart';
404 main(B b) { 438 main(B b) {
405 b.foo(); 439 b.foo();
406 } 440 }
407 '''); 441 ''');
408 assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, ''' 442 assertHasFix(
443 DartFixKind.CHANGE_TO_STATIC_ACCESS,
444 '''
409 import 'libB.dart'; 445 import 'libB.dart';
410 import 'libA.dart'; 446 import 'libA.dart';
411 main(B b) { 447 main(B b) {
412 A.foo(); 448 A.foo();
413 } 449 }
414 '''); 450 ''');
415 } 451 }
416 452
417 void test_changeToStaticAccess_method_prefixLibrary() { 453 void test_changeToStaticAccess_method_prefixLibrary() {
418 resolveTestUnit(''' 454 resolveTestUnit('''
419 import 'dart:async' as pref; 455 import 'dart:async' as pref;
420 main(pref.Future f) { 456 main(pref.Future f) {
421 f.wait([]); 457 f.wait([]);
422 } 458 }
423 '''); 459 ''');
424 assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, ''' 460 assertHasFix(
461 DartFixKind.CHANGE_TO_STATIC_ACCESS,
462 '''
425 import 'dart:async' as pref; 463 import 'dart:async' as pref;
426 main(pref.Future f) { 464 main(pref.Future f) {
427 pref.Future.wait([]); 465 pref.Future.wait([]);
428 } 466 }
429 '''); 467 ''');
430 } 468 }
431 469
432 void test_changeToStaticAccess_property() { 470 void test_changeToStaticAccess_property() {
433 resolveTestUnit(''' 471 resolveTestUnit('''
434 class A { 472 class A {
435 static get foo => 42; 473 static get foo => 42;
436 } 474 }
437 main(A a) { 475 main(A a) {
438 a.foo; 476 a.foo;
439 } 477 }
440 '''); 478 ''');
441 assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, ''' 479 assertHasFix(
480 DartFixKind.CHANGE_TO_STATIC_ACCESS,
481 '''
442 class A { 482 class A {
443 static get foo => 42; 483 static get foo => 42;
444 } 484 }
445 main(A a) { 485 main(A a) {
446 A.foo; 486 A.foo;
447 } 487 }
448 '''); 488 ''');
449 } 489 }
450 490
451 void test_changeToStaticAccess_property_importType() { 491 void test_changeToStaticAccess_property_importType() {
452 addSource('/libA.dart', r''' 492 addSource(
493 '/libA.dart',
494 r'''
453 library libA; 495 library libA;
454 class A { 496 class A {
455 static get foo => null; 497 static get foo => null;
456 } 498 }
457 '''); 499 ''');
458 addSource('/libB.dart', r''' 500 addSource(
501 '/libB.dart',
502 r'''
459 library libB; 503 library libB;
460 import 'libA.dart'; 504 import 'libA.dart';
461 class B extends A {} 505 class B extends A {}
462 '''); 506 ''');
463 resolveTestUnit(''' 507 resolveTestUnit('''
464 import 'libB.dart'; 508 import 'libB.dart';
465 main(B b) { 509 main(B b) {
466 b.foo; 510 b.foo;
467 } 511 }
468 '''); 512 ''');
469 assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, ''' 513 assertHasFix(
514 DartFixKind.CHANGE_TO_STATIC_ACCESS,
515 '''
470 import 'libB.dart'; 516 import 'libB.dart';
471 import 'libA.dart'; 517 import 'libA.dart';
472 main(B b) { 518 main(B b) {
473 A.foo; 519 A.foo;
474 } 520 }
475 '''); 521 ''');
476 } 522 }
477 523
478 void test_createClass() { 524 void test_createClass() {
479 resolveTestUnit(''' 525 resolveTestUnit('''
480 main() { 526 main() {
481 Test v = null; 527 Test v = null;
482 } 528 }
483 '''); 529 ''');
484 assertHasFix(DartFixKind.CREATE_CLASS, ''' 530 assertHasFix(
531 DartFixKind.CREATE_CLASS,
532 '''
485 main() { 533 main() {
486 Test v = null; 534 Test v = null;
487 } 535 }
488 536
489 class Test { 537 class Test {
490 } 538 }
491 '''); 539 ''');
492 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); 540 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']);
493 } 541 }
494 542
(...skipping 13 matching lines...) Expand all
508 } 556 }
509 '''); 557 ''');
510 AnalysisError error = _findErrorToFix(); 558 AnalysisError error = _findErrorToFix();
511 fix = _assertHasFix(DartFixKind.CREATE_CLASS, error); 559 fix = _assertHasFix(DartFixKind.CREATE_CLASS, error);
512 change = fix.change; 560 change = fix.change;
513 // apply to "lib.dart" 561 // apply to "lib.dart"
514 List<SourceFileEdit> fileEdits = change.edits; 562 List<SourceFileEdit> fileEdits = change.edits;
515 expect(fileEdits, hasLength(1)); 563 expect(fileEdits, hasLength(1));
516 SourceFileEdit fileEdit = change.edits[0]; 564 SourceFileEdit fileEdit = change.edits[0];
517 expect(fileEdit.file, '/lib.dart'); 565 expect(fileEdit.file, '/lib.dart');
518 expect(SourceEdit.applySequence(libCode, fileEdit.edits), r''' 566 expect(
567 SourceEdit.applySequence(libCode, fileEdit.edits),
568 r'''
519 library my.lib; 569 library my.lib;
520 570
521 class A {} 571 class A {}
522 572
523 class Test { 573 class Test {
524 } 574 }
525 '''); 575 ''');
526 expect(change.linkedEditGroups, isEmpty); 576 expect(change.linkedEditGroups, isEmpty);
527 } 577 }
528 578
529 void test_createClass_innerLocalFunction() { 579 void test_createClass_innerLocalFunction() {
530 resolveTestUnit(''' 580 resolveTestUnit('''
531 f() { 581 f() {
532 g() { 582 g() {
533 Test v = null; 583 Test v = null;
534 } 584 }
535 } 585 }
536 '''); 586 ''');
537 assertHasFix(DartFixKind.CREATE_CLASS, ''' 587 assertHasFix(
588 DartFixKind.CREATE_CLASS,
589 '''
538 f() { 590 f() {
539 g() { 591 g() {
540 Test v = null; 592 Test v = null;
541 } 593 }
542 } 594 }
543 595
544 class Test { 596 class Test {
545 } 597 }
546 '''); 598 ''');
547 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); 599 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']);
548 } 600 }
549 601
602 void test_createClass_itemOfList() {
603 resolveTestUnit('''
604 main() {
605 var a = [Test];
606 }
607 ''');
608 assertHasFix(
609 DartFixKind.CREATE_CLASS,
610 '''
611 main() {
612 var a = [Test];
613 }
614
615 class Test {
616 }
617 ''');
618 _assertLinkedGroup(change.linkedEditGroups[0], ['Test];', 'Test {']);
619 }
620
621 void test_createClass_itemOfList_inAnnotation() {
622 errorFilter = (AnalysisError error) {
623 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER;
624 };
625 resolveTestUnit('''
626 class MyAnnotation {
627 const MyAnnotation(a, b);
628 }
629 @MyAnnotation(int, const [Test])
630 main() {}
631 ''');
632 assertHasFix(
633 DartFixKind.CREATE_CLASS,
634 '''
635 class MyAnnotation {
636 const MyAnnotation(a, b);
637 }
638 @MyAnnotation(int, const [Test])
639 main() {}
640
641 class Test {
642 }
643 ''');
644 _assertLinkedGroup(change.linkedEditGroups[0], ['Test])', 'Test {']);
645 }
646
550 void test_createConstructor_forFinalFields() { 647 void test_createConstructor_forFinalFields() {
551 errorFilter = (AnalysisError error) { 648 errorFilter = (AnalysisError error) {
552 return error.message.contains("'a'"); 649 return error.message.contains("'a'");
553 }; 650 };
554 resolveTestUnit(''' 651 resolveTestUnit('''
555 class Test { 652 class Test {
556 final int a; 653 final int a;
557 final int b = 2; 654 final int b = 2;
558 final int c; 655 final int c;
559 } 656 }
560 '''); 657 ''');
561 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS, ''' 658 assertHasFix(
659 DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS,
660 '''
562 class Test { 661 class Test {
563 final int a; 662 final int a;
564 final int b = 2; 663 final int b = 2;
565 final int c; 664 final int c;
566 665
567 Test(this.a, this.c); 666 Test(this.a, this.c);
568 } 667 }
569 '''); 668 ''');
570 } 669 }
571 670
572 void test_createConstructor_insteadOfSyntheticDefault() { 671 void test_createConstructor_insteadOfSyntheticDefault() {
573 resolveTestUnit(''' 672 resolveTestUnit('''
574 class A { 673 class A {
575 int field; 674 int field;
576 675
577 method() {} 676 method() {}
578 } 677 }
579 main() { 678 main() {
580 new A(1, 2.0); 679 new A(1, 2.0);
581 } 680 }
582 '''); 681 ''');
583 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR, ''' 682 assertHasFix(
683 DartFixKind.CREATE_CONSTRUCTOR,
684 '''
584 class A { 685 class A {
585 int field; 686 int field;
586 687
587 A(int i, double d) { 688 A(int i, double d) {
588 } 689 }
589 690
590 method() {} 691 method() {}
591 } 692 }
592 main() { 693 main() {
593 new A(1, 2.0); 694 new A(1, 2.0);
594 } 695 }
595 '''); 696 ''');
596 } 697 }
597 698
598 void test_createConstructor_named() { 699 void test_createConstructor_named() {
599 resolveTestUnit(''' 700 resolveTestUnit('''
600 class A { 701 class A {
601 method() {} 702 method() {}
602 } 703 }
603 main() { 704 main() {
604 new A.named(1, 2.0); 705 new A.named(1, 2.0);
605 } 706 }
606 '''); 707 ''');
607 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR, ''' 708 assertHasFix(
709 DartFixKind.CREATE_CONSTRUCTOR,
710 '''
608 class A { 711 class A {
609 A.named(int i, double d) { 712 A.named(int i, double d) {
610 } 713 }
611 714
612 method() {} 715 method() {}
613 } 716 }
614 main() { 717 main() {
615 new A.named(1, 2.0); 718 new A.named(1, 2.0);
616 } 719 }
617 '''); 720 ''');
(...skipping 18 matching lines...) Expand all
636 739
637 void test_createConstructorSuperExplicit() { 740 void test_createConstructorSuperExplicit() {
638 resolveTestUnit(''' 741 resolveTestUnit('''
639 class A { 742 class A {
640 A(bool p1, int p2, double p3, String p4, {p5}); 743 A(bool p1, int p2, double p3, String p4, {p5});
641 } 744 }
642 class B extends A { 745 class B extends A {
643 B() {} 746 B() {}
644 } 747 }
645 '''); 748 ''');
646 assertHasFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' 749 assertHasFix(
750 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION,
751 '''
647 class A { 752 class A {
648 A(bool p1, int p2, double p3, String p4, {p5}); 753 A(bool p1, int p2, double p3, String p4, {p5});
649 } 754 }
650 class B extends A { 755 class B extends A {
651 B() : super(false, 0, 0.0, '') {} 756 B() : super(false, 0, 0.0, '') {}
652 } 757 }
653 '''); 758 ''');
654 } 759 }
655 760
656 void test_createConstructorSuperExplicit_hasInitializers() { 761 void test_createConstructorSuperExplicit_hasInitializers() {
657 resolveTestUnit(''' 762 resolveTestUnit('''
658 class A { 763 class A {
659 A(int p); 764 A(int p);
660 } 765 }
661 class B extends A { 766 class B extends A {
662 int field; 767 int field;
663 B() : field = 42 {} 768 B() : field = 42 {}
664 } 769 }
665 '''); 770 ''');
666 assertHasFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' 771 assertHasFix(
772 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION,
773 '''
667 class A { 774 class A {
668 A(int p); 775 A(int p);
669 } 776 }
670 class B extends A { 777 class B extends A {
671 int field; 778 int field;
672 B() : field = 42, super(0) {} 779 B() : field = 42, super(0) {}
673 } 780 }
674 '''); 781 ''');
675 } 782 }
676 783
677 void test_createConstructorSuperExplicit_named() { 784 void test_createConstructorSuperExplicit_named() {
678 resolveTestUnit(''' 785 resolveTestUnit('''
679 class A { 786 class A {
680 A.named(int p); 787 A.named(int p);
681 } 788 }
682 class B extends A { 789 class B extends A {
683 B() {} 790 B() {}
684 } 791 }
685 '''); 792 ''');
686 assertHasFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' 793 assertHasFix(
794 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION,
795 '''
687 class A { 796 class A {
688 A.named(int p); 797 A.named(int p);
689 } 798 }
690 class B extends A { 799 class B extends A {
691 B() : super.named(0) {} 800 B() : super.named(0) {}
692 } 801 }
693 '''); 802 ''');
694 } 803 }
695 804
696 void test_createConstructorSuperExplicit_named_private() { 805 void test_createConstructorSuperExplicit_named_private() {
(...skipping 10 matching lines...) Expand all
707 816
708 void test_createConstructorSuperExplicit_typeArgument() { 817 void test_createConstructorSuperExplicit_typeArgument() {
709 resolveTestUnit(''' 818 resolveTestUnit('''
710 class A<T> { 819 class A<T> {
711 A(T p); 820 A(T p);
712 } 821 }
713 class B extends A<int> { 822 class B extends A<int> {
714 B(); 823 B();
715 } 824 }
716 '''); 825 ''');
717 assertHasFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' 826 assertHasFix(
827 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION,
828 '''
718 class A<T> { 829 class A<T> {
719 A(T p); 830 A(T p);
720 } 831 }
721 class B extends A<int> { 832 class B extends A<int> {
722 B() : super(0); 833 B() : super(0);
723 } 834 }
724 '''); 835 ''');
725 } 836 }
726 837
727 void test_createConstructorSuperImplicit() { 838 void test_createConstructorSuperImplicit() {
728 resolveTestUnit(''' 839 resolveTestUnit('''
729 class A { 840 class A {
730 A(p1, int p2, List<String> p3, [int p4]); 841 A(p1, int p2, List<String> p3, [int p4]);
731 } 842 }
732 class B extends A { 843 class B extends A {
733 int existingField; 844 int existingField;
734 845
735 void existingMethod() {} 846 void existingMethod() {}
736 } 847 }
737 '''); 848 ''');
738 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, ''' 849 assertHasFix(
850 DartFixKind.CREATE_CONSTRUCTOR_SUPER,
851 '''
739 class A { 852 class A {
740 A(p1, int p2, List<String> p3, [int p4]); 853 A(p1, int p2, List<String> p3, [int p4]);
741 } 854 }
742 class B extends A { 855 class B extends A {
743 int existingField; 856 int existingField;
744 857
745 B(p1, int p2, List<String> p3) : super(p1, p2, p3); 858 B(p1, int p2, List<String> p3) : super(p1, p2, p3);
746 859
747 void existingMethod() {} 860 void existingMethod() {}
748 } 861 }
749 '''); 862 ''');
750 } 863 }
751 864
752 void test_createConstructorSuperImplicit_fieldInitializer() { 865 void test_createConstructorSuperImplicit_fieldInitializer() {
753 resolveTestUnit(''' 866 resolveTestUnit('''
754 class A { 867 class A {
755 int _field; 868 int _field;
756 A(this._field); 869 A(this._field);
757 } 870 }
758 class B extends A { 871 class B extends A {
759 int existingField; 872 int existingField;
760 873
761 void existingMethod() {} 874 void existingMethod() {}
762 } 875 }
763 '''); 876 ''');
764 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, ''' 877 assertHasFix(
878 DartFixKind.CREATE_CONSTRUCTOR_SUPER,
879 '''
765 class A { 880 class A {
766 int _field; 881 int _field;
767 A(this._field); 882 A(this._field);
768 } 883 }
769 class B extends A { 884 class B extends A {
770 int existingField; 885 int existingField;
771 886
772 B(int field) : super(field); 887 B(int field) : super(field);
773 888
774 void existingMethod() {} 889 void existingMethod() {}
775 } 890 }
776 '''); 891 ''');
777 } 892 }
778 893
779 void test_createConstructorSuperImplicit_importType() { 894 void test_createConstructorSuperImplicit_importType() {
780 addSource('/libA.dart', r''' 895 addSource(
896 '/libA.dart',
897 r'''
781 library libA; 898 library libA;
782 class A {} 899 class A {}
783 '''); 900 ''');
784 addSource('/libB.dart', r''' 901 addSource(
902 '/libB.dart',
903 r'''
785 library libB; 904 library libB;
786 import 'libA.dart'; 905 import 'libA.dart';
787 class B { 906 class B {
788 B(A a); 907 B(A a);
789 } 908 }
790 '''); 909 ''');
791 resolveTestUnit(''' 910 resolveTestUnit('''
792 import 'libB.dart'; 911 import 'libB.dart';
793 class C extends B { 912 class C extends B {
794 } 913 }
795 '''); 914 ''');
796 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, ''' 915 assertHasFix(
916 DartFixKind.CREATE_CONSTRUCTOR_SUPER,
917 '''
797 import 'libB.dart'; 918 import 'libB.dart';
798 import 'libA.dart'; 919 import 'libA.dart';
799 class C extends B { 920 class C extends B {
800 C(A a) : super(a); 921 C(A a) : super(a);
801 } 922 }
802 '''); 923 ''');
803 } 924 }
804 925
805 void test_createConstructorSuperImplicit_named() { 926 void test_createConstructorSuperImplicit_named() {
806 resolveTestUnit(''' 927 resolveTestUnit('''
807 class A { 928 class A {
808 A.named(p1, int p2); 929 A.named(p1, int p2);
809 } 930 }
810 class B extends A { 931 class B extends A {
811 int existingField; 932 int existingField;
812 933
813 void existingMethod() {} 934 void existingMethod() {}
814 } 935 }
815 '''); 936 ''');
816 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, ''' 937 assertHasFix(
938 DartFixKind.CREATE_CONSTRUCTOR_SUPER,
939 '''
817 class A { 940 class A {
818 A.named(p1, int p2); 941 A.named(p1, int p2);
819 } 942 }
820 class B extends A { 943 class B extends A {
821 int existingField; 944 int existingField;
822 945
823 B.named(p1, int p2) : super.named(p1, p2); 946 B.named(p1, int p2) : super.named(p1, p2);
824 947
825 void existingMethod() {} 948 void existingMethod() {}
826 } 949 }
(...skipping 12 matching lines...) Expand all
839 } 962 }
840 963
841 void test_createConstructorSuperImplicit_typeArgument() { 964 void test_createConstructorSuperImplicit_typeArgument() {
842 resolveTestUnit(''' 965 resolveTestUnit('''
843 class C<T> { 966 class C<T> {
844 final T x; 967 final T x;
845 C(this.x); 968 C(this.x);
846 } 969 }
847 class D extends C<int> { 970 class D extends C<int> {
848 }'''); 971 }''');
849 assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, ''' 972 assertHasFix(
973 DartFixKind.CREATE_CONSTRUCTOR_SUPER,
974 '''
850 class C<T> { 975 class C<T> {
851 final T x; 976 final T x;
852 C(this.x); 977 C(this.x);
853 } 978 }
854 class D extends C<int> { 979 class D extends C<int> {
855 D(int x) : super(x); 980 D(int x) : super(x);
856 }'''); 981 }''');
857 } 982 }
858 983
859 void test_createField_BAD_inEnum() { 984 void test_createField_BAD_inEnum() {
(...skipping 24 matching lines...) Expand all
884 class B { 1009 class B {
885 A a; 1010 A a;
886 } 1011 }
887 class C { 1012 class C {
888 B b; 1013 B b;
889 } 1014 }
890 main(C c) { 1015 main(C c) {
891 int v = c.b.a.test; 1016 int v = c.b.a.test;
892 } 1017 }
893 '''); 1018 ''');
894 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1019 assertHasFix(
1020 DartFixKind.CREATE_FIELD,
1021 '''
895 class A { 1022 class A {
896 int test; 1023 int test;
897 } 1024 }
898 class B { 1025 class B {
899 A a; 1026 A a;
900 } 1027 }
901 class C { 1028 class C {
902 B b; 1029 B b;
903 } 1030 }
904 main(C c) { 1031 main(C c) {
905 int v = c.b.a.test; 1032 int v = c.b.a.test;
906 } 1033 }
907 '''); 1034 ''');
908 } 1035 }
909 1036
910 void test_createField_getter_qualified_instance() { 1037 void test_createField_getter_qualified_instance() {
911 resolveTestUnit(''' 1038 resolveTestUnit('''
912 class A { 1039 class A {
913 } 1040 }
914 main(A a) { 1041 main(A a) {
915 int v = a.test; 1042 int v = a.test;
916 } 1043 }
917 '''); 1044 ''');
918 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1045 assertHasFix(
1046 DartFixKind.CREATE_FIELD,
1047 '''
919 class A { 1048 class A {
920 int test; 1049 int test;
921 } 1050 }
922 main(A a) { 1051 main(A a) {
923 int v = a.test; 1052 int v = a.test;
924 } 1053 }
925 '''); 1054 ''');
926 } 1055 }
927 1056
928 void test_createField_getter_qualified_instance_dynamicType() { 1057 void test_createField_getter_qualified_instance_dynamicType() {
929 resolveTestUnit(''' 1058 resolveTestUnit('''
930 class A { 1059 class A {
931 B b; 1060 B b;
932 void f(Object p) { 1061 void f(Object p) {
933 p == b.test; 1062 p == b.test;
934 } 1063 }
935 } 1064 }
936 class B { 1065 class B {
937 } 1066 }
938 '''); 1067 ''');
939 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1068 assertHasFix(
1069 DartFixKind.CREATE_FIELD,
1070 '''
940 class A { 1071 class A {
941 B b; 1072 B b;
942 void f(Object p) { 1073 void f(Object p) {
943 p == b.test; 1074 p == b.test;
944 } 1075 }
945 } 1076 }
946 class B { 1077 class B {
947 var test; 1078 var test;
948 } 1079 }
949 '''); 1080 ''');
950 } 1081 }
951 1082
952 void test_createField_getter_unqualified_instance_asInvocationArgument() { 1083 void test_createField_getter_unqualified_instance_asInvocationArgument() {
953 resolveTestUnit(''' 1084 resolveTestUnit('''
954 class A { 1085 class A {
955 main() { 1086 main() {
956 f(test); 1087 f(test);
957 } 1088 }
958 } 1089 }
959 f(String s) {} 1090 f(String s) {}
960 '''); 1091 ''');
961 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1092 assertHasFix(
1093 DartFixKind.CREATE_FIELD,
1094 '''
962 class A { 1095 class A {
963 String test; 1096 String test;
964 1097
965 main() { 1098 main() {
966 f(test); 1099 f(test);
967 } 1100 }
968 } 1101 }
969 f(String s) {} 1102 f(String s) {}
970 '''); 1103 ''');
971 } 1104 }
972 1105
973 void test_createField_getter_unqualified_instance_assignmentRhs() { 1106 void test_createField_getter_unqualified_instance_assignmentRhs() {
974 resolveTestUnit(''' 1107 resolveTestUnit('''
975 class A { 1108 class A {
976 main() { 1109 main() {
977 int v = test; 1110 int v = test;
978 } 1111 }
979 } 1112 }
980 '''); 1113 ''');
981 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1114 assertHasFix(
1115 DartFixKind.CREATE_FIELD,
1116 '''
982 class A { 1117 class A {
983 int test; 1118 int test;
984 1119
985 main() { 1120 main() {
986 int v = test; 1121 int v = test;
987 } 1122 }
988 } 1123 }
989 '''); 1124 ''');
990 } 1125 }
991 1126
992 void test_createField_getter_unqualified_instance_asStatement() { 1127 void test_createField_getter_unqualified_instance_asStatement() {
993 resolveTestUnit(''' 1128 resolveTestUnit('''
994 class A { 1129 class A {
995 main() { 1130 main() {
996 test; 1131 test;
997 } 1132 }
998 } 1133 }
999 '''); 1134 ''');
1000 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1135 assertHasFix(
1136 DartFixKind.CREATE_FIELD,
1137 '''
1001 class A { 1138 class A {
1002 var test; 1139 var test;
1003 1140
1004 main() { 1141 main() {
1005 test; 1142 test;
1006 } 1143 }
1007 } 1144 }
1008 '''); 1145 ''');
1009 } 1146 }
1010 1147
1011 void test_createField_hint() { 1148 void test_createField_hint() {
1012 resolveTestUnit(''' 1149 resolveTestUnit('''
1013 class A { 1150 class A {
1014 } 1151 }
1015 main(A a) { 1152 main(A a) {
1016 var x = a; 1153 var x = a;
1017 int v = x.test; 1154 int v = x.test;
1018 } 1155 }
1019 '''); 1156 ''');
1020 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1157 assertHasFix(
1158 DartFixKind.CREATE_FIELD,
1159 '''
1021 class A { 1160 class A {
1022 int test; 1161 int test;
1023 } 1162 }
1024 main(A a) { 1163 main(A a) {
1025 var x = a; 1164 var x = a;
1026 int v = x.test; 1165 int v = x.test;
1027 } 1166 }
1028 '''); 1167 ''');
1029 } 1168 }
1030 1169
1031 void test_createField_hint_setter() { 1170 void test_createField_hint_setter() {
1032 resolveTestUnit(''' 1171 resolveTestUnit('''
1033 class A { 1172 class A {
1034 } 1173 }
1035 main(A a) { 1174 main(A a) {
1036 var x = a; 1175 var x = a;
1037 x.test = 0; 1176 x.test = 0;
1038 } 1177 }
1039 '''); 1178 ''');
1040 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1179 assertHasFix(
1180 DartFixKind.CREATE_FIELD,
1181 '''
1041 class A { 1182 class A {
1042 int test; 1183 int test;
1043 } 1184 }
1044 main(A a) { 1185 main(A a) {
1045 var x = a; 1186 var x = a;
1046 x.test = 0; 1187 x.test = 0;
1047 } 1188 }
1048 '''); 1189 ''');
1049 } 1190 }
1050 1191
1051 void test_createField_importType() { 1192 void test_createField_importType() {
1052 addSource('/libA.dart', r''' 1193 addSource(
1194 '/libA.dart',
1195 r'''
1053 library libA; 1196 library libA;
1054 class A {} 1197 class A {}
1055 '''); 1198 ''');
1056 addSource('/libB.dart', r''' 1199 addSource(
1200 '/libB.dart',
1201 r'''
1057 library libB; 1202 library libB;
1058 import 'libA.dart'; 1203 import 'libA.dart';
1059 A getA() => null; 1204 A getA() => null;
1060 '''); 1205 ''');
1061 resolveTestUnit(''' 1206 resolveTestUnit('''
1062 import 'libB.dart'; 1207 import 'libB.dart';
1063 class C { 1208 class C {
1064 } 1209 }
1065 main(C c) { 1210 main(C c) {
1066 c.test = getA(); 1211 c.test = getA();
1067 } 1212 }
1068 '''); 1213 ''');
1069 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1214 assertHasFix(
1215 DartFixKind.CREATE_FIELD,
1216 '''
1070 import 'libB.dart'; 1217 import 'libB.dart';
1071 import 'libA.dart'; 1218 import 'libA.dart';
1072 class C { 1219 class C {
1073 A test; 1220 A test;
1074 } 1221 }
1075 main(C c) { 1222 main(C c) {
1076 c.test = getA(); 1223 c.test = getA();
1077 } 1224 }
1078 '''); 1225 ''');
1079 } 1226 }
1080 1227
1081 void test_createField_setter_generic_BAD() { 1228 void test_createField_setter_generic_BAD() {
1082 resolveTestUnit(''' 1229 resolveTestUnit('''
1083 class A { 1230 class A {
1084 } 1231 }
1085 class B<T> { 1232 class B<T> {
1086 List<T> items; 1233 List<T> items;
1087 main(A a) { 1234 main(A a) {
1088 a.test = items; 1235 a.test = items;
1089 } 1236 }
1090 } 1237 }
1091 '''); 1238 ''');
1092 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1239 assertHasFix(
1240 DartFixKind.CREATE_FIELD,
1241 '''
1093 class A { 1242 class A {
1094 List test; 1243 List test;
1095 } 1244 }
1096 class B<T> { 1245 class B<T> {
1097 List<T> items; 1246 List<T> items;
1098 main(A a) { 1247 main(A a) {
1099 a.test = items; 1248 a.test = items;
1100 } 1249 }
1101 } 1250 }
1102 '''); 1251 ''');
1103 } 1252 }
1104 1253
1105 void test_createField_setter_generic_OK_local() { 1254 void test_createField_setter_generic_OK_local() {
1106 resolveTestUnit(''' 1255 resolveTestUnit('''
1107 class A<T> { 1256 class A<T> {
1108 List<T> items; 1257 List<T> items;
1109 1258
1110 main(A a) { 1259 main(A a) {
1111 test = items; 1260 test = items;
1112 } 1261 }
1113 } 1262 }
1114 '''); 1263 ''');
1115 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1264 assertHasFix(
1265 DartFixKind.CREATE_FIELD,
1266 '''
1116 class A<T> { 1267 class A<T> {
1117 List<T> items; 1268 List<T> items;
1118 1269
1119 List<T> test; 1270 List<T> test;
1120 1271
1121 main(A a) { 1272 main(A a) {
1122 test = items; 1273 test = items;
1123 } 1274 }
1124 } 1275 }
1125 '''); 1276 ''');
1126 } 1277 }
1127 1278
1128 void test_createField_setter_qualified_instance_hasField() { 1279 void test_createField_setter_qualified_instance_hasField() {
1129 resolveTestUnit(''' 1280 resolveTestUnit('''
1130 class A { 1281 class A {
1131 int aaa; 1282 int aaa;
1132 int zzz; 1283 int zzz;
1133 1284
1134 existingMethod() {} 1285 existingMethod() {}
1135 } 1286 }
1136 main(A a) { 1287 main(A a) {
1137 a.test = 5; 1288 a.test = 5;
1138 } 1289 }
1139 '''); 1290 ''');
1140 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1291 assertHasFix(
1292 DartFixKind.CREATE_FIELD,
1293 '''
1141 class A { 1294 class A {
1142 int aaa; 1295 int aaa;
1143 int zzz; 1296 int zzz;
1144 1297
1145 int test; 1298 int test;
1146 1299
1147 existingMethod() {} 1300 existingMethod() {}
1148 } 1301 }
1149 main(A a) { 1302 main(A a) {
1150 a.test = 5; 1303 a.test = 5;
1151 } 1304 }
1152 '''); 1305 ''');
1153 } 1306 }
1154 1307
1155 void test_createField_setter_qualified_instance_hasMethod() { 1308 void test_createField_setter_qualified_instance_hasMethod() {
1156 resolveTestUnit(''' 1309 resolveTestUnit('''
1157 class A { 1310 class A {
1158 existingMethod() {} 1311 existingMethod() {}
1159 } 1312 }
1160 main(A a) { 1313 main(A a) {
1161 a.test = 5; 1314 a.test = 5;
1162 } 1315 }
1163 '''); 1316 ''');
1164 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1317 assertHasFix(
1318 DartFixKind.CREATE_FIELD,
1319 '''
1165 class A { 1320 class A {
1166 int test; 1321 int test;
1167 1322
1168 existingMethod() {} 1323 existingMethod() {}
1169 } 1324 }
1170 main(A a) { 1325 main(A a) {
1171 a.test = 5; 1326 a.test = 5;
1172 } 1327 }
1173 '''); 1328 ''');
1174 } 1329 }
1175 1330
1176 void test_createField_setter_qualified_static() { 1331 void test_createField_setter_qualified_static() {
1177 resolveTestUnit(''' 1332 resolveTestUnit('''
1178 class A { 1333 class A {
1179 } 1334 }
1180 main() { 1335 main() {
1181 A.test = 5; 1336 A.test = 5;
1182 } 1337 }
1183 '''); 1338 ''');
1184 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1339 assertHasFix(
1340 DartFixKind.CREATE_FIELD,
1341 '''
1185 class A { 1342 class A {
1186 static int test; 1343 static int test;
1187 } 1344 }
1188 main() { 1345 main() {
1189 A.test = 5; 1346 A.test = 5;
1190 } 1347 }
1191 '''); 1348 ''');
1192 } 1349 }
1193 1350
1194 void test_createField_setter_unqualified_instance() { 1351 void test_createField_setter_unqualified_instance() {
1195 resolveTestUnit(''' 1352 resolveTestUnit('''
1196 class A { 1353 class A {
1197 main() { 1354 main() {
1198 test = 5; 1355 test = 5;
1199 } 1356 }
1200 } 1357 }
1201 '''); 1358 ''');
1202 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1359 assertHasFix(
1360 DartFixKind.CREATE_FIELD,
1361 '''
1203 class A { 1362 class A {
1204 int test; 1363 int test;
1205 1364
1206 main() { 1365 main() {
1207 test = 5; 1366 test = 5;
1208 } 1367 }
1209 } 1368 }
1210 '''); 1369 ''');
1211 } 1370 }
1212 1371
1213 void test_createField_setter_unqualified_static() { 1372 void test_createField_setter_unqualified_static() {
1214 resolveTestUnit(''' 1373 resolveTestUnit('''
1215 class A { 1374 class A {
1216 static main() { 1375 static main() {
1217 test = 5; 1376 test = 5;
1218 } 1377 }
1219 } 1378 }
1220 '''); 1379 ''');
1221 assertHasFix(DartFixKind.CREATE_FIELD, ''' 1380 assertHasFix(
1381 DartFixKind.CREATE_FIELD,
1382 '''
1222 class A { 1383 class A {
1223 static int test; 1384 static int test;
1224 1385
1225 static main() { 1386 static main() {
1226 test = 5; 1387 test = 5;
1227 } 1388 }
1228 } 1389 }
1229 '''); 1390 ''');
1230 } 1391 }
1231 1392
(...skipping 28 matching lines...) Expand all
1260 List<SourceFileEdit> fileEdits = change.edits; 1421 List<SourceFileEdit> fileEdits = change.edits;
1261 expect(fileEdits, hasLength(1)); 1422 expect(fileEdits, hasLength(1));
1262 SourceFileEdit fileEdit = change.edits[0]; 1423 SourceFileEdit fileEdit = change.edits[0];
1263 expect(fileEdit.file, '/my/project/bin/my_part.dart'); 1424 expect(fileEdit.file, '/my/project/bin/my_part.dart');
1264 expect(fileEdit.fileStamp, -1); 1425 expect(fileEdit.fileStamp, -1);
1265 expect(fileEdit.edits, hasLength(1)); 1426 expect(fileEdit.edits, hasLength(1));
1266 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); 1427 expect(fileEdit.edits[0].replacement, contains('part of my.lib;'));
1267 } 1428 }
1268 1429
1269 void test_createFile_forPart_inPackageLib() { 1430 void test_createFile_forPart_inPackageLib() {
1270 provider.newFile('/my/pubspec.yaml', r''' 1431 provider.newFile(
1432 '/my/pubspec.yaml',
1433 r'''
1271 name: my_test 1434 name: my_test
1272 '''); 1435 ''');
1273 testFile = '/my/lib/test.dart'; 1436 testFile = '/my/lib/test.dart';
1274 addTestSource(''' 1437 addTestSource(
1438 '''
1275 library my.lib; 1439 library my.lib;
1276 part 'my_part.dart'; 1440 part 'my_part.dart';
1277 ''', Uri.parse('package:my/test.dart')); 1441 ''',
1442 Uri.parse('package:my/test.dart'));
1278 // configure SourceFactory 1443 // configure SourceFactory
1279 UriResolver pkgResolver = new PackageMapUriResolver( 1444 UriResolver pkgResolver = new PackageMapUriResolver(provider, {
1280 provider, {'my': [provider.getResource('/my/lib')],}); 1445 'my': [provider.getResource('/my/lib')],
1446 });
1281 context.sourceFactory = new SourceFactory( 1447 context.sourceFactory = new SourceFactory(
1282 [AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]); 1448 [AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]);
1283 // prepare fix 1449 // prepare fix
1284 testUnit = resolveLibraryUnit(testSource); 1450 testUnit = resolveLibraryUnit(testSource);
1285 AnalysisError error = _findErrorToFix(); 1451 AnalysisError error = _findErrorToFix();
1286 fix = _assertHasFix(DartFixKind.CREATE_FILE, error); 1452 fix = _assertHasFix(DartFixKind.CREATE_FILE, error);
1287 change = fix.change; 1453 change = fix.change;
1288 // validate change 1454 // validate change
1289 List<SourceFileEdit> fileEdits = change.edits; 1455 List<SourceFileEdit> fileEdits = change.edits;
1290 expect(fileEdits, hasLength(1)); 1456 expect(fileEdits, hasLength(1));
(...skipping 15 matching lines...) Expand all
1306 1472
1307 void test_createGetter_hint_getter() { 1473 void test_createGetter_hint_getter() {
1308 resolveTestUnit(''' 1474 resolveTestUnit('''
1309 class A { 1475 class A {
1310 } 1476 }
1311 main(A a) { 1477 main(A a) {
1312 var x = a; 1478 var x = a;
1313 int v = x.test; 1479 int v = x.test;
1314 } 1480 }
1315 '''); 1481 ''');
1316 assertHasFix(DartFixKind.CREATE_GETTER, ''' 1482 assertHasFix(
1483 DartFixKind.CREATE_GETTER,
1484 '''
1317 class A { 1485 class A {
1318 int get test => null; 1486 int get test => null;
1319 } 1487 }
1320 main(A a) { 1488 main(A a) {
1321 var x = a; 1489 var x = a;
1322 int v = x.test; 1490 int v = x.test;
1323 } 1491 }
1324 '''); 1492 ''');
1325 } 1493 }
1326 1494
1327 void test_createGetter_multiLevel() { 1495 void test_createGetter_multiLevel() {
1328 resolveTestUnit(''' 1496 resolveTestUnit('''
1329 class A { 1497 class A {
1330 } 1498 }
1331 class B { 1499 class B {
1332 A a; 1500 A a;
1333 } 1501 }
1334 class C { 1502 class C {
1335 B b; 1503 B b;
1336 } 1504 }
1337 main(C c) { 1505 main(C c) {
1338 int v = c.b.a.test; 1506 int v = c.b.a.test;
1339 } 1507 }
1340 '''); 1508 ''');
1341 assertHasFix(DartFixKind.CREATE_GETTER, ''' 1509 assertHasFix(
1510 DartFixKind.CREATE_GETTER,
1511 '''
1342 class A { 1512 class A {
1343 int get test => null; 1513 int get test => null;
1344 } 1514 }
1345 class B { 1515 class B {
1346 A a; 1516 A a;
1347 } 1517 }
1348 class C { 1518 class C {
1349 B b; 1519 B b;
1350 } 1520 }
1351 main(C c) { 1521 main(C c) {
1352 int v = c.b.a.test; 1522 int v = c.b.a.test;
1353 } 1523 }
1354 '''); 1524 ''');
1355 } 1525 }
1356 1526
1357 void test_createGetter_qualified_instance() { 1527 void test_createGetter_qualified_instance() {
1358 resolveTestUnit(''' 1528 resolveTestUnit('''
1359 class A { 1529 class A {
1360 } 1530 }
1361 main(A a) { 1531 main(A a) {
1362 int v = a.test; 1532 int v = a.test;
1363 } 1533 }
1364 '''); 1534 ''');
1365 assertHasFix(DartFixKind.CREATE_GETTER, ''' 1535 assertHasFix(
1536 DartFixKind.CREATE_GETTER,
1537 '''
1366 class A { 1538 class A {
1367 int get test => null; 1539 int get test => null;
1368 } 1540 }
1369 main(A a) { 1541 main(A a) {
1370 int v = a.test; 1542 int v = a.test;
1371 } 1543 }
1372 '''); 1544 ''');
1373 } 1545 }
1374 1546
1375 void test_createGetter_qualified_instance_dynamicType() { 1547 void test_createGetter_qualified_instance_dynamicType() {
1376 resolveTestUnit(''' 1548 resolveTestUnit('''
1377 class A { 1549 class A {
1378 B b; 1550 B b;
1379 void f(Object p) { 1551 void f(Object p) {
1380 p == b.test; 1552 p == b.test;
1381 } 1553 }
1382 } 1554 }
1383 class B { 1555 class B {
1384 } 1556 }
1385 '''); 1557 ''');
1386 assertHasFix(DartFixKind.CREATE_GETTER, ''' 1558 assertHasFix(
1559 DartFixKind.CREATE_GETTER,
1560 '''
1387 class A { 1561 class A {
1388 B b; 1562 B b;
1389 void f(Object p) { 1563 void f(Object p) {
1390 p == b.test; 1564 p == b.test;
1391 } 1565 }
1392 } 1566 }
1393 class B { 1567 class B {
1394 get test => null; 1568 get test => null;
1395 } 1569 }
1396 '''); 1570 ''');
(...skipping 12 matching lines...) Expand all
1409 1583
1410 void test_createGetter_unqualified_instance_asInvocationArgument() { 1584 void test_createGetter_unqualified_instance_asInvocationArgument() {
1411 resolveTestUnit(''' 1585 resolveTestUnit('''
1412 class A { 1586 class A {
1413 main() { 1587 main() {
1414 f(test); 1588 f(test);
1415 } 1589 }
1416 } 1590 }
1417 f(String s) {} 1591 f(String s) {}
1418 '''); 1592 ''');
1419 assertHasFix(DartFixKind.CREATE_GETTER, ''' 1593 assertHasFix(
1594 DartFixKind.CREATE_GETTER,
1595 '''
1420 class A { 1596 class A {
1421 String get test => null; 1597 String get test => null;
1422 1598
1423 main() { 1599 main() {
1424 f(test); 1600 f(test);
1425 } 1601 }
1426 } 1602 }
1427 f(String s) {} 1603 f(String s) {}
1428 '''); 1604 ''');
1429 } 1605 }
(...skipping 10 matching lines...) Expand all
1440 } 1616 }
1441 1617
1442 void test_createGetter_unqualified_instance_assignmentRhs() { 1618 void test_createGetter_unqualified_instance_assignmentRhs() {
1443 resolveTestUnit(''' 1619 resolveTestUnit('''
1444 class A { 1620 class A {
1445 main() { 1621 main() {
1446 int v = test; 1622 int v = test;
1447 } 1623 }
1448 } 1624 }
1449 '''); 1625 ''');
1450 assertHasFix(DartFixKind.CREATE_GETTER, ''' 1626 assertHasFix(
1627 DartFixKind.CREATE_GETTER,
1628 '''
1451 class A { 1629 class A {
1452 int get test => null; 1630 int get test => null;
1453 1631
1454 main() { 1632 main() {
1455 int v = test; 1633 int v = test;
1456 } 1634 }
1457 } 1635 }
1458 '''); 1636 ''');
1459 } 1637 }
1460 1638
1461 void test_createGetter_unqualified_instance_asStatement() { 1639 void test_createGetter_unqualified_instance_asStatement() {
1462 resolveTestUnit(''' 1640 resolveTestUnit('''
1463 class A { 1641 class A {
1464 main() { 1642 main() {
1465 test; 1643 test;
1466 } 1644 }
1467 } 1645 }
1468 '''); 1646 ''');
1469 assertHasFix(DartFixKind.CREATE_GETTER, ''' 1647 assertHasFix(
1648 DartFixKind.CREATE_GETTER,
1649 '''
1470 class A { 1650 class A {
1471 get test => null; 1651 get test => null;
1472 1652
1473 main() { 1653 main() {
1474 test; 1654 test;
1475 } 1655 }
1476 } 1656 }
1477 '''); 1657 ''');
1478 } 1658 }
1479 1659
1480 void test_createLocalVariable_functionType_named() { 1660 void test_createLocalVariable_functionType_named() {
1481 resolveTestUnit(''' 1661 resolveTestUnit('''
1482 typedef MY_FUNCTION(int p); 1662 typedef MY_FUNCTION(int p);
1483 foo(MY_FUNCTION f) {} 1663 foo(MY_FUNCTION f) {}
1484 main() { 1664 main() {
1485 foo(bar); 1665 foo(bar);
1486 } 1666 }
1487 '''); 1667 ''');
1488 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' 1668 assertHasFix(
1669 DartFixKind.CREATE_LOCAL_VARIABLE,
1670 '''
1489 typedef MY_FUNCTION(int p); 1671 typedef MY_FUNCTION(int p);
1490 foo(MY_FUNCTION f) {} 1672 foo(MY_FUNCTION f) {}
1491 main() { 1673 main() {
1492 MY_FUNCTION bar; 1674 MY_FUNCTION bar;
1493 foo(bar); 1675 foo(bar);
1494 } 1676 }
1495 '''); 1677 ''');
1496 } 1678 }
1497 1679
1498 void test_createLocalVariable_functionType_synthetic() { 1680 void test_createLocalVariable_functionType_synthetic() {
1499 resolveTestUnit(''' 1681 resolveTestUnit('''
1500 foo(f(int p)) {} 1682 foo(f(int p)) {}
1501 main() { 1683 main() {
1502 foo(bar); 1684 foo(bar);
1503 } 1685 }
1504 '''); 1686 ''');
1505 assertNoFix(DartFixKind.CREATE_LOCAL_VARIABLE); 1687 assertNoFix(DartFixKind.CREATE_LOCAL_VARIABLE);
1506 } 1688 }
1507 1689
1508 void test_createLocalVariable_read_typeAssignment() { 1690 void test_createLocalVariable_read_typeAssignment() {
1509 resolveTestUnit(''' 1691 resolveTestUnit('''
1510 main() { 1692 main() {
1511 int a = test; 1693 int a = test;
1512 } 1694 }
1513 '''); 1695 ''');
1514 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' 1696 assertHasFix(
1697 DartFixKind.CREATE_LOCAL_VARIABLE,
1698 '''
1515 main() { 1699 main() {
1516 int test; 1700 int test;
1517 int a = test; 1701 int a = test;
1518 } 1702 }
1519 '''); 1703 ''');
1520 } 1704 }
1521 1705
1522 void test_createLocalVariable_read_typeCondition() { 1706 void test_createLocalVariable_read_typeCondition() {
1523 resolveTestUnit(''' 1707 resolveTestUnit('''
1524 main() { 1708 main() {
1525 if (!test) { 1709 if (!test) {
1526 print(42); 1710 print(42);
1527 } 1711 }
1528 } 1712 }
1529 '''); 1713 ''');
1530 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' 1714 assertHasFix(
1715 DartFixKind.CREATE_LOCAL_VARIABLE,
1716 '''
1531 main() { 1717 main() {
1532 bool test; 1718 bool test;
1533 if (!test) { 1719 if (!test) {
1534 print(42); 1720 print(42);
1535 } 1721 }
1536 } 1722 }
1537 '''); 1723 ''');
1538 } 1724 }
1539 1725
1540 void test_createLocalVariable_read_typeInvocationArgument() { 1726 void test_createLocalVariable_read_typeInvocationArgument() {
1541 resolveTestUnit(''' 1727 resolveTestUnit('''
1542 main() { 1728 main() {
1543 f(test); 1729 f(test);
1544 } 1730 }
1545 f(String p) {} 1731 f(String p) {}
1546 '''); 1732 ''');
1547 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' 1733 assertHasFix(
1734 DartFixKind.CREATE_LOCAL_VARIABLE,
1735 '''
1548 main() { 1736 main() {
1549 String test; 1737 String test;
1550 f(test); 1738 f(test);
1551 } 1739 }
1552 f(String p) {} 1740 f(String p) {}
1553 '''); 1741 ''');
1554 _assertLinkedGroup(change.linkedEditGroups[0], ['String test;']); 1742 _assertLinkedGroup(change.linkedEditGroups[0], ['String test;']);
1555 _assertLinkedGroup(change.linkedEditGroups[1], ['test;', 'test);']); 1743 _assertLinkedGroup(change.linkedEditGroups[1], ['test;', 'test);']);
1556 } 1744 }
1557 1745
1558 void test_createLocalVariable_read_typeInvocationTarget() { 1746 void test_createLocalVariable_read_typeInvocationTarget() {
1559 resolveTestUnit(''' 1747 resolveTestUnit('''
1560 main() { 1748 main() {
1561 test.add('hello'); 1749 test.add('hello');
1562 } 1750 }
1563 '''); 1751 ''');
1564 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' 1752 assertHasFix(
1753 DartFixKind.CREATE_LOCAL_VARIABLE,
1754 '''
1565 main() { 1755 main() {
1566 var test; 1756 var test;
1567 test.add('hello'); 1757 test.add('hello');
1568 } 1758 }
1569 '''); 1759 ''');
1570 _assertLinkedGroup(change.linkedEditGroups[0], ['test;', 'test.add(']); 1760 _assertLinkedGroup(change.linkedEditGroups[0], ['test;', 'test.add(']);
1571 } 1761 }
1572 1762
1573 void test_createLocalVariable_write_assignment() { 1763 void test_createLocalVariable_write_assignment() {
1574 resolveTestUnit(''' 1764 resolveTestUnit('''
1575 main() { 1765 main() {
1576 test = 42; 1766 test = 42;
1577 } 1767 }
1578 '''); 1768 ''');
1579 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' 1769 assertHasFix(
1770 DartFixKind.CREATE_LOCAL_VARIABLE,
1771 '''
1580 main() { 1772 main() {
1581 var test = 42; 1773 var test = 42;
1582 } 1774 }
1583 '''); 1775 ''');
1584 } 1776 }
1585 1777
1586 void test_createLocalVariable_write_assignment_compound() { 1778 void test_createLocalVariable_write_assignment_compound() {
1587 resolveTestUnit(''' 1779 resolveTestUnit('''
1588 main() { 1780 main() {
1589 test += 42; 1781 test += 42;
1590 } 1782 }
1591 '''); 1783 ''');
1592 assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' 1784 assertHasFix(
1785 DartFixKind.CREATE_LOCAL_VARIABLE,
1786 '''
1593 main() { 1787 main() {
1594 int test; 1788 int test;
1595 test += 42; 1789 test += 42;
1596 } 1790 }
1597 '''); 1791 ''');
1598 } 1792 }
1599 1793
1600 void test_createMissingOverrides_functionTypeAlias() { 1794 void test_createMissingOverrides_functionTypeAlias() {
1601 resolveTestUnit(''' 1795 resolveTestUnit('''
1602 typedef int Binary(int left, int right); 1796 typedef int Binary(int left, int right);
1603 1797
1604 abstract class Emulator { 1798 abstract class Emulator {
1605 void performBinary(Binary binary); 1799 void performBinary(Binary binary);
1606 } 1800 }
1607 1801
1608 class MyEmulator extends Emulator { 1802 class MyEmulator extends Emulator {
1609 } 1803 }
1610 '''); 1804 ''');
1611 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' 1805 assertHasFix(
1806 DartFixKind.CREATE_MISSING_OVERRIDES,
1807 '''
1612 typedef int Binary(int left, int right); 1808 typedef int Binary(int left, int right);
1613 1809
1614 abstract class Emulator { 1810 abstract class Emulator {
1615 void performBinary(Binary binary); 1811 void performBinary(Binary binary);
1616 } 1812 }
1617 1813
1618 class MyEmulator extends Emulator { 1814 class MyEmulator extends Emulator {
1619 @override 1815 @override
1620 void performBinary(Binary binary) { 1816 void performBinary(Binary binary) {
1621 // TODO: implement performBinary 1817 // TODO: implement performBinary
1622 } 1818 }
1623 } 1819 }
1624 '''); 1820 ''');
1625 } 1821 }
1626 1822
1627 void test_createMissingOverrides_functionTypedParameter() { 1823 void test_createMissingOverrides_functionTypedParameter() {
1628 resolveTestUnit(''' 1824 resolveTestUnit('''
1629 abstract class A { 1825 abstract class A {
1630 forEach(int f(double p1, String p2)); 1826 forEach(int f(double p1, String p2));
1631 } 1827 }
1632 1828
1633 class B extends A { 1829 class B extends A {
1634 } 1830 }
1635 '''); 1831 ''');
1636 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' 1832 assertHasFix(
1833 DartFixKind.CREATE_MISSING_OVERRIDES,
1834 '''
1637 abstract class A { 1835 abstract class A {
1638 forEach(int f(double p1, String p2)); 1836 forEach(int f(double p1, String p2));
1639 } 1837 }
1640 1838
1641 class B extends A { 1839 class B extends A {
1642 @override 1840 @override
1643 forEach(int f(double p1, String p2)) { 1841 forEach(int f(double p1, String p2)) {
1644 // TODO: implement forEach 1842 // TODO: implement forEach
1645 } 1843 }
1646 } 1844 }
1647 '''); 1845 ''');
1648 } 1846 }
1649 1847
1650 void test_createMissingOverrides_generics_typeArguments() { 1848 void test_createMissingOverrides_generics_typeArguments() {
1651 resolveTestUnit(''' 1849 resolveTestUnit('''
1652 class Iterator<T> { 1850 class Iterator<T> {
1653 } 1851 }
1654 1852
1655 abstract class IterableMixin<T> { 1853 abstract class IterableMixin<T> {
1656 Iterator<T> get iterator; 1854 Iterator<T> get iterator;
1657 } 1855 }
1658 1856
1659 class Test extends IterableMixin<int> { 1857 class Test extends IterableMixin<int> {
1660 } 1858 }
1661 '''); 1859 ''');
1662 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' 1860 assertHasFix(
1861 DartFixKind.CREATE_MISSING_OVERRIDES,
1862 '''
1663 class Iterator<T> { 1863 class Iterator<T> {
1664 } 1864 }
1665 1865
1666 abstract class IterableMixin<T> { 1866 abstract class IterableMixin<T> {
1667 Iterator<T> get iterator; 1867 Iterator<T> get iterator;
1668 } 1868 }
1669 1869
1670 class Test extends IterableMixin<int> { 1870 class Test extends IterableMixin<int> {
1671 // TODO: implement iterator 1871 // TODO: implement iterator
1672 @override 1872 @override
1673 Iterator<int> get iterator => null; 1873 Iterator<int> get iterator => null;
1674 } 1874 }
1675 '''); 1875 ''');
1676 } 1876 }
1677 1877
1678 void test_createMissingOverrides_generics_typeParameters() { 1878 void test_createMissingOverrides_generics_typeParameters() {
1679 resolveTestUnit(''' 1879 resolveTestUnit('''
1680 abstract class ItemProvider<T> { 1880 abstract class ItemProvider<T> {
1681 List<T> getItems(); 1881 List<T> getItems();
1682 } 1882 }
1683 1883
1684 class Test<V> extends ItemProvider<V> { 1884 class Test<V> extends ItemProvider<V> {
1685 } 1885 }
1686 '''); 1886 ''');
1687 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' 1887 assertHasFix(
1888 DartFixKind.CREATE_MISSING_OVERRIDES,
1889 '''
1688 abstract class ItemProvider<T> { 1890 abstract class ItemProvider<T> {
1689 List<T> getItems(); 1891 List<T> getItems();
1690 } 1892 }
1691 1893
1692 class Test<V> extends ItemProvider<V> { 1894 class Test<V> extends ItemProvider<V> {
1693 @override 1895 @override
1694 List<V> getItems() { 1896 List<V> getItems() {
1695 // TODO: implement getItems 1897 // TODO: implement getItems
1696 } 1898 }
1697 } 1899 }
1698 '''); 1900 ''');
1699 } 1901 }
1700 1902
1701 void test_createMissingOverrides_getter() { 1903 void test_createMissingOverrides_getter() {
1702 resolveTestUnit(''' 1904 resolveTestUnit('''
1703 abstract class A { 1905 abstract class A {
1704 get g1; 1906 get g1;
1705 int get g2; 1907 int get g2;
1706 } 1908 }
1707 1909
1708 class B extends A { 1910 class B extends A {
1709 } 1911 }
1710 '''); 1912 ''');
1711 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' 1913 assertHasFix(
1914 DartFixKind.CREATE_MISSING_OVERRIDES,
1915 '''
1712 abstract class A { 1916 abstract class A {
1713 get g1; 1917 get g1;
1714 int get g2; 1918 int get g2;
1715 } 1919 }
1716 1920
1717 class B extends A { 1921 class B extends A {
1718 // TODO: implement g1 1922 // TODO: implement g1
1719 @override 1923 @override
1720 get g1 => null; 1924 get g1 => null;
1721 1925
1722 // TODO: implement g2 1926 // TODO: implement g2
1723 @override 1927 @override
1724 int get g2 => null; 1928 int get g2 => null;
1725 } 1929 }
1726 '''); 1930 ''');
1727 } 1931 }
1728 1932
1729 void test_createMissingOverrides_importPrefix() { 1933 void test_createMissingOverrides_importPrefix() {
1730 resolveTestUnit(''' 1934 resolveTestUnit('''
1731 import 'dart:async' as aaa; 1935 import 'dart:async' as aaa;
1732 abstract class A { 1936 abstract class A {
1733 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); 1937 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p);
1734 } 1938 }
1735 1939
1736 class B extends A { 1940 class B extends A {
1737 } 1941 }
1738 '''); 1942 ''');
1739 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' 1943 assertHasFix(
1944 DartFixKind.CREATE_MISSING_OVERRIDES,
1945 '''
1740 import 'dart:async' as aaa; 1946 import 'dart:async' as aaa;
1741 abstract class A { 1947 abstract class A {
1742 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); 1948 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p);
1743 } 1949 }
1744 1950
1745 class B extends A { 1951 class B extends A {
1746 @override 1952 @override
1747 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) { 1953 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) {
1748 // TODO: implement g 1954 // TODO: implement g
1749 } 1955 }
1750 } 1956 }
1751 '''); 1957 ''');
1752 } 1958 }
1753 1959
1754 void test_createMissingOverrides_mergeToField_getterSetter() { 1960 void test_createMissingOverrides_mergeToField_getterSetter() {
1755 resolveTestUnit(''' 1961 resolveTestUnit('''
1756 class A { 1962 class A {
1757 int ma; 1963 int ma;
1758 void mb() {} 1964 void mb() {}
1759 double mc; 1965 double mc;
1760 } 1966 }
1761 1967
1762 class B implements A { 1968 class B implements A {
1763 } 1969 }
1764 '''); 1970 ''');
1765 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' 1971 assertHasFix(
1972 DartFixKind.CREATE_MISSING_OVERRIDES,
1973 '''
1766 class A { 1974 class A {
1767 int ma; 1975 int ma;
1768 void mb() {} 1976 void mb() {}
1769 double mc; 1977 double mc;
1770 } 1978 }
1771 1979
1772 class B implements A { 1980 class B implements A {
1773 int ma; 1981 int ma;
1774 1982
1775 double mc; 1983 double mc;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 void test_createMissingOverrides_operator() { 2066 void test_createMissingOverrides_operator() {
1859 resolveTestUnit(''' 2067 resolveTestUnit('''
1860 abstract class A { 2068 abstract class A {
1861 int operator [](int index); 2069 int operator [](int index);
1862 void operator []=(int index, String value); 2070 void operator []=(int index, String value);
1863 } 2071 }
1864 2072
1865 class B extends A { 2073 class B extends A {
1866 } 2074 }
1867 '''); 2075 ''');
1868 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' 2076 assertHasFix(
2077 DartFixKind.CREATE_MISSING_OVERRIDES,
2078 '''
1869 abstract class A { 2079 abstract class A {
1870 int operator [](int index); 2080 int operator [](int index);
1871 void operator []=(int index, String value); 2081 void operator []=(int index, String value);
1872 } 2082 }
1873 2083
1874 class B extends A { 2084 class B extends A {
1875 @override 2085 @override
1876 int operator [](int index) { 2086 int operator [](int index) {
1877 // TODO: implement [] 2087 // TODO: implement []
1878 } 2088 }
(...skipping 10 matching lines...) Expand all
1889 resolveTestUnit(''' 2099 resolveTestUnit('''
1890 abstract class A { 2100 abstract class A {
1891 set s1(x); 2101 set s1(x);
1892 set s2(int x); 2102 set s2(int x);
1893 void set s3(String x); 2103 void set s3(String x);
1894 } 2104 }
1895 2105
1896 class B extends A { 2106 class B extends A {
1897 } 2107 }
1898 '''); 2108 ''');
1899 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' 2109 assertHasFix(
2110 DartFixKind.CREATE_MISSING_OVERRIDES,
2111 '''
1900 abstract class A { 2112 abstract class A {
1901 set s1(x); 2113 set s1(x);
1902 set s2(int x); 2114 set s2(int x);
1903 void set s3(String x); 2115 void set s3(String x);
1904 } 2116 }
1905 2117
1906 class B extends A { 2118 class B extends A {
1907 @override 2119 @override
1908 set s1(x) { 2120 set s1(x) {
1909 // TODO: implement s1 2121 // TODO: implement s1
(...skipping 16 matching lines...) Expand all
1926 resolveTestUnit(''' 2138 resolveTestUnit('''
1927 abstract class A { 2139 abstract class A {
1928 m1(); 2140 m1();
1929 int m2(); 2141 int m2();
1930 } 2142 }
1931 2143
1932 class B extends A { 2144 class B extends A {
1933 existing() {} 2145 existing() {}
1934 } 2146 }
1935 '''); 2147 ''');
1936 assertHasFix(DartFixKind.CREATE_NO_SUCH_METHOD, ''' 2148 assertHasFix(
2149 DartFixKind.CREATE_NO_SUCH_METHOD,
2150 '''
1937 abstract class A { 2151 abstract class A {
1938 m1(); 2152 m1();
1939 int m2(); 2153 int m2();
1940 } 2154 }
1941 2155
1942 class B extends A { 2156 class B extends A {
1943 existing() {} 2157 existing() {}
1944 2158
1945 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 2159 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
1946 } 2160 }
1947 '''); 2161 ''');
1948 } 2162 }
1949 2163
1950 void test_creatGetter_location_afterLastGetter() { 2164 void test_creatGetter_location_afterLastGetter() {
1951 resolveTestUnit(''' 2165 resolveTestUnit('''
1952 class A { 2166 class A {
1953 int existingField; 2167 int existingField;
1954 2168
1955 int get existingGetter => null; 2169 int get existingGetter => null;
1956 2170
1957 existingMethod() {} 2171 existingMethod() {}
1958 } 2172 }
1959 main(A a) { 2173 main(A a) {
1960 int v = a.test; 2174 int v = a.test;
1961 } 2175 }
1962 '''); 2176 ''');
1963 assertHasFix(DartFixKind.CREATE_GETTER, ''' 2177 assertHasFix(
2178 DartFixKind.CREATE_GETTER,
2179 '''
1964 class A { 2180 class A {
1965 int existingField; 2181 int existingField;
1966 2182
1967 int get existingGetter => null; 2183 int get existingGetter => null;
1968 2184
1969 int get test => null; 2185 int get test => null;
1970 2186
1971 existingMethod() {} 2187 existingMethod() {}
1972 } 2188 }
1973 main(A a) { 2189 main(A a) {
1974 int v = a.test; 2190 int v = a.test;
1975 } 2191 }
1976 '''); 2192 ''');
1977 } 2193 }
1978 2194
1979 void test_creationFunction_forFunctionType_cascadeSecond() { 2195 void test_creationFunction_forFunctionType_cascadeSecond() {
1980 resolveTestUnit(''' 2196 resolveTestUnit('''
1981 class A { 2197 class A {
1982 B ma() => null; 2198 B ma() => null;
1983 } 2199 }
1984 class B { 2200 class B {
1985 useFunction(int g(double a, String b)) {} 2201 useFunction(int g(double a, String b)) {}
1986 } 2202 }
1987 2203
1988 main() { 2204 main() {
1989 A a = new A(); 2205 A a = new A();
1990 a..ma().useFunction(test); 2206 a..ma().useFunction(test);
1991 } 2207 }
1992 '''); 2208 ''');
1993 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 2209 assertHasFix(
2210 DartFixKind.CREATE_FUNCTION,
2211 '''
1994 class A { 2212 class A {
1995 B ma() => null; 2213 B ma() => null;
1996 } 2214 }
1997 class B { 2215 class B {
1998 useFunction(int g(double a, String b)) {} 2216 useFunction(int g(double a, String b)) {}
1999 } 2217 }
2000 2218
2001 main() { 2219 main() {
2002 A a = new A(); 2220 A a = new A();
2003 a..ma().useFunction(test); 2221 a..ma().useFunction(test);
2004 } 2222 }
2005 2223
2006 int test(double a, String b) { 2224 int test(double a, String b) {
2007 } 2225 }
2008 '''); 2226 ''');
2009 } 2227 }
2010 2228
2011 void test_creationFunction_forFunctionType_coreFunction() { 2229 void test_creationFunction_forFunctionType_coreFunction() {
2012 resolveTestUnit(''' 2230 resolveTestUnit('''
2013 main() { 2231 main() {
2014 useFunction(g: test); 2232 useFunction(g: test);
2015 } 2233 }
2016 useFunction({Function g}) {} 2234 useFunction({Function g}) {}
2017 '''); 2235 ''');
2018 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 2236 assertHasFix(
2237 DartFixKind.CREATE_FUNCTION,
2238 '''
2019 main() { 2239 main() {
2020 useFunction(g: test); 2240 useFunction(g: test);
2021 } 2241 }
2022 useFunction({Function g}) {} 2242 useFunction({Function g}) {}
2023 2243
2024 test() { 2244 test() {
2025 } 2245 }
2026 '''); 2246 ''');
2027 } 2247 }
2028 2248
2029 void test_creationFunction_forFunctionType_dynamicArgument() { 2249 void test_creationFunction_forFunctionType_dynamicArgument() {
2030 resolveTestUnit(''' 2250 resolveTestUnit('''
2031 main() { 2251 main() {
2032 useFunction(test); 2252 useFunction(test);
2033 } 2253 }
2034 useFunction(int g(a, b)) {} 2254 useFunction(int g(a, b)) {}
2035 '''); 2255 ''');
2036 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 2256 assertHasFix(
2257 DartFixKind.CREATE_FUNCTION,
2258 '''
2037 main() { 2259 main() {
2038 useFunction(test); 2260 useFunction(test);
2039 } 2261 }
2040 useFunction(int g(a, b)) {} 2262 useFunction(int g(a, b)) {}
2041 2263
2042 int test(a, b) { 2264 int test(a, b) {
2043 } 2265 }
2044 '''); 2266 ''');
2045 } 2267 }
2046 2268
2047 void test_creationFunction_forFunctionType_function() { 2269 void test_creationFunction_forFunctionType_function() {
2048 resolveTestUnit(''' 2270 resolveTestUnit('''
2049 main() { 2271 main() {
2050 useFunction(test); 2272 useFunction(test);
2051 } 2273 }
2052 useFunction(int g(double a, String b)) {} 2274 useFunction(int g(double a, String b)) {}
2053 '''); 2275 ''');
2054 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 2276 assertHasFix(
2277 DartFixKind.CREATE_FUNCTION,
2278 '''
2055 main() { 2279 main() {
2056 useFunction(test); 2280 useFunction(test);
2057 } 2281 }
2058 useFunction(int g(double a, String b)) {} 2282 useFunction(int g(double a, String b)) {}
2059 2283
2060 int test(double a, String b) { 2284 int test(double a, String b) {
2061 } 2285 }
2062 '''); 2286 ''');
2063 } 2287 }
2064 2288
2065 void test_creationFunction_forFunctionType_function_namedArgument() { 2289 void test_creationFunction_forFunctionType_function_namedArgument() {
2066 resolveTestUnit(''' 2290 resolveTestUnit('''
2067 main() { 2291 main() {
2068 useFunction(g: test); 2292 useFunction(g: test);
2069 } 2293 }
2070 useFunction({int g(double a, String b)}) {} 2294 useFunction({int g(double a, String b)}) {}
2071 '''); 2295 ''');
2072 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 2296 assertHasFix(
2297 DartFixKind.CREATE_FUNCTION,
2298 '''
2073 main() { 2299 main() {
2074 useFunction(g: test); 2300 useFunction(g: test);
2075 } 2301 }
2076 useFunction({int g(double a, String b)}) {} 2302 useFunction({int g(double a, String b)}) {}
2077 2303
2078 int test(double a, String b) { 2304 int test(double a, String b) {
2079 } 2305 }
2080 '''); 2306 ''');
2081 } 2307 }
2082 2308
2083 void test_creationFunction_forFunctionType_importType() { 2309 void test_creationFunction_forFunctionType_importType() {
2084 addSource('/libA.dart', r''' 2310 addSource(
2311 '/libA.dart',
2312 r'''
2085 library libA; 2313 library libA;
2086 class A {} 2314 class A {}
2087 '''); 2315 ''');
2088 addSource('/libB.dart', r''' 2316 addSource(
2317 '/libB.dart',
2318 r'''
2089 library libB; 2319 library libB;
2090 import 'libA.dart'; 2320 import 'libA.dart';
2091 useFunction(int g(A a)) {} 2321 useFunction(int g(A a)) {}
2092 '''); 2322 ''');
2093 resolveTestUnit(''' 2323 resolveTestUnit('''
2094 import 'libB.dart'; 2324 import 'libB.dart';
2095 main() { 2325 main() {
2096 useFunction(test); 2326 useFunction(test);
2097 } 2327 }
2098 '''); 2328 ''');
2099 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 2329 assertHasFix(
2330 DartFixKind.CREATE_FUNCTION,
2331 '''
2100 import 'libB.dart'; 2332 import 'libB.dart';
2101 import 'libA.dart'; 2333 import 'libA.dart';
2102 main() { 2334 main() {
2103 useFunction(test); 2335 useFunction(test);
2104 } 2336 }
2105 2337
2106 int test(A a) { 2338 int test(A a) {
2107 } 2339 }
2108 '''); 2340 ''');
2109 } 2341 }
2110 2342
2111 void test_creationFunction_forFunctionType_method_enclosingClass_static() { 2343 void test_creationFunction_forFunctionType_method_enclosingClass_static() {
2112 resolveTestUnit(''' 2344 resolveTestUnit('''
2113 class A { 2345 class A {
2114 static foo() { 2346 static foo() {
2115 useFunction(test); 2347 useFunction(test);
2116 } 2348 }
2117 } 2349 }
2118 useFunction(int g(double a, String b)) {} 2350 useFunction(int g(double a, String b)) {}
2119 '''); 2351 ''');
2120 assertHasFix(DartFixKind.CREATE_METHOD, ''' 2352 assertHasFix(
2353 DartFixKind.CREATE_METHOD,
2354 '''
2121 class A { 2355 class A {
2122 static foo() { 2356 static foo() {
2123 useFunction(test); 2357 useFunction(test);
2124 } 2358 }
2125 2359
2126 static int test(double a, String b) { 2360 static int test(double a, String b) {
2127 } 2361 }
2128 } 2362 }
2129 useFunction(int g(double a, String b)) {} 2363 useFunction(int g(double a, String b)) {}
2130 '''); 2364 ''');
2131 } 2365 }
2132 2366
2133 void test_creationFunction_forFunctionType_method_enclosingClass_static2() { 2367 void test_creationFunction_forFunctionType_method_enclosingClass_static2() {
2134 resolveTestUnit(''' 2368 resolveTestUnit('''
2135 class A { 2369 class A {
2136 var f; 2370 var f;
2137 A() : f = useFunction(test); 2371 A() : f = useFunction(test);
2138 } 2372 }
2139 useFunction(int g(double a, String b)) {} 2373 useFunction(int g(double a, String b)) {}
2140 '''); 2374 ''');
2141 assertHasFix(DartFixKind.CREATE_METHOD, ''' 2375 assertHasFix(
2376 DartFixKind.CREATE_METHOD,
2377 '''
2142 class A { 2378 class A {
2143 var f; 2379 var f;
2144 A() : f = useFunction(test); 2380 A() : f = useFunction(test);
2145 2381
2146 static int test(double a, String b) { 2382 static int test(double a, String b) {
2147 } 2383 }
2148 } 2384 }
2149 useFunction(int g(double a, String b)) {} 2385 useFunction(int g(double a, String b)) {}
2150 '''); 2386 ''');
2151 } 2387 }
2152 2388
2153 void test_creationFunction_forFunctionType_method_targetClass() { 2389 void test_creationFunction_forFunctionType_method_targetClass() {
2154 resolveTestUnit(''' 2390 resolveTestUnit('''
2155 main(A a) { 2391 main(A a) {
2156 useFunction(a.test); 2392 useFunction(a.test);
2157 } 2393 }
2158 class A { 2394 class A {
2159 } 2395 }
2160 useFunction(int g(double a, String b)) {} 2396 useFunction(int g(double a, String b)) {}
2161 '''); 2397 ''');
2162 assertHasFix(DartFixKind.CREATE_METHOD, ''' 2398 assertHasFix(
2399 DartFixKind.CREATE_METHOD,
2400 '''
2163 main(A a) { 2401 main(A a) {
2164 useFunction(a.test); 2402 useFunction(a.test);
2165 } 2403 }
2166 class A { 2404 class A {
2167 int test(double a, String b) { 2405 int test(double a, String b) {
2168 } 2406 }
2169 } 2407 }
2170 useFunction(int g(double a, String b)) {} 2408 useFunction(int g(double a, String b)) {}
2171 '''); 2409 ''');
2172 } 2410 }
2173 2411
2174 void test_creationFunction_forFunctionType_method_targetClass_hasOtherMember() { 2412 void test_creationFunction_forFunctionType_method_targetClass_hasOtherMember() {
2175 resolveTestUnit(''' 2413 resolveTestUnit('''
2176 main(A a) { 2414 main(A a) {
2177 useFunction(a.test); 2415 useFunction(a.test);
2178 } 2416 }
2179 class A { 2417 class A {
2180 m() {} 2418 m() {}
2181 } 2419 }
2182 useFunction(int g(double a, String b)) {} 2420 useFunction(int g(double a, String b)) {}
2183 '''); 2421 ''');
2184 assertHasFix(DartFixKind.CREATE_METHOD, ''' 2422 assertHasFix(
2423 DartFixKind.CREATE_METHOD,
2424 '''
2185 main(A a) { 2425 main(A a) {
2186 useFunction(a.test); 2426 useFunction(a.test);
2187 } 2427 }
2188 class A { 2428 class A {
2189 m() {} 2429 m() {}
2190 2430
2191 int test(double a, String b) { 2431 int test(double a, String b) {
2192 } 2432 }
2193 } 2433 }
2194 useFunction(int g(double a, String b)) {} 2434 useFunction(int g(double a, String b)) {}
(...skipping 23 matching lines...) Expand all
2218 '''); 2458 ''');
2219 assertNoFix(DartFixKind.CREATE_METHOD); 2459 assertNoFix(DartFixKind.CREATE_METHOD);
2220 } 2460 }
2221 2461
2222 void test_expectedToken_semicolon() { 2462 void test_expectedToken_semicolon() {
2223 resolveTestUnit(''' 2463 resolveTestUnit('''
2224 main() { 2464 main() {
2225 print(0) 2465 print(0)
2226 } 2466 }
2227 '''); 2467 ''');
2228 assertHasFix(DartFixKind.INSERT_SEMICOLON, ''' 2468 assertHasFix(
2469 DartFixKind.INSERT_SEMICOLON,
2470 '''
2229 main() { 2471 main() {
2230 print(0); 2472 print(0);
2231 } 2473 }
2232 '''); 2474 ''');
2233 } 2475 }
2234 2476
2235 void test_illegalAsyncReturnType_asyncLibrary_import() { 2477 void test_illegalAsyncReturnType_asyncLibrary_import() {
2236 errorFilter = (AnalysisError error) { 2478 errorFilter = (AnalysisError error) {
2237 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; 2479 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE;
2238 }; 2480 };
2239 resolveTestUnit(''' 2481 resolveTestUnit('''
2240 library main; 2482 library main;
2241 int main() async { 2483 int main() async {
2242 } 2484 }
2243 '''); 2485 ''');
2244 assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, ''' 2486 assertHasFix(
2487 DartFixKind.REPLACE_RETURN_TYPE_FUTURE,
2488 '''
2245 library main; 2489 library main;
2246 import 'dart:async'; 2490 import 'dart:async';
2247 Future<int> main() async { 2491 Future<int> main() async {
2248 } 2492 }
2249 '''); 2493 ''');
2250 } 2494 }
2251 2495
2252 void test_illegalAsyncReturnType_asyncLibrary_usePrefix() { 2496 void test_illegalAsyncReturnType_asyncLibrary_usePrefix() {
2253 errorFilter = (AnalysisError error) { 2497 errorFilter = (AnalysisError error) {
2254 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; 2498 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE;
2255 }; 2499 };
2256 resolveTestUnit(''' 2500 resolveTestUnit('''
2257 import 'dart:async' as al; 2501 import 'dart:async' as al;
2258 int main() async { 2502 int main() async {
2259 } 2503 }
2260 '''); 2504 ''');
2261 assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, ''' 2505 assertHasFix(
2506 DartFixKind.REPLACE_RETURN_TYPE_FUTURE,
2507 '''
2262 import 'dart:async' as al; 2508 import 'dart:async' as al;
2263 al.Future<int> main() async { 2509 al.Future<int> main() async {
2264 } 2510 }
2265 '''); 2511 ''');
2266 } 2512 }
2267 2513
2268 void test_illegalAsyncReturnType_complexTypeName() { 2514 void test_illegalAsyncReturnType_complexTypeName() {
2269 errorFilter = (AnalysisError error) { 2515 errorFilter = (AnalysisError error) {
2270 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; 2516 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE;
2271 }; 2517 };
2272 resolveTestUnit(''' 2518 resolveTestUnit('''
2273 import 'dart:async'; 2519 import 'dart:async';
2274 List<int> main() async { 2520 List<int> main() async {
2275 } 2521 }
2276 '''); 2522 ''');
2277 assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, ''' 2523 assertHasFix(
2524 DartFixKind.REPLACE_RETURN_TYPE_FUTURE,
2525 '''
2278 import 'dart:async'; 2526 import 'dart:async';
2279 Future<List<int>> main() async { 2527 Future<List<int>> main() async {
2280 } 2528 }
2281 '''); 2529 ''');
2282 } 2530 }
2283 2531
2284 void test_illegalAsyncReturnType_void() { 2532 void test_illegalAsyncReturnType_void() {
2285 errorFilter = (AnalysisError error) { 2533 errorFilter = (AnalysisError error) {
2286 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; 2534 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE;
2287 }; 2535 };
2288 resolveTestUnit(''' 2536 resolveTestUnit('''
2289 import 'dart:async'; 2537 import 'dart:async';
2290 void main() async { 2538 void main() async {
2291 } 2539 }
2292 '''); 2540 ''');
2293 assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, ''' 2541 assertHasFix(
2542 DartFixKind.REPLACE_RETURN_TYPE_FUTURE,
2543 '''
2294 import 'dart:async'; 2544 import 'dart:async';
2295 Future main() async { 2545 Future main() async {
2296 } 2546 }
2297 '''); 2547 ''');
2298 } 2548 }
2299 2549
2300 void test_importLibraryPackage_withClass() { 2550 void test_importLibraryPackage_withClass() {
2301 _configureMyPkg(''' 2551 _configureMyPkg('''
2302 library my_lib; 2552 library my_lib;
2303 class Test {} 2553 class Test {}
2304 '''); 2554 ''');
2305 // try to find a fix 2555 // try to find a fix
2306 resolveTestUnit(''' 2556 resolveTestUnit('''
2307 main() { 2557 main() {
2308 Test test = null; 2558 Test test = null;
2309 } 2559 }
2310 '''); 2560 ''');
2311 performAllAnalysisTasks(); 2561 performAllAnalysisTasks();
2312 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, ''' 2562 assertHasFix(
2563 DartFixKind.IMPORT_LIBRARY_PROJECT,
2564 '''
2313 import 'package:my_pkg/my_lib.dart'; 2565 import 'package:my_pkg/my_lib.dart';
2314 2566
2315 main() { 2567 main() {
2316 Test test = null; 2568 Test test = null;
2317 } 2569 }
2318 '''); 2570 ''');
2319 } 2571 }
2320 2572
2321 void test_importLibraryPrefix_withClass() { 2573 void test_importLibraryPrefix_withClass() {
2322 resolveTestUnit(''' 2574 resolveTestUnit('''
2323 import 'dart:async' as pref; 2575 import 'dart:async' as pref;
2324 main() { 2576 main() {
2325 pref.Stream s = null; 2577 pref.Stream s = null;
2326 Future f = null; 2578 Future f = null;
2327 } 2579 }
2328 '''); 2580 ''');
2329 assertHasFix(DartFixKind.IMPORT_LIBRARY_PREFIX, ''' 2581 assertHasFix(
2582 DartFixKind.IMPORT_LIBRARY_PREFIX,
2583 '''
2330 import 'dart:async' as pref; 2584 import 'dart:async' as pref;
2331 main() { 2585 main() {
2332 pref.Stream s = null; 2586 pref.Stream s = null;
2333 pref.Future f = null; 2587 pref.Future f = null;
2334 } 2588 }
2335 '''); 2589 ''');
2336 } 2590 }
2337 2591
2338 void test_importLibraryPrefix_withTopLevelVariable() { 2592 void test_importLibraryPrefix_withTopLevelVariable() {
2339 resolveTestUnit(''' 2593 resolveTestUnit('''
2340 import 'dart:math' as pref; 2594 import 'dart:math' as pref;
2341 main() { 2595 main() {
2342 print(pref.E); 2596 print(pref.E);
2343 print(PI); 2597 print(PI);
2344 } 2598 }
2345 '''); 2599 ''');
2346 assertHasFix(DartFixKind.IMPORT_LIBRARY_PREFIX, ''' 2600 assertHasFix(
2601 DartFixKind.IMPORT_LIBRARY_PREFIX,
2602 '''
2347 import 'dart:math' as pref; 2603 import 'dart:math' as pref;
2348 main() { 2604 main() {
2349 print(pref.E); 2605 print(pref.E);
2350 print(pref.PI); 2606 print(pref.PI);
2351 } 2607 }
2352 '''); 2608 ''');
2353 } 2609 }
2354 2610
2355 void test_importLibraryProject_withClass_annotation() { 2611 void test_importLibraryProject_withClass_annotation() {
2356 addSource('/lib.dart', ''' 2612 addSource(
2613 '/lib.dart',
2614 '''
2357 library lib; 2615 library lib;
2358 class Test { 2616 class Test {
2359 const Test(int p); 2617 const Test(int p);
2360 } 2618 }
2361 '''); 2619 ''');
2362 resolveTestUnit(''' 2620 resolveTestUnit('''
2363 @Test(0) 2621 @Test(0)
2364 main() { 2622 main() {
2365 } 2623 }
2366 '''); 2624 ''');
2367 performAllAnalysisTasks(); 2625 performAllAnalysisTasks();
2368 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, ''' 2626 assertHasFix(
2627 DartFixKind.IMPORT_LIBRARY_PROJECT,
2628 '''
2369 import 'lib.dart'; 2629 import 'lib.dart';
2370 2630
2371 @Test(0) 2631 @Test(0)
2372 main() { 2632 main() {
2373 } 2633 }
2374 '''); 2634 ''');
2375 } 2635 }
2376 2636
2377 void test_importLibraryProject_withClass_inParentFolder() { 2637 void test_importLibraryProject_withClass_inParentFolder() {
2378 testFile = '/project/bin/test.dart'; 2638 testFile = '/project/bin/test.dart';
2379 addSource('/project/lib.dart', ''' 2639 addSource(
2640 '/project/lib.dart',
2641 '''
2380 library lib; 2642 library lib;
2381 class Test {} 2643 class Test {}
2382 '''); 2644 ''');
2383 resolveTestUnit(''' 2645 resolveTestUnit('''
2384 main() { 2646 main() {
2385 Test t = null; 2647 Test t = null;
2386 } 2648 }
2387 '''); 2649 ''');
2388 performAllAnalysisTasks(); 2650 performAllAnalysisTasks();
2389 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, ''' 2651 assertHasFix(
2652 DartFixKind.IMPORT_LIBRARY_PROJECT,
2653 '''
2390 import '../lib.dart'; 2654 import '../lib.dart';
2391 2655
2392 main() { 2656 main() {
2393 Test t = null; 2657 Test t = null;
2394 } 2658 }
2395 '''); 2659 ''');
2396 } 2660 }
2397 2661
2398 void test_importLibraryProject_withClass_inRelativeFolder() { 2662 void test_importLibraryProject_withClass_inRelativeFolder() {
2399 testFile = '/project/bin/test.dart'; 2663 testFile = '/project/bin/test.dart';
2400 addSource('/project/lib/sub/folder/lib.dart', ''' 2664 addSource(
2665 '/project/lib/sub/folder/lib.dart',
2666 '''
2401 library lib; 2667 library lib;
2402 class Test {} 2668 class Test {}
2403 '''); 2669 ''');
2404 resolveTestUnit(''' 2670 resolveTestUnit('''
2405 main() { 2671 main() {
2406 Test t = null; 2672 Test t = null;
2407 } 2673 }
2408 '''); 2674 ''');
2409 performAllAnalysisTasks(); 2675 performAllAnalysisTasks();
2410 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, ''' 2676 assertHasFix(
2677 DartFixKind.IMPORT_LIBRARY_PROJECT,
2678 '''
2411 import '../lib/sub/folder/lib.dart'; 2679 import '../lib/sub/folder/lib.dart';
2412 2680
2413 main() { 2681 main() {
2414 Test t = null; 2682 Test t = null;
2415 } 2683 }
2416 '''); 2684 ''');
2417 } 2685 }
2418 2686
2419 void test_importLibraryProject_withClass_inSameFolder() { 2687 void test_importLibraryProject_withClass_inSameFolder() {
2420 testFile = '/project/bin/test.dart'; 2688 testFile = '/project/bin/test.dart';
2421 addSource('/project/bin/lib.dart', ''' 2689 addSource(
2690 '/project/bin/lib.dart',
2691 '''
2422 library lib; 2692 library lib;
2423 class Test {} 2693 class Test {}
2424 '''); 2694 ''');
2425 resolveTestUnit(''' 2695 resolveTestUnit('''
2426 main() { 2696 main() {
2427 Test t = null; 2697 Test t = null;
2428 } 2698 }
2429 '''); 2699 ''');
2430 performAllAnalysisTasks(); 2700 performAllAnalysisTasks();
2431 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, ''' 2701 assertHasFix(
2702 DartFixKind.IMPORT_LIBRARY_PROJECT,
2703 '''
2432 import 'lib.dart'; 2704 import 'lib.dart';
2433 2705
2434 main() { 2706 main() {
2435 Test t = null; 2707 Test t = null;
2436 } 2708 }
2437 '''); 2709 ''');
2438 } 2710 }
2439 2711
2440 void test_importLibraryProject_withFunction() { 2712 void test_importLibraryProject_withFunction() {
2441 addSource('/lib.dart', ''' 2713 addSource(
2714 '/lib.dart',
2715 '''
2442 library lib; 2716 library lib;
2443 myFunction() {} 2717 myFunction() {}
2444 '''); 2718 ''');
2445 resolveTestUnit(''' 2719 resolveTestUnit('''
2446 main() { 2720 main() {
2447 myFunction(); 2721 myFunction();
2448 } 2722 }
2449 '''); 2723 ''');
2450 performAllAnalysisTasks(); 2724 performAllAnalysisTasks();
2451 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, ''' 2725 assertHasFix(
2726 DartFixKind.IMPORT_LIBRARY_PROJECT,
2727 '''
2452 import 'lib.dart'; 2728 import 'lib.dart';
2453 2729
2454 main() { 2730 main() {
2455 myFunction(); 2731 myFunction();
2456 } 2732 }
2457 '''); 2733 ''');
2458 } 2734 }
2459 2735
2460 void test_importLibraryProject_withFunction_unresolvedMethod() { 2736 void test_importLibraryProject_withFunction_unresolvedMethod() {
2461 addSource('/lib.dart', ''' 2737 addSource(
2738 '/lib.dart',
2739 '''
2462 library lib; 2740 library lib;
2463 myFunction() {} 2741 myFunction() {}
2464 '''); 2742 ''');
2465 resolveTestUnit(''' 2743 resolveTestUnit('''
2466 class A { 2744 class A {
2467 main() { 2745 main() {
2468 myFunction(); 2746 myFunction();
2469 } 2747 }
2470 } 2748 }
2471 '''); 2749 ''');
2472 performAllAnalysisTasks(); 2750 performAllAnalysisTasks();
2473 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, ''' 2751 assertHasFix(
2752 DartFixKind.IMPORT_LIBRARY_PROJECT,
2753 '''
2474 import 'lib.dart'; 2754 import 'lib.dart';
2475 2755
2476 class A { 2756 class A {
2477 main() { 2757 main() {
2478 myFunction(); 2758 myFunction();
2479 } 2759 }
2480 } 2760 }
2481 '''); 2761 ''');
2482 } 2762 }
2483 2763
2484 void test_importLibraryProject_withFunctionTypeAlias() { 2764 void test_importLibraryProject_withFunctionTypeAlias() {
2485 testFile = '/project/bin/test.dart'; 2765 testFile = '/project/bin/test.dart';
2486 addSource('/project/bin/lib.dart', ''' 2766 addSource(
2767 '/project/bin/lib.dart',
2768 '''
2487 library lib; 2769 library lib;
2488 typedef MyFunction(); 2770 typedef MyFunction();
2489 '''); 2771 ''');
2490 resolveTestUnit(''' 2772 resolveTestUnit('''
2491 main() { 2773 main() {
2492 MyFunction t = null; 2774 MyFunction t = null;
2493 } 2775 }
2494 '''); 2776 ''');
2495 performAllAnalysisTasks(); 2777 performAllAnalysisTasks();
2496 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, ''' 2778 assertHasFix(
2779 DartFixKind.IMPORT_LIBRARY_PROJECT,
2780 '''
2497 import 'lib.dart'; 2781 import 'lib.dart';
2498 2782
2499 main() { 2783 main() {
2500 MyFunction t = null; 2784 MyFunction t = null;
2501 } 2785 }
2502 '''); 2786 ''');
2503 } 2787 }
2504 2788
2505 void test_importLibraryProject_withTopLevelVariable() { 2789 void test_importLibraryProject_withTopLevelVariable() {
2506 addSource('/lib.dart', ''' 2790 addSource(
2791 '/lib.dart',
2792 '''
2507 library lib; 2793 library lib;
2508 int MY_VAR = 42; 2794 int MY_VAR = 42;
2509 '''); 2795 ''');
2510 resolveTestUnit(''' 2796 resolveTestUnit('''
2511 main() { 2797 main() {
2512 print(MY_VAR); 2798 print(MY_VAR);
2513 } 2799 }
2514 '''); 2800 ''');
2515 performAllAnalysisTasks(); 2801 performAllAnalysisTasks();
2516 assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT, ''' 2802 assertHasFix(
2803 DartFixKind.IMPORT_LIBRARY_PROJECT,
2804 '''
2517 import 'lib.dart'; 2805 import 'lib.dart';
2518 2806
2519 main() { 2807 main() {
2520 print(MY_VAR); 2808 print(MY_VAR);
2521 } 2809 }
2522 '''); 2810 ''');
2523 } 2811 }
2524 2812
2525 void test_importLibrarySdk_withClass_AsExpression() { 2813 void test_importLibrarySdk_withClass_AsExpression() {
2526 resolveTestUnit(''' 2814 resolveTestUnit('''
2527 main(p) { 2815 main(p) {
2528 p as Future; 2816 p as Future;
2529 } 2817 }
2530 '''); 2818 ''');
2531 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' 2819 assertHasFix(
2820 DartFixKind.IMPORT_LIBRARY_SDK,
2821 '''
2532 import 'dart:async'; 2822 import 'dart:async';
2533 2823
2534 main(p) { 2824 main(p) {
2535 p as Future; 2825 p as Future;
2536 } 2826 }
2537 '''); 2827 ''');
2538 } 2828 }
2539 2829
2540 void test_importLibrarySdk_withClass_invocationTarget() { 2830 void test_importLibrarySdk_withClass_invocationTarget() {
2541 resolveTestUnit(''' 2831 resolveTestUnit('''
2542 main() { 2832 main() {
2543 Future.wait(null); 2833 Future.wait(null);
2544 } 2834 }
2545 '''); 2835 ''');
2546 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' 2836 assertHasFix(
2837 DartFixKind.IMPORT_LIBRARY_SDK,
2838 '''
2547 import 'dart:async'; 2839 import 'dart:async';
2548 2840
2549 main() { 2841 main() {
2550 Future.wait(null); 2842 Future.wait(null);
2551 } 2843 }
2552 '''); 2844 ''');
2553 } 2845 }
2554 2846
2555 void test_importLibrarySdk_withClass_IsExpression() { 2847 void test_importLibrarySdk_withClass_IsExpression() {
2556 resolveTestUnit(''' 2848 resolveTestUnit('''
2557 main(p) { 2849 main(p) {
2558 p is Future; 2850 p is Future;
2559 } 2851 }
2560 '''); 2852 ''');
2561 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' 2853 assertHasFix(
2854 DartFixKind.IMPORT_LIBRARY_SDK,
2855 '''
2562 import 'dart:async'; 2856 import 'dart:async';
2563 2857
2564 main(p) { 2858 main(p) {
2565 p is Future; 2859 p is Future;
2566 } 2860 }
2567 '''); 2861 ''');
2568 } 2862 }
2569 2863
2864 void test_importLibrarySdk_withClass_itemOfList() {
2865 resolveTestUnit('''
2866 main() {
2867 var a = [Future];
2868 }
2869 ''');
2870 performAllAnalysisTasks();
2871 assertHasFix(
2872 DartFixKind.IMPORT_LIBRARY_SDK,
2873 '''
2874 import 'dart:async';
2875
2876 main() {
2877 var a = [Future];
2878 }
2879 ''');
2880 }
2881
2882 void test_importLibrarySdk_withClass_itemOfList_inAnnotation() {
2883 errorFilter = (AnalysisError error) {
2884 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER;
2885 };
2886 resolveTestUnit('''
2887 class MyAnnotation {
2888 const MyAnnotation(a, b);
2889 }
2890 @MyAnnotation(int, const [Future])
2891 main() {}
2892 ''');
2893 assertHasFix(
2894 DartFixKind.IMPORT_LIBRARY_SDK,
2895 '''
2896 import 'dart:async';
2897
2898 class MyAnnotation {
2899 const MyAnnotation(a, b);
2900 }
2901 @MyAnnotation(int, const [Future])
2902 main() {}
2903 ''');
2904 }
2905
2570 void test_importLibrarySdk_withClass_typeAnnotation() { 2906 void test_importLibrarySdk_withClass_typeAnnotation() {
2571 resolveTestUnit(''' 2907 resolveTestUnit('''
2572 main() { 2908 main() {
2573 Future f = null; 2909 Future f = null;
2574 } 2910 }
2575 '''); 2911 ''');
2576 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' 2912 assertHasFix(
2913 DartFixKind.IMPORT_LIBRARY_SDK,
2914 '''
2577 import 'dart:async'; 2915 import 'dart:async';
2578 2916
2579 main() { 2917 main() {
2580 Future f = null; 2918 Future f = null;
2581 } 2919 }
2582 '''); 2920 ''');
2583 } 2921 }
2584 2922
2585 void test_importLibrarySdk_withClass_typeAnnotation_PrefixedIdentifier() { 2923 void test_importLibrarySdk_withClass_typeAnnotation_PrefixedIdentifier() {
2586 resolveTestUnit(''' 2924 resolveTestUnit('''
2587 main() { 2925 main() {
2588 Future.wait; 2926 Future.wait;
2589 } 2927 }
2590 '''); 2928 ''');
2591 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' 2929 assertHasFix(
2930 DartFixKind.IMPORT_LIBRARY_SDK,
2931 '''
2592 import 'dart:async'; 2932 import 'dart:async';
2593 2933
2594 main() { 2934 main() {
2595 Future.wait; 2935 Future.wait;
2596 } 2936 }
2597 '''); 2937 ''');
2598 } 2938 }
2599 2939
2600 void test_importLibrarySdk_withClass_typeArgument() { 2940 void test_importLibrarySdk_withClass_typeArgument() {
2601 resolveTestUnit(''' 2941 resolveTestUnit('''
2602 main() { 2942 main() {
2603 List<Future> futures = []; 2943 List<Future> futures = [];
2604 } 2944 }
2605 '''); 2945 ''');
2606 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' 2946 assertHasFix(
2947 DartFixKind.IMPORT_LIBRARY_SDK,
2948 '''
2607 import 'dart:async'; 2949 import 'dart:async';
2608 2950
2609 main() { 2951 main() {
2610 List<Future> futures = []; 2952 List<Future> futures = [];
2611 } 2953 }
2612 '''); 2954 ''');
2613 } 2955 }
2614 2956
2615 void test_importLibrarySdk_withTopLevelVariable() { 2957 void test_importLibrarySdk_withTopLevelVariable() {
2616 resolveTestUnit(''' 2958 resolveTestUnit('''
2617 main() { 2959 main() {
2618 print(PI); 2960 print(PI);
2619 } 2961 }
2620 '''); 2962 ''');
2621 performAllAnalysisTasks(); 2963 performAllAnalysisTasks();
2622 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' 2964 assertHasFix(
2965 DartFixKind.IMPORT_LIBRARY_SDK,
2966 '''
2623 import 'dart:math'; 2967 import 'dart:math';
2624 2968
2625 main() { 2969 main() {
2626 print(PI); 2970 print(PI);
2627 } 2971 }
2628 '''); 2972 ''');
2629 } 2973 }
2630 2974
2631 void test_importLibrarySdk_withTopLevelVariable_annotation() { 2975 void test_importLibrarySdk_withTopLevelVariable_annotation() {
2632 resolveTestUnit(''' 2976 resolveTestUnit('''
2633 @PI 2977 @PI
2634 main() { 2978 main() {
2635 } 2979 }
2636 '''); 2980 ''');
2637 performAllAnalysisTasks(); 2981 performAllAnalysisTasks();
2638 assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' 2982 assertHasFix(
2983 DartFixKind.IMPORT_LIBRARY_SDK,
2984 '''
2639 import 'dart:math'; 2985 import 'dart:math';
2640 2986
2641 @PI 2987 @PI
2642 main() { 2988 main() {
2643 } 2989 }
2644 '''); 2990 ''');
2645 } 2991 }
2646 2992
2647 void test_importLibraryShow() { 2993 void test_importLibraryShow() {
2648 resolveTestUnit(''' 2994 resolveTestUnit('''
2649 import 'dart:async' show Stream; 2995 import 'dart:async' show Stream;
2650 main() { 2996 main() {
2651 Stream s = null; 2997 Stream s = null;
2652 Future f = null; 2998 Future f = null;
2653 } 2999 }
2654 '''); 3000 ''');
2655 assertHasFix(DartFixKind.IMPORT_LIBRARY_SHOW, ''' 3001 assertHasFix(
3002 DartFixKind.IMPORT_LIBRARY_SHOW,
3003 '''
2656 import 'dart:async' show Future, Stream; 3004 import 'dart:async' show Future, Stream;
2657 main() { 3005 main() {
2658 Stream s = null; 3006 Stream s = null;
2659 Future f = null; 3007 Future f = null;
2660 } 3008 }
2661 '''); 3009 ''');
2662 } 3010 }
2663 3011
2664 void test_isNotNull() { 3012 void test_isNotNull() {
2665 resolveTestUnit(''' 3013 resolveTestUnit('''
2666 main(p) { 3014 main(p) {
2667 p is! Null; 3015 p is! Null;
2668 } 3016 }
2669 '''); 3017 ''');
2670 assertHasFix(DartFixKind.USE_NOT_EQ_NULL, ''' 3018 assertHasFix(
3019 DartFixKind.USE_NOT_EQ_NULL,
3020 '''
2671 main(p) { 3021 main(p) {
2672 p != null; 3022 p != null;
2673 } 3023 }
2674 '''); 3024 ''');
2675 } 3025 }
2676 3026
2677 void test_isNull() { 3027 void test_isNull() {
2678 resolveTestUnit(''' 3028 resolveTestUnit('''
2679 main(p) { 3029 main(p) {
2680 p is Null; 3030 p is Null;
2681 } 3031 }
2682 '''); 3032 ''');
2683 assertHasFix(DartFixKind.USE_EQ_EQ_NULL, ''' 3033 assertHasFix(
3034 DartFixKind.USE_EQ_EQ_NULL,
3035 '''
2684 main(p) { 3036 main(p) {
2685 p == null; 3037 p == null;
2686 } 3038 }
2687 '''); 3039 ''');
2688 } 3040 }
2689 3041
2690 void test_makeEnclosingClassAbstract_declaresAbstractMethod() { 3042 void test_makeEnclosingClassAbstract_declaresAbstractMethod() {
2691 resolveTestUnit(''' 3043 resolveTestUnit('''
2692 class A { 3044 class A {
2693 m(); 3045 m();
2694 } 3046 }
2695 '''); 3047 ''');
2696 assertHasFix(DartFixKind.MAKE_CLASS_ABSTRACT, ''' 3048 assertHasFix(
3049 DartFixKind.MAKE_CLASS_ABSTRACT,
3050 '''
2697 abstract class A { 3051 abstract class A {
2698 m(); 3052 m();
2699 } 3053 }
2700 '''); 3054 ''');
2701 } 3055 }
2702 3056
2703 void test_makeEnclosingClassAbstract_inheritsAbstractMethod() { 3057 void test_makeEnclosingClassAbstract_inheritsAbstractMethod() {
2704 resolveTestUnit(''' 3058 resolveTestUnit('''
2705 abstract class A { 3059 abstract class A {
2706 m(); 3060 m();
2707 } 3061 }
2708 class B extends A { 3062 class B extends A {
2709 } 3063 }
2710 '''); 3064 ''');
2711 assertHasFix(DartFixKind.MAKE_CLASS_ABSTRACT, ''' 3065 assertHasFix(
3066 DartFixKind.MAKE_CLASS_ABSTRACT,
3067 '''
2712 abstract class A { 3068 abstract class A {
2713 m(); 3069 m();
2714 } 3070 }
2715 abstract class B extends A { 3071 abstract class B extends A {
2716 } 3072 }
2717 '''); 3073 ''');
2718 } 3074 }
2719 3075
2720 void test_noException_1() { 3076 void test_noException_1() {
2721 resolveTestUnit(''' 3077 resolveTestUnit('''
2722 main(p) { 3078 main(p) {
2723 p i s Null; 3079 p i s Null;
2724 }'''); 3080 }''');
2725 List<AnalysisError> errors = context.computeErrors(testSource); 3081 List<AnalysisError> errors = context.computeErrors(testSource);
2726 for (var error in errors) { 3082 for (var error in errors) {
2727 _computeFixes(error); 3083 _computeFixes(error);
2728 } 3084 }
2729 } 3085 }
2730 3086
2731 void test_removeDeadCode_condition() { 3087 void test_removeDeadCode_condition() {
2732 resolveTestUnit(''' 3088 resolveTestUnit('''
2733 main(int p) { 3089 main(int p) {
2734 if (true || p > 5) { 3090 if (true || p > 5) {
2735 print(1); 3091 print(1);
2736 } 3092 }
2737 } 3093 }
2738 '''); 3094 ''');
2739 assertHasFix(DartFixKind.REMOVE_DEAD_CODE, ''' 3095 assertHasFix(
3096 DartFixKind.REMOVE_DEAD_CODE,
3097 '''
2740 main(int p) { 3098 main(int p) {
2741 if (true) { 3099 if (true) {
2742 print(1); 3100 print(1);
2743 } 3101 }
2744 } 3102 }
2745 '''); 3103 ''');
2746 } 3104 }
2747 3105
2748 void test_removeDeadCode_statements_one() { 3106 void test_removeDeadCode_statements_one() {
2749 resolveTestUnit(''' 3107 resolveTestUnit('''
2750 int main() { 3108 int main() {
2751 print(0); 3109 print(0);
2752 return 42; 3110 return 42;
2753 print(1); 3111 print(1);
2754 } 3112 }
2755 '''); 3113 ''');
2756 assertHasFix(DartFixKind.REMOVE_DEAD_CODE, ''' 3114 assertHasFix(
3115 DartFixKind.REMOVE_DEAD_CODE,
3116 '''
2757 int main() { 3117 int main() {
2758 print(0); 3118 print(0);
2759 return 42; 3119 return 42;
2760 } 3120 }
2761 '''); 3121 ''');
2762 } 3122 }
2763 3123
2764 void test_removeDeadCode_statements_two() { 3124 void test_removeDeadCode_statements_two() {
2765 resolveTestUnit(''' 3125 resolveTestUnit('''
2766 int main() { 3126 int main() {
2767 print(0); 3127 print(0);
2768 return 42; 3128 return 42;
2769 print(1); 3129 print(1);
2770 print(2); 3130 print(2);
2771 } 3131 }
2772 '''); 3132 ''');
2773 assertHasFix(DartFixKind.REMOVE_DEAD_CODE, ''' 3133 assertHasFix(
3134 DartFixKind.REMOVE_DEAD_CODE,
3135 '''
2774 int main() { 3136 int main() {
2775 print(0); 3137 print(0);
2776 return 42; 3138 return 42;
2777 } 3139 }
2778 '''); 3140 ''');
2779 } 3141 }
2780 3142
2781 void test_removeParentheses_inGetterDeclaration() { 3143 void test_removeParentheses_inGetterDeclaration() {
2782 resolveTestUnit(''' 3144 resolveTestUnit('''
2783 class A { 3145 class A {
2784 int get foo() => 0; 3146 int get foo() => 0;
2785 } 3147 }
2786 '''); 3148 ''');
2787 assertHasFix(DartFixKind.REMOVE_PARAMETERS_IN_GETTER_DECLARATION, ''' 3149 assertHasFix(
3150 DartFixKind.REMOVE_PARAMETERS_IN_GETTER_DECLARATION,
3151 '''
2788 class A { 3152 class A {
2789 int get foo => 0; 3153 int get foo => 0;
2790 } 3154 }
2791 '''); 3155 ''');
2792 } 3156 }
2793 3157
2794 void test_removeParentheses_inGetterInvocation() { 3158 void test_removeParentheses_inGetterInvocation() {
2795 resolveTestUnit(''' 3159 resolveTestUnit('''
2796 class A { 3160 class A {
2797 int get foo => 0; 3161 int get foo => 0;
2798 } 3162 }
2799 main(A a) { 3163 main(A a) {
2800 a.foo(); 3164 a.foo();
2801 } 3165 }
2802 '''); 3166 ''');
2803 assertHasFix(DartFixKind.REMOVE_PARENTHESIS_IN_GETTER_INVOCATION, ''' 3167 assertHasFix(
3168 DartFixKind.REMOVE_PARENTHESIS_IN_GETTER_INVOCATION,
3169 '''
2804 class A { 3170 class A {
2805 int get foo => 0; 3171 int get foo => 0;
2806 } 3172 }
2807 main(A a) { 3173 main(A a) {
2808 a.foo; 3174 a.foo;
2809 } 3175 }
2810 '''); 3176 ''');
2811 } 3177 }
2812 3178
2813 void test_removeUnnecessaryCast_assignment() { 3179 void test_removeUnnecessaryCast_assignment() {
2814 resolveTestUnit(''' 3180 resolveTestUnit('''
2815 main(Object p) { 3181 main(Object p) {
2816 if (p is String) { 3182 if (p is String) {
2817 String v = ((p as String)); 3183 String v = ((p as String));
2818 } 3184 }
2819 } 3185 }
2820 '''); 3186 ''');
2821 assertHasFix(DartFixKind.REMOVE_UNNECASSARY_CAST, ''' 3187 assertHasFix(
3188 DartFixKind.REMOVE_UNNECASSARY_CAST,
3189 '''
2822 main(Object p) { 3190 main(Object p) {
2823 if (p is String) { 3191 if (p is String) {
2824 String v = p; 3192 String v = p;
2825 } 3193 }
2826 } 3194 }
2827 '''); 3195 ''');
2828 } 3196 }
2829 3197
2830 void test_removeUnusedCatchClause() { 3198 void test_removeUnusedCatchClause() {
2831 errorFilter = (AnalysisError error) => true; 3199 errorFilter = (AnalysisError error) => true;
2832 resolveTestUnit(''' 3200 resolveTestUnit('''
2833 main() { 3201 main() {
2834 try { 3202 try {
2835 throw 42; 3203 throw 42;
2836 } on int catch (e) { 3204 } on int catch (e) {
2837 } 3205 }
2838 } 3206 }
2839 '''); 3207 ''');
2840 assertHasFix(DartFixKind.REMOVE_UNUSED_CATCH_CLAUSE, ''' 3208 assertHasFix(
3209 DartFixKind.REMOVE_UNUSED_CATCH_CLAUSE,
3210 '''
2841 main() { 3211 main() {
2842 try { 3212 try {
2843 throw 42; 3213 throw 42;
2844 } on int { 3214 } on int {
2845 } 3215 }
2846 } 3216 }
2847 '''); 3217 ''');
2848 } 3218 }
2849 3219
2850 void test_removeUnusedCatchStack() { 3220 void test_removeUnusedCatchStack() {
2851 errorFilter = (AnalysisError error) => true; 3221 errorFilter = (AnalysisError error) => true;
2852 resolveTestUnit(''' 3222 resolveTestUnit('''
2853 main() { 3223 main() {
2854 try { 3224 try {
2855 throw 42; 3225 throw 42;
2856 } catch (e, stack) { 3226 } catch (e, stack) {
2857 } 3227 }
2858 } 3228 }
2859 '''); 3229 ''');
2860 assertHasFix(DartFixKind.REMOVE_UNUSED_CATCH_STACK, ''' 3230 assertHasFix(
3231 DartFixKind.REMOVE_UNUSED_CATCH_STACK,
3232 '''
2861 main() { 3233 main() {
2862 try { 3234 try {
2863 throw 42; 3235 throw 42;
2864 } catch (e) { 3236 } catch (e) {
2865 } 3237 }
2866 } 3238 }
2867 '''); 3239 ''');
2868 } 3240 }
2869 3241
2870 void test_removeUnusedImport() { 3242 void test_removeUnusedImport() {
2871 resolveTestUnit(''' 3243 resolveTestUnit('''
2872 import 'dart:math'; 3244 import 'dart:math';
2873 main() { 3245 main() {
2874 } 3246 }
2875 '''); 3247 ''');
2876 assertHasFix(DartFixKind.REMOVE_UNUSED_IMPORT, ''' 3248 assertHasFix(
3249 DartFixKind.REMOVE_UNUSED_IMPORT,
3250 '''
2877 main() { 3251 main() {
2878 } 3252 }
2879 '''); 3253 ''');
2880 } 3254 }
2881 3255
2882 void test_removeUnusedImport_anotherImportOnLine() { 3256 void test_removeUnusedImport_anotherImportOnLine() {
2883 resolveTestUnit(''' 3257 resolveTestUnit('''
2884 import 'dart:math'; import 'dart:async'; 3258 import 'dart:math'; import 'dart:async';
2885 3259
2886 main() { 3260 main() {
2887 Future f; 3261 Future f;
2888 } 3262 }
2889 '''); 3263 ''');
2890 assertHasFix(DartFixKind.REMOVE_UNUSED_IMPORT, ''' 3264 assertHasFix(
3265 DartFixKind.REMOVE_UNUSED_IMPORT,
3266 '''
2891 import 'dart:async'; 3267 import 'dart:async';
2892 3268
2893 main() { 3269 main() {
2894 Future f; 3270 Future f;
2895 } 3271 }
2896 '''); 3272 ''');
2897 } 3273 }
2898 3274
2899 void test_removeUnusedImport_severalLines() { 3275 void test_removeUnusedImport_severalLines() {
2900 resolveTestUnit(''' 3276 resolveTestUnit('''
2901 import 3277 import
2902 'dart:math'; 3278 'dart:math';
2903 main() { 3279 main() {
2904 } 3280 }
2905 '''); 3281 ''');
2906 assertHasFix(DartFixKind.REMOVE_UNUSED_IMPORT, ''' 3282 assertHasFix(
3283 DartFixKind.REMOVE_UNUSED_IMPORT,
3284 '''
2907 main() { 3285 main() {
2908 } 3286 }
2909 '''); 3287 ''');
2910 } 3288 }
2911 3289
2912 void test_replaceImportUri_inProject() { 3290 void test_replaceImportUri_inProject() {
2913 testFile = '/project/bin/test.dart'; 3291 testFile = '/project/bin/test.dart';
2914 addSource('/project/foo/bar/lib.dart', ''); 3292 addSource('/project/foo/bar/lib.dart', '');
2915 resolveTestUnit(''' 3293 resolveTestUnit('''
2916 import 'no/matter/lib.dart'; 3294 import 'no/matter/lib.dart';
2917 '''); 3295 ''');
2918 performAllAnalysisTasks(); 3296 performAllAnalysisTasks();
2919 assertHasFix(DartFixKind.REPLACE_IMPORT_URI, ''' 3297 assertHasFix(
3298 DartFixKind.REPLACE_IMPORT_URI,
3299 '''
2920 import '../foo/bar/lib.dart'; 3300 import '../foo/bar/lib.dart';
2921 '''); 3301 ''');
2922 } 3302 }
2923 3303
2924 void test_replaceImportUri_package() { 3304 void test_replaceImportUri_package() {
2925 _configureMyPkg(''); 3305 _configureMyPkg('');
2926 resolveTestUnit(''' 3306 resolveTestUnit('''
2927 import 'no/matter/my_lib.dart'; 3307 import 'no/matter/my_lib.dart';
2928 '''); 3308 ''');
2929 performAllAnalysisTasks(); 3309 performAllAnalysisTasks();
2930 assertHasFix(DartFixKind.REPLACE_IMPORT_URI, ''' 3310 assertHasFix(
3311 DartFixKind.REPLACE_IMPORT_URI,
3312 '''
2931 import 'package:my_pkg/my_lib.dart'; 3313 import 'package:my_pkg/my_lib.dart';
2932 '''); 3314 ''');
2933 } 3315 }
2934 3316
2935 void test_replaceVarWithDynamic() { 3317 void test_replaceVarWithDynamic() {
2936 errorFilter = (AnalysisError error) { 3318 errorFilter = (AnalysisError error) {
2937 return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME; 3319 return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME;
2938 }; 3320 };
2939 resolveTestUnit(''' 3321 resolveTestUnit('''
2940 class A { 3322 class A {
2941 Map<String, var> m; 3323 Map<String, var> m;
2942 } 3324 }
2943 '''); 3325 ''');
2944 assertHasFix(DartFixKind.REPLACE_VAR_WITH_DYNAMIC, ''' 3326 assertHasFix(
3327 DartFixKind.REPLACE_VAR_WITH_DYNAMIC,
3328 '''
2945 class A { 3329 class A {
2946 Map<String, dynamic> m; 3330 Map<String, dynamic> m;
2947 } 3331 }
2948 '''); 3332 ''');
2949 } 3333 }
2950 3334
2951 void test_replaceWithConstInstanceCreation() { 3335 void test_replaceWithConstInstanceCreation() {
2952 resolveTestUnit(''' 3336 resolveTestUnit('''
2953 class A { 3337 class A {
2954 const A(); 3338 const A();
2955 } 3339 }
2956 const a = new A(); 3340 const a = new A();
2957 '''); 3341 ''');
2958 assertHasFix(DartFixKind.USE_CONST, ''' 3342 assertHasFix(
3343 DartFixKind.USE_CONST,
3344 '''
2959 class A { 3345 class A {
2960 const A(); 3346 const A();
2961 } 3347 }
2962 const a = const A(); 3348 const a = const A();
2963 '''); 3349 ''');
2964 } 3350 }
2965 3351
2966 void test_undefinedClass_useSimilar_fromImport() { 3352 void test_undefinedClass_useSimilar_fromImport() {
2967 resolveTestUnit(''' 3353 resolveTestUnit('''
2968 main() { 3354 main() {
2969 Stirng s = 'abc'; 3355 Stirng s = 'abc';
2970 } 3356 }
2971 '''); 3357 ''');
2972 assertHasFix(DartFixKind.CHANGE_TO, ''' 3358 assertHasFix(
3359 DartFixKind.CHANGE_TO,
3360 '''
2973 main() { 3361 main() {
2974 String s = 'abc'; 3362 String s = 'abc';
2975 } 3363 }
2976 '''); 3364 ''');
2977 } 3365 }
2978 3366
2979 void test_undefinedClass_useSimilar_fromThisLibrary() { 3367 void test_undefinedClass_useSimilar_fromThisLibrary() {
2980 resolveTestUnit(''' 3368 resolveTestUnit('''
2981 class MyClass {} 3369 class MyClass {}
2982 main() { 3370 main() {
2983 MyCalss v = null; 3371 MyCalss v = null;
2984 } 3372 }
2985 '''); 3373 ''');
2986 assertHasFix(DartFixKind.CHANGE_TO, ''' 3374 assertHasFix(
3375 DartFixKind.CHANGE_TO,
3376 '''
2987 class MyClass {} 3377 class MyClass {}
2988 main() { 3378 main() {
2989 MyClass v = null; 3379 MyClass v = null;
2990 } 3380 }
2991 '''); 3381 ''');
2992 } 3382 }
2993 3383
2994 void test_undefinedFunction_create_dynamicArgument() { 3384 void test_undefinedFunction_create_dynamicArgument() {
2995 resolveTestUnit(''' 3385 resolveTestUnit('''
2996 main() { 3386 main() {
2997 dynamic v; 3387 dynamic v;
2998 test(v); 3388 test(v);
2999 } 3389 }
3000 '''); 3390 ''');
3001 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3391 assertHasFix(
3392 DartFixKind.CREATE_FUNCTION,
3393 '''
3002 main() { 3394 main() {
3003 dynamic v; 3395 dynamic v;
3004 test(v); 3396 test(v);
3005 } 3397 }
3006 3398
3007 void test(v) { 3399 void test(v) {
3008 } 3400 }
3009 '''); 3401 ''');
3010 } 3402 }
3011 3403
3012 void test_undefinedFunction_create_dynamicReturnType() { 3404 void test_undefinedFunction_create_dynamicReturnType() {
3013 resolveTestUnit(''' 3405 resolveTestUnit('''
3014 main() { 3406 main() {
3015 dynamic v = test(); 3407 dynamic v = test();
3016 } 3408 }
3017 '''); 3409 ''');
3018 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3410 assertHasFix(
3411 DartFixKind.CREATE_FUNCTION,
3412 '''
3019 main() { 3413 main() {
3020 dynamic v = test(); 3414 dynamic v = test();
3021 } 3415 }
3022 3416
3023 test() { 3417 test() {
3024 } 3418 }
3025 '''); 3419 ''');
3026 } 3420 }
3027 3421
3028 void test_undefinedFunction_create_fromFunction() { 3422 void test_undefinedFunction_create_fromFunction() {
3029 resolveTestUnit(''' 3423 resolveTestUnit('''
3030 main() { 3424 main() {
3031 int v = myUndefinedFunction(1, 2.0, '3'); 3425 int v = myUndefinedFunction(1, 2.0, '3');
3032 } 3426 }
3033 '''); 3427 ''');
3034 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3428 assertHasFix(
3429 DartFixKind.CREATE_FUNCTION,
3430 '''
3035 main() { 3431 main() {
3036 int v = myUndefinedFunction(1, 2.0, '3'); 3432 int v = myUndefinedFunction(1, 2.0, '3');
3037 } 3433 }
3038 3434
3039 int myUndefinedFunction(int i, double d, String s) { 3435 int myUndefinedFunction(int i, double d, String s) {
3040 } 3436 }
3041 '''); 3437 ''');
3042 } 3438 }
3043 3439
3044 void test_undefinedFunction_create_fromMethod() { 3440 void test_undefinedFunction_create_fromMethod() {
3045 resolveTestUnit(''' 3441 resolveTestUnit('''
3046 class A { 3442 class A {
3047 main() { 3443 main() {
3048 int v = myUndefinedFunction(1, 2.0, '3'); 3444 int v = myUndefinedFunction(1, 2.0, '3');
3049 } 3445 }
3050 } 3446 }
3051 '''); 3447 ''');
3052 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3448 assertHasFix(
3449 DartFixKind.CREATE_FUNCTION,
3450 '''
3053 class A { 3451 class A {
3054 main() { 3452 main() {
3055 int v = myUndefinedFunction(1, 2.0, '3'); 3453 int v = myUndefinedFunction(1, 2.0, '3');
3056 } 3454 }
3057 } 3455 }
3058 3456
3059 int myUndefinedFunction(int i, double d, String s) { 3457 int myUndefinedFunction(int i, double d, String s) {
3060 } 3458 }
3061 '''); 3459 ''');
3062 } 3460 }
3063 3461
3064 void test_undefinedFunction_create_generic_BAD() { 3462 void test_undefinedFunction_create_generic_BAD() {
3065 resolveTestUnit(''' 3463 resolveTestUnit('''
3066 class A<T> { 3464 class A<T> {
3067 Map<int, T> items; 3465 Map<int, T> items;
3068 main() { 3466 main() {
3069 process(items); 3467 process(items);
3070 } 3468 }
3071 } 3469 }
3072 '''); 3470 ''');
3073 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3471 assertHasFix(
3472 DartFixKind.CREATE_FUNCTION,
3473 '''
3074 class A<T> { 3474 class A<T> {
3075 Map<int, T> items; 3475 Map<int, T> items;
3076 main() { 3476 main() {
3077 process(items); 3477 process(items);
3078 } 3478 }
3079 } 3479 }
3080 3480
3081 void process(Map items) { 3481 void process(Map items) {
3082 } 3482 }
3083 '''); 3483 ''');
3084 } 3484 }
3085 3485
3086 void test_undefinedFunction_create_generic_OK() { 3486 void test_undefinedFunction_create_generic_OK() {
3087 resolveTestUnit(''' 3487 resolveTestUnit('''
3088 class A { 3488 class A {
3089 List<int> items; 3489 List<int> items;
3090 main() { 3490 main() {
3091 process(items); 3491 process(items);
3092 } 3492 }
3093 } 3493 }
3094 '''); 3494 ''');
3095 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3495 assertHasFix(
3496 DartFixKind.CREATE_FUNCTION,
3497 '''
3096 class A { 3498 class A {
3097 List<int> items; 3499 List<int> items;
3098 main() { 3500 main() {
3099 process(items); 3501 process(items);
3100 } 3502 }
3101 } 3503 }
3102 3504
3103 void process(List<int> items) { 3505 void process(List<int> items) {
3104 } 3506 }
3105 '''); 3507 ''');
3106 } 3508 }
3107 3509
3108 void test_undefinedFunction_create_importType() { 3510 void test_undefinedFunction_create_importType() {
3109 addSource('/lib.dart', r''' 3511 addSource(
3512 '/lib.dart',
3513 r'''
3110 library lib; 3514 library lib;
3111 import 'dart:async'; 3515 import 'dart:async';
3112 Future getFuture() => null; 3516 Future getFuture() => null;
3113 '''); 3517 ''');
3114 resolveTestUnit(''' 3518 resolveTestUnit('''
3115 import 'lib.dart'; 3519 import 'lib.dart';
3116 main() { 3520 main() {
3117 test(getFuture()); 3521 test(getFuture());
3118 } 3522 }
3119 '''); 3523 ''');
3120 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3524 assertHasFix(
3525 DartFixKind.CREATE_FUNCTION,
3526 '''
3121 import 'lib.dart'; 3527 import 'lib.dart';
3122 import 'dart:async'; 3528 import 'dart:async';
3123 main() { 3529 main() {
3124 test(getFuture()); 3530 test(getFuture());
3125 } 3531 }
3126 3532
3127 void test(Future future) { 3533 void test(Future future) {
3128 } 3534 }
3129 '''); 3535 ''');
3130 } 3536 }
3131 3537
3132 void test_undefinedFunction_create_nullArgument() { 3538 void test_undefinedFunction_create_nullArgument() {
3133 resolveTestUnit(''' 3539 resolveTestUnit('''
3134 main() { 3540 main() {
3135 test(null); 3541 test(null);
3136 } 3542 }
3137 '''); 3543 ''');
3138 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3544 assertHasFix(
3545 DartFixKind.CREATE_FUNCTION,
3546 '''
3139 main() { 3547 main() {
3140 test(null); 3548 test(null);
3141 } 3549 }
3142 3550
3143 void test(arg0) { 3551 void test(arg0) {
3144 } 3552 }
3145 '''); 3553 ''');
3146 } 3554 }
3147 3555
3148 void test_undefinedFunction_create_returnType_bool_expressions() { 3556 void test_undefinedFunction_create_returnType_bool_expressions() {
(...skipping 11 matching lines...) Expand all
3160 assert_undefinedFunction_create_returnType_bool("do {} while ( test() );"); 3568 assert_undefinedFunction_create_returnType_bool("do {} while ( test() );");
3161 } 3569 }
3162 3570
3163 void test_undefinedFunction_create_returnType_fromAssignment_eq() { 3571 void test_undefinedFunction_create_returnType_fromAssignment_eq() {
3164 resolveTestUnit(''' 3572 resolveTestUnit('''
3165 main() { 3573 main() {
3166 int v; 3574 int v;
3167 v = myUndefinedFunction(); 3575 v = myUndefinedFunction();
3168 } 3576 }
3169 '''); 3577 ''');
3170 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3578 assertHasFix(
3579 DartFixKind.CREATE_FUNCTION,
3580 '''
3171 main() { 3581 main() {
3172 int v; 3582 int v;
3173 v = myUndefinedFunction(); 3583 v = myUndefinedFunction();
3174 } 3584 }
3175 3585
3176 int myUndefinedFunction() { 3586 int myUndefinedFunction() {
3177 } 3587 }
3178 '''); 3588 ''');
3179 } 3589 }
3180 3590
3181 void test_undefinedFunction_create_returnType_fromAssignment_plusEq() { 3591 void test_undefinedFunction_create_returnType_fromAssignment_plusEq() {
3182 resolveTestUnit(''' 3592 resolveTestUnit('''
3183 main() { 3593 main() {
3184 int v; 3594 int v;
3185 v += myUndefinedFunction(); 3595 v += myUndefinedFunction();
3186 } 3596 }
3187 '''); 3597 ''');
3188 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3598 assertHasFix(
3599 DartFixKind.CREATE_FUNCTION,
3600 '''
3189 main() { 3601 main() {
3190 int v; 3602 int v;
3191 v += myUndefinedFunction(); 3603 v += myUndefinedFunction();
3192 } 3604 }
3193 3605
3194 num myUndefinedFunction() { 3606 num myUndefinedFunction() {
3195 } 3607 }
3196 '''); 3608 ''');
3197 } 3609 }
3198 3610
3199 void test_undefinedFunction_create_returnType_fromBinary_right() { 3611 void test_undefinedFunction_create_returnType_fromBinary_right() {
3200 resolveTestUnit(''' 3612 resolveTestUnit('''
3201 main() { 3613 main() {
3202 0 + myUndefinedFunction(); 3614 0 + myUndefinedFunction();
3203 } 3615 }
3204 '''); 3616 ''');
3205 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3617 assertHasFix(
3618 DartFixKind.CREATE_FUNCTION,
3619 '''
3206 main() { 3620 main() {
3207 0 + myUndefinedFunction(); 3621 0 + myUndefinedFunction();
3208 } 3622 }
3209 3623
3210 num myUndefinedFunction() { 3624 num myUndefinedFunction() {
3211 } 3625 }
3212 '''); 3626 ''');
3213 } 3627 }
3214 3628
3215 void test_undefinedFunction_create_returnType_fromInitializer() { 3629 void test_undefinedFunction_create_returnType_fromInitializer() {
3216 resolveTestUnit(''' 3630 resolveTestUnit('''
3217 main() { 3631 main() {
3218 int v = myUndefinedFunction(); 3632 int v = myUndefinedFunction();
3219 } 3633 }
3220 '''); 3634 ''');
3221 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3635 assertHasFix(
3636 DartFixKind.CREATE_FUNCTION,
3637 '''
3222 main() { 3638 main() {
3223 int v = myUndefinedFunction(); 3639 int v = myUndefinedFunction();
3224 } 3640 }
3225 3641
3226 int myUndefinedFunction() { 3642 int myUndefinedFunction() {
3227 } 3643 }
3228 '''); 3644 ''');
3229 } 3645 }
3230 3646
3231 void test_undefinedFunction_create_returnType_fromInvocationArgument() { 3647 void test_undefinedFunction_create_returnType_fromInvocationArgument() {
3232 resolveTestUnit(''' 3648 resolveTestUnit('''
3233 foo(int p) {} 3649 foo(int p) {}
3234 main() { 3650 main() {
3235 foo( myUndefinedFunction() ); 3651 foo( myUndefinedFunction() );
3236 } 3652 }
3237 '''); 3653 ''');
3238 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3654 assertHasFix(
3655 DartFixKind.CREATE_FUNCTION,
3656 '''
3239 foo(int p) {} 3657 foo(int p) {}
3240 main() { 3658 main() {
3241 foo( myUndefinedFunction() ); 3659 foo( myUndefinedFunction() );
3242 } 3660 }
3243 3661
3244 int myUndefinedFunction() { 3662 int myUndefinedFunction() {
3245 } 3663 }
3246 '''); 3664 ''');
3247 } 3665 }
3248 3666
3249 void test_undefinedFunction_create_returnType_fromReturn() { 3667 void test_undefinedFunction_create_returnType_fromReturn() {
3250 resolveTestUnit(''' 3668 resolveTestUnit('''
3251 int main() { 3669 int main() {
3252 return myUndefinedFunction(); 3670 return myUndefinedFunction();
3253 } 3671 }
3254 '''); 3672 ''');
3255 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3673 assertHasFix(
3674 DartFixKind.CREATE_FUNCTION,
3675 '''
3256 int main() { 3676 int main() {
3257 return myUndefinedFunction(); 3677 return myUndefinedFunction();
3258 } 3678 }
3259 3679
3260 int myUndefinedFunction() { 3680 int myUndefinedFunction() {
3261 } 3681 }
3262 '''); 3682 ''');
3263 } 3683 }
3264 3684
3265 void test_undefinedFunction_create_returnType_void() { 3685 void test_undefinedFunction_create_returnType_void() {
3266 resolveTestUnit(''' 3686 resolveTestUnit('''
3267 main() { 3687 main() {
3268 myUndefinedFunction(); 3688 myUndefinedFunction();
3269 } 3689 }
3270 '''); 3690 ''');
3271 assertHasFix(DartFixKind.CREATE_FUNCTION, ''' 3691 assertHasFix(
3692 DartFixKind.CREATE_FUNCTION,
3693 '''
3272 main() { 3694 main() {
3273 myUndefinedFunction(); 3695 myUndefinedFunction();
3274 } 3696 }
3275 3697
3276 void myUndefinedFunction() { 3698 void myUndefinedFunction() {
3277 } 3699 }
3278 '''); 3700 ''');
3279 } 3701 }
3280 3702
3281 void test_undefinedFunction_useSimilar_fromImport() { 3703 void test_undefinedFunction_useSimilar_fromImport() {
3282 resolveTestUnit(''' 3704 resolveTestUnit('''
3283 main() { 3705 main() {
3284 pritn(0); 3706 pritn(0);
3285 } 3707 }
3286 '''); 3708 ''');
3287 assertHasFix(DartFixKind.CHANGE_TO, ''' 3709 assertHasFix(
3710 DartFixKind.CHANGE_TO,
3711 '''
3288 main() { 3712 main() {
3289 print(0); 3713 print(0);
3290 } 3714 }
3291 '''); 3715 ''');
3292 } 3716 }
3293 3717
3294 void test_undefinedFunction_useSimilar_thisLibrary() { 3718 void test_undefinedFunction_useSimilar_thisLibrary() {
3295 resolveTestUnit(''' 3719 resolveTestUnit('''
3296 myFunction() {} 3720 myFunction() {}
3297 main() { 3721 main() {
3298 myFuntcion(); 3722 myFuntcion();
3299 } 3723 }
3300 '''); 3724 ''');
3301 assertHasFix(DartFixKind.CHANGE_TO, ''' 3725 assertHasFix(
3726 DartFixKind.CHANGE_TO,
3727 '''
3302 myFunction() {} 3728 myFunction() {}
3303 main() { 3729 main() {
3304 myFunction(); 3730 myFunction();
3305 } 3731 }
3306 '''); 3732 ''');
3307 } 3733 }
3308 3734
3309 void test_undefinedGetter_useSimilar_hint() { 3735 void test_undefinedGetter_useSimilar_hint() {
3310 resolveTestUnit(''' 3736 resolveTestUnit('''
3311 class A { 3737 class A {
3312 int myField; 3738 int myField;
3313 } 3739 }
3314 main(A a) { 3740 main(A a) {
3315 var x = a; 3741 var x = a;
3316 print(x.myFild); 3742 print(x.myFild);
3317 } 3743 }
3318 '''); 3744 ''');
3319 assertHasFix(DartFixKind.CHANGE_TO, ''' 3745 assertHasFix(
3746 DartFixKind.CHANGE_TO,
3747 '''
3320 class A { 3748 class A {
3321 int myField; 3749 int myField;
3322 } 3750 }
3323 main(A a) { 3751 main(A a) {
3324 var x = a; 3752 var x = a;
3325 print(x.myField); 3753 print(x.myField);
3326 } 3754 }
3327 '''); 3755 ''');
3328 } 3756 }
3329 3757
3330 void test_undefinedGetter_useSimilar_qualified() { 3758 void test_undefinedGetter_useSimilar_qualified() {
3331 resolveTestUnit(''' 3759 resolveTestUnit('''
3332 class A { 3760 class A {
3333 int myField; 3761 int myField;
3334 } 3762 }
3335 main(A a) { 3763 main(A a) {
3336 print(a.myFild); 3764 print(a.myFild);
3337 } 3765 }
3338 '''); 3766 ''');
3339 assertHasFix(DartFixKind.CHANGE_TO, ''' 3767 assertHasFix(
3768 DartFixKind.CHANGE_TO,
3769 '''
3340 class A { 3770 class A {
3341 int myField; 3771 int myField;
3342 } 3772 }
3343 main(A a) { 3773 main(A a) {
3344 print(a.myField); 3774 print(a.myField);
3345 } 3775 }
3346 '''); 3776 ''');
3347 } 3777 }
3348 3778
3349 void test_undefinedGetter_useSimilar_qualified_static() { 3779 void test_undefinedGetter_useSimilar_qualified_static() {
3350 resolveTestUnit(''' 3780 resolveTestUnit('''
3351 class A { 3781 class A {
3352 static int MY_NAME = 1; 3782 static int MY_NAME = 1;
3353 } 3783 }
3354 main() { 3784 main() {
3355 A.MY_NAM; 3785 A.MY_NAM;
3356 } 3786 }
3357 '''); 3787 ''');
3358 assertHasFix(DartFixKind.CHANGE_TO, ''' 3788 assertHasFix(
3789 DartFixKind.CHANGE_TO,
3790 '''
3359 class A { 3791 class A {
3360 static int MY_NAME = 1; 3792 static int MY_NAME = 1;
3361 } 3793 }
3362 main() { 3794 main() {
3363 A.MY_NAME; 3795 A.MY_NAME;
3364 } 3796 }
3365 '''); 3797 ''');
3366 } 3798 }
3367 3799
3368 void test_undefinedGetter_useSimilar_unqualified() { 3800 void test_undefinedGetter_useSimilar_unqualified() {
3369 resolveTestUnit(''' 3801 resolveTestUnit('''
3370 class A { 3802 class A {
3371 int myField; 3803 int myField;
3372 main() { 3804 main() {
3373 print(myFild); 3805 print(myFild);
3374 } 3806 }
3375 } 3807 }
3376 '''); 3808 ''');
3377 assertHasFix(DartFixKind.CHANGE_TO, ''' 3809 assertHasFix(
3810 DartFixKind.CHANGE_TO,
3811 '''
3378 class A { 3812 class A {
3379 int myField; 3813 int myField;
3380 main() { 3814 main() {
3381 print(myField); 3815 print(myField);
3382 } 3816 }
3383 } 3817 }
3384 '''); 3818 ''');
3385 } 3819 }
3386 3820
3387 void test_undefinedMethod_create_BAD_inSDK() { 3821 void test_undefinedMethod_create_BAD_inSDK() {
(...skipping 11 matching lines...) Expand all
3399 B b; 3833 B b;
3400 Map<int, T> items; 3834 Map<int, T> items;
3401 main() { 3835 main() {
3402 b.process(items); 3836 b.process(items);
3403 } 3837 }
3404 } 3838 }
3405 3839
3406 class B { 3840 class B {
3407 } 3841 }
3408 '''); 3842 ''');
3409 assertHasFix(DartFixKind.CREATE_METHOD, ''' 3843 assertHasFix(
3844 DartFixKind.CREATE_METHOD,
3845 '''
3410 class A<T> { 3846 class A<T> {
3411 B b; 3847 B b;
3412 Map<int, T> items; 3848 Map<int, T> items;
3413 main() { 3849 main() {
3414 b.process(items); 3850 b.process(items);
3415 } 3851 }
3416 } 3852 }
3417 3853
3418 class B { 3854 class B {
3419 void process(Map items) { 3855 void process(Map items) {
3420 } 3856 }
3421 } 3857 }
3422 '''); 3858 ''');
3423 } 3859 }
3424 3860
3425 void test_undefinedMethod_create_generic_BAD_returnType() { 3861 void test_undefinedMethod_create_generic_BAD_returnType() {
3426 resolveTestUnit(''' 3862 resolveTestUnit('''
3427 class A<T> { 3863 class A<T> {
3428 main() { 3864 main() {
3429 T t = new B().compute(); 3865 T t = new B().compute();
3430 } 3866 }
3431 } 3867 }
3432 3868
3433 class B { 3869 class B {
3434 } 3870 }
3435 '''); 3871 ''');
3436 assertHasFix(DartFixKind.CREATE_METHOD, ''' 3872 assertHasFix(
3873 DartFixKind.CREATE_METHOD,
3874 '''
3437 class A<T> { 3875 class A<T> {
3438 main() { 3876 main() {
3439 T t = new B().compute(); 3877 T t = new B().compute();
3440 } 3878 }
3441 } 3879 }
3442 3880
3443 class B { 3881 class B {
3444 dynamic compute() { 3882 dynamic compute() {
3445 } 3883 }
3446 } 3884 }
3447 '''); 3885 ''');
3448 } 3886 }
3449 3887
3450 void test_undefinedMethod_create_generic_OK_literal() { 3888 void test_undefinedMethod_create_generic_OK_literal() {
3451 resolveTestUnit(''' 3889 resolveTestUnit('''
3452 class A { 3890 class A {
3453 B b; 3891 B b;
3454 List<int> items; 3892 List<int> items;
3455 main() { 3893 main() {
3456 b.process(items); 3894 b.process(items);
3457 } 3895 }
3458 } 3896 }
3459 3897
3460 class B { 3898 class B {
3461 } 3899 }
3462 '''); 3900 ''');
3463 assertHasFix(DartFixKind.CREATE_METHOD, ''' 3901 assertHasFix(
3902 DartFixKind.CREATE_METHOD,
3903 '''
3464 class A { 3904 class A {
3465 B b; 3905 B b;
3466 List<int> items; 3906 List<int> items;
3467 main() { 3907 main() {
3468 b.process(items); 3908 b.process(items);
3469 } 3909 }
3470 } 3910 }
3471 3911
3472 class B { 3912 class B {
3473 void process(List<int> items) { 3913 void process(List<int> items) {
3474 } 3914 }
3475 } 3915 }
3476 '''); 3916 ''');
3477 } 3917 }
3478 3918
3479 void test_undefinedMethod_create_generic_OK_local() { 3919 void test_undefinedMethod_create_generic_OK_local() {
3480 resolveTestUnit(''' 3920 resolveTestUnit('''
3481 class A<T> { 3921 class A<T> {
3482 List<T> items; 3922 List<T> items;
3483 main() { 3923 main() {
3484 process(items); 3924 process(items);
3485 } 3925 }
3486 } 3926 }
3487 '''); 3927 ''');
3488 assertHasFix(DartFixKind.CREATE_METHOD, ''' 3928 assertHasFix(
3929 DartFixKind.CREATE_METHOD,
3930 '''
3489 class A<T> { 3931 class A<T> {
3490 List<T> items; 3932 List<T> items;
3491 main() { 3933 main() {
3492 process(items); 3934 process(items);
3493 } 3935 }
3494 3936
3495 void process(List<T> items) { 3937 void process(List<T> items) {
3496 } 3938 }
3497 } 3939 }
3498 '''); 3940 ''');
3499 } 3941 }
3500 3942
3501 void test_undefinedMethod_createQualified_fromClass() { 3943 void test_undefinedMethod_createQualified_fromClass() {
3502 resolveTestUnit(''' 3944 resolveTestUnit('''
3503 class A { 3945 class A {
3504 } 3946 }
3505 main() { 3947 main() {
3506 A.myUndefinedMethod(); 3948 A.myUndefinedMethod();
3507 } 3949 }
3508 '''); 3950 ''');
3509 assertHasFix(DartFixKind.CREATE_METHOD, ''' 3951 assertHasFix(
3952 DartFixKind.CREATE_METHOD,
3953 '''
3510 class A { 3954 class A {
3511 static void myUndefinedMethod() { 3955 static void myUndefinedMethod() {
3512 } 3956 }
3513 } 3957 }
3514 main() { 3958 main() {
3515 A.myUndefinedMethod(); 3959 A.myUndefinedMethod();
3516 } 3960 }
3517 '''); 3961 ''');
3518 } 3962 }
3519 3963
3520 void test_undefinedMethod_createQualified_fromClass_hasOtherMember() { 3964 void test_undefinedMethod_createQualified_fromClass_hasOtherMember() {
3521 resolveTestUnit(''' 3965 resolveTestUnit('''
3522 class A { 3966 class A {
3523 foo() {} 3967 foo() {}
3524 } 3968 }
3525 main() { 3969 main() {
3526 A.myUndefinedMethod(); 3970 A.myUndefinedMethod();
3527 } 3971 }
3528 '''); 3972 ''');
3529 assertHasFix(DartFixKind.CREATE_METHOD, ''' 3973 assertHasFix(
3974 DartFixKind.CREATE_METHOD,
3975 '''
3530 class A { 3976 class A {
3531 foo() {} 3977 foo() {}
3532 3978
3533 static void myUndefinedMethod() { 3979 static void myUndefinedMethod() {
3534 } 3980 }
3535 } 3981 }
3536 main() { 3982 main() {
3537 A.myUndefinedMethod(); 3983 A.myUndefinedMethod();
3538 } 3984 }
3539 '''); 3985 ''');
3540 } 3986 }
3541 3987
3542 void test_undefinedMethod_createQualified_fromInstance() { 3988 void test_undefinedMethod_createQualified_fromInstance() {
3543 resolveTestUnit(''' 3989 resolveTestUnit('''
3544 class A { 3990 class A {
3545 } 3991 }
3546 main(A a) { 3992 main(A a) {
3547 a.myUndefinedMethod(); 3993 a.myUndefinedMethod();
3548 } 3994 }
3549 '''); 3995 ''');
3550 assertHasFix(DartFixKind.CREATE_METHOD, ''' 3996 assertHasFix(
3997 DartFixKind.CREATE_METHOD,
3998 '''
3551 class A { 3999 class A {
3552 void myUndefinedMethod() { 4000 void myUndefinedMethod() {
3553 } 4001 }
3554 } 4002 }
3555 main(A a) { 4003 main(A a) {
3556 a.myUndefinedMethod(); 4004 a.myUndefinedMethod();
3557 } 4005 }
3558 '''); 4006 ''');
3559 } 4007 }
3560 4008
(...skipping 17 matching lines...) Expand all
3578 } 4026 }
3579 4027
3580 void test_undefinedMethod_createUnqualified_parameters() { 4028 void test_undefinedMethod_createUnqualified_parameters() {
3581 resolveTestUnit(''' 4029 resolveTestUnit('''
3582 class A { 4030 class A {
3583 main() { 4031 main() {
3584 myUndefinedMethod(0, 1.0, '3'); 4032 myUndefinedMethod(0, 1.0, '3');
3585 } 4033 }
3586 } 4034 }
3587 '''); 4035 ''');
3588 assertHasFix(DartFixKind.CREATE_METHOD, ''' 4036 assertHasFix(
4037 DartFixKind.CREATE_METHOD,
4038 '''
3589 class A { 4039 class A {
3590 main() { 4040 main() {
3591 myUndefinedMethod(0, 1.0, '3'); 4041 myUndefinedMethod(0, 1.0, '3');
3592 } 4042 }
3593 4043
3594 void myUndefinedMethod(int i, double d, String s) { 4044 void myUndefinedMethod(int i, double d, String s) {
3595 } 4045 }
3596 } 4046 }
3597 '''); 4047 ''');
3598 // linked positions 4048 // linked positions
3599 int index = 0; 4049 int index = 0;
3600 _assertLinkedGroup( 4050 _assertLinkedGroup(
3601 change.linkedEditGroups[index++], ['void myUndefinedMethod(']); 4051 change.linkedEditGroups[index++], ['void myUndefinedMethod(']);
3602 _assertLinkedGroup(change.linkedEditGroups[index++], [ 4052 _assertLinkedGroup(change.linkedEditGroups[index++],
3603 'myUndefinedMethod(0', 4053 ['myUndefinedMethod(0', 'myUndefinedMethod(int']);
3604 'myUndefinedMethod(int' 4054 _assertLinkedGroup(
3605 ]); 4055 change.linkedEditGroups[index++],
3606 _assertLinkedGroup(change.linkedEditGroups[index++], [ 4056 ['int i'],
3607 'int i' 4057 expectedSuggestions(LinkedEditSuggestionKind.TYPE,
3608 ], expectedSuggestions( 4058 ['int', 'num', 'Object', 'Comparable']));
3609 LinkedEditSuggestionKind.TYPE, ['int', 'num', 'Object', 'Comparable']));
3610 _assertLinkedGroup(change.linkedEditGroups[index++], ['i,']); 4059 _assertLinkedGroup(change.linkedEditGroups[index++], ['i,']);
3611 _assertLinkedGroup(change.linkedEditGroups[index++], ['double d'], 4060 _assertLinkedGroup(
3612 expectedSuggestions(LinkedEditSuggestionKind.TYPE, [ 4061 change.linkedEditGroups[index++],
3613 'double', 4062 ['double d'],
3614 'num', 4063 expectedSuggestions(LinkedEditSuggestionKind.TYPE,
3615 'Object', 4064 ['double', 'num', 'Object', 'Comparable']));
3616 'Comparable'
3617 ]));
3618 _assertLinkedGroup(change.linkedEditGroups[index++], ['d,']); 4065 _assertLinkedGroup(change.linkedEditGroups[index++], ['d,']);
3619 _assertLinkedGroup(change.linkedEditGroups[index++], ['String s'], 4066 _assertLinkedGroup(
4067 change.linkedEditGroups[index++],
4068 ['String s'],
3620 expectedSuggestions( 4069 expectedSuggestions(
3621 LinkedEditSuggestionKind.TYPE, ['String', 'Object', 'Comparable'])); 4070 LinkedEditSuggestionKind.TYPE, ['String', 'Object', 'Comparable']));
3622 _assertLinkedGroup(change.linkedEditGroups[index++], ['s)']); 4071 _assertLinkedGroup(change.linkedEditGroups[index++], ['s)']);
3623 } 4072 }
3624 4073
3625 void test_undefinedMethod_createUnqualified_returnType() { 4074 void test_undefinedMethod_createUnqualified_returnType() {
3626 resolveTestUnit(''' 4075 resolveTestUnit('''
3627 class A { 4076 class A {
3628 main() { 4077 main() {
3629 int v = myUndefinedMethod(); 4078 int v = myUndefinedMethod();
3630 } 4079 }
3631 } 4080 }
3632 '''); 4081 ''');
3633 assertHasFix(DartFixKind.CREATE_METHOD, ''' 4082 assertHasFix(
4083 DartFixKind.CREATE_METHOD,
4084 '''
3634 class A { 4085 class A {
3635 main() { 4086 main() {
3636 int v = myUndefinedMethod(); 4087 int v = myUndefinedMethod();
3637 } 4088 }
3638 4089
3639 int myUndefinedMethod() { 4090 int myUndefinedMethod() {
3640 } 4091 }
3641 } 4092 }
3642 '''); 4093 ''');
3643 // linked positions 4094 // linked positions
3644 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); 4095 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']);
3645 _assertLinkedGroup(change.linkedEditGroups[1], [ 4096 _assertLinkedGroup(change.linkedEditGroups[1],
3646 'myUndefinedMethod();', 4097 ['myUndefinedMethod();', 'myUndefinedMethod() {']);
3647 'myUndefinedMethod() {'
3648 ]);
3649 } 4098 }
3650 4099
3651 void test_undefinedMethod_createUnqualified_staticFromField() { 4100 void test_undefinedMethod_createUnqualified_staticFromField() {
3652 resolveTestUnit(''' 4101 resolveTestUnit('''
3653 class A { 4102 class A {
3654 static var f = myUndefinedMethod(); 4103 static var f = myUndefinedMethod();
3655 } 4104 }
3656 '''); 4105 ''');
3657 assertHasFix(DartFixKind.CREATE_METHOD, ''' 4106 assertHasFix(
4107 DartFixKind.CREATE_METHOD,
4108 '''
3658 class A { 4109 class A {
3659 static var f = myUndefinedMethod(); 4110 static var f = myUndefinedMethod();
3660 4111
3661 static myUndefinedMethod() { 4112 static myUndefinedMethod() {
3662 } 4113 }
3663 } 4114 }
3664 '''); 4115 ''');
3665 } 4116 }
3666 4117
3667 void test_undefinedMethod_createUnqualified_staticFromMethod() { 4118 void test_undefinedMethod_createUnqualified_staticFromMethod() {
3668 resolveTestUnit(''' 4119 resolveTestUnit('''
3669 class A { 4120 class A {
3670 static main() { 4121 static main() {
3671 myUndefinedMethod(); 4122 myUndefinedMethod();
3672 } 4123 }
3673 } 4124 }
3674 '''); 4125 ''');
3675 assertHasFix(DartFixKind.CREATE_METHOD, ''' 4126 assertHasFix(
4127 DartFixKind.CREATE_METHOD,
4128 '''
3676 class A { 4129 class A {
3677 static main() { 4130 static main() {
3678 myUndefinedMethod(); 4131 myUndefinedMethod();
3679 } 4132 }
3680 4133
3681 static void myUndefinedMethod() { 4134 static void myUndefinedMethod() {
3682 } 4135 }
3683 } 4136 }
3684 '''); 4137 ''');
3685 } 4138 }
3686 4139
3687 void test_undefinedMethod_hint_createQualified_fromInstance() { 4140 void test_undefinedMethod_hint_createQualified_fromInstance() {
3688 resolveTestUnit(''' 4141 resolveTestUnit('''
3689 class A { 4142 class A {
3690 } 4143 }
3691 main() { 4144 main() {
3692 var a = new A(); 4145 var a = new A();
3693 a.myUndefinedMethod(); 4146 a.myUndefinedMethod();
3694 } 4147 }
3695 '''); 4148 ''');
3696 assertHasFix(DartFixKind.CREATE_METHOD, ''' 4149 assertHasFix(
4150 DartFixKind.CREATE_METHOD,
4151 '''
3697 class A { 4152 class A {
3698 void myUndefinedMethod() { 4153 void myUndefinedMethod() {
3699 } 4154 }
3700 } 4155 }
3701 main() { 4156 main() {
3702 var a = new A(); 4157 var a = new A();
3703 a.myUndefinedMethod(); 4158 a.myUndefinedMethod();
3704 } 4159 }
3705 '''); 4160 ''');
3706 } 4161 }
(...skipping 10 matching lines...) Expand all
3717 void test_undefinedMethod_useSimilar_qualified() { 4172 void test_undefinedMethod_useSimilar_qualified() {
3718 resolveTestUnit(''' 4173 resolveTestUnit('''
3719 class A { 4174 class A {
3720 myMethod() {} 4175 myMethod() {}
3721 } 4176 }
3722 main() { 4177 main() {
3723 A a = new A(); 4178 A a = new A();
3724 a.myMehtod(); 4179 a.myMehtod();
3725 } 4180 }
3726 '''); 4181 ''');
3727 assertHasFix(DartFixKind.CHANGE_TO, ''' 4182 assertHasFix(
4183 DartFixKind.CHANGE_TO,
4184 '''
3728 class A { 4185 class A {
3729 myMethod() {} 4186 myMethod() {}
3730 } 4187 }
3731 main() { 4188 main() {
3732 A a = new A(); 4189 A a = new A();
3733 a.myMethod(); 4190 a.myMethod();
3734 } 4191 }
3735 '''); 4192 ''');
3736 } 4193 }
3737 4194
3738 void test_undefinedMethod_useSimilar_unqualified_superClass() { 4195 void test_undefinedMethod_useSimilar_unqualified_superClass() {
3739 resolveTestUnit(''' 4196 resolveTestUnit('''
3740 class A { 4197 class A {
3741 myMethod() {} 4198 myMethod() {}
3742 } 4199 }
3743 class B extends A { 4200 class B extends A {
3744 main() { 4201 main() {
3745 myMehtod(); 4202 myMehtod();
3746 } 4203 }
3747 } 4204 }
3748 '''); 4205 ''');
3749 assertHasFix(DartFixKind.CHANGE_TO, ''' 4206 assertHasFix(
4207 DartFixKind.CHANGE_TO,
4208 '''
3750 class A { 4209 class A {
3751 myMethod() {} 4210 myMethod() {}
3752 } 4211 }
3753 class B extends A { 4212 class B extends A {
3754 main() { 4213 main() {
3755 myMethod(); 4214 myMethod();
3756 } 4215 }
3757 } 4216 }
3758 '''); 4217 ''');
3759 } 4218 }
3760 4219
3761 void test_undefinedMethod_useSimilar_unqualified_thisClass() { 4220 void test_undefinedMethod_useSimilar_unqualified_thisClass() {
3762 resolveTestUnit(''' 4221 resolveTestUnit('''
3763 class A { 4222 class A {
3764 myMethod() {} 4223 myMethod() {}
3765 main() { 4224 main() {
3766 myMehtod(); 4225 myMehtod();
3767 } 4226 }
3768 } 4227 }
3769 '''); 4228 ''');
3770 assertHasFix(DartFixKind.CHANGE_TO, ''' 4229 assertHasFix(
4230 DartFixKind.CHANGE_TO,
4231 '''
3771 class A { 4232 class A {
3772 myMethod() {} 4233 myMethod() {}
3773 main() { 4234 main() {
3774 myMethod(); 4235 myMethod();
3775 } 4236 }
3776 } 4237 }
3777 '''); 4238 ''');
3778 } 4239 }
3779 4240
3780 void test_undefinedSetter_useSimilar_hint() { 4241 void test_undefinedSetter_useSimilar_hint() {
3781 resolveTestUnit(''' 4242 resolveTestUnit('''
3782 class A { 4243 class A {
3783 int myField; 4244 int myField;
3784 } 4245 }
3785 main(A a) { 4246 main(A a) {
3786 var x = a; 4247 var x = a;
3787 x.myFild = 42; 4248 x.myFild = 42;
3788 } 4249 }
3789 '''); 4250 ''');
3790 assertHasFix(DartFixKind.CHANGE_TO, ''' 4251 assertHasFix(
4252 DartFixKind.CHANGE_TO,
4253 '''
3791 class A { 4254 class A {
3792 int myField; 4255 int myField;
3793 } 4256 }
3794 main(A a) { 4257 main(A a) {
3795 var x = a; 4258 var x = a;
3796 x.myField = 42; 4259 x.myField = 42;
3797 } 4260 }
3798 '''); 4261 ''');
3799 } 4262 }
3800 4263
3801 void test_undefinedSetter_useSimilar_qualified() { 4264 void test_undefinedSetter_useSimilar_qualified() {
3802 resolveTestUnit(''' 4265 resolveTestUnit('''
3803 class A { 4266 class A {
3804 int myField; 4267 int myField;
3805 } 4268 }
3806 main(A a) { 4269 main(A a) {
3807 a.myFild = 42; 4270 a.myFild = 42;
3808 } 4271 }
3809 '''); 4272 ''');
3810 assertHasFix(DartFixKind.CHANGE_TO, ''' 4273 assertHasFix(
4274 DartFixKind.CHANGE_TO,
4275 '''
3811 class A { 4276 class A {
3812 int myField; 4277 int myField;
3813 } 4278 }
3814 main(A a) { 4279 main(A a) {
3815 a.myField = 42; 4280 a.myField = 42;
3816 } 4281 }
3817 '''); 4282 ''');
3818 } 4283 }
3819 4284
3820 void test_undefinedSetter_useSimilar_unqualified() { 4285 void test_undefinedSetter_useSimilar_unqualified() {
3821 resolveTestUnit(''' 4286 resolveTestUnit('''
3822 class A { 4287 class A {
3823 int myField; 4288 int myField;
3824 main() { 4289 main() {
3825 myFild = 42; 4290 myFild = 42;
3826 } 4291 }
3827 } 4292 }
3828 '''); 4293 ''');
3829 assertHasFix(DartFixKind.CHANGE_TO, ''' 4294 assertHasFix(
4295 DartFixKind.CHANGE_TO,
4296 '''
3830 class A { 4297 class A {
3831 int myField; 4298 int myField;
3832 main() { 4299 main() {
3833 myField = 42; 4300 myField = 42;
3834 } 4301 }
3835 } 4302 }
3836 '''); 4303 ''');
3837 } 4304 }
3838 4305
3839 void test_useEffectiveIntegerDivision() { 4306 void test_useEffectiveIntegerDivision() {
3840 resolveTestUnit(''' 4307 resolveTestUnit('''
3841 main() { 4308 main() {
3842 var a = 5; 4309 var a = 5;
3843 var b = 2; 4310 var b = 2;
3844 print((a / b).toInt()); 4311 print((a / b).toInt());
3845 } 4312 }
3846 '''); 4313 ''');
3847 assertHasFix(DartFixKind.USE_EFFECTIVE_INTEGER_DIVISION, ''' 4314 assertHasFix(
4315 DartFixKind.USE_EFFECTIVE_INTEGER_DIVISION,
4316 '''
3848 main() { 4317 main() {
3849 var a = 5; 4318 var a = 5;
3850 var b = 2; 4319 var b = 2;
3851 print(a ~/ b); 4320 print(a ~/ b);
3852 } 4321 }
3853 '''); 4322 ''');
3854 } 4323 }
3855 4324
3856 /** 4325 /**
3857 * Computes fixes and verifies that there is a fix of the given kind. 4326 * Computes fixes and verifies that there is a fix of the given kind.
(...skipping 26 matching lines...) Expand all
3884 } 4353 }
3885 4354
3886 /** 4355 /**
3887 * Configures the [SourceFactory] to have the `my_pkg` package in 4356 * Configures the [SourceFactory] to have the `my_pkg` package in
3888 * `/packages/my_pkg/lib` folder. 4357 * `/packages/my_pkg/lib` folder.
3889 */ 4358 */
3890 void _configureMyPkg(String myLibCode) { 4359 void _configureMyPkg(String myLibCode) {
3891 provider.newFile('/packages/my_pkg/lib/my_lib.dart', myLibCode); 4360 provider.newFile('/packages/my_pkg/lib/my_lib.dart', myLibCode);
3892 // configure SourceFactory 4361 // configure SourceFactory
3893 Folder myPkgFolder = provider.getResource('/packages/my_pkg/lib'); 4362 Folder myPkgFolder = provider.getResource('/packages/my_pkg/lib');
3894 UriResolver pkgResolver = 4363 UriResolver pkgResolver = new PackageMapUriResolver(provider, {
3895 new PackageMapUriResolver(provider, {'my_pkg': [myPkgFolder]}); 4364 'my_pkg': [myPkgFolder]
4365 });
3896 context.sourceFactory = new SourceFactory( 4366 context.sourceFactory = new SourceFactory(
3897 [AbstractContextTest.SDK_RESOLVER, resourceResolver, pkgResolver]); 4367 [AbstractContextTest.SDK_RESOLVER, resourceResolver, pkgResolver]);
3898 // force 'my_pkg' resolution 4368 // force 'my_pkg' resolution
3899 addSource('/tmp/other.dart', "import 'package:my_pkg/my_lib.dart';"); 4369 addSource('/tmp/other.dart', "import 'package:my_pkg/my_lib.dart';");
3900 } 4370 }
3901 4371
3902 AnalysisError _findErrorToFix() { 4372 AnalysisError _findErrorToFix() {
3903 List<AnalysisError> errors = context.computeErrors(testSource); 4373 List<AnalysisError> errors = context.computeErrors(testSource);
3904 if (errorFilter != null) { 4374 if (errorFilter != null) {
3905 errors = errors.where(errorFilter).toList(); 4375 errors = errors.where(errorFilter).toList();
3906 } 4376 }
3907 expect(errors, hasLength(1)); 4377 expect(errors, hasLength(1));
3908 return errors[0]; 4378 return errors[0];
3909 } 4379 }
3910 4380
3911 List<Position> _findResultPositions(List<String> searchStrings) { 4381 List<Position> _findResultPositions(List<String> searchStrings) {
3912 List<Position> positions = <Position>[]; 4382 List<Position> positions = <Position>[];
3913 for (String search in searchStrings) { 4383 for (String search in searchStrings) {
3914 int offset = resultCode.indexOf(search); 4384 int offset = resultCode.indexOf(search);
3915 positions.add(new Position(testFile, offset)); 4385 positions.add(new Position(testFile, offset));
3916 } 4386 }
3917 return positions; 4387 return positions;
3918 } 4388 }
3919 4389
3920 void _performAnalysis() { 4390 void _performAnalysis() {
3921 while (context.performAnalysisTask().hasMoreWork); 4391 while (context.performAnalysisTask().hasMoreWork);
3922 } 4392 }
3923 } 4393 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698