OLD | NEW |
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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
8 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; | 8 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; |
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 SourceChange change; | 58 SourceChange change; |
59 String resultCode; | 59 String resultCode; |
60 | 60 |
61 assert_undefinedFunction_create_returnType_bool(String lineWithTest) async { | 61 assert_undefinedFunction_create_returnType_bool(String lineWithTest) async { |
62 await resolveTestUnit(''' | 62 await resolveTestUnit(''' |
63 main() { | 63 main() { |
64 bool b = true; | 64 bool b = true; |
65 $lineWithTest | 65 $lineWithTest |
66 } | 66 } |
67 '''); | 67 '''); |
68 await assertHasFix( | 68 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
69 DartFixKind.CREATE_FUNCTION, | |
70 ''' | |
71 main() { | 69 main() { |
72 bool b = true; | 70 bool b = true; |
73 $lineWithTest | 71 $lineWithTest |
74 } | 72 } |
75 | 73 |
76 bool test() { | 74 bool test() { |
77 } | 75 } |
78 '''); | 76 '''); |
79 } | 77 } |
80 | 78 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 class FixProcessorTest extends BaseFixProcessorTest { | 211 class FixProcessorTest extends BaseFixProcessorTest { |
214 test_addFieldFormalParameters_hasRequiredParameter() async { | 212 test_addFieldFormalParameters_hasRequiredParameter() async { |
215 await resolveTestUnit(''' | 213 await resolveTestUnit(''' |
216 class Test { | 214 class Test { |
217 final int a; | 215 final int a; |
218 final int b; | 216 final int b; |
219 final int c; | 217 final int c; |
220 Test(this.a); | 218 Test(this.a); |
221 } | 219 } |
222 '''); | 220 '''); |
223 await assertHasFix( | 221 await assertHasFix(DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, ''' |
224 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, | |
225 ''' | |
226 class Test { | 222 class Test { |
227 final int a; | 223 final int a; |
228 final int b; | 224 final int b; |
229 final int c; | 225 final int c; |
230 Test(this.a, this.b, this.c); | 226 Test(this.a, this.b, this.c); |
231 } | 227 } |
232 '''); | 228 '''); |
233 } | 229 } |
234 | 230 |
235 test_addFieldFormalParameters_noParameters() async { | 231 test_addFieldFormalParameters_noParameters() async { |
236 await resolveTestUnit(''' | 232 await resolveTestUnit(''' |
237 class Test { | 233 class Test { |
238 final int a; | 234 final int a; |
239 final int b; | 235 final int b; |
240 final int c; | 236 final int c; |
241 Test(); | 237 Test(); |
242 } | 238 } |
243 '''); | 239 '''); |
244 await assertHasFix( | 240 await assertHasFix(DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, ''' |
245 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, | |
246 ''' | |
247 class Test { | 241 class Test { |
248 final int a; | 242 final int a; |
249 final int b; | 243 final int b; |
250 final int c; | 244 final int c; |
251 Test(this.a, this.b, this.c); | 245 Test(this.a, this.b, this.c); |
252 } | 246 } |
253 '''); | 247 '''); |
254 } | 248 } |
255 | 249 |
256 test_addFieldFormalParameters_noRequiredParameter() async { | 250 test_addFieldFormalParameters_noRequiredParameter() async { |
257 await resolveTestUnit(''' | 251 await resolveTestUnit(''' |
258 class Test { | 252 class Test { |
259 final int a; | 253 final int a; |
260 final int b; | 254 final int b; |
261 final int c; | 255 final int c; |
262 Test([this.c]); | 256 Test([this.c]); |
263 } | 257 } |
264 '''); | 258 '''); |
265 await assertHasFix( | 259 await assertHasFix(DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, ''' |
266 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, | |
267 ''' | |
268 class Test { | 260 class Test { |
269 final int a; | 261 final int a; |
270 final int b; | 262 final int b; |
271 final int c; | 263 final int c; |
272 Test(this.a, this.b, [this.c]); | 264 Test(this.a, this.b, [this.c]); |
273 } | 265 } |
274 '''); | 266 '''); |
275 } | 267 } |
276 | 268 |
277 test_addMissingParameter_function_positional_hasNamed() async { | 269 test_addMissingParameter_function_positional_hasNamed() async { |
278 await resolveTestUnit(''' | 270 await resolveTestUnit(''' |
279 test({int a}) {} | 271 test({int a}) {} |
280 main() { | 272 main() { |
281 test(1); | 273 test(1); |
282 } | 274 } |
283 '''); | 275 '''); |
284 await assertNoFix(DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL); | 276 await assertNoFix(DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL); |
285 } | 277 } |
286 | 278 |
287 test_addMissingParameter_function_positional_hasZero() async { | 279 test_addMissingParameter_function_positional_hasZero() async { |
288 await resolveTestUnit(''' | 280 await resolveTestUnit(''' |
289 test() {} | 281 test() {} |
290 main() { | 282 main() { |
291 test(1); | 283 test(1); |
292 } | 284 } |
293 '''); | 285 '''); |
294 await assertHasFix( | 286 await assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, ''' |
295 DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, | |
296 ''' | |
297 test([int i]) {} | 287 test([int i]) {} |
298 main() { | 288 main() { |
299 test(1); | 289 test(1); |
300 } | 290 } |
301 '''); | 291 '''); |
302 } | 292 } |
303 | 293 |
304 test_addMissingParameter_function_required_hasNamed() async { | 294 test_addMissingParameter_function_required_hasNamed() async { |
305 await resolveTestUnit(''' | 295 await resolveTestUnit(''' |
306 test({int a}) {} | 296 test({int a}) {} |
307 main() { | 297 main() { |
308 test(1); | 298 test(1); |
309 } | 299 } |
310 '''); | 300 '''); |
311 await assertHasFix( | 301 await assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' |
312 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | |
313 ''' | |
314 test(int i, {int a}) {} | 302 test(int i, {int a}) {} |
315 main() { | 303 main() { |
316 test(1); | 304 test(1); |
317 } | 305 } |
318 '''); | 306 '''); |
319 } | 307 } |
320 | 308 |
321 test_addMissingParameter_function_required_hasOne() async { | 309 test_addMissingParameter_function_required_hasOne() async { |
322 await resolveTestUnit(''' | 310 await resolveTestUnit(''' |
323 test(int a) {} | 311 test(int a) {} |
324 main() { | 312 main() { |
325 test(1, 2.0); | 313 test(1, 2.0); |
326 } | 314 } |
327 '''); | 315 '''); |
328 await assertHasFix( | 316 await assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' |
329 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | |
330 ''' | |
331 test(int a, double d) {} | 317 test(int a, double d) {} |
332 main() { | 318 main() { |
333 test(1, 2.0); | 319 test(1, 2.0); |
334 } | 320 } |
335 '''); | 321 '''); |
336 } | 322 } |
337 | 323 |
338 test_addMissingParameter_function_required_hasZero() async { | 324 test_addMissingParameter_function_required_hasZero() async { |
339 await resolveTestUnit(''' | 325 await resolveTestUnit(''' |
340 test() {} | 326 test() {} |
341 main() { | 327 main() { |
342 test(1); | 328 test(1); |
343 } | 329 } |
344 '''); | 330 '''); |
345 await assertHasFix( | 331 await assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' |
346 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | |
347 ''' | |
348 test(int i) {} | 332 test(int i) {} |
349 main() { | 333 main() { |
350 test(1); | 334 test(1); |
351 } | 335 } |
352 '''); | 336 '''); |
353 } | 337 } |
354 | 338 |
355 test_addMissingParameter_method_positional_hasOne() async { | 339 test_addMissingParameter_method_positional_hasOne() async { |
356 await resolveTestUnit(''' | 340 await resolveTestUnit(''' |
357 class A { | 341 class A { |
358 test(int a) {} | 342 test(int a) {} |
359 main() { | 343 main() { |
360 test(1, 2.0); | 344 test(1, 2.0); |
361 } | 345 } |
362 } | 346 } |
363 '''); | 347 '''); |
364 await assertHasFix( | 348 await assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, ''' |
365 DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, | |
366 ''' | |
367 class A { | 349 class A { |
368 test(int a, [double d]) {} | 350 test(int a, [double d]) {} |
369 main() { | 351 main() { |
370 test(1, 2.0); | 352 test(1, 2.0); |
371 } | 353 } |
372 } | 354 } |
373 '''); | 355 '''); |
374 } | 356 } |
375 | 357 |
376 test_addMissingParameter_method_required_hasOne() async { | 358 test_addMissingParameter_method_required_hasOne() async { |
377 await resolveTestUnit(''' | 359 await resolveTestUnit(''' |
378 class A { | 360 class A { |
379 test(int a) {} | 361 test(int a) {} |
380 main() { | 362 main() { |
381 test(1, 2.0); | 363 test(1, 2.0); |
382 } | 364 } |
383 } | 365 } |
384 '''); | 366 '''); |
385 await assertHasFix( | 367 await assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' |
386 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | |
387 ''' | |
388 class A { | 368 class A { |
389 test(int a, double d) {} | 369 test(int a, double d) {} |
390 main() { | 370 main() { |
391 test(1, 2.0); | 371 test(1, 2.0); |
392 } | 372 } |
393 } | 373 } |
394 '''); | 374 '''); |
395 } | 375 } |
396 | 376 |
397 test_addMissingParameter_method_required_hasZero() async { | 377 test_addMissingParameter_method_required_hasZero() async { |
398 await resolveTestUnit(''' | 378 await resolveTestUnit(''' |
399 class A { | 379 class A { |
400 test() {} | 380 test() {} |
401 main() { | 381 main() { |
402 test(1); | 382 test(1); |
403 } | 383 } |
404 } | 384 } |
405 '''); | 385 '''); |
406 await assertHasFix( | 386 await assertHasFix(DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, ''' |
407 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | |
408 ''' | |
409 class A { | 387 class A { |
410 test(int i) {} | 388 test(int i) {} |
411 main() { | 389 main() { |
412 test(1); | 390 test(1); |
413 } | 391 } |
414 } | 392 } |
415 '''); | 393 '''); |
416 } | 394 } |
417 | 395 |
418 test_addMissingRequiredArg_cons_flutter_children() async { | 396 test_addMissingRequiredArg_cons_flutter_children() async { |
(...skipping 27 matching lines...) Expand all Loading... |
446 | 424 |
447 build() { | 425 build() { |
448 return new MyWidget(children: <Widget>[],); | 426 return new MyWidget(children: <Widget>[],); |
449 } | 427 } |
450 ''', | 428 ''', |
451 target: '/test.dart'); | 429 target: '/test.dart'); |
452 } | 430 } |
453 | 431 |
454 test_addMissingRequiredArg_cons_single() async { | 432 test_addMissingRequiredArg_cons_single() async { |
455 _addMetaPackageSource(); | 433 _addMetaPackageSource(); |
456 addSource( | 434 addSource('/libA.dart', r''' |
457 '/libA.dart', | |
458 r''' | |
459 library libA; | 435 library libA; |
460 import 'package:meta/meta.dart'; | 436 import 'package:meta/meta.dart'; |
461 | 437 |
462 class A { | 438 class A { |
463 A({@required int a}) {} | 439 A({@required int a}) {} |
464 } | 440 } |
465 '''); | 441 '''); |
466 | 442 |
467 await resolveTestUnit(''' | 443 await resolveTestUnit(''' |
468 import 'libA.dart'; | 444 import 'libA.dart'; |
(...skipping 10 matching lines...) Expand all Loading... |
479 main() { | 455 main() { |
480 A a = new A(a: null); | 456 A a = new A(a: null); |
481 } | 457 } |
482 ''', | 458 ''', |
483 target: '/test.dart'); | 459 target: '/test.dart'); |
484 } | 460 } |
485 | 461 |
486 test_addMissingRequiredArg_cons_single_closure() async { | 462 test_addMissingRequiredArg_cons_single_closure() async { |
487 _addMetaPackageSource(); | 463 _addMetaPackageSource(); |
488 | 464 |
489 addSource( | 465 addSource('/libA.dart', r''' |
490 '/libA.dart', | |
491 r''' | |
492 library libA; | 466 library libA; |
493 import 'package:meta/meta.dart'; | 467 import 'package:meta/meta.dart'; |
494 | 468 |
495 typedef void VoidCallback(); | 469 typedef void VoidCallback(); |
496 | 470 |
497 class A { | 471 class A { |
498 A({@required VoidCallback onPressed}) {} | 472 A({@required VoidCallback onPressed}) {} |
499 } | 473 } |
500 '''); | 474 '''); |
501 | 475 |
(...skipping 12 matching lines...) Expand all Loading... |
514 main() { | 488 main() { |
515 A a = new A(onPressed: () {}); | 489 A a = new A(onPressed: () {}); |
516 } | 490 } |
517 ''', | 491 ''', |
518 target: '/test.dart'); | 492 target: '/test.dart'); |
519 } | 493 } |
520 | 494 |
521 test_addMissingRequiredArg_cons_single_closure_2() async { | 495 test_addMissingRequiredArg_cons_single_closure_2() async { |
522 _addMetaPackageSource(); | 496 _addMetaPackageSource(); |
523 | 497 |
524 addSource( | 498 addSource('/libA.dart', r''' |
525 '/libA.dart', | |
526 r''' | |
527 library libA; | 499 library libA; |
528 import 'package:meta/meta.dart'; | 500 import 'package:meta/meta.dart'; |
529 | 501 |
530 typedef void Callback(e); | 502 typedef void Callback(e); |
531 | 503 |
532 class A { | 504 class A { |
533 A({@required Callback callback}) {} | 505 A({@required Callback callback}) {} |
534 } | 506 } |
535 '''); | 507 '''); |
536 | 508 |
(...skipping 12 matching lines...) Expand all Loading... |
549 main() { | 521 main() { |
550 A a = new A(callback: (e) {}); | 522 A a = new A(callback: (e) {}); |
551 } | 523 } |
552 ''', | 524 ''', |
553 target: '/test.dart'); | 525 target: '/test.dart'); |
554 } | 526 } |
555 | 527 |
556 test_addMissingRequiredArg_cons_single_closure_3() async { | 528 test_addMissingRequiredArg_cons_single_closure_3() async { |
557 _addMetaPackageSource(); | 529 _addMetaPackageSource(); |
558 | 530 |
559 addSource( | 531 addSource('/libA.dart', r''' |
560 '/libA.dart', | |
561 r''' | |
562 library libA; | 532 library libA; |
563 import 'package:meta/meta.dart'; | 533 import 'package:meta/meta.dart'; |
564 | 534 |
565 typedef void Callback(a,b,c); | 535 typedef void Callback(a,b,c); |
566 | 536 |
567 class A { | 537 class A { |
568 A({@required Callback callback}) {} | 538 A({@required Callback callback}) {} |
569 } | 539 } |
570 '''); | 540 '''); |
571 | 541 |
(...skipping 12 matching lines...) Expand all Loading... |
584 main() { | 554 main() { |
585 A a = new A(callback: (a, b, c) {}); | 555 A a = new A(callback: (a, b, c) {}); |
586 } | 556 } |
587 ''', | 557 ''', |
588 target: '/test.dart'); | 558 target: '/test.dart'); |
589 } | 559 } |
590 | 560 |
591 test_addMissingRequiredArg_cons_single_closure_4() async { | 561 test_addMissingRequiredArg_cons_single_closure_4() async { |
592 _addMetaPackageSource(); | 562 _addMetaPackageSource(); |
593 | 563 |
594 addSource( | 564 addSource('/libA.dart', r''' |
595 '/libA.dart', | |
596 r''' | |
597 library libA; | 565 library libA; |
598 import 'package:meta/meta.dart'; | 566 import 'package:meta/meta.dart'; |
599 | 567 |
600 typedef int Callback(int a, String b,c); | 568 typedef int Callback(int a, String b,c); |
601 | 569 |
602 class A { | 570 class A { |
603 A({@required Callback callback}) {} | 571 A({@required Callback callback}) {} |
604 } | 572 } |
605 '''); | 573 '''); |
606 | 574 |
(...skipping 12 matching lines...) Expand all Loading... |
619 main() { | 587 main() { |
620 A a = new A(callback: (int a, String b, c) {}); | 588 A a = new A(callback: (int a, String b, c) {}); |
621 } | 589 } |
622 ''', | 590 ''', |
623 target: '/test.dart'); | 591 target: '/test.dart'); |
624 } | 592 } |
625 | 593 |
626 test_addMissingRequiredArg_cons_single_list() async { | 594 test_addMissingRequiredArg_cons_single_list() async { |
627 _addMetaPackageSource(); | 595 _addMetaPackageSource(); |
628 | 596 |
629 addSource( | 597 addSource('/libA.dart', r''' |
630 '/libA.dart', | |
631 r''' | |
632 library libA; | 598 library libA; |
633 import 'package:meta/meta.dart'; | 599 import 'package:meta/meta.dart'; |
634 | 600 |
635 class A { | 601 class A { |
636 A({@required List<String> names}) {} | 602 A({@required List<String> names}) {} |
637 } | 603 } |
638 '''); | 604 '''); |
639 | 605 |
640 await resolveTestUnit(''' | 606 await resolveTestUnit(''' |
641 import 'libA.dart'; | 607 import 'libA.dart'; |
(...skipping 18 matching lines...) Expand all Loading... |
660 _addMetaPackageSource(); | 626 _addMetaPackageSource(); |
661 | 627 |
662 await resolveTestUnit(''' | 628 await resolveTestUnit(''' |
663 import 'package:meta/meta.dart'; | 629 import 'package:meta/meta.dart'; |
664 | 630 |
665 test({@required int a, @required int bcd}) {} | 631 test({@required int a, @required int bcd}) {} |
666 main() { | 632 main() { |
667 test(a: 3); | 633 test(a: 3); |
668 } | 634 } |
669 '''); | 635 '''); |
670 await assertHasFix( | 636 await assertHasFix(DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, ''' |
671 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, | |
672 ''' | |
673 import 'package:meta/meta.dart'; | 637 import 'package:meta/meta.dart'; |
674 | 638 |
675 test({@required int a, @required int bcd}) {} | 639 test({@required int a, @required int bcd}) {} |
676 main() { | 640 main() { |
677 test(a: 3, bcd: null); | 641 test(a: 3, bcd: null); |
678 } | 642 } |
679 '''); | 643 '''); |
680 } | 644 } |
681 | 645 |
682 test_addMissingRequiredArg_multiple_2() async { | 646 test_addMissingRequiredArg_multiple_2() async { |
(...skipping 19 matching lines...) Expand all Loading... |
702 | 666 |
703 List<Fix> fixes = await _computeFixes(filteredErrors.first); | 667 List<Fix> fixes = await _computeFixes(filteredErrors.first); |
704 | 668 |
705 List<Fix> filteredFixes = fixes | 669 List<Fix> filteredFixes = fixes |
706 .where((fix) => fix.change.message == "Add required argument 'a'") | 670 .where((fix) => fix.change.message == "Add required argument 'a'") |
707 .toList(); | 671 .toList(); |
708 expect(filteredFixes, hasLength(1)); | 672 expect(filteredFixes, hasLength(1)); |
709 change = filteredFixes.first.change; | 673 change = filteredFixes.first.change; |
710 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); | 674 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); |
711 // verify | 675 // verify |
712 expect( | 676 expect(resultCode, ''' |
713 resultCode, | |
714 ''' | |
715 import 'package:meta/meta.dart'; | 677 import 'package:meta/meta.dart'; |
716 | 678 |
717 test({@required int a, @required int bcd}) {} | 679 test({@required int a, @required int bcd}) {} |
718 main() { | 680 main() { |
719 test(a: null); | 681 test(a: null); |
720 } | 682 } |
721 '''); | 683 '''); |
722 } | 684 } |
723 | 685 |
724 test_addMissingRequiredArg_single() async { | 686 test_addMissingRequiredArg_single() async { |
725 _addMetaPackageSource(); | 687 _addMetaPackageSource(); |
726 | 688 |
727 await resolveTestUnit(''' | 689 await resolveTestUnit(''' |
728 import 'package:meta/meta.dart'; | 690 import 'package:meta/meta.dart'; |
729 | 691 |
730 test({@required int abc}) {} | 692 test({@required int abc}) {} |
731 main() { | 693 main() { |
732 test(); | 694 test(); |
733 } | 695 } |
734 '''); | 696 '''); |
735 await assertHasFix( | 697 await assertHasFix(DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, ''' |
736 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, | |
737 ''' | |
738 import 'package:meta/meta.dart'; | 698 import 'package:meta/meta.dart'; |
739 | 699 |
740 test({@required int abc}) {} | 700 test({@required int abc}) {} |
741 main() { | 701 main() { |
742 test(abc: null); | 702 test(abc: null); |
743 } | 703 } |
744 '''); | 704 '''); |
745 } | 705 } |
746 | 706 |
747 test_addMissingRequiredArg_single_normal() async { | 707 test_addMissingRequiredArg_single_normal() async { |
748 _addMetaPackageSource(); | 708 _addMetaPackageSource(); |
749 | 709 |
750 await resolveTestUnit(''' | 710 await resolveTestUnit(''' |
751 import 'package:meta/meta.dart'; | 711 import 'package:meta/meta.dart'; |
752 | 712 |
753 test(String x, {@required int abc}) {} | 713 test(String x, {@required int abc}) {} |
754 main() { | 714 main() { |
755 test("foo"); | 715 test("foo"); |
756 } | 716 } |
757 '''); | 717 '''); |
758 await assertHasFix( | 718 await assertHasFix(DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, ''' |
759 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, | |
760 ''' | |
761 import 'package:meta/meta.dart'; | 719 import 'package:meta/meta.dart'; |
762 | 720 |
763 test(String x, {@required int abc}) {} | 721 test(String x, {@required int abc}) {} |
764 main() { | 722 main() { |
765 test("foo", abc: null); | 723 test("foo", abc: null); |
766 } | 724 } |
767 '''); | 725 '''); |
768 } | 726 } |
769 | 727 |
770 test_addMissingRequiredArg_single_with_details() async { | 728 test_addMissingRequiredArg_single_with_details() async { |
771 _addMetaPackageSource(); | 729 _addMetaPackageSource(); |
772 | 730 |
773 await resolveTestUnit(''' | 731 await resolveTestUnit(''' |
774 import 'package:meta/meta.dart'; | 732 import 'package:meta/meta.dart'; |
775 | 733 |
776 test({@Required("Really who doesn't need an abc?") int abc}) {} | 734 test({@Required("Really who doesn't need an abc?") int abc}) {} |
777 main() { | 735 main() { |
778 test(); | 736 test(); |
779 } | 737 } |
780 '''); | 738 '''); |
781 await assertHasFix( | 739 await assertHasFix(DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, ''' |
782 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, | |
783 ''' | |
784 import 'package:meta/meta.dart'; | 740 import 'package:meta/meta.dart'; |
785 | 741 |
786 test({@Required("Really who doesn't need an abc?") int abc}) {} | 742 test({@Required("Really who doesn't need an abc?") int abc}) {} |
787 main() { | 743 main() { |
788 test(abc: null); | 744 test(abc: null); |
789 } | 745 } |
790 '''); | 746 '''); |
791 } | 747 } |
792 | 748 |
793 test_addSync_asyncFor() async { | 749 test_addSync_asyncFor() async { |
794 await resolveTestUnit(''' | 750 await resolveTestUnit(''' |
795 import 'dart:async'; | 751 import 'dart:async'; |
796 void main(Stream<String> names) { | 752 void main(Stream<String> names) { |
797 await for (String name in names) { | 753 await for (String name in names) { |
798 print(name); | 754 print(name); |
799 } | 755 } |
800 } | 756 } |
801 '''); | 757 '''); |
802 await assertHasFix( | 758 await assertHasFix(DartFixKind.ADD_ASYNC, ''' |
803 DartFixKind.ADD_ASYNC, | |
804 ''' | |
805 import 'dart:async'; | 759 import 'dart:async'; |
806 Future main(Stream<String> names) async { | 760 Future main(Stream<String> names) async { |
807 await for (String name in names) { | 761 await for (String name in names) { |
808 print(name); | 762 print(name); |
809 } | 763 } |
810 } | 764 } |
811 '''); | 765 '''); |
812 } | 766 } |
813 | 767 |
814 test_addSync_BAD_nullFunctionBody() async { | 768 test_addSync_BAD_nullFunctionBody() async { |
(...skipping 27 matching lines...) Expand all Loading... |
842 List<Fix> fixes = await _computeFixes(error); | 796 List<Fix> fixes = await _computeFixes(error); |
843 // has exactly one fix | 797 // has exactly one fix |
844 expect(fixes, hasLength(1)); | 798 expect(fixes, hasLength(1)); |
845 Fix fix = fixes[0]; | 799 Fix fix = fixes[0]; |
846 expect(fix.kind, DartFixKind.ADD_ASYNC); | 800 expect(fix.kind, DartFixKind.ADD_ASYNC); |
847 // apply to "file" | 801 // apply to "file" |
848 List<SourceFileEdit> fileEdits = fix.change.edits; | 802 List<SourceFileEdit> fileEdits = fix.change.edits; |
849 expect(fileEdits, hasLength(1)); | 803 expect(fileEdits, hasLength(1)); |
850 resultCode = SourceEdit.applySequence(testCode, fileEdits[0].edits); | 804 resultCode = SourceEdit.applySequence(testCode, fileEdits[0].edits); |
851 // verify | 805 // verify |
852 expect( | 806 expect(resultCode, ''' |
853 resultCode, | |
854 ''' | |
855 foo() {} | 807 foo() {} |
856 main() async { | 808 main() async { |
857 await foo(); | 809 await foo(); |
858 } | 810 } |
859 '''); | 811 '''); |
860 } | 812 } |
861 } | 813 } |
862 | 814 |
863 test_addSync_expressionFunctionBody() async { | 815 test_addSync_expressionFunctionBody() async { |
864 errorFilter = (AnalysisError error) { | 816 errorFilter = (AnalysisError error) { |
865 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; | 817 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; |
866 }; | 818 }; |
867 await resolveTestUnit(''' | 819 await resolveTestUnit(''' |
868 foo() {} | 820 foo() {} |
869 main() => await foo(); | 821 main() => await foo(); |
870 '''); | 822 '''); |
871 await assertHasFix( | 823 await assertHasFix(DartFixKind.ADD_ASYNC, ''' |
872 DartFixKind.ADD_ASYNC, | |
873 ''' | |
874 foo() {} | 824 foo() {} |
875 main() async => await foo(); | 825 main() async => await foo(); |
876 '''); | 826 '''); |
877 } | 827 } |
878 | 828 |
879 test_addSync_returnFuture() async { | 829 test_addSync_returnFuture() async { |
880 errorFilter = (AnalysisError error) { | 830 errorFilter = (AnalysisError error) { |
881 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; | 831 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; |
882 }; | 832 }; |
883 await resolveTestUnit(''' | 833 await resolveTestUnit(''' |
884 foo() {} | 834 foo() {} |
885 int main() { | 835 int main() { |
886 await foo(); | 836 await foo(); |
887 return 42; | 837 return 42; |
888 } | 838 } |
889 '''); | 839 '''); |
890 await assertHasFix( | 840 await assertHasFix(DartFixKind.ADD_ASYNC, ''' |
891 DartFixKind.ADD_ASYNC, | |
892 ''' | |
893 import 'dart:async'; | 841 import 'dart:async'; |
894 | 842 |
895 foo() {} | 843 foo() {} |
896 Future<int> main() async { | 844 Future<int> main() async { |
897 await foo(); | 845 await foo(); |
898 return 42; | 846 return 42; |
899 } | 847 } |
900 '''); | 848 '''); |
901 } | 849 } |
902 | 850 |
903 test_addSync_returnFuture_alreadyFuture() async { | 851 test_addSync_returnFuture_alreadyFuture() async { |
904 errorFilter = (AnalysisError error) { | 852 errorFilter = (AnalysisError error) { |
905 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; | 853 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; |
906 }; | 854 }; |
907 await resolveTestUnit(''' | 855 await resolveTestUnit(''' |
908 import 'dart:async'; | 856 import 'dart:async'; |
909 foo() {} | 857 foo() {} |
910 Future<int> main() { | 858 Future<int> main() { |
911 await foo(); | 859 await foo(); |
912 return 42; | 860 return 42; |
913 } | 861 } |
914 '''); | 862 '''); |
915 await assertHasFix( | 863 await assertHasFix(DartFixKind.ADD_ASYNC, ''' |
916 DartFixKind.ADD_ASYNC, | |
917 ''' | |
918 import 'dart:async'; | 864 import 'dart:async'; |
919 foo() {} | 865 foo() {} |
920 Future<int> main() async { | 866 Future<int> main() async { |
921 await foo(); | 867 await foo(); |
922 return 42; | 868 return 42; |
923 } | 869 } |
924 '''); | 870 '''); |
925 } | 871 } |
926 | 872 |
927 test_addSync_returnFuture_dynamic() async { | 873 test_addSync_returnFuture_dynamic() async { |
928 errorFilter = (AnalysisError error) { | 874 errorFilter = (AnalysisError error) { |
929 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; | 875 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; |
930 }; | 876 }; |
931 await resolveTestUnit(''' | 877 await resolveTestUnit(''' |
932 foo() {} | 878 foo() {} |
933 dynamic main() { | 879 dynamic main() { |
934 await foo(); | 880 await foo(); |
935 return 42; | 881 return 42; |
936 } | 882 } |
937 '''); | 883 '''); |
938 await assertHasFix( | 884 await assertHasFix(DartFixKind.ADD_ASYNC, ''' |
939 DartFixKind.ADD_ASYNC, | |
940 ''' | |
941 foo() {} | 885 foo() {} |
942 dynamic main() async { | 886 dynamic main() async { |
943 await foo(); | 887 await foo(); |
944 return 42; | 888 return 42; |
945 } | 889 } |
946 '''); | 890 '''); |
947 } | 891 } |
948 | 892 |
949 test_addSync_returnFuture_noType() async { | 893 test_addSync_returnFuture_noType() async { |
950 errorFilter = (AnalysisError error) { | 894 errorFilter = (AnalysisError error) { |
951 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; | 895 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; |
952 }; | 896 }; |
953 await resolveTestUnit(''' | 897 await resolveTestUnit(''' |
954 foo() {} | 898 foo() {} |
955 main() { | 899 main() { |
956 await foo(); | 900 await foo(); |
957 return 42; | 901 return 42; |
958 } | 902 } |
959 '''); | 903 '''); |
960 await assertHasFix( | 904 await assertHasFix(DartFixKind.ADD_ASYNC, ''' |
961 DartFixKind.ADD_ASYNC, | |
962 ''' | |
963 foo() {} | 905 foo() {} |
964 main() async { | 906 main() async { |
965 await foo(); | 907 await foo(); |
966 return 42; | 908 return 42; |
967 } | 909 } |
968 '''); | 910 '''); |
969 } | 911 } |
970 | 912 |
971 test_boolean() async { | 913 test_boolean() async { |
972 await resolveTestUnit(''' | 914 await resolveTestUnit(''' |
973 main() { | 915 main() { |
974 boolean v; | 916 boolean v; |
975 } | 917 } |
976 '''); | 918 '''); |
977 await assertHasFix( | 919 await assertHasFix(DartFixKind.REPLACE_BOOLEAN_WITH_BOOL, ''' |
978 DartFixKind.REPLACE_BOOLEAN_WITH_BOOL, | |
979 ''' | |
980 main() { | 920 main() { |
981 bool v; | 921 bool v; |
982 } | 922 } |
983 '''); | 923 '''); |
984 } | 924 } |
985 | 925 |
986 test_canBeNullAfterNullAware_chain() async { | 926 test_canBeNullAfterNullAware_chain() async { |
987 await resolveTestUnit(''' | 927 await resolveTestUnit(''' |
988 main(x) { | 928 main(x) { |
989 x?.a.b.c; | 929 x?.a.b.c; |
990 } | 930 } |
991 '''); | 931 '''); |
992 await assertHasFix( | 932 await assertHasFix(DartFixKind.REPLACE_WITH_NULL_AWARE, ''' |
993 DartFixKind.REPLACE_WITH_NULL_AWARE, | |
994 ''' | |
995 main(x) { | 933 main(x) { |
996 x?.a?.b?.c; | 934 x?.a?.b?.c; |
997 } | 935 } |
998 '''); | 936 '''); |
999 } | 937 } |
1000 | 938 |
1001 test_canBeNullAfterNullAware_methodInvocation() async { | 939 test_canBeNullAfterNullAware_methodInvocation() async { |
1002 await resolveTestUnit(''' | 940 await resolveTestUnit(''' |
1003 main(x) { | 941 main(x) { |
1004 x?.a.b(); | 942 x?.a.b(); |
1005 } | 943 } |
1006 '''); | 944 '''); |
1007 await assertHasFix( | 945 await assertHasFix(DartFixKind.REPLACE_WITH_NULL_AWARE, ''' |
1008 DartFixKind.REPLACE_WITH_NULL_AWARE, | |
1009 ''' | |
1010 main(x) { | 946 main(x) { |
1011 x?.a?.b(); | 947 x?.a?.b(); |
1012 } | 948 } |
1013 '''); | 949 '''); |
1014 } | 950 } |
1015 | 951 |
1016 test_canBeNullAfterNullAware_propertyAccess() async { | 952 test_canBeNullAfterNullAware_propertyAccess() async { |
1017 await resolveTestUnit(''' | 953 await resolveTestUnit(''' |
1018 main(x) { | 954 main(x) { |
1019 x?.a().b; | 955 x?.a().b; |
1020 } | 956 } |
1021 '''); | 957 '''); |
1022 await assertHasFix( | 958 await assertHasFix(DartFixKind.REPLACE_WITH_NULL_AWARE, ''' |
1023 DartFixKind.REPLACE_WITH_NULL_AWARE, | |
1024 ''' | |
1025 main(x) { | 959 main(x) { |
1026 x?.a()?.b; | 960 x?.a()?.b; |
1027 } | 961 } |
1028 '''); | 962 '''); |
1029 } | 963 } |
1030 | 964 |
1031 test_changeToStaticAccess_method() async { | 965 test_changeToStaticAccess_method() async { |
1032 await resolveTestUnit(''' | 966 await resolveTestUnit(''' |
1033 class A { | 967 class A { |
1034 static foo() {} | 968 static foo() {} |
1035 } | 969 } |
1036 main(A a) { | 970 main(A a) { |
1037 a.foo(); | 971 a.foo(); |
1038 } | 972 } |
1039 '''); | 973 '''); |
1040 await assertHasFix( | 974 await assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, ''' |
1041 DartFixKind.CHANGE_TO_STATIC_ACCESS, | |
1042 ''' | |
1043 class A { | 975 class A { |
1044 static foo() {} | 976 static foo() {} |
1045 } | 977 } |
1046 main(A a) { | 978 main(A a) { |
1047 A.foo(); | 979 A.foo(); |
1048 } | 980 } |
1049 '''); | 981 '''); |
1050 } | 982 } |
1051 | 983 |
1052 test_changeToStaticAccess_method_importType() async { | 984 test_changeToStaticAccess_method_importType() async { |
1053 addSource( | 985 addSource('/libA.dart', r''' |
1054 '/libA.dart', | |
1055 r''' | |
1056 library libA; | 986 library libA; |
1057 class A { | 987 class A { |
1058 static foo() {} | 988 static foo() {} |
1059 } | 989 } |
1060 '''); | 990 '''); |
1061 addSource( | 991 addSource('/libB.dart', r''' |
1062 '/libB.dart', | |
1063 r''' | |
1064 library libB; | 992 library libB; |
1065 import 'libA.dart'; | 993 import 'libA.dart'; |
1066 class B extends A {} | 994 class B extends A {} |
1067 '''); | 995 '''); |
1068 await resolveTestUnit(''' | 996 await resolveTestUnit(''' |
1069 import 'libB.dart'; | 997 import 'libB.dart'; |
1070 main(B b) { | 998 main(B b) { |
1071 b.foo(); | 999 b.foo(); |
1072 } | 1000 } |
1073 '''); | 1001 '''); |
1074 await assertHasFix( | 1002 await assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, ''' |
1075 DartFixKind.CHANGE_TO_STATIC_ACCESS, | |
1076 ''' | |
1077 import 'libA.dart'; | 1003 import 'libA.dart'; |
1078 import 'libB.dart'; | 1004 import 'libB.dart'; |
1079 main(B b) { | 1005 main(B b) { |
1080 A.foo(); | 1006 A.foo(); |
1081 } | 1007 } |
1082 '''); | 1008 '''); |
1083 } | 1009 } |
1084 | 1010 |
1085 test_changeToStaticAccess_method_prefixLibrary() async { | 1011 test_changeToStaticAccess_method_prefixLibrary() async { |
1086 await resolveTestUnit(''' | 1012 await resolveTestUnit(''' |
1087 import 'dart:async' as pref; | 1013 import 'dart:async' as pref; |
1088 main(pref.Future f) { | 1014 main(pref.Future f) { |
1089 f.wait([]); | 1015 f.wait([]); |
1090 } | 1016 } |
1091 '''); | 1017 '''); |
1092 await assertHasFix( | 1018 await assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, ''' |
1093 DartFixKind.CHANGE_TO_STATIC_ACCESS, | |
1094 ''' | |
1095 import 'dart:async' as pref; | 1019 import 'dart:async' as pref; |
1096 main(pref.Future f) { | 1020 main(pref.Future f) { |
1097 pref.Future.wait([]); | 1021 pref.Future.wait([]); |
1098 } | 1022 } |
1099 '''); | 1023 '''); |
1100 } | 1024 } |
1101 | 1025 |
1102 test_changeToStaticAccess_property() async { | 1026 test_changeToStaticAccess_property() async { |
1103 await resolveTestUnit(''' | 1027 await resolveTestUnit(''' |
1104 class A { | 1028 class A { |
1105 static get foo => 42; | 1029 static get foo => 42; |
1106 } | 1030 } |
1107 main(A a) { | 1031 main(A a) { |
1108 a.foo; | 1032 a.foo; |
1109 } | 1033 } |
1110 '''); | 1034 '''); |
1111 await assertHasFix( | 1035 await assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, ''' |
1112 DartFixKind.CHANGE_TO_STATIC_ACCESS, | |
1113 ''' | |
1114 class A { | 1036 class A { |
1115 static get foo => 42; | 1037 static get foo => 42; |
1116 } | 1038 } |
1117 main(A a) { | 1039 main(A a) { |
1118 A.foo; | 1040 A.foo; |
1119 } | 1041 } |
1120 '''); | 1042 '''); |
1121 } | 1043 } |
1122 | 1044 |
1123 test_changeToStaticAccess_property_importType() async { | 1045 test_changeToStaticAccess_property_importType() async { |
1124 addSource( | 1046 addSource('/libA.dart', r''' |
1125 '/libA.dart', | |
1126 r''' | |
1127 library libA; | 1047 library libA; |
1128 class A { | 1048 class A { |
1129 static get foo => null; | 1049 static get foo => null; |
1130 } | 1050 } |
1131 '''); | 1051 '''); |
1132 addSource( | 1052 addSource('/libB.dart', r''' |
1133 '/libB.dart', | |
1134 r''' | |
1135 library libB; | 1053 library libB; |
1136 import 'libA.dart'; | 1054 import 'libA.dart'; |
1137 class B extends A {} | 1055 class B extends A {} |
1138 '''); | 1056 '''); |
1139 await resolveTestUnit(''' | 1057 await resolveTestUnit(''' |
1140 import 'libB.dart'; | 1058 import 'libB.dart'; |
1141 main(B b) { | 1059 main(B b) { |
1142 b.foo; | 1060 b.foo; |
1143 } | 1061 } |
1144 '''); | 1062 '''); |
1145 await assertHasFix( | 1063 await assertHasFix(DartFixKind.CHANGE_TO_STATIC_ACCESS, ''' |
1146 DartFixKind.CHANGE_TO_STATIC_ACCESS, | |
1147 ''' | |
1148 import 'libA.dart'; | 1064 import 'libA.dart'; |
1149 import 'libB.dart'; | 1065 import 'libB.dart'; |
1150 main(B b) { | 1066 main(B b) { |
1151 A.foo; | 1067 A.foo; |
1152 } | 1068 } |
1153 '''); | 1069 '''); |
1154 } | 1070 } |
1155 | 1071 |
1156 test_changeTypeAnnotation_BAD_multipleVariables() async { | 1072 test_changeTypeAnnotation_BAD_multipleVariables() async { |
1157 await resolveTestUnit(''' | 1073 await resolveTestUnit(''' |
(...skipping 13 matching lines...) Expand all Loading... |
1171 '''); | 1087 '''); |
1172 await assertNoFix(DartFixKind.CHANGE_TYPE_ANNOTATION); | 1088 await assertNoFix(DartFixKind.CHANGE_TYPE_ANNOTATION); |
1173 } | 1089 } |
1174 | 1090 |
1175 test_changeTypeAnnotation_OK_generic() async { | 1091 test_changeTypeAnnotation_OK_generic() async { |
1176 await resolveTestUnit(''' | 1092 await resolveTestUnit(''' |
1177 main() { | 1093 main() { |
1178 String v = <int>[]; | 1094 String v = <int>[]; |
1179 } | 1095 } |
1180 '''); | 1096 '''); |
1181 await assertHasFix( | 1097 await assertHasFix(DartFixKind.CHANGE_TYPE_ANNOTATION, ''' |
1182 DartFixKind.CHANGE_TYPE_ANNOTATION, | |
1183 ''' | |
1184 main() { | 1098 main() { |
1185 List<int> v = <int>[]; | 1099 List<int> v = <int>[]; |
1186 } | 1100 } |
1187 '''); | 1101 '''); |
1188 } | 1102 } |
1189 | 1103 |
1190 test_changeTypeAnnotation_OK_simple() async { | 1104 test_changeTypeAnnotation_OK_simple() async { |
1191 await resolveTestUnit(''' | 1105 await resolveTestUnit(''' |
1192 main() { | 1106 main() { |
1193 String v = 'abc'.length; | 1107 String v = 'abc'.length; |
1194 } | 1108 } |
1195 '''); | 1109 '''); |
1196 await assertHasFix( | 1110 await assertHasFix(DartFixKind.CHANGE_TYPE_ANNOTATION, ''' |
1197 DartFixKind.CHANGE_TYPE_ANNOTATION, | |
1198 ''' | |
1199 main() { | 1111 main() { |
1200 int v = 'abc'.length; | 1112 int v = 'abc'.length; |
1201 } | 1113 } |
1202 '''); | 1114 '''); |
1203 } | 1115 } |
1204 | 1116 |
1205 test_createClass() async { | 1117 test_createClass() async { |
1206 await resolveTestUnit(''' | 1118 await resolveTestUnit(''' |
1207 main() { | 1119 main() { |
1208 Test v = null; | 1120 Test v = null; |
1209 } | 1121 } |
1210 '''); | 1122 '''); |
1211 await assertHasFix( | 1123 await assertHasFix(DartFixKind.CREATE_CLASS, ''' |
1212 DartFixKind.CREATE_CLASS, | |
1213 ''' | |
1214 main() { | 1124 main() { |
1215 Test v = null; | 1125 Test v = null; |
1216 } | 1126 } |
1217 | 1127 |
1218 class Test { | 1128 class Test { |
1219 } | 1129 } |
1220 '''); | 1130 '''); |
1221 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); | 1131 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); |
1222 } | 1132 } |
1223 | 1133 |
(...skipping 22 matching lines...) Expand all Loading... |
1246 } | 1156 } |
1247 '''); | 1157 '''); |
1248 AnalysisError error = await _findErrorToFix(); | 1158 AnalysisError error = await _findErrorToFix(); |
1249 fix = await _assertHasFix(DartFixKind.CREATE_CLASS, error); | 1159 fix = await _assertHasFix(DartFixKind.CREATE_CLASS, error); |
1250 change = fix.change; | 1160 change = fix.change; |
1251 // apply to "lib.dart" | 1161 // apply to "lib.dart" |
1252 List<SourceFileEdit> fileEdits = change.edits; | 1162 List<SourceFileEdit> fileEdits = change.edits; |
1253 expect(fileEdits, hasLength(1)); | 1163 expect(fileEdits, hasLength(1)); |
1254 SourceFileEdit fileEdit = change.edits[0]; | 1164 SourceFileEdit fileEdit = change.edits[0]; |
1255 expect(fileEdit.file, '/lib.dart'); | 1165 expect(fileEdit.file, '/lib.dart'); |
1256 expect( | 1166 expect(SourceEdit.applySequence(libCode, fileEdit.edits), r''' |
1257 SourceEdit.applySequence(libCode, fileEdit.edits), | |
1258 r''' | |
1259 library my.lib; | 1167 library my.lib; |
1260 | 1168 |
1261 class A {} | 1169 class A {} |
1262 | 1170 |
1263 class Test { | 1171 class Test { |
1264 } | 1172 } |
1265 '''); | 1173 '''); |
1266 expect(change.linkedEditGroups, hasLength(1)); | 1174 expect(change.linkedEditGroups, hasLength(1)); |
1267 } | 1175 } |
1268 | 1176 |
1269 test_createClass_innerLocalFunction() async { | 1177 test_createClass_innerLocalFunction() async { |
1270 await resolveTestUnit(''' | 1178 await resolveTestUnit(''' |
1271 f() { | 1179 f() { |
1272 g() { | 1180 g() { |
1273 Test v = null; | 1181 Test v = null; |
1274 } | 1182 } |
1275 } | 1183 } |
1276 '''); | 1184 '''); |
1277 await assertHasFix( | 1185 await assertHasFix(DartFixKind.CREATE_CLASS, ''' |
1278 DartFixKind.CREATE_CLASS, | |
1279 ''' | |
1280 f() { | 1186 f() { |
1281 g() { | 1187 g() { |
1282 Test v = null; | 1188 Test v = null; |
1283 } | 1189 } |
1284 } | 1190 } |
1285 | 1191 |
1286 class Test { | 1192 class Test { |
1287 } | 1193 } |
1288 '''); | 1194 '''); |
1289 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); | 1195 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); |
1290 } | 1196 } |
1291 | 1197 |
1292 test_createClass_itemOfList() async { | 1198 test_createClass_itemOfList() async { |
1293 await resolveTestUnit(''' | 1199 await resolveTestUnit(''' |
1294 main() { | 1200 main() { |
1295 var a = [Test]; | 1201 var a = [Test]; |
1296 } | 1202 } |
1297 '''); | 1203 '''); |
1298 await assertHasFix( | 1204 await assertHasFix(DartFixKind.CREATE_CLASS, ''' |
1299 DartFixKind.CREATE_CLASS, | |
1300 ''' | |
1301 main() { | 1205 main() { |
1302 var a = [Test]; | 1206 var a = [Test]; |
1303 } | 1207 } |
1304 | 1208 |
1305 class Test { | 1209 class Test { |
1306 } | 1210 } |
1307 '''); | 1211 '''); |
1308 _assertLinkedGroup(change.linkedEditGroups[0], ['Test];', 'Test {']); | 1212 _assertLinkedGroup(change.linkedEditGroups[0], ['Test];', 'Test {']); |
1309 } | 1213 } |
1310 | 1214 |
1311 test_createClass_itemOfList_inAnnotation() async { | 1215 test_createClass_itemOfList_inAnnotation() async { |
1312 errorFilter = (AnalysisError error) { | 1216 errorFilter = (AnalysisError error) { |
1313 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; | 1217 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; |
1314 }; | 1218 }; |
1315 await resolveTestUnit(''' | 1219 await resolveTestUnit(''' |
1316 class MyAnnotation { | 1220 class MyAnnotation { |
1317 const MyAnnotation(a, b); | 1221 const MyAnnotation(a, b); |
1318 } | 1222 } |
1319 @MyAnnotation(int, const [Test]) | 1223 @MyAnnotation(int, const [Test]) |
1320 main() {} | 1224 main() {} |
1321 '''); | 1225 '''); |
1322 await assertHasFix( | 1226 await assertHasFix(DartFixKind.CREATE_CLASS, ''' |
1323 DartFixKind.CREATE_CLASS, | |
1324 ''' | |
1325 class MyAnnotation { | 1227 class MyAnnotation { |
1326 const MyAnnotation(a, b); | 1228 const MyAnnotation(a, b); |
1327 } | 1229 } |
1328 @MyAnnotation(int, const [Test]) | 1230 @MyAnnotation(int, const [Test]) |
1329 main() {} | 1231 main() {} |
1330 | 1232 |
1331 class Test { | 1233 class Test { |
1332 } | 1234 } |
1333 '''); | 1235 '''); |
1334 _assertLinkedGroup(change.linkedEditGroups[0], ['Test])', 'Test {']); | 1236 _assertLinkedGroup(change.linkedEditGroups[0], ['Test])', 'Test {']); |
1335 } | 1237 } |
1336 | 1238 |
1337 test_createConstructor_forFinalFields() async { | 1239 test_createConstructor_forFinalFields() async { |
1338 errorFilter = (AnalysisError error) { | 1240 errorFilter = (AnalysisError error) { |
1339 return error.message.contains("'a'"); | 1241 return error.message.contains("'a'"); |
1340 }; | 1242 }; |
1341 await resolveTestUnit(''' | 1243 await resolveTestUnit(''' |
1342 class Test { | 1244 class Test { |
1343 final int a; | 1245 final int a; |
1344 final int b = 2; | 1246 final int b = 2; |
1345 final int c; | 1247 final int c; |
1346 } | 1248 } |
1347 '''); | 1249 '''); |
1348 await assertHasFix( | 1250 await assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS, ''' |
1349 DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS, | |
1350 ''' | |
1351 class Test { | 1251 class Test { |
1352 final int a; | 1252 final int a; |
1353 final int b = 2; | 1253 final int b = 2; |
1354 final int c; | 1254 final int c; |
1355 | 1255 |
1356 Test(this.a, this.c); | 1256 Test(this.a, this.c); |
1357 } | 1257 } |
1358 '''); | 1258 '''); |
1359 } | 1259 } |
1360 | 1260 |
1361 test_createConstructor_insteadOfSyntheticDefault() async { | 1261 test_createConstructor_insteadOfSyntheticDefault() async { |
1362 await resolveTestUnit(''' | 1262 await resolveTestUnit(''' |
1363 class A { | 1263 class A { |
1364 int field; | 1264 int field; |
1365 | 1265 |
1366 method() {} | 1266 method() {} |
1367 } | 1267 } |
1368 main() { | 1268 main() { |
1369 new A(1, 2.0); | 1269 new A(1, 2.0); |
1370 } | 1270 } |
1371 '''); | 1271 '''); |
1372 await assertHasFix( | 1272 await assertHasFix(DartFixKind.CREATE_CONSTRUCTOR, ''' |
1373 DartFixKind.CREATE_CONSTRUCTOR, | |
1374 ''' | |
1375 class A { | 1273 class A { |
1376 int field; | 1274 int field; |
1377 | 1275 |
1378 A(int i, double d); | 1276 A(int i, double d); |
1379 | 1277 |
1380 method() {} | 1278 method() {} |
1381 } | 1279 } |
1382 main() { | 1280 main() { |
1383 new A(1, 2.0); | 1281 new A(1, 2.0); |
1384 } | 1282 } |
1385 '''); | 1283 '''); |
1386 } | 1284 } |
1387 | 1285 |
1388 test_createConstructor_named() async { | 1286 test_createConstructor_named() async { |
1389 await resolveTestUnit(''' | 1287 await resolveTestUnit(''' |
1390 class A { | 1288 class A { |
1391 method() {} | 1289 method() {} |
1392 } | 1290 } |
1393 main() { | 1291 main() { |
1394 new A.named(1, 2.0); | 1292 new A.named(1, 2.0); |
1395 } | 1293 } |
1396 '''); | 1294 '''); |
1397 await assertHasFix( | 1295 await assertHasFix(DartFixKind.CREATE_CONSTRUCTOR, ''' |
1398 DartFixKind.CREATE_CONSTRUCTOR, | |
1399 ''' | |
1400 class A { | 1296 class A { |
1401 A.named(int i, double d); | 1297 A.named(int i, double d); |
1402 | 1298 |
1403 method() {} | 1299 method() {} |
1404 } | 1300 } |
1405 main() { | 1301 main() { |
1406 new A.named(1, 2.0); | 1302 new A.named(1, 2.0); |
1407 } | 1303 } |
1408 '''); | 1304 '''); |
1409 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']); | 1305 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']); |
1410 } | 1306 } |
1411 | 1307 |
1412 test_createConstructor_named_emptyClassBody() async { | 1308 test_createConstructor_named_emptyClassBody() async { |
1413 await resolveTestUnit(''' | 1309 await resolveTestUnit(''' |
1414 class A {} | 1310 class A {} |
1415 main() { | 1311 main() { |
1416 new A.named(1); | 1312 new A.named(1); |
1417 } | 1313 } |
1418 '''); | 1314 '''); |
1419 await assertHasFix( | 1315 await assertHasFix(DartFixKind.CREATE_CONSTRUCTOR, ''' |
1420 DartFixKind.CREATE_CONSTRUCTOR, | |
1421 ''' | |
1422 class A { | 1316 class A { |
1423 A.named(int i); | 1317 A.named(int i); |
1424 } | 1318 } |
1425 main() { | 1319 main() { |
1426 new A.named(1); | 1320 new A.named(1); |
1427 } | 1321 } |
1428 '''); | 1322 '''); |
1429 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']); | 1323 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']); |
1430 } | 1324 } |
1431 | 1325 |
(...skipping 15 matching lines...) Expand all Loading... |
1447 | 1341 |
1448 test_createConstructorSuperExplicit() async { | 1342 test_createConstructorSuperExplicit() async { |
1449 await resolveTestUnit(''' | 1343 await resolveTestUnit(''' |
1450 class A { | 1344 class A { |
1451 A(bool p1, int p2, double p3, String p4, {p5}); | 1345 A(bool p1, int p2, double p3, String p4, {p5}); |
1452 } | 1346 } |
1453 class B extends A { | 1347 class B extends A { |
1454 B() {} | 1348 B() {} |
1455 } | 1349 } |
1456 '''); | 1350 '''); |
1457 await assertHasFix( | 1351 await assertHasFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' |
1458 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, | |
1459 ''' | |
1460 class A { | 1352 class A { |
1461 A(bool p1, int p2, double p3, String p4, {p5}); | 1353 A(bool p1, int p2, double p3, String p4, {p5}); |
1462 } | 1354 } |
1463 class B extends A { | 1355 class B extends A { |
1464 B() : super(false, 0, 0.0, '') {} | 1356 B() : super(false, 0, 0.0, '') {} |
1465 } | 1357 } |
1466 '''); | 1358 '''); |
1467 } | 1359 } |
1468 | 1360 |
1469 test_createConstructorSuperExplicit_hasInitializers() async { | 1361 test_createConstructorSuperExplicit_hasInitializers() async { |
1470 await resolveTestUnit(''' | 1362 await resolveTestUnit(''' |
1471 class A { | 1363 class A { |
1472 A(int p); | 1364 A(int p); |
1473 } | 1365 } |
1474 class B extends A { | 1366 class B extends A { |
1475 int field; | 1367 int field; |
1476 B() : field = 42 {} | 1368 B() : field = 42 {} |
1477 } | 1369 } |
1478 '''); | 1370 '''); |
1479 await assertHasFix( | 1371 await assertHasFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' |
1480 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, | |
1481 ''' | |
1482 class A { | 1372 class A { |
1483 A(int p); | 1373 A(int p); |
1484 } | 1374 } |
1485 class B extends A { | 1375 class B extends A { |
1486 int field; | 1376 int field; |
1487 B() : field = 42, super(0) {} | 1377 B() : field = 42, super(0) {} |
1488 } | 1378 } |
1489 '''); | 1379 '''); |
1490 } | 1380 } |
1491 | 1381 |
1492 test_createConstructorSuperExplicit_named() async { | 1382 test_createConstructorSuperExplicit_named() async { |
1493 await resolveTestUnit(''' | 1383 await resolveTestUnit(''' |
1494 class A { | 1384 class A { |
1495 A.named(int p); | 1385 A.named(int p); |
1496 } | 1386 } |
1497 class B extends A { | 1387 class B extends A { |
1498 B() {} | 1388 B() {} |
1499 } | 1389 } |
1500 '''); | 1390 '''); |
1501 await assertHasFix( | 1391 await assertHasFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' |
1502 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, | |
1503 ''' | |
1504 class A { | 1392 class A { |
1505 A.named(int p); | 1393 A.named(int p); |
1506 } | 1394 } |
1507 class B extends A { | 1395 class B extends A { |
1508 B() : super.named(0) {} | 1396 B() : super.named(0) {} |
1509 } | 1397 } |
1510 '''); | 1398 '''); |
1511 } | 1399 } |
1512 | 1400 |
1513 test_createConstructorSuperExplicit_named_private() async { | 1401 test_createConstructorSuperExplicit_named_private() async { |
(...skipping 10 matching lines...) Expand all Loading... |
1524 | 1412 |
1525 test_createConstructorSuperExplicit_typeArgument() async { | 1413 test_createConstructorSuperExplicit_typeArgument() async { |
1526 await resolveTestUnit(''' | 1414 await resolveTestUnit(''' |
1527 class A<T> { | 1415 class A<T> { |
1528 A(T p); | 1416 A(T p); |
1529 } | 1417 } |
1530 class B extends A<int> { | 1418 class B extends A<int> { |
1531 B(); | 1419 B(); |
1532 } | 1420 } |
1533 '''); | 1421 '''); |
1534 await assertHasFix( | 1422 await assertHasFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, ''' |
1535 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, | |
1536 ''' | |
1537 class A<T> { | 1423 class A<T> { |
1538 A(T p); | 1424 A(T p); |
1539 } | 1425 } |
1540 class B extends A<int> { | 1426 class B extends A<int> { |
1541 B() : super(0); | 1427 B() : super(0); |
1542 } | 1428 } |
1543 '''); | 1429 '''); |
1544 } | 1430 } |
1545 | 1431 |
1546 test_createConstructorSuperImplicit() async { | 1432 test_createConstructorSuperImplicit() async { |
1547 await resolveTestUnit(''' | 1433 await resolveTestUnit(''' |
1548 class A { | 1434 class A { |
1549 A(p1, int p2, List<String> p3, [int p4]); | 1435 A(p1, int p2, List<String> p3, [int p4]); |
1550 } | 1436 } |
1551 class B extends A { | 1437 class B extends A { |
1552 int existingField; | 1438 int existingField; |
1553 | 1439 |
1554 void existingMethod() {} | 1440 void existingMethod() {} |
1555 } | 1441 } |
1556 '''); | 1442 '''); |
1557 await assertHasFix( | 1443 await assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, ''' |
1558 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | |
1559 ''' | |
1560 class A { | 1444 class A { |
1561 A(p1, int p2, List<String> p3, [int p4]); | 1445 A(p1, int p2, List<String> p3, [int p4]); |
1562 } | 1446 } |
1563 class B extends A { | 1447 class B extends A { |
1564 int existingField; | 1448 int existingField; |
1565 | 1449 |
1566 B(p1, int p2, List<String> p3) : super(p1, p2, p3); | 1450 B(p1, int p2, List<String> p3) : super(p1, p2, p3); |
1567 | 1451 |
1568 void existingMethod() {} | 1452 void existingMethod() {} |
1569 } | 1453 } |
1570 '''); | 1454 '''); |
1571 } | 1455 } |
1572 | 1456 |
1573 test_createConstructorSuperImplicit_fieldInitializer() async { | 1457 test_createConstructorSuperImplicit_fieldInitializer() async { |
1574 await resolveTestUnit(''' | 1458 await resolveTestUnit(''' |
1575 class A { | 1459 class A { |
1576 int _field; | 1460 int _field; |
1577 A(this._field); | 1461 A(this._field); |
1578 } | 1462 } |
1579 class B extends A { | 1463 class B extends A { |
1580 int existingField; | 1464 int existingField; |
1581 | 1465 |
1582 void existingMethod() {} | 1466 void existingMethod() {} |
1583 } | 1467 } |
1584 '''); | 1468 '''); |
1585 await assertHasFix( | 1469 await assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, ''' |
1586 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | |
1587 ''' | |
1588 class A { | 1470 class A { |
1589 int _field; | 1471 int _field; |
1590 A(this._field); | 1472 A(this._field); |
1591 } | 1473 } |
1592 class B extends A { | 1474 class B extends A { |
1593 int existingField; | 1475 int existingField; |
1594 | 1476 |
1595 B(int field) : super(field); | 1477 B(int field) : super(field); |
1596 | 1478 |
1597 void existingMethod() {} | 1479 void existingMethod() {} |
1598 } | 1480 } |
1599 '''); | 1481 '''); |
1600 } | 1482 } |
1601 | 1483 |
1602 test_createConstructorSuperImplicit_importType() async { | 1484 test_createConstructorSuperImplicit_importType() async { |
1603 addSource( | 1485 addSource('/libA.dart', r''' |
1604 '/libA.dart', | |
1605 r''' | |
1606 library libA; | 1486 library libA; |
1607 class A {} | 1487 class A {} |
1608 '''); | 1488 '''); |
1609 addSource( | 1489 addSource('/libB.dart', r''' |
1610 '/libB.dart', | |
1611 r''' | |
1612 library libB; | 1490 library libB; |
1613 import 'libA.dart'; | 1491 import 'libA.dart'; |
1614 class B { | 1492 class B { |
1615 B(A a); | 1493 B(A a); |
1616 } | 1494 } |
1617 '''); | 1495 '''); |
1618 await resolveTestUnit(''' | 1496 await resolveTestUnit(''' |
1619 import 'libB.dart'; | 1497 import 'libB.dart'; |
1620 class C extends B { | 1498 class C extends B { |
1621 } | 1499 } |
1622 '''); | 1500 '''); |
1623 await assertHasFix( | 1501 await assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, ''' |
1624 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | |
1625 ''' | |
1626 import 'libA.dart'; | 1502 import 'libA.dart'; |
1627 import 'libB.dart'; | 1503 import 'libB.dart'; |
1628 class C extends B { | 1504 class C extends B { |
1629 C(A a) : super(a); | 1505 C(A a) : super(a); |
1630 } | 1506 } |
1631 '''); | 1507 '''); |
1632 } | 1508 } |
1633 | 1509 |
1634 test_createConstructorSuperImplicit_named() async { | 1510 test_createConstructorSuperImplicit_named() async { |
1635 await resolveTestUnit(''' | 1511 await resolveTestUnit(''' |
1636 class A { | 1512 class A { |
1637 A.named(p1, int p2); | 1513 A.named(p1, int p2); |
1638 } | 1514 } |
1639 class B extends A { | 1515 class B extends A { |
1640 int existingField; | 1516 int existingField; |
1641 | 1517 |
1642 void existingMethod() {} | 1518 void existingMethod() {} |
1643 } | 1519 } |
1644 '''); | 1520 '''); |
1645 await assertHasFix( | 1521 await assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, ''' |
1646 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | |
1647 ''' | |
1648 class A { | 1522 class A { |
1649 A.named(p1, int p2); | 1523 A.named(p1, int p2); |
1650 } | 1524 } |
1651 class B extends A { | 1525 class B extends A { |
1652 int existingField; | 1526 int existingField; |
1653 | 1527 |
1654 B.named(p1, int p2) : super.named(p1, p2); | 1528 B.named(p1, int p2) : super.named(p1, p2); |
1655 | 1529 |
1656 void existingMethod() {} | 1530 void existingMethod() {} |
1657 } | 1531 } |
(...skipping 12 matching lines...) Expand all Loading... |
1670 } | 1544 } |
1671 | 1545 |
1672 test_createConstructorSuperImplicit_typeArgument() async { | 1546 test_createConstructorSuperImplicit_typeArgument() async { |
1673 await resolveTestUnit(''' | 1547 await resolveTestUnit(''' |
1674 class C<T> { | 1548 class C<T> { |
1675 final T x; | 1549 final T x; |
1676 C(this.x); | 1550 C(this.x); |
1677 } | 1551 } |
1678 class D extends C<int> { | 1552 class D extends C<int> { |
1679 }'''); | 1553 }'''); |
1680 await assertHasFix( | 1554 await assertHasFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER, ''' |
1681 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | |
1682 ''' | |
1683 class C<T> { | 1555 class C<T> { |
1684 final T x; | 1556 final T x; |
1685 C(this.x); | 1557 C(this.x); |
1686 } | 1558 } |
1687 class D extends C<int> { | 1559 class D extends C<int> { |
1688 D(int x) : super(x); | 1560 D(int x) : super(x); |
1689 }'''); | 1561 }'''); |
1690 } | 1562 } |
1691 | 1563 |
1692 test_createField_BAD_inEnum() async { | 1564 test_createField_BAD_inEnum() async { |
(...skipping 24 matching lines...) Expand all Loading... |
1717 class B { | 1589 class B { |
1718 A a; | 1590 A a; |
1719 } | 1591 } |
1720 class C { | 1592 class C { |
1721 B b; | 1593 B b; |
1722 } | 1594 } |
1723 main(C c) { | 1595 main(C c) { |
1724 int v = c.b.a.test; | 1596 int v = c.b.a.test; |
1725 } | 1597 } |
1726 '''); | 1598 '''); |
1727 await assertHasFix( | 1599 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
1728 DartFixKind.CREATE_FIELD, | |
1729 ''' | |
1730 class A { | 1600 class A { |
1731 int test; | 1601 int test; |
1732 } | 1602 } |
1733 class B { | 1603 class B { |
1734 A a; | 1604 A a; |
1735 } | 1605 } |
1736 class C { | 1606 class C { |
1737 B b; | 1607 B b; |
1738 } | 1608 } |
1739 main(C c) { | 1609 main(C c) { |
1740 int v = c.b.a.test; | 1610 int v = c.b.a.test; |
1741 } | 1611 } |
1742 '''); | 1612 '''); |
1743 } | 1613 } |
1744 | 1614 |
1745 test_createField_getter_qualified_instance() async { | 1615 test_createField_getter_qualified_instance() async { |
1746 await resolveTestUnit(''' | 1616 await resolveTestUnit(''' |
1747 class A { | 1617 class A { |
1748 } | 1618 } |
1749 main(A a) { | 1619 main(A a) { |
1750 int v = a.test; | 1620 int v = a.test; |
1751 } | 1621 } |
1752 '''); | 1622 '''); |
1753 await assertHasFix( | 1623 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
1754 DartFixKind.CREATE_FIELD, | |
1755 ''' | |
1756 class A { | 1624 class A { |
1757 int test; | 1625 int test; |
1758 } | 1626 } |
1759 main(A a) { | 1627 main(A a) { |
1760 int v = a.test; | 1628 int v = a.test; |
1761 } | 1629 } |
1762 '''); | 1630 '''); |
1763 } | 1631 } |
1764 | 1632 |
1765 test_createField_getter_qualified_instance_dynamicType() async { | 1633 test_createField_getter_qualified_instance_dynamicType() async { |
1766 await resolveTestUnit(''' | 1634 await resolveTestUnit(''' |
1767 class A { | 1635 class A { |
1768 B b; | 1636 B b; |
1769 void f(Object p) { | 1637 void f(Object p) { |
1770 p == b.test; | 1638 p == b.test; |
1771 } | 1639 } |
1772 } | 1640 } |
1773 class B { | 1641 class B { |
1774 } | 1642 } |
1775 '''); | 1643 '''); |
1776 await assertHasFix( | 1644 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
1777 DartFixKind.CREATE_FIELD, | |
1778 ''' | |
1779 class A { | 1645 class A { |
1780 B b; | 1646 B b; |
1781 void f(Object p) { | 1647 void f(Object p) { |
1782 p == b.test; | 1648 p == b.test; |
1783 } | 1649 } |
1784 } | 1650 } |
1785 class B { | 1651 class B { |
1786 var test; | 1652 var test; |
1787 } | 1653 } |
1788 '''); | 1654 '''); |
1789 } | 1655 } |
1790 | 1656 |
1791 test_createField_getter_qualified_propagatedType() async { | 1657 test_createField_getter_qualified_propagatedType() async { |
1792 await resolveTestUnit(''' | 1658 await resolveTestUnit(''' |
1793 class A { | 1659 class A { |
1794 A get self => this; | 1660 A get self => this; |
1795 } | 1661 } |
1796 main() { | 1662 main() { |
1797 var a = new A(); | 1663 var a = new A(); |
1798 int v = a.self.test; | 1664 int v = a.self.test; |
1799 } | 1665 } |
1800 '''); | 1666 '''); |
1801 await assertHasFix( | 1667 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
1802 DartFixKind.CREATE_FIELD, | |
1803 ''' | |
1804 class A { | 1668 class A { |
1805 int test; | 1669 int test; |
1806 | 1670 |
1807 A get self => this; | 1671 A get self => this; |
1808 } | 1672 } |
1809 main() { | 1673 main() { |
1810 var a = new A(); | 1674 var a = new A(); |
1811 int v = a.self.test; | 1675 int v = a.self.test; |
1812 } | 1676 } |
1813 '''); | 1677 '''); |
1814 } | 1678 } |
1815 | 1679 |
1816 test_createField_getter_unqualified_instance_asInvocationArgument() async { | 1680 test_createField_getter_unqualified_instance_asInvocationArgument() async { |
1817 await resolveTestUnit(''' | 1681 await resolveTestUnit(''' |
1818 class A { | 1682 class A { |
1819 main() { | 1683 main() { |
1820 f(test); | 1684 f(test); |
1821 } | 1685 } |
1822 } | 1686 } |
1823 f(String s) {} | 1687 f(String s) {} |
1824 '''); | 1688 '''); |
1825 await assertHasFix( | 1689 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
1826 DartFixKind.CREATE_FIELD, | |
1827 ''' | |
1828 class A { | 1690 class A { |
1829 String test; | 1691 String test; |
1830 | 1692 |
1831 main() { | 1693 main() { |
1832 f(test); | 1694 f(test); |
1833 } | 1695 } |
1834 } | 1696 } |
1835 f(String s) {} | 1697 f(String s) {} |
1836 '''); | 1698 '''); |
1837 } | 1699 } |
1838 | 1700 |
1839 test_createField_getter_unqualified_instance_assignmentRhs() async { | 1701 test_createField_getter_unqualified_instance_assignmentRhs() async { |
1840 await resolveTestUnit(''' | 1702 await resolveTestUnit(''' |
1841 class A { | 1703 class A { |
1842 main() { | 1704 main() { |
1843 int v = test; | 1705 int v = test; |
1844 } | 1706 } |
1845 } | 1707 } |
1846 '''); | 1708 '''); |
1847 await assertHasFix( | 1709 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
1848 DartFixKind.CREATE_FIELD, | |
1849 ''' | |
1850 class A { | 1710 class A { |
1851 int test; | 1711 int test; |
1852 | 1712 |
1853 main() { | 1713 main() { |
1854 int v = test; | 1714 int v = test; |
1855 } | 1715 } |
1856 } | 1716 } |
1857 '''); | 1717 '''); |
1858 } | 1718 } |
1859 | 1719 |
1860 test_createField_getter_unqualified_instance_asStatement() async { | 1720 test_createField_getter_unqualified_instance_asStatement() async { |
1861 await resolveTestUnit(''' | 1721 await resolveTestUnit(''' |
1862 class A { | 1722 class A { |
1863 main() { | 1723 main() { |
1864 test; | 1724 test; |
1865 } | 1725 } |
1866 } | 1726 } |
1867 '''); | 1727 '''); |
1868 await assertHasFix( | 1728 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
1869 DartFixKind.CREATE_FIELD, | |
1870 ''' | |
1871 class A { | 1729 class A { |
1872 var test; | 1730 var test; |
1873 | 1731 |
1874 main() { | 1732 main() { |
1875 test; | 1733 test; |
1876 } | 1734 } |
1877 } | 1735 } |
1878 '''); | 1736 '''); |
1879 } | 1737 } |
1880 | 1738 |
1881 test_createField_hint() async { | 1739 test_createField_hint() async { |
1882 await resolveTestUnit(''' | 1740 await resolveTestUnit(''' |
1883 class A { | 1741 class A { |
1884 } | 1742 } |
1885 main(A a) { | 1743 main(A a) { |
1886 var x = a; | 1744 var x = a; |
1887 int v = x.test; | 1745 int v = x.test; |
1888 } | 1746 } |
1889 '''); | 1747 '''); |
1890 await assertHasFix( | 1748 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
1891 DartFixKind.CREATE_FIELD, | |
1892 ''' | |
1893 class A { | 1749 class A { |
1894 int test; | 1750 int test; |
1895 } | 1751 } |
1896 main(A a) { | 1752 main(A a) { |
1897 var x = a; | 1753 var x = a; |
1898 int v = x.test; | 1754 int v = x.test; |
1899 } | 1755 } |
1900 '''); | 1756 '''); |
1901 } | 1757 } |
1902 | 1758 |
1903 test_createField_hint_setter() async { | 1759 test_createField_hint_setter() async { |
1904 await resolveTestUnit(''' | 1760 await resolveTestUnit(''' |
1905 class A { | 1761 class A { |
1906 } | 1762 } |
1907 main(A a) { | 1763 main(A a) { |
1908 var x = a; | 1764 var x = a; |
1909 x.test = 0; | 1765 x.test = 0; |
1910 } | 1766 } |
1911 '''); | 1767 '''); |
1912 await assertHasFix( | 1768 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
1913 DartFixKind.CREATE_FIELD, | |
1914 ''' | |
1915 class A { | 1769 class A { |
1916 int test; | 1770 int test; |
1917 } | 1771 } |
1918 main(A a) { | 1772 main(A a) { |
1919 var x = a; | 1773 var x = a; |
1920 x.test = 0; | 1774 x.test = 0; |
1921 } | 1775 } |
1922 '''); | 1776 '''); |
1923 } | 1777 } |
1924 | 1778 |
1925 test_createField_importType() async { | 1779 test_createField_importType() async { |
1926 addSource( | 1780 addSource('/libA.dart', r''' |
1927 '/libA.dart', | |
1928 r''' | |
1929 library libA; | 1781 library libA; |
1930 class A {} | 1782 class A {} |
1931 '''); | 1783 '''); |
1932 addSource( | 1784 addSource('/libB.dart', r''' |
1933 '/libB.dart', | |
1934 r''' | |
1935 library libB; | 1785 library libB; |
1936 import 'libA.dart'; | 1786 import 'libA.dart'; |
1937 A getA() => null; | 1787 A getA() => null; |
1938 '''); | 1788 '''); |
1939 await resolveTestUnit(''' | 1789 await resolveTestUnit(''' |
1940 import 'libB.dart'; | 1790 import 'libB.dart'; |
1941 class C { | 1791 class C { |
1942 } | 1792 } |
1943 main(C c) { | 1793 main(C c) { |
1944 c.test = getA(); | 1794 c.test = getA(); |
1945 } | 1795 } |
1946 '''); | 1796 '''); |
1947 await assertHasFix( | 1797 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
1948 DartFixKind.CREATE_FIELD, | |
1949 ''' | |
1950 import 'libA.dart'; | 1798 import 'libA.dart'; |
1951 import 'libB.dart'; | 1799 import 'libB.dart'; |
1952 class C { | 1800 class C { |
1953 A test; | 1801 A test; |
1954 } | 1802 } |
1955 main(C c) { | 1803 main(C c) { |
1956 c.test = getA(); | 1804 c.test = getA(); |
1957 } | 1805 } |
1958 '''); | 1806 '''); |
1959 } | 1807 } |
1960 | 1808 |
1961 test_createField_invalidInitializer_withoutType() async { | 1809 test_createField_invalidInitializer_withoutType() async { |
1962 await resolveTestUnit(''' | 1810 await resolveTestUnit(''' |
1963 class C { | 1811 class C { |
1964 C(this.text); | 1812 C(this.text); |
1965 } | 1813 } |
1966 '''); | 1814 '''); |
1967 await assertHasFix( | 1815 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
1968 DartFixKind.CREATE_FIELD, | |
1969 ''' | |
1970 class C { | 1816 class C { |
1971 var text; | 1817 var text; |
1972 | 1818 |
1973 C(this.text); | 1819 C(this.text); |
1974 } | 1820 } |
1975 '''); | 1821 '''); |
1976 } | 1822 } |
1977 | 1823 |
1978 test_createField_invalidInitializer_withType() async { | 1824 test_createField_invalidInitializer_withType() async { |
1979 await resolveTestUnit(''' | 1825 await resolveTestUnit(''' |
1980 class C { | 1826 class C { |
1981 C(String this.text); | 1827 C(String this.text); |
1982 } | 1828 } |
1983 '''); | 1829 '''); |
1984 await assertHasFix( | 1830 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
1985 DartFixKind.CREATE_FIELD, | |
1986 ''' | |
1987 class C { | 1831 class C { |
1988 String text; | 1832 String text; |
1989 | 1833 |
1990 C(String this.text); | 1834 C(String this.text); |
1991 } | 1835 } |
1992 '''); | 1836 '''); |
1993 } | 1837 } |
1994 | 1838 |
1995 test_createField_setter_generic_BAD() async { | 1839 test_createField_setter_generic_BAD() async { |
1996 await resolveTestUnit(''' | 1840 await resolveTestUnit(''' |
1997 class A { | 1841 class A { |
1998 } | 1842 } |
1999 class B<T> { | 1843 class B<T> { |
2000 List<T> items; | 1844 List<T> items; |
2001 main(A a) { | 1845 main(A a) { |
2002 a.test = items; | 1846 a.test = items; |
2003 } | 1847 } |
2004 } | 1848 } |
2005 '''); | 1849 '''); |
2006 await assertHasFix( | 1850 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
2007 DartFixKind.CREATE_FIELD, | |
2008 ''' | |
2009 class A { | 1851 class A { |
2010 List test; | 1852 List test; |
2011 } | 1853 } |
2012 class B<T> { | 1854 class B<T> { |
2013 List<T> items; | 1855 List<T> items; |
2014 main(A a) { | 1856 main(A a) { |
2015 a.test = items; | 1857 a.test = items; |
2016 } | 1858 } |
2017 } | 1859 } |
2018 '''); | 1860 '''); |
2019 } | 1861 } |
2020 | 1862 |
2021 test_createField_setter_generic_OK_local() async { | 1863 test_createField_setter_generic_OK_local() async { |
2022 await resolveTestUnit(''' | 1864 await resolveTestUnit(''' |
2023 class A<T> { | 1865 class A<T> { |
2024 List<T> items; | 1866 List<T> items; |
2025 | 1867 |
2026 main(A a) { | 1868 main(A a) { |
2027 test = items; | 1869 test = items; |
2028 } | 1870 } |
2029 } | 1871 } |
2030 '''); | 1872 '''); |
2031 await assertHasFix( | 1873 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
2032 DartFixKind.CREATE_FIELD, | |
2033 ''' | |
2034 class A<T> { | 1874 class A<T> { |
2035 List<T> items; | 1875 List<T> items; |
2036 | 1876 |
2037 List<T> test; | 1877 List<T> test; |
2038 | 1878 |
2039 main(A a) { | 1879 main(A a) { |
2040 test = items; | 1880 test = items; |
2041 } | 1881 } |
2042 } | 1882 } |
2043 '''); | 1883 '''); |
2044 } | 1884 } |
2045 | 1885 |
2046 test_createField_setter_qualified_instance_hasField() async { | 1886 test_createField_setter_qualified_instance_hasField() async { |
2047 await resolveTestUnit(''' | 1887 await resolveTestUnit(''' |
2048 class A { | 1888 class A { |
2049 int aaa; | 1889 int aaa; |
2050 int zzz; | 1890 int zzz; |
2051 | 1891 |
2052 existingMethod() {} | 1892 existingMethod() {} |
2053 } | 1893 } |
2054 main(A a) { | 1894 main(A a) { |
2055 a.test = 5; | 1895 a.test = 5; |
2056 } | 1896 } |
2057 '''); | 1897 '''); |
2058 await assertHasFix( | 1898 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
2059 DartFixKind.CREATE_FIELD, | |
2060 ''' | |
2061 class A { | 1899 class A { |
2062 int aaa; | 1900 int aaa; |
2063 int zzz; | 1901 int zzz; |
2064 | 1902 |
2065 int test; | 1903 int test; |
2066 | 1904 |
2067 existingMethod() {} | 1905 existingMethod() {} |
2068 } | 1906 } |
2069 main(A a) { | 1907 main(A a) { |
2070 a.test = 5; | 1908 a.test = 5; |
2071 } | 1909 } |
2072 '''); | 1910 '''); |
2073 } | 1911 } |
2074 | 1912 |
2075 test_createField_setter_qualified_instance_hasMethod() async { | 1913 test_createField_setter_qualified_instance_hasMethod() async { |
2076 await resolveTestUnit(''' | 1914 await resolveTestUnit(''' |
2077 class A { | 1915 class A { |
2078 existingMethod() {} | 1916 existingMethod() {} |
2079 } | 1917 } |
2080 main(A a) { | 1918 main(A a) { |
2081 a.test = 5; | 1919 a.test = 5; |
2082 } | 1920 } |
2083 '''); | 1921 '''); |
2084 await assertHasFix( | 1922 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
2085 DartFixKind.CREATE_FIELD, | |
2086 ''' | |
2087 class A { | 1923 class A { |
2088 int test; | 1924 int test; |
2089 | 1925 |
2090 existingMethod() {} | 1926 existingMethod() {} |
2091 } | 1927 } |
2092 main(A a) { | 1928 main(A a) { |
2093 a.test = 5; | 1929 a.test = 5; |
2094 } | 1930 } |
2095 '''); | 1931 '''); |
2096 } | 1932 } |
2097 | 1933 |
2098 test_createField_setter_qualified_static() async { | 1934 test_createField_setter_qualified_static() async { |
2099 await resolveTestUnit(''' | 1935 await resolveTestUnit(''' |
2100 class A { | 1936 class A { |
2101 } | 1937 } |
2102 main() { | 1938 main() { |
2103 A.test = 5; | 1939 A.test = 5; |
2104 } | 1940 } |
2105 '''); | 1941 '''); |
2106 await assertHasFix( | 1942 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
2107 DartFixKind.CREATE_FIELD, | |
2108 ''' | |
2109 class A { | 1943 class A { |
2110 static int test; | 1944 static int test; |
2111 } | 1945 } |
2112 main() { | 1946 main() { |
2113 A.test = 5; | 1947 A.test = 5; |
2114 } | 1948 } |
2115 '''); | 1949 '''); |
2116 } | 1950 } |
2117 | 1951 |
2118 test_createField_setter_unqualified_instance() async { | 1952 test_createField_setter_unqualified_instance() async { |
2119 await resolveTestUnit(''' | 1953 await resolveTestUnit(''' |
2120 class A { | 1954 class A { |
2121 main() { | 1955 main() { |
2122 test = 5; | 1956 test = 5; |
2123 } | 1957 } |
2124 } | 1958 } |
2125 '''); | 1959 '''); |
2126 await assertHasFix( | 1960 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
2127 DartFixKind.CREATE_FIELD, | |
2128 ''' | |
2129 class A { | 1961 class A { |
2130 int test; | 1962 int test; |
2131 | 1963 |
2132 main() { | 1964 main() { |
2133 test = 5; | 1965 test = 5; |
2134 } | 1966 } |
2135 } | 1967 } |
2136 '''); | 1968 '''); |
2137 } | 1969 } |
2138 | 1970 |
2139 test_createField_setter_unqualified_static() async { | 1971 test_createField_setter_unqualified_static() async { |
2140 await resolveTestUnit(''' | 1972 await resolveTestUnit(''' |
2141 class A { | 1973 class A { |
2142 static main() { | 1974 static main() { |
2143 test = 5; | 1975 test = 5; |
2144 } | 1976 } |
2145 } | 1977 } |
2146 '''); | 1978 '''); |
2147 await assertHasFix( | 1979 await assertHasFix(DartFixKind.CREATE_FIELD, ''' |
2148 DartFixKind.CREATE_FIELD, | |
2149 ''' | |
2150 class A { | 1980 class A { |
2151 static int test; | 1981 static int test; |
2152 | 1982 |
2153 static main() { | 1983 static main() { |
2154 test = 5; | 1984 test = 5; |
2155 } | 1985 } |
2156 } | 1986 } |
2157 '''); | 1987 '''); |
2158 } | 1988 } |
2159 | 1989 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2246 List<SourceFileEdit> fileEdits = change.edits; | 2076 List<SourceFileEdit> fileEdits = change.edits; |
2247 expect(fileEdits, hasLength(1)); | 2077 expect(fileEdits, hasLength(1)); |
2248 SourceFileEdit fileEdit = change.edits[0]; | 2078 SourceFileEdit fileEdit = change.edits[0]; |
2249 expect(fileEdit.file, '/my/project/bin/my_part.dart'); | 2079 expect(fileEdit.file, '/my/project/bin/my_part.dart'); |
2250 expect(fileEdit.fileStamp, -1); | 2080 expect(fileEdit.fileStamp, -1); |
2251 expect(fileEdit.edits, hasLength(1)); | 2081 expect(fileEdit.edits, hasLength(1)); |
2252 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); | 2082 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); |
2253 } | 2083 } |
2254 | 2084 |
2255 test_createFile_forPart_inPackageLib() async { | 2085 test_createFile_forPart_inPackageLib() async { |
2256 provider.newFile( | 2086 provider.newFile('/my/pubspec.yaml', r''' |
2257 '/my/pubspec.yaml', | |
2258 r''' | |
2259 name: my_test | 2087 name: my_test |
2260 '''); | 2088 '''); |
2261 testFile = '/my/lib/test.dart'; | 2089 testFile = '/my/lib/test.dart'; |
2262 addTestSource( | 2090 addTestSource(''' |
2263 ''' | |
2264 library my.lib; | 2091 library my.lib; |
2265 part 'my_part.dart'; | 2092 part 'my_part.dart'; |
2266 ''', | 2093 ''', Uri.parse('package:my/test.dart')); |
2267 Uri.parse('package:my/test.dart')); | |
2268 // configure SourceFactory | 2094 // configure SourceFactory |
2269 UriResolver pkgResolver = new PackageMapUriResolver(provider, { | 2095 UriResolver pkgResolver = new PackageMapUriResolver(provider, { |
2270 'my': <Folder>[provider.getResource('/my/lib')], | 2096 'my': <Folder>[provider.getResource('/my/lib')], |
2271 }); | 2097 }); |
2272 SourceFactory sourceFactory = new SourceFactory( | 2098 SourceFactory sourceFactory = new SourceFactory( |
2273 [new DartUriResolver(sdk), pkgResolver, resourceResolver]); | 2099 [new DartUriResolver(sdk), pkgResolver, resourceResolver]); |
2274 driver.configure(sourceFactory: sourceFactory); | 2100 driver.configure(sourceFactory: sourceFactory); |
2275 testUnit = (await driver.getResult(testFile)).unit; | 2101 testUnit = (await driver.getResult(testFile)).unit; |
2276 // prepare fix | 2102 // prepare fix |
2277 AnalysisError error = await _findErrorToFix(); | 2103 AnalysisError error = await _findErrorToFix(); |
(...skipping 20 matching lines...) Expand all Loading... |
2298 | 2124 |
2299 test_createGetter_hint_getter() async { | 2125 test_createGetter_hint_getter() async { |
2300 await resolveTestUnit(''' | 2126 await resolveTestUnit(''' |
2301 class A { | 2127 class A { |
2302 } | 2128 } |
2303 main(A a) { | 2129 main(A a) { |
2304 var x = a; | 2130 var x = a; |
2305 int v = x.test; | 2131 int v = x.test; |
2306 } | 2132 } |
2307 '''); | 2133 '''); |
2308 await assertHasFix( | 2134 await assertHasFix(DartFixKind.CREATE_GETTER, ''' |
2309 DartFixKind.CREATE_GETTER, | |
2310 ''' | |
2311 class A { | 2135 class A { |
2312 int get test => null; | 2136 int get test => null; |
2313 } | 2137 } |
2314 main(A a) { | 2138 main(A a) { |
2315 var x = a; | 2139 var x = a; |
2316 int v = x.test; | 2140 int v = x.test; |
2317 } | 2141 } |
2318 '''); | 2142 '''); |
2319 } | 2143 } |
2320 | 2144 |
2321 test_createGetter_location_afterLastGetter() async { | 2145 test_createGetter_location_afterLastGetter() async { |
2322 await resolveTestUnit(''' | 2146 await resolveTestUnit(''' |
2323 class A { | 2147 class A { |
2324 int existingField; | 2148 int existingField; |
2325 | 2149 |
2326 int get existingGetter => null; | 2150 int get existingGetter => null; |
2327 | 2151 |
2328 existingMethod() {} | 2152 existingMethod() {} |
2329 } | 2153 } |
2330 main(A a) { | 2154 main(A a) { |
2331 int v = a.test; | 2155 int v = a.test; |
2332 } | 2156 } |
2333 '''); | 2157 '''); |
2334 await assertHasFix( | 2158 await assertHasFix(DartFixKind.CREATE_GETTER, ''' |
2335 DartFixKind.CREATE_GETTER, | |
2336 ''' | |
2337 class A { | 2159 class A { |
2338 int existingField; | 2160 int existingField; |
2339 | 2161 |
2340 int get existingGetter => null; | 2162 int get existingGetter => null; |
2341 | 2163 |
2342 int get test => null; | 2164 int get test => null; |
2343 | 2165 |
2344 existingMethod() {} | 2166 existingMethod() {} |
2345 } | 2167 } |
2346 main(A a) { | 2168 main(A a) { |
2347 int v = a.test; | 2169 int v = a.test; |
2348 } | 2170 } |
2349 '''); | 2171 '''); |
2350 } | 2172 } |
2351 | 2173 |
2352 test_createGetter_multiLevel() async { | 2174 test_createGetter_multiLevel() async { |
2353 await resolveTestUnit(''' | 2175 await resolveTestUnit(''' |
2354 class A { | 2176 class A { |
2355 } | 2177 } |
2356 class B { | 2178 class B { |
2357 A a; | 2179 A a; |
2358 } | 2180 } |
2359 class C { | 2181 class C { |
2360 B b; | 2182 B b; |
2361 } | 2183 } |
2362 main(C c) { | 2184 main(C c) { |
2363 int v = c.b.a.test; | 2185 int v = c.b.a.test; |
2364 } | 2186 } |
2365 '''); | 2187 '''); |
2366 await assertHasFix( | 2188 await assertHasFix(DartFixKind.CREATE_GETTER, ''' |
2367 DartFixKind.CREATE_GETTER, | |
2368 ''' | |
2369 class A { | 2189 class A { |
2370 int get test => null; | 2190 int get test => null; |
2371 } | 2191 } |
2372 class B { | 2192 class B { |
2373 A a; | 2193 A a; |
2374 } | 2194 } |
2375 class C { | 2195 class C { |
2376 B b; | 2196 B b; |
2377 } | 2197 } |
2378 main(C c) { | 2198 main(C c) { |
2379 int v = c.b.a.test; | 2199 int v = c.b.a.test; |
2380 } | 2200 } |
2381 '''); | 2201 '''); |
2382 } | 2202 } |
2383 | 2203 |
2384 test_createGetter_qualified_instance() async { | 2204 test_createGetter_qualified_instance() async { |
2385 await resolveTestUnit(''' | 2205 await resolveTestUnit(''' |
2386 class A { | 2206 class A { |
2387 } | 2207 } |
2388 main(A a) { | 2208 main(A a) { |
2389 int v = a.test; | 2209 int v = a.test; |
2390 } | 2210 } |
2391 '''); | 2211 '''); |
2392 await assertHasFix( | 2212 await assertHasFix(DartFixKind.CREATE_GETTER, ''' |
2393 DartFixKind.CREATE_GETTER, | |
2394 ''' | |
2395 class A { | 2213 class A { |
2396 int get test => null; | 2214 int get test => null; |
2397 } | 2215 } |
2398 main(A a) { | 2216 main(A a) { |
2399 int v = a.test; | 2217 int v = a.test; |
2400 } | 2218 } |
2401 '''); | 2219 '''); |
2402 } | 2220 } |
2403 | 2221 |
2404 test_createGetter_qualified_instance_dynamicType() async { | 2222 test_createGetter_qualified_instance_dynamicType() async { |
2405 await resolveTestUnit(''' | 2223 await resolveTestUnit(''' |
2406 class A { | 2224 class A { |
2407 B b; | 2225 B b; |
2408 void f(Object p) { | 2226 void f(Object p) { |
2409 p == b.test; | 2227 p == b.test; |
2410 } | 2228 } |
2411 } | 2229 } |
2412 class B { | 2230 class B { |
2413 } | 2231 } |
2414 '''); | 2232 '''); |
2415 await assertHasFix( | 2233 await assertHasFix(DartFixKind.CREATE_GETTER, ''' |
2416 DartFixKind.CREATE_GETTER, | |
2417 ''' | |
2418 class A { | 2234 class A { |
2419 B b; | 2235 B b; |
2420 void f(Object p) { | 2236 void f(Object p) { |
2421 p == b.test; | 2237 p == b.test; |
2422 } | 2238 } |
2423 } | 2239 } |
2424 class B { | 2240 class B { |
2425 get test => null; | 2241 get test => null; |
2426 } | 2242 } |
2427 '''); | 2243 '''); |
2428 } | 2244 } |
2429 | 2245 |
2430 test_createGetter_qualified_propagatedType() async { | 2246 test_createGetter_qualified_propagatedType() async { |
2431 await resolveTestUnit(''' | 2247 await resolveTestUnit(''' |
2432 class A { | 2248 class A { |
2433 A get self => this; | 2249 A get self => this; |
2434 } | 2250 } |
2435 main() { | 2251 main() { |
2436 var a = new A(); | 2252 var a = new A(); |
2437 int v = a.self.test; | 2253 int v = a.self.test; |
2438 } | 2254 } |
2439 '''); | 2255 '''); |
2440 await assertHasFix( | 2256 await assertHasFix(DartFixKind.CREATE_GETTER, ''' |
2441 DartFixKind.CREATE_GETTER, | |
2442 ''' | |
2443 class A { | 2257 class A { |
2444 A get self => this; | 2258 A get self => this; |
2445 | 2259 |
2446 int get test => null; | 2260 int get test => null; |
2447 } | 2261 } |
2448 main() { | 2262 main() { |
2449 var a = new A(); | 2263 var a = new A(); |
2450 int v = a.self.test; | 2264 int v = a.self.test; |
2451 } | 2265 } |
2452 '''); | 2266 '''); |
(...skipping 12 matching lines...) Expand all Loading... |
2465 | 2279 |
2466 test_createGetter_unqualified_instance_asInvocationArgument() async { | 2280 test_createGetter_unqualified_instance_asInvocationArgument() async { |
2467 await resolveTestUnit(''' | 2281 await resolveTestUnit(''' |
2468 class A { | 2282 class A { |
2469 main() { | 2283 main() { |
2470 f(test); | 2284 f(test); |
2471 } | 2285 } |
2472 } | 2286 } |
2473 f(String s) {} | 2287 f(String s) {} |
2474 '''); | 2288 '''); |
2475 await assertHasFix( | 2289 await assertHasFix(DartFixKind.CREATE_GETTER, ''' |
2476 DartFixKind.CREATE_GETTER, | |
2477 ''' | |
2478 class A { | 2290 class A { |
2479 String get test => null; | 2291 String get test => null; |
2480 | 2292 |
2481 main() { | 2293 main() { |
2482 f(test); | 2294 f(test); |
2483 } | 2295 } |
2484 } | 2296 } |
2485 f(String s) {} | 2297 f(String s) {} |
2486 '''); | 2298 '''); |
2487 } | 2299 } |
(...skipping 10 matching lines...) Expand all Loading... |
2498 } | 2310 } |
2499 | 2311 |
2500 test_createGetter_unqualified_instance_assignmentRhs() async { | 2312 test_createGetter_unqualified_instance_assignmentRhs() async { |
2501 await resolveTestUnit(''' | 2313 await resolveTestUnit(''' |
2502 class A { | 2314 class A { |
2503 main() { | 2315 main() { |
2504 int v = test; | 2316 int v = test; |
2505 } | 2317 } |
2506 } | 2318 } |
2507 '''); | 2319 '''); |
2508 await assertHasFix( | 2320 await assertHasFix(DartFixKind.CREATE_GETTER, ''' |
2509 DartFixKind.CREATE_GETTER, | |
2510 ''' | |
2511 class A { | 2321 class A { |
2512 int get test => null; | 2322 int get test => null; |
2513 | 2323 |
2514 main() { | 2324 main() { |
2515 int v = test; | 2325 int v = test; |
2516 } | 2326 } |
2517 } | 2327 } |
2518 '''); | 2328 '''); |
2519 } | 2329 } |
2520 | 2330 |
2521 test_createGetter_unqualified_instance_asStatement() async { | 2331 test_createGetter_unqualified_instance_asStatement() async { |
2522 await resolveTestUnit(''' | 2332 await resolveTestUnit(''' |
2523 class A { | 2333 class A { |
2524 main() { | 2334 main() { |
2525 test; | 2335 test; |
2526 } | 2336 } |
2527 } | 2337 } |
2528 '''); | 2338 '''); |
2529 await assertHasFix( | 2339 await assertHasFix(DartFixKind.CREATE_GETTER, ''' |
2530 DartFixKind.CREATE_GETTER, | |
2531 ''' | |
2532 class A { | 2340 class A { |
2533 get test => null; | 2341 get test => null; |
2534 | 2342 |
2535 main() { | 2343 main() { |
2536 test; | 2344 test; |
2537 } | 2345 } |
2538 } | 2346 } |
2539 '''); | 2347 '''); |
2540 } | 2348 } |
2541 | 2349 |
2542 test_createLocalVariable_functionType_named() async { | 2350 test_createLocalVariable_functionType_named() async { |
2543 await resolveTestUnit(''' | 2351 await resolveTestUnit(''' |
2544 typedef MY_FUNCTION(int p); | 2352 typedef MY_FUNCTION(int p); |
2545 foo(MY_FUNCTION f) {} | 2353 foo(MY_FUNCTION f) {} |
2546 main() { | 2354 main() { |
2547 foo(bar); | 2355 foo(bar); |
2548 } | 2356 } |
2549 '''); | 2357 '''); |
2550 await assertHasFix( | 2358 await assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' |
2551 DartFixKind.CREATE_LOCAL_VARIABLE, | |
2552 ''' | |
2553 typedef MY_FUNCTION(int p); | 2359 typedef MY_FUNCTION(int p); |
2554 foo(MY_FUNCTION f) {} | 2360 foo(MY_FUNCTION f) {} |
2555 main() { | 2361 main() { |
2556 MY_FUNCTION bar; | 2362 MY_FUNCTION bar; |
2557 foo(bar); | 2363 foo(bar); |
2558 } | 2364 } |
2559 '''); | 2365 '''); |
2560 } | 2366 } |
2561 | 2367 |
2562 test_createLocalVariable_functionType_synthetic() async { | 2368 test_createLocalVariable_functionType_synthetic() async { |
2563 await resolveTestUnit(''' | 2369 await resolveTestUnit(''' |
2564 foo(f(int p)) {} | 2370 foo(f(int p)) {} |
2565 main() { | 2371 main() { |
2566 foo(bar); | 2372 foo(bar); |
2567 } | 2373 } |
2568 '''); | 2374 '''); |
2569 await assertNoFix(DartFixKind.CREATE_LOCAL_VARIABLE); | 2375 await assertNoFix(DartFixKind.CREATE_LOCAL_VARIABLE); |
2570 } | 2376 } |
2571 | 2377 |
2572 test_createLocalVariable_read_typeAssignment() async { | 2378 test_createLocalVariable_read_typeAssignment() async { |
2573 await resolveTestUnit(''' | 2379 await resolveTestUnit(''' |
2574 main() { | 2380 main() { |
2575 int a = test; | 2381 int a = test; |
2576 } | 2382 } |
2577 '''); | 2383 '''); |
2578 await assertHasFix( | 2384 await assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' |
2579 DartFixKind.CREATE_LOCAL_VARIABLE, | |
2580 ''' | |
2581 main() { | 2385 main() { |
2582 int test; | 2386 int test; |
2583 int a = test; | 2387 int a = test; |
2584 } | 2388 } |
2585 '''); | 2389 '''); |
2586 } | 2390 } |
2587 | 2391 |
2588 test_createLocalVariable_read_typeCondition() async { | 2392 test_createLocalVariable_read_typeCondition() async { |
2589 await resolveTestUnit(''' | 2393 await resolveTestUnit(''' |
2590 main() { | 2394 main() { |
2591 if (!test) { | 2395 if (!test) { |
2592 print(42); | 2396 print(42); |
2593 } | 2397 } |
2594 } | 2398 } |
2595 '''); | 2399 '''); |
2596 await assertHasFix( | 2400 await assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' |
2597 DartFixKind.CREATE_LOCAL_VARIABLE, | |
2598 ''' | |
2599 main() { | 2401 main() { |
2600 bool test; | 2402 bool test; |
2601 if (!test) { | 2403 if (!test) { |
2602 print(42); | 2404 print(42); |
2603 } | 2405 } |
2604 } | 2406 } |
2605 '''); | 2407 '''); |
2606 } | 2408 } |
2607 | 2409 |
2608 test_createLocalVariable_read_typeInvocationArgument() async { | 2410 test_createLocalVariable_read_typeInvocationArgument() async { |
2609 await resolveTestUnit(''' | 2411 await resolveTestUnit(''' |
2610 main() { | 2412 main() { |
2611 f(test); | 2413 f(test); |
2612 } | 2414 } |
2613 f(String p) {} | 2415 f(String p) {} |
2614 '''); | 2416 '''); |
2615 await assertHasFix( | 2417 await assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' |
2616 DartFixKind.CREATE_LOCAL_VARIABLE, | |
2617 ''' | |
2618 main() { | 2418 main() { |
2619 String test; | 2419 String test; |
2620 f(test); | 2420 f(test); |
2621 } | 2421 } |
2622 f(String p) {} | 2422 f(String p) {} |
2623 '''); | 2423 '''); |
2624 _assertLinkedGroup(change.linkedEditGroups[0], ['String test;']); | 2424 _assertLinkedGroup(change.linkedEditGroups[0], ['String test;']); |
2625 _assertLinkedGroup(change.linkedEditGroups[1], ['test;', 'test);']); | 2425 _assertLinkedGroup(change.linkedEditGroups[1], ['test;', 'test);']); |
2626 } | 2426 } |
2627 | 2427 |
2628 test_createLocalVariable_read_typeInvocationTarget() async { | 2428 test_createLocalVariable_read_typeInvocationTarget() async { |
2629 await resolveTestUnit(''' | 2429 await resolveTestUnit(''' |
2630 main() { | 2430 main() { |
2631 test.add('hello'); | 2431 test.add('hello'); |
2632 } | 2432 } |
2633 '''); | 2433 '''); |
2634 await assertHasFix( | 2434 await assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' |
2635 DartFixKind.CREATE_LOCAL_VARIABLE, | |
2636 ''' | |
2637 main() { | 2435 main() { |
2638 var test; | 2436 var test; |
2639 test.add('hello'); | 2437 test.add('hello'); |
2640 } | 2438 } |
2641 '''); | 2439 '''); |
2642 _assertLinkedGroup(change.linkedEditGroups[0], ['test;', 'test.add(']); | 2440 _assertLinkedGroup(change.linkedEditGroups[0], ['test;', 'test.add(']); |
2643 } | 2441 } |
2644 | 2442 |
2645 test_createLocalVariable_write_assignment() async { | 2443 test_createLocalVariable_write_assignment() async { |
2646 await resolveTestUnit(''' | 2444 await resolveTestUnit(''' |
2647 main() { | 2445 main() { |
2648 test = 42; | 2446 test = 42; |
2649 } | 2447 } |
2650 '''); | 2448 '''); |
2651 await assertHasFix( | 2449 await assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' |
2652 DartFixKind.CREATE_LOCAL_VARIABLE, | |
2653 ''' | |
2654 main() { | 2450 main() { |
2655 var test = 42; | 2451 var test = 42; |
2656 } | 2452 } |
2657 '''); | 2453 '''); |
2658 } | 2454 } |
2659 | 2455 |
2660 test_createLocalVariable_write_assignment_compound() async { | 2456 test_createLocalVariable_write_assignment_compound() async { |
2661 await resolveTestUnit(''' | 2457 await resolveTestUnit(''' |
2662 main() { | 2458 main() { |
2663 test += 42; | 2459 test += 42; |
2664 } | 2460 } |
2665 '''); | 2461 '''); |
2666 await assertHasFix( | 2462 await assertHasFix(DartFixKind.CREATE_LOCAL_VARIABLE, ''' |
2667 DartFixKind.CREATE_LOCAL_VARIABLE, | |
2668 ''' | |
2669 main() { | 2463 main() { |
2670 int test; | 2464 int test; |
2671 test += 42; | 2465 test += 42; |
2672 } | 2466 } |
2673 '''); | 2467 '''); |
2674 } | 2468 } |
2675 | 2469 |
2676 test_createMissingMethodCall() async { | 2470 test_createMissingMethodCall() async { |
2677 await resolveTestUnit(''' | 2471 await resolveTestUnit(''' |
2678 class C implements Function { | 2472 class C implements Function { |
2679 } | 2473 } |
2680 '''); | 2474 '''); |
2681 await assertHasFix( | 2475 await assertHasFix(DartFixKind.CREATE_MISSING_METHOD_CALL, ''' |
2682 DartFixKind.CREATE_MISSING_METHOD_CALL, | |
2683 ''' | |
2684 class C implements Function { | 2476 class C implements Function { |
2685 call() { | 2477 call() { |
2686 // TODO: implement call | 2478 // TODO: implement call |
2687 } | 2479 } |
2688 } | 2480 } |
2689 '''); | 2481 '''); |
2690 } | 2482 } |
2691 | 2483 |
2692 test_createMissingOverrides_field_untyped() async { | 2484 test_createMissingOverrides_field_untyped() async { |
2693 await resolveTestUnit(''' | 2485 await resolveTestUnit(''' |
2694 class A { | 2486 class A { |
2695 var f; | 2487 var f; |
2696 } | 2488 } |
2697 | 2489 |
2698 class B implements A { | 2490 class B implements A { |
2699 } | 2491 } |
2700 '''); | 2492 '''); |
2701 await assertHasFix( | 2493 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' |
2702 DartFixKind.CREATE_MISSING_OVERRIDES, | |
2703 ''' | |
2704 class A { | 2494 class A { |
2705 var f; | 2495 var f; |
2706 } | 2496 } |
2707 | 2497 |
2708 class B implements A { | 2498 class B implements A { |
2709 @override | 2499 @override |
2710 var f; | 2500 var f; |
2711 } | 2501 } |
2712 '''); | 2502 '''); |
2713 } | 2503 } |
2714 | 2504 |
2715 test_createMissingOverrides_functionTypeAlias() async { | 2505 test_createMissingOverrides_functionTypeAlias() async { |
2716 await resolveTestUnit(''' | 2506 await resolveTestUnit(''' |
2717 typedef int Binary(int left, int right); | 2507 typedef int Binary(int left, int right); |
2718 | 2508 |
2719 abstract class Emulator { | 2509 abstract class Emulator { |
2720 void performBinary(Binary binary); | 2510 void performBinary(Binary binary); |
2721 } | 2511 } |
2722 | 2512 |
2723 class MyEmulator extends Emulator { | 2513 class MyEmulator extends Emulator { |
2724 } | 2514 } |
2725 '''); | 2515 '''); |
2726 await assertHasFix( | 2516 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' |
2727 DartFixKind.CREATE_MISSING_OVERRIDES, | |
2728 ''' | |
2729 typedef int Binary(int left, int right); | 2517 typedef int Binary(int left, int right); |
2730 | 2518 |
2731 abstract class Emulator { | 2519 abstract class Emulator { |
2732 void performBinary(Binary binary); | 2520 void performBinary(Binary binary); |
2733 } | 2521 } |
2734 | 2522 |
2735 class MyEmulator extends Emulator { | 2523 class MyEmulator extends Emulator { |
2736 @override | 2524 @override |
2737 void performBinary(Binary binary) { | 2525 void performBinary(Binary binary) { |
2738 // TODO: implement performBinary | 2526 // TODO: implement performBinary |
2739 } | 2527 } |
2740 } | 2528 } |
2741 '''); | 2529 '''); |
2742 } | 2530 } |
2743 | 2531 |
2744 test_createMissingOverrides_functionTypedParameter() async { | 2532 test_createMissingOverrides_functionTypedParameter() async { |
2745 await resolveTestUnit(''' | 2533 await resolveTestUnit(''' |
2746 abstract class A { | 2534 abstract class A { |
2747 forEach(int f(double p1, String p2)); | 2535 forEach(int f(double p1, String p2)); |
2748 } | 2536 } |
2749 | 2537 |
2750 class B extends A { | 2538 class B extends A { |
2751 } | 2539 } |
2752 '''); | 2540 '''); |
2753 await assertHasFix( | 2541 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' |
2754 DartFixKind.CREATE_MISSING_OVERRIDES, | |
2755 ''' | |
2756 abstract class A { | 2542 abstract class A { |
2757 forEach(int f(double p1, String p2)); | 2543 forEach(int f(double p1, String p2)); |
2758 } | 2544 } |
2759 | 2545 |
2760 class B extends A { | 2546 class B extends A { |
2761 @override | 2547 @override |
2762 forEach(int f(double p1, String p2)) { | 2548 forEach(int f(double p1, String p2)) { |
2763 // TODO: implement forEach | 2549 // TODO: implement forEach |
2764 } | 2550 } |
2765 } | 2551 } |
2766 '''); | 2552 '''); |
2767 } | 2553 } |
2768 | 2554 |
2769 test_createMissingOverrides_generics_typeArguments() async { | 2555 test_createMissingOverrides_generics_typeArguments() async { |
2770 await resolveTestUnit(''' | 2556 await resolveTestUnit(''' |
2771 class Iterator<T> { | 2557 class Iterator<T> { |
2772 } | 2558 } |
2773 | 2559 |
2774 abstract class IterableMixin<T> { | 2560 abstract class IterableMixin<T> { |
2775 Iterator<T> get iterator; | 2561 Iterator<T> get iterator; |
2776 } | 2562 } |
2777 | 2563 |
2778 class Test extends IterableMixin<int> { | 2564 class Test extends IterableMixin<int> { |
2779 } | 2565 } |
2780 '''); | 2566 '''); |
2781 await assertHasFix( | 2567 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' |
2782 DartFixKind.CREATE_MISSING_OVERRIDES, | |
2783 ''' | |
2784 class Iterator<T> { | 2568 class Iterator<T> { |
2785 } | 2569 } |
2786 | 2570 |
2787 abstract class IterableMixin<T> { | 2571 abstract class IterableMixin<T> { |
2788 Iterator<T> get iterator; | 2572 Iterator<T> get iterator; |
2789 } | 2573 } |
2790 | 2574 |
2791 class Test extends IterableMixin<int> { | 2575 class Test extends IterableMixin<int> { |
2792 // TODO: implement iterator | 2576 // TODO: implement iterator |
2793 @override | 2577 @override |
2794 Iterator<int> get iterator => null; | 2578 Iterator<int> get iterator => null; |
2795 } | 2579 } |
2796 '''); | 2580 '''); |
2797 } | 2581 } |
2798 | 2582 |
2799 test_createMissingOverrides_generics_typeParameters() async { | 2583 test_createMissingOverrides_generics_typeParameters() async { |
2800 await resolveTestUnit(''' | 2584 await resolveTestUnit(''' |
2801 abstract class ItemProvider<T> { | 2585 abstract class ItemProvider<T> { |
2802 List<T> getItems(); | 2586 List<T> getItems(); |
2803 } | 2587 } |
2804 | 2588 |
2805 class Test<V> extends ItemProvider<V> { | 2589 class Test<V> extends ItemProvider<V> { |
2806 } | 2590 } |
2807 '''); | 2591 '''); |
2808 await assertHasFix( | 2592 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' |
2809 DartFixKind.CREATE_MISSING_OVERRIDES, | |
2810 ''' | |
2811 abstract class ItemProvider<T> { | 2593 abstract class ItemProvider<T> { |
2812 List<T> getItems(); | 2594 List<T> getItems(); |
2813 } | 2595 } |
2814 | 2596 |
2815 class Test<V> extends ItemProvider<V> { | 2597 class Test<V> extends ItemProvider<V> { |
2816 @override | 2598 @override |
2817 List<V> getItems() { | 2599 List<V> getItems() { |
2818 // TODO: implement getItems | 2600 // TODO: implement getItems |
2819 } | 2601 } |
2820 } | 2602 } |
2821 '''); | 2603 '''); |
2822 } | 2604 } |
2823 | 2605 |
2824 test_createMissingOverrides_getter() async { | 2606 test_createMissingOverrides_getter() async { |
2825 await resolveTestUnit(''' | 2607 await resolveTestUnit(''' |
2826 abstract class A { | 2608 abstract class A { |
2827 get g1; | 2609 get g1; |
2828 int get g2; | 2610 int get g2; |
2829 } | 2611 } |
2830 | 2612 |
2831 class B extends A { | 2613 class B extends A { |
2832 } | 2614 } |
2833 '''); | 2615 '''); |
2834 await assertHasFix( | 2616 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' |
2835 DartFixKind.CREATE_MISSING_OVERRIDES, | |
2836 ''' | |
2837 abstract class A { | 2617 abstract class A { |
2838 get g1; | 2618 get g1; |
2839 int get g2; | 2619 int get g2; |
2840 } | 2620 } |
2841 | 2621 |
2842 class B extends A { | 2622 class B extends A { |
2843 // TODO: implement g1 | 2623 // TODO: implement g1 |
2844 @override | 2624 @override |
2845 get g1 => null; | 2625 get g1 => null; |
2846 | 2626 |
2847 // TODO: implement g2 | 2627 // TODO: implement g2 |
2848 @override | 2628 @override |
2849 int get g2 => null; | 2629 int get g2 => null; |
2850 } | 2630 } |
2851 '''); | 2631 '''); |
2852 } | 2632 } |
2853 | 2633 |
2854 test_createMissingOverrides_importPrefix() async { | 2634 test_createMissingOverrides_importPrefix() async { |
2855 await resolveTestUnit(''' | 2635 await resolveTestUnit(''' |
2856 import 'dart:async' as aaa; | 2636 import 'dart:async' as aaa; |
2857 abstract class A { | 2637 abstract class A { |
2858 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); | 2638 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); |
2859 } | 2639 } |
2860 | 2640 |
2861 class B extends A { | 2641 class B extends A { |
2862 } | 2642 } |
2863 '''); | 2643 '''); |
2864 await assertHasFix( | 2644 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' |
2865 DartFixKind.CREATE_MISSING_OVERRIDES, | |
2866 ''' | |
2867 import 'dart:async' as aaa; | 2645 import 'dart:async' as aaa; |
2868 abstract class A { | 2646 abstract class A { |
2869 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); | 2647 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); |
2870 } | 2648 } |
2871 | 2649 |
2872 class B extends A { | 2650 class B extends A { |
2873 @override | 2651 @override |
2874 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) { | 2652 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) { |
2875 // TODO: implement g | 2653 // TODO: implement g |
2876 } | 2654 } |
2877 } | 2655 } |
2878 '''); | 2656 '''); |
2879 } | 2657 } |
2880 | 2658 |
2881 test_createMissingOverrides_mergeToField_getterSetter() async { | 2659 test_createMissingOverrides_mergeToField_getterSetter() async { |
2882 await resolveTestUnit(''' | 2660 await resolveTestUnit(''' |
2883 class A { | 2661 class A { |
2884 int ma; | 2662 int ma; |
2885 void mb() {} | 2663 void mb() {} |
2886 double mc; | 2664 double mc; |
2887 } | 2665 } |
2888 | 2666 |
2889 class B implements A { | 2667 class B implements A { |
2890 } | 2668 } |
2891 '''); | 2669 '''); |
2892 await assertHasFix( | 2670 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' |
2893 DartFixKind.CREATE_MISSING_OVERRIDES, | |
2894 ''' | |
2895 class A { | 2671 class A { |
2896 int ma; | 2672 int ma; |
2897 void mb() {} | 2673 void mb() {} |
2898 double mc; | 2674 double mc; |
2899 } | 2675 } |
2900 | 2676 |
2901 class B implements A { | 2677 class B implements A { |
2902 @override | 2678 @override |
2903 int ma; | 2679 int ma; |
2904 | 2680 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2987 } | 2763 } |
2988 | 2764 |
2989 test_createMissingOverrides_method_emptyClassBody() async { | 2765 test_createMissingOverrides_method_emptyClassBody() async { |
2990 await resolveTestUnit(''' | 2766 await resolveTestUnit(''' |
2991 abstract class A { | 2767 abstract class A { |
2992 void foo(); | 2768 void foo(); |
2993 } | 2769 } |
2994 | 2770 |
2995 class B extends A {} | 2771 class B extends A {} |
2996 '''); | 2772 '''); |
2997 await assertHasFix( | 2773 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' |
2998 DartFixKind.CREATE_MISSING_OVERRIDES, | |
2999 ''' | |
3000 abstract class A { | 2774 abstract class A { |
3001 void foo(); | 2775 void foo(); |
3002 } | 2776 } |
3003 | 2777 |
3004 class B extends A { | 2778 class B extends A { |
3005 @override | 2779 @override |
3006 void foo() { | 2780 void foo() { |
3007 // TODO: implement foo | 2781 // TODO: implement foo |
3008 } | 2782 } |
3009 } | 2783 } |
3010 '''); | 2784 '''); |
3011 } | 2785 } |
3012 | 2786 |
3013 test_createMissingOverrides_method_generic() async { | 2787 test_createMissingOverrides_method_generic() async { |
3014 await resolveTestUnit(''' | 2788 await resolveTestUnit(''' |
3015 class C<T> {} | 2789 class C<T> {} |
3016 class V<E> {} | 2790 class V<E> {} |
3017 | 2791 |
3018 abstract class A { | 2792 abstract class A { |
3019 E1 foo<E1, E2 extends C<int>>(V<E2> v); | 2793 E1 foo<E1, E2 extends C<int>>(V<E2> v); |
3020 } | 2794 } |
3021 | 2795 |
3022 class B implements A { | 2796 class B implements A { |
3023 } | 2797 } |
3024 '''); | 2798 '''); |
3025 await assertHasFix( | 2799 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' |
3026 DartFixKind.CREATE_MISSING_OVERRIDES, | |
3027 ''' | |
3028 class C<T> {} | 2800 class C<T> {} |
3029 class V<E> {} | 2801 class V<E> {} |
3030 | 2802 |
3031 abstract class A { | 2803 abstract class A { |
3032 E1 foo<E1, E2 extends C<int>>(V<E2> v); | 2804 E1 foo<E1, E2 extends C<int>>(V<E2> v); |
3033 } | 2805 } |
3034 | 2806 |
3035 class B implements A { | 2807 class B implements A { |
3036 @override | 2808 @override |
3037 E1 foo<E1, E2 extends C<int>>(V<E2> v) { | 2809 E1 foo<E1, E2 extends C<int>>(V<E2> v) { |
3038 // TODO: implement foo | 2810 // TODO: implement foo |
3039 } | 2811 } |
3040 } | 2812 } |
3041 '''); | 2813 '''); |
3042 } | 2814 } |
3043 | 2815 |
3044 test_createMissingOverrides_operator() async { | 2816 test_createMissingOverrides_operator() async { |
3045 await resolveTestUnit(''' | 2817 await resolveTestUnit(''' |
3046 abstract class A { | 2818 abstract class A { |
3047 int operator [](int index); | 2819 int operator [](int index); |
3048 void operator []=(int index, String value); | 2820 void operator []=(int index, String value); |
3049 } | 2821 } |
3050 | 2822 |
3051 class B extends A { | 2823 class B extends A { |
3052 } | 2824 } |
3053 '''); | 2825 '''); |
3054 await assertHasFix( | 2826 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' |
3055 DartFixKind.CREATE_MISSING_OVERRIDES, | |
3056 ''' | |
3057 abstract class A { | 2827 abstract class A { |
3058 int operator [](int index); | 2828 int operator [](int index); |
3059 void operator []=(int index, String value); | 2829 void operator []=(int index, String value); |
3060 } | 2830 } |
3061 | 2831 |
3062 class B extends A { | 2832 class B extends A { |
3063 @override | 2833 @override |
3064 int operator [](int index) { | 2834 int operator [](int index) { |
3065 // TODO: implement [] | 2835 // TODO: implement [] |
3066 } | 2836 } |
(...skipping 10 matching lines...) Expand all Loading... |
3077 await resolveTestUnit(''' | 2847 await resolveTestUnit(''' |
3078 abstract class A { | 2848 abstract class A { |
3079 set s1(x); | 2849 set s1(x); |
3080 set s2(int x); | 2850 set s2(int x); |
3081 void set s3(String x); | 2851 void set s3(String x); |
3082 } | 2852 } |
3083 | 2853 |
3084 class B extends A { | 2854 class B extends A { |
3085 } | 2855 } |
3086 '''); | 2856 '''); |
3087 await assertHasFix( | 2857 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, ''' |
3088 DartFixKind.CREATE_MISSING_OVERRIDES, | |
3089 ''' | |
3090 abstract class A { | 2858 abstract class A { |
3091 set s1(x); | 2859 set s1(x); |
3092 set s2(int x); | 2860 set s2(int x); |
3093 void set s3(String x); | 2861 void set s3(String x); |
3094 } | 2862 } |
3095 | 2863 |
3096 class B extends A { | 2864 class B extends A { |
3097 @override | 2865 @override |
3098 set s1(x) { | 2866 set s1(x) { |
3099 // TODO: implement s1 | 2867 // TODO: implement s1 |
(...skipping 16 matching lines...) Expand all Loading... |
3116 await resolveTestUnit(''' | 2884 await resolveTestUnit(''' |
3117 abstract class A { | 2885 abstract class A { |
3118 m1(); | 2886 m1(); |
3119 int m2(); | 2887 int m2(); |
3120 } | 2888 } |
3121 | 2889 |
3122 class B extends A { | 2890 class B extends A { |
3123 existing() {} | 2891 existing() {} |
3124 } | 2892 } |
3125 '''); | 2893 '''); |
3126 await assertHasFix( | 2894 await assertHasFix(DartFixKind.CREATE_NO_SUCH_METHOD, ''' |
3127 DartFixKind.CREATE_NO_SUCH_METHOD, | |
3128 ''' | |
3129 abstract class A { | 2895 abstract class A { |
3130 m1(); | 2896 m1(); |
3131 int m2(); | 2897 int m2(); |
3132 } | 2898 } |
3133 | 2899 |
3134 class B extends A { | 2900 class B extends A { |
3135 existing() {} | 2901 existing() {} |
3136 | 2902 |
3137 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 2903 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
3138 } | 2904 } |
3139 '''); | 2905 '''); |
3140 } | 2906 } |
3141 | 2907 |
3142 test_creationFunction_forFunctionType_cascadeSecond() async { | 2908 test_creationFunction_forFunctionType_cascadeSecond() async { |
3143 await resolveTestUnit(''' | 2909 await resolveTestUnit(''' |
3144 class A { | 2910 class A { |
3145 B ma() => null; | 2911 B ma() => null; |
3146 } | 2912 } |
3147 class B { | 2913 class B { |
3148 useFunction(int g(double a, String b)) {} | 2914 useFunction(int g(double a, String b)) {} |
3149 } | 2915 } |
3150 | 2916 |
3151 main() { | 2917 main() { |
3152 A a = new A(); | 2918 A a = new A(); |
3153 a..ma().useFunction(test); | 2919 a..ma().useFunction(test); |
3154 } | 2920 } |
3155 '''); | 2921 '''); |
3156 await assertHasFix( | 2922 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
3157 DartFixKind.CREATE_FUNCTION, | |
3158 ''' | |
3159 class A { | 2923 class A { |
3160 B ma() => null; | 2924 B ma() => null; |
3161 } | 2925 } |
3162 class B { | 2926 class B { |
3163 useFunction(int g(double a, String b)) {} | 2927 useFunction(int g(double a, String b)) {} |
3164 } | 2928 } |
3165 | 2929 |
3166 main() { | 2930 main() { |
3167 A a = new A(); | 2931 A a = new A(); |
3168 a..ma().useFunction(test); | 2932 a..ma().useFunction(test); |
3169 } | 2933 } |
3170 | 2934 |
3171 int test(double a, String b) { | 2935 int test(double a, String b) { |
3172 } | 2936 } |
3173 '''); | 2937 '''); |
3174 } | 2938 } |
3175 | 2939 |
3176 test_creationFunction_forFunctionType_coreFunction() async { | 2940 test_creationFunction_forFunctionType_coreFunction() async { |
3177 await resolveTestUnit(''' | 2941 await resolveTestUnit(''' |
3178 main() { | 2942 main() { |
3179 useFunction(g: test); | 2943 useFunction(g: test); |
3180 } | 2944 } |
3181 useFunction({Function g}) {} | 2945 useFunction({Function g}) {} |
3182 '''); | 2946 '''); |
3183 await assertHasFix( | 2947 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
3184 DartFixKind.CREATE_FUNCTION, | |
3185 ''' | |
3186 main() { | 2948 main() { |
3187 useFunction(g: test); | 2949 useFunction(g: test); |
3188 } | 2950 } |
3189 useFunction({Function g}) {} | 2951 useFunction({Function g}) {} |
3190 | 2952 |
3191 test() { | 2953 test() { |
3192 } | 2954 } |
3193 '''); | 2955 '''); |
3194 } | 2956 } |
3195 | 2957 |
3196 test_creationFunction_forFunctionType_dynamicArgument() async { | 2958 test_creationFunction_forFunctionType_dynamicArgument() async { |
3197 await resolveTestUnit(''' | 2959 await resolveTestUnit(''' |
3198 main() { | 2960 main() { |
3199 useFunction(test); | 2961 useFunction(test); |
3200 } | 2962 } |
3201 useFunction(int g(a, b)) {} | 2963 useFunction(int g(a, b)) {} |
3202 '''); | 2964 '''); |
3203 await assertHasFix( | 2965 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
3204 DartFixKind.CREATE_FUNCTION, | |
3205 ''' | |
3206 main() { | 2966 main() { |
3207 useFunction(test); | 2967 useFunction(test); |
3208 } | 2968 } |
3209 useFunction(int g(a, b)) {} | 2969 useFunction(int g(a, b)) {} |
3210 | 2970 |
3211 int test(a, b) { | 2971 int test(a, b) { |
3212 } | 2972 } |
3213 '''); | 2973 '''); |
3214 } | 2974 } |
3215 | 2975 |
3216 test_creationFunction_forFunctionType_function() async { | 2976 test_creationFunction_forFunctionType_function() async { |
3217 await resolveTestUnit(''' | 2977 await resolveTestUnit(''' |
3218 main() { | 2978 main() { |
3219 useFunction(test); | 2979 useFunction(test); |
3220 } | 2980 } |
3221 useFunction(int g(double a, String b)) {} | 2981 useFunction(int g(double a, String b)) {} |
3222 '''); | 2982 '''); |
3223 await assertHasFix( | 2983 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
3224 DartFixKind.CREATE_FUNCTION, | |
3225 ''' | |
3226 main() { | 2984 main() { |
3227 useFunction(test); | 2985 useFunction(test); |
3228 } | 2986 } |
3229 useFunction(int g(double a, String b)) {} | 2987 useFunction(int g(double a, String b)) {} |
3230 | 2988 |
3231 int test(double a, String b) { | 2989 int test(double a, String b) { |
3232 } | 2990 } |
3233 '''); | 2991 '''); |
3234 } | 2992 } |
3235 | 2993 |
3236 test_creationFunction_forFunctionType_function_namedArgument() async { | 2994 test_creationFunction_forFunctionType_function_namedArgument() async { |
3237 await resolveTestUnit(''' | 2995 await resolveTestUnit(''' |
3238 main() { | 2996 main() { |
3239 useFunction(g: test); | 2997 useFunction(g: test); |
3240 } | 2998 } |
3241 useFunction({int g(double a, String b)}) {} | 2999 useFunction({int g(double a, String b)}) {} |
3242 '''); | 3000 '''); |
3243 await assertHasFix( | 3001 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
3244 DartFixKind.CREATE_FUNCTION, | |
3245 ''' | |
3246 main() { | 3002 main() { |
3247 useFunction(g: test); | 3003 useFunction(g: test); |
3248 } | 3004 } |
3249 useFunction({int g(double a, String b)}) {} | 3005 useFunction({int g(double a, String b)}) {} |
3250 | 3006 |
3251 int test(double a, String b) { | 3007 int test(double a, String b) { |
3252 } | 3008 } |
3253 '''); | 3009 '''); |
3254 } | 3010 } |
3255 | 3011 |
3256 test_creationFunction_forFunctionType_importType() async { | 3012 test_creationFunction_forFunctionType_importType() async { |
3257 addSource( | 3013 addSource('/libA.dart', r''' |
3258 '/libA.dart', | |
3259 r''' | |
3260 library libA; | 3014 library libA; |
3261 class A {} | 3015 class A {} |
3262 '''); | 3016 '''); |
3263 addSource( | 3017 addSource('/libB.dart', r''' |
3264 '/libB.dart', | |
3265 r''' | |
3266 library libB; | 3018 library libB; |
3267 import 'libA.dart'; | 3019 import 'libA.dart'; |
3268 useFunction(int g(A a)) {} | 3020 useFunction(int g(A a)) {} |
3269 '''); | 3021 '''); |
3270 await resolveTestUnit(''' | 3022 await resolveTestUnit(''' |
3271 import 'libB.dart'; | 3023 import 'libB.dart'; |
3272 main() { | 3024 main() { |
3273 useFunction(test); | 3025 useFunction(test); |
3274 } | 3026 } |
3275 '''); | 3027 '''); |
3276 await assertHasFix( | 3028 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
3277 DartFixKind.CREATE_FUNCTION, | |
3278 ''' | |
3279 import 'libA.dart'; | 3029 import 'libA.dart'; |
3280 import 'libB.dart'; | 3030 import 'libB.dart'; |
3281 main() { | 3031 main() { |
3282 useFunction(test); | 3032 useFunction(test); |
3283 } | 3033 } |
3284 | 3034 |
3285 int test(A a) { | 3035 int test(A a) { |
3286 } | 3036 } |
3287 '''); | 3037 '''); |
3288 } | 3038 } |
3289 | 3039 |
3290 test_creationFunction_forFunctionType_method_enclosingClass_static() async { | 3040 test_creationFunction_forFunctionType_method_enclosingClass_static() async { |
3291 await resolveTestUnit(''' | 3041 await resolveTestUnit(''' |
3292 class A { | 3042 class A { |
3293 static foo() { | 3043 static foo() { |
3294 useFunction(test); | 3044 useFunction(test); |
3295 } | 3045 } |
3296 } | 3046 } |
3297 useFunction(int g(double a, String b)) {} | 3047 useFunction(int g(double a, String b)) {} |
3298 '''); | 3048 '''); |
3299 await assertHasFix( | 3049 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
3300 DartFixKind.CREATE_METHOD, | |
3301 ''' | |
3302 class A { | 3050 class A { |
3303 static foo() { | 3051 static foo() { |
3304 useFunction(test); | 3052 useFunction(test); |
3305 } | 3053 } |
3306 | 3054 |
3307 static int test(double a, String b) { | 3055 static int test(double a, String b) { |
3308 } | 3056 } |
3309 } | 3057 } |
3310 useFunction(int g(double a, String b)) {} | 3058 useFunction(int g(double a, String b)) {} |
3311 '''); | 3059 '''); |
3312 } | 3060 } |
3313 | 3061 |
3314 test_creationFunction_forFunctionType_method_enclosingClass_static2() async { | 3062 test_creationFunction_forFunctionType_method_enclosingClass_static2() async { |
3315 await resolveTestUnit(''' | 3063 await resolveTestUnit(''' |
3316 class A { | 3064 class A { |
3317 var f; | 3065 var f; |
3318 A() : f = useFunction(test); | 3066 A() : f = useFunction(test); |
3319 } | 3067 } |
3320 useFunction(int g(double a, String b)) {} | 3068 useFunction(int g(double a, String b)) {} |
3321 '''); | 3069 '''); |
3322 await assertHasFix( | 3070 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
3323 DartFixKind.CREATE_METHOD, | |
3324 ''' | |
3325 class A { | 3071 class A { |
3326 var f; | 3072 var f; |
3327 A() : f = useFunction(test); | 3073 A() : f = useFunction(test); |
3328 | 3074 |
3329 static int test(double a, String b) { | 3075 static int test(double a, String b) { |
3330 } | 3076 } |
3331 } | 3077 } |
3332 useFunction(int g(double a, String b)) {} | 3078 useFunction(int g(double a, String b)) {} |
3333 '''); | 3079 '''); |
3334 } | 3080 } |
3335 | 3081 |
3336 test_creationFunction_forFunctionType_method_targetClass() async { | 3082 test_creationFunction_forFunctionType_method_targetClass() async { |
3337 await resolveTestUnit(''' | 3083 await resolveTestUnit(''' |
3338 main(A a) { | 3084 main(A a) { |
3339 useFunction(a.test); | 3085 useFunction(a.test); |
3340 } | 3086 } |
3341 class A { | 3087 class A { |
3342 } | 3088 } |
3343 useFunction(int g(double a, String b)) {} | 3089 useFunction(int g(double a, String b)) {} |
3344 '''); | 3090 '''); |
3345 await assertHasFix( | 3091 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
3346 DartFixKind.CREATE_METHOD, | |
3347 ''' | |
3348 main(A a) { | 3092 main(A a) { |
3349 useFunction(a.test); | 3093 useFunction(a.test); |
3350 } | 3094 } |
3351 class A { | 3095 class A { |
3352 int test(double a, String b) { | 3096 int test(double a, String b) { |
3353 } | 3097 } |
3354 } | 3098 } |
3355 useFunction(int g(double a, String b)) {} | 3099 useFunction(int g(double a, String b)) {} |
3356 '''); | 3100 '''); |
3357 } | 3101 } |
3358 | 3102 |
3359 test_creationFunction_forFunctionType_method_targetClass_hasOtherMember() asyn
c { | 3103 test_creationFunction_forFunctionType_method_targetClass_hasOtherMember() asyn
c { |
3360 await resolveTestUnit(''' | 3104 await resolveTestUnit(''' |
3361 main(A a) { | 3105 main(A a) { |
3362 useFunction(a.test); | 3106 useFunction(a.test); |
3363 } | 3107 } |
3364 class A { | 3108 class A { |
3365 m() {} | 3109 m() {} |
3366 } | 3110 } |
3367 useFunction(int g(double a, String b)) {} | 3111 useFunction(int g(double a, String b)) {} |
3368 '''); | 3112 '''); |
3369 await assertHasFix( | 3113 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
3370 DartFixKind.CREATE_METHOD, | |
3371 ''' | |
3372 main(A a) { | 3114 main(A a) { |
3373 useFunction(a.test); | 3115 useFunction(a.test); |
3374 } | 3116 } |
3375 class A { | 3117 class A { |
3376 m() {} | 3118 m() {} |
3377 | 3119 |
3378 int test(double a, String b) { | 3120 int test(double a, String b) { |
3379 } | 3121 } |
3380 } | 3122 } |
3381 useFunction(int g(double a, String b)) {} | 3123 useFunction(int g(double a, String b)) {} |
(...skipping 23 matching lines...) Expand all Loading... |
3405 '''); | 3147 '''); |
3406 await assertNoFix(DartFixKind.CREATE_METHOD); | 3148 await assertNoFix(DartFixKind.CREATE_METHOD); |
3407 } | 3149 } |
3408 | 3150 |
3409 test_expectedToken_semicolon() async { | 3151 test_expectedToken_semicolon() async { |
3410 await resolveTestUnit(''' | 3152 await resolveTestUnit(''' |
3411 main() { | 3153 main() { |
3412 print(0) | 3154 print(0) |
3413 } | 3155 } |
3414 '''); | 3156 '''); |
3415 await assertHasFix( | 3157 await assertHasFix(DartFixKind.INSERT_SEMICOLON, ''' |
3416 DartFixKind.INSERT_SEMICOLON, | |
3417 ''' | |
3418 main() { | 3158 main() { |
3419 print(0); | 3159 print(0); |
3420 } | 3160 } |
3421 '''); | 3161 '''); |
3422 } | 3162 } |
3423 | 3163 |
3424 test_illegalAsyncReturnType_adjacentNodes() async { | 3164 test_illegalAsyncReturnType_adjacentNodes() async { |
3425 errorFilter = (AnalysisError error) { | 3165 errorFilter = (AnalysisError error) { |
3426 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 3166 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
3427 }; | 3167 }; |
3428 await resolveTestUnit(''' | 3168 await resolveTestUnit(''' |
3429 import 'dart:async'; | 3169 import 'dart:async'; |
3430 var v;int main() async => 0; | 3170 var v;int main() async => 0; |
3431 '''); | 3171 '''); |
3432 await assertHasFix( | 3172 await assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, ''' |
3433 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | |
3434 ''' | |
3435 import 'dart:async'; | 3173 import 'dart:async'; |
3436 var v;Future<int> main() async => 0; | 3174 var v;Future<int> main() async => 0; |
3437 '''); | 3175 '''); |
3438 } | 3176 } |
3439 | 3177 |
3440 test_illegalAsyncReturnType_asyncLibrary_import() async { | 3178 test_illegalAsyncReturnType_asyncLibrary_import() async { |
3441 errorFilter = (AnalysisError error) { | 3179 errorFilter = (AnalysisError error) { |
3442 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 3180 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
3443 }; | 3181 }; |
3444 await resolveTestUnit(''' | 3182 await resolveTestUnit(''' |
3445 library main; | 3183 library main; |
3446 int main() async { | 3184 int main() async { |
3447 } | 3185 } |
3448 '''); | 3186 '''); |
3449 await assertHasFix( | 3187 await assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, ''' |
3450 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | |
3451 ''' | |
3452 library main; | 3188 library main; |
3453 | 3189 |
3454 import 'dart:async'; | 3190 import 'dart:async'; |
3455 | 3191 |
3456 Future<int> main() async { | 3192 Future<int> main() async { |
3457 } | 3193 } |
3458 '''); | 3194 '''); |
3459 } | 3195 } |
3460 | 3196 |
3461 test_illegalAsyncReturnType_asyncLibrary_usePrefix() async { | 3197 test_illegalAsyncReturnType_asyncLibrary_usePrefix() async { |
3462 errorFilter = (AnalysisError error) { | 3198 errorFilter = (AnalysisError error) { |
3463 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 3199 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
3464 }; | 3200 }; |
3465 await resolveTestUnit(''' | 3201 await resolveTestUnit(''' |
3466 import 'dart:async' as al; | 3202 import 'dart:async' as al; |
3467 int main() async { | 3203 int main() async { |
3468 } | 3204 } |
3469 '''); | 3205 '''); |
3470 await assertHasFix( | 3206 await assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, ''' |
3471 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | |
3472 ''' | |
3473 import 'dart:async' as al; | 3207 import 'dart:async' as al; |
3474 al.Future<int> main() async { | 3208 al.Future<int> main() async { |
3475 } | 3209 } |
3476 '''); | 3210 '''); |
3477 } | 3211 } |
3478 | 3212 |
3479 test_illegalAsyncReturnType_complexTypeName() async { | 3213 test_illegalAsyncReturnType_complexTypeName() async { |
3480 errorFilter = (AnalysisError error) { | 3214 errorFilter = (AnalysisError error) { |
3481 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 3215 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
3482 }; | 3216 }; |
3483 await resolveTestUnit(''' | 3217 await resolveTestUnit(''' |
3484 import 'dart:async'; | 3218 import 'dart:async'; |
3485 List<int> main() async { | 3219 List<int> main() async { |
3486 } | 3220 } |
3487 '''); | 3221 '''); |
3488 await assertHasFix( | 3222 await assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, ''' |
3489 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | |
3490 ''' | |
3491 import 'dart:async'; | 3223 import 'dart:async'; |
3492 Future<List<int>> main() async { | 3224 Future<List<int>> main() async { |
3493 } | 3225 } |
3494 '''); | 3226 '''); |
3495 } | 3227 } |
3496 | 3228 |
3497 test_illegalAsyncReturnType_void() async { | 3229 test_illegalAsyncReturnType_void() async { |
3498 errorFilter = (AnalysisError error) { | 3230 errorFilter = (AnalysisError error) { |
3499 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 3231 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
3500 }; | 3232 }; |
3501 await resolveTestUnit(''' | 3233 await resolveTestUnit(''' |
3502 import 'dart:async'; | 3234 import 'dart:async'; |
3503 void main() async { | 3235 void main() async { |
3504 } | 3236 } |
3505 '''); | 3237 '''); |
3506 await assertHasFix( | 3238 await assertHasFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, ''' |
3507 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | |
3508 ''' | |
3509 import 'dart:async'; | 3239 import 'dart:async'; |
3510 Future main() async { | 3240 Future main() async { |
3511 } | 3241 } |
3512 '''); | 3242 '''); |
3513 } | 3243 } |
3514 | 3244 |
3515 test_importLibraryPackage_preferDirectOverExport() async { | 3245 test_importLibraryPackage_preferDirectOverExport() async { |
3516 _configureMyPkg({'b.dart': 'class Test {}', 'a.dart': "export 'b.dart';"}); | 3246 _configureMyPkg({'b.dart': 'class Test {}', 'a.dart': "export 'b.dart';"}); |
3517 await resolveTestUnit(''' | 3247 await resolveTestUnit(''' |
3518 main() { | 3248 main() { |
3519 Test test = null; | 3249 Test test = null; |
3520 } | 3250 } |
3521 '''); | 3251 '''); |
3522 await assertHasFix( | 3252 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, ''' |
3523 DartFixKind.IMPORT_LIBRARY_PROJECT1, | |
3524 ''' | |
3525 import 'package:my_pkg/b.dart'; | 3253 import 'package:my_pkg/b.dart'; |
3526 | 3254 |
3527 main() { | 3255 main() { |
3528 Test test = null; | 3256 Test test = null; |
3529 } | 3257 } |
3530 '''); | 3258 '''); |
3531 await assertHasFix( | 3259 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT2, ''' |
3532 DartFixKind.IMPORT_LIBRARY_PROJECT2, | |
3533 ''' | |
3534 import 'package:my_pkg/a.dart'; | 3260 import 'package:my_pkg/a.dart'; |
3535 | 3261 |
3536 main() { | 3262 main() { |
3537 Test test = null; | 3263 Test test = null; |
3538 } | 3264 } |
3539 '''); | 3265 '''); |
3540 } | 3266 } |
3541 | 3267 |
3542 test_importLibraryPackage_preferDirectOverExport_src() async { | 3268 test_importLibraryPackage_preferDirectOverExport_src() async { |
3543 myPkgLibPath = '/my/src/packages/my_pkg/lib'; | 3269 myPkgLibPath = '/my/src/packages/my_pkg/lib'; |
3544 _configureMyPkg({'b.dart': 'class Test {}', 'a.dart': "export 'b.dart';"}); | 3270 _configureMyPkg({'b.dart': 'class Test {}', 'a.dart': "export 'b.dart';"}); |
3545 await resolveTestUnit(''' | 3271 await resolveTestUnit(''' |
3546 main() { | 3272 main() { |
3547 Test test = null; | 3273 Test test = null; |
3548 } | 3274 } |
3549 '''); | 3275 '''); |
3550 await assertHasFix( | 3276 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, ''' |
3551 DartFixKind.IMPORT_LIBRARY_PROJECT1, | |
3552 ''' | |
3553 import 'package:my_pkg/b.dart'; | 3277 import 'package:my_pkg/b.dart'; |
3554 | 3278 |
3555 main() { | 3279 main() { |
3556 Test test = null; | 3280 Test test = null; |
3557 } | 3281 } |
3558 '''); | 3282 '''); |
3559 await assertHasFix( | 3283 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT2, ''' |
3560 DartFixKind.IMPORT_LIBRARY_PROJECT2, | |
3561 ''' | |
3562 import 'package:my_pkg/a.dart'; | 3284 import 'package:my_pkg/a.dart'; |
3563 | 3285 |
3564 main() { | 3286 main() { |
3565 Test test = null; | 3287 Test test = null; |
3566 } | 3288 } |
3567 '''); | 3289 '''); |
3568 } | 3290 } |
3569 | 3291 |
3570 test_importLibraryPackage_preferPublicOverPrivate() async { | 3292 test_importLibraryPackage_preferPublicOverPrivate() async { |
3571 _configureMyPkg( | 3293 _configureMyPkg( |
3572 {'src/a.dart': 'class Test {}', 'b.dart': "export 'src/a.dart';"}); | 3294 {'src/a.dart': 'class Test {}', 'b.dart': "export 'src/a.dart';"}); |
3573 await resolveTestUnit(''' | 3295 await resolveTestUnit(''' |
3574 main() { | 3296 main() { |
3575 Test test = null; | 3297 Test test = null; |
3576 } | 3298 } |
3577 '''); | 3299 '''); |
3578 await assertHasFix( | 3300 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT2, ''' |
3579 DartFixKind.IMPORT_LIBRARY_PROJECT2, | |
3580 ''' | |
3581 import 'package:my_pkg/b.dart'; | 3301 import 'package:my_pkg/b.dart'; |
3582 | 3302 |
3583 main() { | 3303 main() { |
3584 Test test = null; | 3304 Test test = null; |
3585 } | 3305 } |
3586 '''); | 3306 '''); |
3587 await assertHasFix( | 3307 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT3, ''' |
3588 DartFixKind.IMPORT_LIBRARY_PROJECT3, | |
3589 ''' | |
3590 import 'package:my_pkg/src/a.dart'; | 3308 import 'package:my_pkg/src/a.dart'; |
3591 | 3309 |
3592 main() { | 3310 main() { |
3593 Test test = null; | 3311 Test test = null; |
3594 } | 3312 } |
3595 '''); | 3313 '''); |
3596 } | 3314 } |
3597 | 3315 |
3598 test_importLibraryProject_BAD_notInLib_BUILD() async { | 3316 test_importLibraryProject_BAD_notInLib_BUILD() async { |
3599 testFile = '/aaa/bin/test.dart'; | 3317 testFile = '/aaa/bin/test.dart'; |
(...skipping 15 matching lines...) Expand all Loading... |
3615 addSource('/bbb/test/lib.dart', 'class Test {}'); | 3333 addSource('/bbb/test/lib.dart', 'class Test {}'); |
3616 await resolveTestUnit(''' | 3334 await resolveTestUnit(''' |
3617 main() { | 3335 main() { |
3618 Test t; | 3336 Test t; |
3619 } | 3337 } |
3620 '''); | 3338 '''); |
3621 await assertNoFix(DartFixKind.IMPORT_LIBRARY_PROJECT1); | 3339 await assertNoFix(DartFixKind.IMPORT_LIBRARY_PROJECT1); |
3622 } | 3340 } |
3623 | 3341 |
3624 test_importLibraryProject_withClass_annotation() async { | 3342 test_importLibraryProject_withClass_annotation() async { |
3625 addSource( | 3343 addSource('/lib.dart', ''' |
3626 '/lib.dart', | |
3627 ''' | |
3628 library lib; | 3344 library lib; |
3629 class Test { | 3345 class Test { |
3630 const Test(int p); | 3346 const Test(int p); |
3631 } | 3347 } |
3632 '''); | 3348 '''); |
3633 await resolveTestUnit(''' | 3349 await resolveTestUnit(''' |
3634 @Test(0) | 3350 @Test(0) |
3635 main() { | 3351 main() { |
3636 } | 3352 } |
3637 '''); | 3353 '''); |
3638 await assertHasFix( | 3354 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, ''' |
3639 DartFixKind.IMPORT_LIBRARY_PROJECT1, | |
3640 ''' | |
3641 import 'lib.dart'; | 3355 import 'lib.dart'; |
3642 | 3356 |
3643 @Test(0) | 3357 @Test(0) |
3644 main() { | 3358 main() { |
3645 } | 3359 } |
3646 '''); | 3360 '''); |
3647 } | 3361 } |
3648 | 3362 |
3649 test_importLibraryProject_withClass_constInstanceCreation() async { | 3363 test_importLibraryProject_withClass_constInstanceCreation() async { |
3650 addSource( | 3364 addSource('/lib.dart', ''' |
3651 '/lib.dart', | |
3652 ''' | |
3653 class Test { | 3365 class Test { |
3654 const Test(); | 3366 const Test(); |
3655 } | 3367 } |
3656 '''); | 3368 '''); |
3657 await resolveTestUnit(''' | 3369 await resolveTestUnit(''' |
3658 main() { | 3370 main() { |
3659 const Test(); | 3371 const Test(); |
3660 } | 3372 } |
3661 '''); | 3373 '''); |
3662 await assertHasFix( | 3374 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, ''' |
3663 DartFixKind.IMPORT_LIBRARY_PROJECT1, | |
3664 ''' | |
3665 import 'lib.dart'; | 3375 import 'lib.dart'; |
3666 | 3376 |
3667 main() { | 3377 main() { |
3668 const Test(); | 3378 const Test(); |
3669 } | 3379 } |
3670 '''); | 3380 '''); |
3671 } | 3381 } |
3672 | 3382 |
3673 test_importLibraryProject_withClass_hasOtherLibraryWithPrefix() async { | 3383 test_importLibraryProject_withClass_hasOtherLibraryWithPrefix() async { |
3674 testFile = '/project/bin/test.dart'; | 3384 testFile = '/project/bin/test.dart'; |
3675 addSource( | 3385 addSource('/project/bin/a.dart', ''' |
3676 '/project/bin/a.dart', | |
3677 ''' | |
3678 library a; | 3386 library a; |
3679 class One {} | 3387 class One {} |
3680 '''); | 3388 '''); |
3681 addSource( | 3389 addSource('/project/bin/b.dart', ''' |
3682 '/project/bin/b.dart', | |
3683 ''' | |
3684 library b; | 3390 library b; |
3685 class One {} | 3391 class One {} |
3686 class Two {} | 3392 class Two {} |
3687 '''); | 3393 '''); |
3688 await resolveTestUnit(''' | 3394 await resolveTestUnit(''' |
3689 import 'b.dart' show Two; | 3395 import 'b.dart' show Two; |
3690 main () { | 3396 main () { |
3691 new Two(); | 3397 new Two(); |
3692 new One(); | 3398 new One(); |
3693 } | 3399 } |
3694 '''); | 3400 '''); |
3695 await assertHasFix( | 3401 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, ''' |
3696 DartFixKind.IMPORT_LIBRARY_PROJECT1, | |
3697 ''' | |
3698 import 'a.dart'; | 3402 import 'a.dart'; |
3699 import 'b.dart' show Two; | 3403 import 'b.dart' show Two; |
3700 main () { | 3404 main () { |
3701 new Two(); | 3405 new Two(); |
3702 new One(); | 3406 new One(); |
3703 } | 3407 } |
3704 '''); | 3408 '''); |
3705 } | 3409 } |
3706 | 3410 |
3707 test_importLibraryProject_withClass_inParentFolder() async { | 3411 test_importLibraryProject_withClass_inParentFolder() async { |
3708 testFile = '/project/bin/test.dart'; | 3412 testFile = '/project/bin/test.dart'; |
3709 addSource( | 3413 addSource('/project/lib.dart', ''' |
3710 '/project/lib.dart', | |
3711 ''' | |
3712 library lib; | 3414 library lib; |
3713 class Test {} | 3415 class Test {} |
3714 '''); | 3416 '''); |
3715 await resolveTestUnit(''' | 3417 await resolveTestUnit(''' |
3716 main() { | 3418 main() { |
3717 Test t = null; | 3419 Test t = null; |
3718 } | 3420 } |
3719 '''); | 3421 '''); |
3720 await assertHasFix( | 3422 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, ''' |
3721 DartFixKind.IMPORT_LIBRARY_PROJECT1, | |
3722 ''' | |
3723 import '../lib.dart'; | 3423 import '../lib.dart'; |
3724 | 3424 |
3725 main() { | 3425 main() { |
3726 Test t = null; | 3426 Test t = null; |
3727 } | 3427 } |
3728 '''); | 3428 '''); |
3729 } | 3429 } |
3730 | 3430 |
3731 test_importLibraryProject_withClass_inRelativeFolder() async { | 3431 test_importLibraryProject_withClass_inRelativeFolder() async { |
3732 testFile = '/project/bin/test.dart'; | 3432 testFile = '/project/bin/test.dart'; |
3733 addSource( | 3433 addSource('/project/lib/sub/folder/lib.dart', ''' |
3734 '/project/lib/sub/folder/lib.dart', | |
3735 ''' | |
3736 library lib; | 3434 library lib; |
3737 class Test {} | 3435 class Test {} |
3738 '''); | 3436 '''); |
3739 await resolveTestUnit(''' | 3437 await resolveTestUnit(''' |
3740 main() { | 3438 main() { |
3741 Test t = null; | 3439 Test t = null; |
3742 } | 3440 } |
3743 '''); | 3441 '''); |
3744 await assertHasFix( | 3442 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, ''' |
3745 DartFixKind.IMPORT_LIBRARY_PROJECT1, | |
3746 ''' | |
3747 import '../lib/sub/folder/lib.dart'; | 3443 import '../lib/sub/folder/lib.dart'; |
3748 | 3444 |
3749 main() { | 3445 main() { |
3750 Test t = null; | 3446 Test t = null; |
3751 } | 3447 } |
3752 '''); | 3448 '''); |
3753 } | 3449 } |
3754 | 3450 |
3755 test_importLibraryProject_withClass_inSameFolder() async { | 3451 test_importLibraryProject_withClass_inSameFolder() async { |
3756 testFile = '/project/bin/test.dart'; | 3452 testFile = '/project/bin/test.dart'; |
3757 addSource( | 3453 addSource('/project/bin/lib.dart', ''' |
3758 '/project/bin/lib.dart', | |
3759 ''' | |
3760 library lib; | 3454 library lib; |
3761 class Test {} | 3455 class Test {} |
3762 '''); | 3456 '''); |
3763 await resolveTestUnit(''' | 3457 await resolveTestUnit(''' |
3764 main() { | 3458 main() { |
3765 Test t = null; | 3459 Test t = null; |
3766 } | 3460 } |
3767 '''); | 3461 '''); |
3768 await assertHasFix( | 3462 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, ''' |
3769 DartFixKind.IMPORT_LIBRARY_PROJECT1, | |
3770 ''' | |
3771 import 'lib.dart'; | 3463 import 'lib.dart'; |
3772 | 3464 |
3773 main() { | 3465 main() { |
3774 Test t = null; | 3466 Test t = null; |
3775 } | 3467 } |
3776 '''); | 3468 '''); |
3777 } | 3469 } |
3778 | 3470 |
3779 test_importLibraryProject_withFunction() async { | 3471 test_importLibraryProject_withFunction() async { |
3780 addSource( | 3472 addSource('/lib.dart', ''' |
3781 '/lib.dart', | |
3782 ''' | |
3783 library lib; | 3473 library lib; |
3784 myFunction() {} | 3474 myFunction() {} |
3785 '''); | 3475 '''); |
3786 await resolveTestUnit(''' | 3476 await resolveTestUnit(''' |
3787 main() { | 3477 main() { |
3788 myFunction(); | 3478 myFunction(); |
3789 } | 3479 } |
3790 '''); | 3480 '''); |
3791 await assertHasFix( | 3481 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, ''' |
3792 DartFixKind.IMPORT_LIBRARY_PROJECT1, | |
3793 ''' | |
3794 import 'lib.dart'; | 3482 import 'lib.dart'; |
3795 | 3483 |
3796 main() { | 3484 main() { |
3797 myFunction(); | 3485 myFunction(); |
3798 } | 3486 } |
3799 '''); | 3487 '''); |
3800 } | 3488 } |
3801 | 3489 |
3802 test_importLibraryProject_withFunction_unresolvedMethod() async { | 3490 test_importLibraryProject_withFunction_unresolvedMethod() async { |
3803 addSource( | 3491 addSource('/lib.dart', ''' |
3804 '/lib.dart', | |
3805 ''' | |
3806 library lib; | 3492 library lib; |
3807 myFunction() {} | 3493 myFunction() {} |
3808 '''); | 3494 '''); |
3809 await resolveTestUnit(''' | 3495 await resolveTestUnit(''' |
3810 class A { | 3496 class A { |
3811 main() { | 3497 main() { |
3812 myFunction(); | 3498 myFunction(); |
3813 } | 3499 } |
3814 } | 3500 } |
3815 '''); | 3501 '''); |
3816 await assertHasFix( | 3502 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, ''' |
3817 DartFixKind.IMPORT_LIBRARY_PROJECT1, | |
3818 ''' | |
3819 import 'lib.dart'; | 3503 import 'lib.dart'; |
3820 | 3504 |
3821 class A { | 3505 class A { |
3822 main() { | 3506 main() { |
3823 myFunction(); | 3507 myFunction(); |
3824 } | 3508 } |
3825 } | 3509 } |
3826 '''); | 3510 '''); |
3827 } | 3511 } |
3828 | 3512 |
3829 test_importLibraryProject_withFunctionTypeAlias() async { | 3513 test_importLibraryProject_withFunctionTypeAlias() async { |
3830 testFile = '/project/bin/test.dart'; | 3514 testFile = '/project/bin/test.dart'; |
3831 addSource( | 3515 addSource('/project/bin/lib.dart', ''' |
3832 '/project/bin/lib.dart', | |
3833 ''' | |
3834 library lib; | 3516 library lib; |
3835 typedef MyFunction(); | 3517 typedef MyFunction(); |
3836 '''); | 3518 '''); |
3837 await resolveTestUnit(''' | 3519 await resolveTestUnit(''' |
3838 main() { | 3520 main() { |
3839 MyFunction t = null; | 3521 MyFunction t = null; |
3840 } | 3522 } |
3841 '''); | 3523 '''); |
3842 await assertHasFix( | 3524 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, ''' |
3843 DartFixKind.IMPORT_LIBRARY_PROJECT1, | |
3844 ''' | |
3845 import 'lib.dart'; | 3525 import 'lib.dart'; |
3846 | 3526 |
3847 main() { | 3527 main() { |
3848 MyFunction t = null; | 3528 MyFunction t = null; |
3849 } | 3529 } |
3850 '''); | 3530 '''); |
3851 } | 3531 } |
3852 | 3532 |
3853 test_importLibraryProject_withTopLevelVariable() async { | 3533 test_importLibraryProject_withTopLevelVariable() async { |
3854 addSource( | 3534 addSource('/lib.dart', ''' |
3855 '/lib.dart', | |
3856 ''' | |
3857 library lib; | 3535 library lib; |
3858 int MY_VAR = 42; | 3536 int MY_VAR = 42; |
3859 '''); | 3537 '''); |
3860 await resolveTestUnit(''' | 3538 await resolveTestUnit(''' |
3861 main() { | 3539 main() { |
3862 print(MY_VAR); | 3540 print(MY_VAR); |
3863 } | 3541 } |
3864 '''); | 3542 '''); |
3865 await assertHasFix( | 3543 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PROJECT1, ''' |
3866 DartFixKind.IMPORT_LIBRARY_PROJECT1, | |
3867 ''' | |
3868 import 'lib.dart'; | 3544 import 'lib.dart'; |
3869 | 3545 |
3870 main() { | 3546 main() { |
3871 print(MY_VAR); | 3547 print(MY_VAR); |
3872 } | 3548 } |
3873 '''); | 3549 '''); |
3874 } | 3550 } |
3875 | 3551 |
3876 test_importLibrarySdk_withClass_AsExpression() async { | 3552 test_importLibrarySdk_withClass_AsExpression() async { |
3877 await resolveTestUnit(''' | 3553 await resolveTestUnit(''' |
3878 main(p) { | 3554 main(p) { |
3879 p as Future; | 3555 p as Future; |
3880 } | 3556 } |
3881 '''); | 3557 '''); |
3882 await assertHasFix( | 3558 await assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' |
3883 DartFixKind.IMPORT_LIBRARY_SDK, | |
3884 ''' | |
3885 import 'dart:async'; | 3559 import 'dart:async'; |
3886 | 3560 |
3887 main(p) { | 3561 main(p) { |
3888 p as Future; | 3562 p as Future; |
3889 } | 3563 } |
3890 '''); | 3564 '''); |
3891 } | 3565 } |
3892 | 3566 |
3893 test_importLibrarySdk_withClass_invocationTarget() async { | 3567 test_importLibrarySdk_withClass_invocationTarget() async { |
3894 await resolveTestUnit(''' | 3568 await resolveTestUnit(''' |
3895 main() { | 3569 main() { |
3896 Future.wait(null); | 3570 Future.wait(null); |
3897 } | 3571 } |
3898 '''); | 3572 '''); |
3899 await assertHasFix( | 3573 await assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' |
3900 DartFixKind.IMPORT_LIBRARY_SDK, | |
3901 ''' | |
3902 import 'dart:async'; | 3574 import 'dart:async'; |
3903 | 3575 |
3904 main() { | 3576 main() { |
3905 Future.wait(null); | 3577 Future.wait(null); |
3906 } | 3578 } |
3907 '''); | 3579 '''); |
3908 } | 3580 } |
3909 | 3581 |
3910 test_importLibrarySdk_withClass_IsExpression() async { | 3582 test_importLibrarySdk_withClass_IsExpression() async { |
3911 await resolveTestUnit(''' | 3583 await resolveTestUnit(''' |
3912 main(p) { | 3584 main(p) { |
3913 p is Future; | 3585 p is Future; |
3914 } | 3586 } |
3915 '''); | 3587 '''); |
3916 await assertHasFix( | 3588 await assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' |
3917 DartFixKind.IMPORT_LIBRARY_SDK, | |
3918 ''' | |
3919 import 'dart:async'; | 3589 import 'dart:async'; |
3920 | 3590 |
3921 main(p) { | 3591 main(p) { |
3922 p is Future; | 3592 p is Future; |
3923 } | 3593 } |
3924 '''); | 3594 '''); |
3925 } | 3595 } |
3926 | 3596 |
3927 test_importLibrarySdk_withClass_itemOfList() async { | 3597 test_importLibrarySdk_withClass_itemOfList() async { |
3928 await resolveTestUnit(''' | 3598 await resolveTestUnit(''' |
3929 main() { | 3599 main() { |
3930 var a = [Future]; | 3600 var a = [Future]; |
3931 } | 3601 } |
3932 '''); | 3602 '''); |
3933 await assertHasFix( | 3603 await assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' |
3934 DartFixKind.IMPORT_LIBRARY_SDK, | |
3935 ''' | |
3936 import 'dart:async'; | 3604 import 'dart:async'; |
3937 | 3605 |
3938 main() { | 3606 main() { |
3939 var a = [Future]; | 3607 var a = [Future]; |
3940 } | 3608 } |
3941 '''); | 3609 '''); |
3942 } | 3610 } |
3943 | 3611 |
3944 test_importLibrarySdk_withClass_itemOfList_inAnnotation() async { | 3612 test_importLibrarySdk_withClass_itemOfList_inAnnotation() async { |
3945 errorFilter = (AnalysisError error) { | 3613 errorFilter = (AnalysisError error) { |
3946 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; | 3614 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; |
3947 }; | 3615 }; |
3948 await resolveTestUnit(''' | 3616 await resolveTestUnit(''' |
3949 class MyAnnotation { | 3617 class MyAnnotation { |
3950 const MyAnnotation(a, b); | 3618 const MyAnnotation(a, b); |
3951 } | 3619 } |
3952 @MyAnnotation(int, const [Future]) | 3620 @MyAnnotation(int, const [Future]) |
3953 main() {} | 3621 main() {} |
3954 '''); | 3622 '''); |
3955 await assertHasFix( | 3623 await assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' |
3956 DartFixKind.IMPORT_LIBRARY_SDK, | |
3957 ''' | |
3958 import 'dart:async'; | 3624 import 'dart:async'; |
3959 | 3625 |
3960 class MyAnnotation { | 3626 class MyAnnotation { |
3961 const MyAnnotation(a, b); | 3627 const MyAnnotation(a, b); |
3962 } | 3628 } |
3963 @MyAnnotation(int, const [Future]) | 3629 @MyAnnotation(int, const [Future]) |
3964 main() {} | 3630 main() {} |
3965 '''); | 3631 '''); |
3966 } | 3632 } |
3967 | 3633 |
3968 test_importLibrarySdk_withClass_typeAnnotation() async { | 3634 test_importLibrarySdk_withClass_typeAnnotation() async { |
3969 await resolveTestUnit(''' | 3635 await resolveTestUnit(''' |
3970 main() { | 3636 main() { |
3971 Future f = null; | 3637 Future f = null; |
3972 } | 3638 } |
3973 '''); | 3639 '''); |
3974 await assertHasFix( | 3640 await assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' |
3975 DartFixKind.IMPORT_LIBRARY_SDK, | |
3976 ''' | |
3977 import 'dart:async'; | 3641 import 'dart:async'; |
3978 | 3642 |
3979 main() { | 3643 main() { |
3980 Future f = null; | 3644 Future f = null; |
3981 } | 3645 } |
3982 '''); | 3646 '''); |
3983 } | 3647 } |
3984 | 3648 |
3985 test_importLibrarySdk_withClass_typeAnnotation_PrefixedIdentifier() async { | 3649 test_importLibrarySdk_withClass_typeAnnotation_PrefixedIdentifier() async { |
3986 await resolveTestUnit(''' | 3650 await resolveTestUnit(''' |
3987 main() { | 3651 main() { |
3988 Future.wait; | 3652 Future.wait; |
3989 } | 3653 } |
3990 '''); | 3654 '''); |
3991 await assertHasFix( | 3655 await assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' |
3992 DartFixKind.IMPORT_LIBRARY_SDK, | |
3993 ''' | |
3994 import 'dart:async'; | 3656 import 'dart:async'; |
3995 | 3657 |
3996 main() { | 3658 main() { |
3997 Future.wait; | 3659 Future.wait; |
3998 } | 3660 } |
3999 '''); | 3661 '''); |
4000 } | 3662 } |
4001 | 3663 |
4002 test_importLibrarySdk_withClass_typeArgument() async { | 3664 test_importLibrarySdk_withClass_typeArgument() async { |
4003 await resolveTestUnit(''' | 3665 await resolveTestUnit(''' |
4004 main() { | 3666 main() { |
4005 List<Future> futures = []; | 3667 List<Future> futures = []; |
4006 } | 3668 } |
4007 '''); | 3669 '''); |
4008 await assertHasFix( | 3670 await assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' |
4009 DartFixKind.IMPORT_LIBRARY_SDK, | |
4010 ''' | |
4011 import 'dart:async'; | 3671 import 'dart:async'; |
4012 | 3672 |
4013 main() { | 3673 main() { |
4014 List<Future> futures = []; | 3674 List<Future> futures = []; |
4015 } | 3675 } |
4016 '''); | 3676 '''); |
4017 } | 3677 } |
4018 | 3678 |
4019 test_importLibrarySdk_withTopLevelVariable() async { | 3679 test_importLibrarySdk_withTopLevelVariable() async { |
4020 await resolveTestUnit(''' | 3680 await resolveTestUnit(''' |
4021 main() { | 3681 main() { |
4022 print(PI); | 3682 print(PI); |
4023 } | 3683 } |
4024 '''); | 3684 '''); |
4025 await assertHasFix( | 3685 await assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' |
4026 DartFixKind.IMPORT_LIBRARY_SDK, | |
4027 ''' | |
4028 import 'dart:math'; | 3686 import 'dart:math'; |
4029 | 3687 |
4030 main() { | 3688 main() { |
4031 print(PI); | 3689 print(PI); |
4032 } | 3690 } |
4033 '''); | 3691 '''); |
4034 } | 3692 } |
4035 | 3693 |
4036 test_importLibrarySdk_withTopLevelVariable_annotation() async { | 3694 test_importLibrarySdk_withTopLevelVariable_annotation() async { |
4037 await resolveTestUnit(''' | 3695 await resolveTestUnit(''' |
4038 @PI | 3696 @PI |
4039 main() { | 3697 main() { |
4040 } | 3698 } |
4041 '''); | 3699 '''); |
4042 await assertHasFix( | 3700 await assertHasFix(DartFixKind.IMPORT_LIBRARY_SDK, ''' |
4043 DartFixKind.IMPORT_LIBRARY_SDK, | |
4044 ''' | |
4045 import 'dart:math'; | 3701 import 'dart:math'; |
4046 | 3702 |
4047 @PI | 3703 @PI |
4048 main() { | 3704 main() { |
4049 } | 3705 } |
4050 '''); | 3706 '''); |
4051 } | 3707 } |
4052 | 3708 |
4053 test_importLibraryShow_project() async { | 3709 test_importLibraryShow_project() async { |
4054 testFile = '/project/bin/test.dart'; | 3710 testFile = '/project/bin/test.dart'; |
4055 addSource( | 3711 addSource('/project/bin/lib.dart', ''' |
4056 '/project/bin/lib.dart', | |
4057 ''' | |
4058 class A {} | 3712 class A {} |
4059 class B {} | 3713 class B {} |
4060 '''); | 3714 '''); |
4061 await resolveTestUnit(''' | 3715 await resolveTestUnit(''' |
4062 import 'lib.dart' show A; | 3716 import 'lib.dart' show A; |
4063 main() { | 3717 main() { |
4064 A a; | 3718 A a; |
4065 B b; | 3719 B b; |
4066 } | 3720 } |
4067 '''); | 3721 '''); |
4068 await assertNoFix(DartFixKind.IMPORT_LIBRARY_PROJECT1); | 3722 await assertNoFix(DartFixKind.IMPORT_LIBRARY_PROJECT1); |
4069 await assertHasFix( | 3723 await assertHasFix(DartFixKind.IMPORT_LIBRARY_SHOW, ''' |
4070 DartFixKind.IMPORT_LIBRARY_SHOW, | |
4071 ''' | |
4072 import 'lib.dart' show A, B; | 3724 import 'lib.dart' show A, B; |
4073 main() { | 3725 main() { |
4074 A a; | 3726 A a; |
4075 B b; | 3727 B b; |
4076 } | 3728 } |
4077 '''); | 3729 '''); |
4078 } | 3730 } |
4079 | 3731 |
4080 test_importLibraryShow_sdk() async { | 3732 test_importLibraryShow_sdk() async { |
4081 await resolveTestUnit(''' | 3733 await resolveTestUnit(''' |
4082 import 'dart:async' show Stream; | 3734 import 'dart:async' show Stream; |
4083 main() { | 3735 main() { |
4084 Stream s = null; | 3736 Stream s = null; |
4085 Future f = null; | 3737 Future f = null; |
4086 } | 3738 } |
4087 '''); | 3739 '''); |
4088 await assertNoFix(DartFixKind.IMPORT_LIBRARY_SDK); | 3740 await assertNoFix(DartFixKind.IMPORT_LIBRARY_SDK); |
4089 await assertHasFix( | 3741 await assertHasFix(DartFixKind.IMPORT_LIBRARY_SHOW, ''' |
4090 DartFixKind.IMPORT_LIBRARY_SHOW, | |
4091 ''' | |
4092 import 'dart:async' show Future, Stream; | 3742 import 'dart:async' show Future, Stream; |
4093 main() { | 3743 main() { |
4094 Stream s = null; | 3744 Stream s = null; |
4095 Future f = null; | 3745 Future f = null; |
4096 } | 3746 } |
4097 '''); | 3747 '''); |
4098 } | 3748 } |
4099 | 3749 |
4100 test_invokeConstructorUsingNew() async { | 3750 test_invokeConstructorUsingNew() async { |
4101 await resolveTestUnit(''' | 3751 await resolveTestUnit(''' |
4102 class C { | 3752 class C { |
4103 C.c(); | 3753 C.c(); |
4104 } | 3754 } |
4105 main() { | 3755 main() { |
4106 C c = C.c(); | 3756 C c = C.c(); |
4107 } | 3757 } |
4108 '''); | 3758 '''); |
4109 await assertHasFix( | 3759 await assertHasFix(DartFixKind.INVOKE_CONSTRUCTOR_USING_NEW, ''' |
4110 DartFixKind.INVOKE_CONSTRUCTOR_USING_NEW, | |
4111 ''' | |
4112 class C { | 3760 class C { |
4113 C.c(); | 3761 C.c(); |
4114 } | 3762 } |
4115 main() { | 3763 main() { |
4116 C c = new C.c(); | 3764 C c = new C.c(); |
4117 } | 3765 } |
4118 '''); | 3766 '''); |
4119 } | 3767 } |
4120 | 3768 |
4121 test_isNotNull() async { | 3769 test_isNotNull() async { |
4122 await resolveTestUnit(''' | 3770 await resolveTestUnit(''' |
4123 main(p) { | 3771 main(p) { |
4124 p is! Null; | 3772 p is! Null; |
4125 } | 3773 } |
4126 '''); | 3774 '''); |
4127 await assertHasFix( | 3775 await assertHasFix(DartFixKind.USE_NOT_EQ_NULL, ''' |
4128 DartFixKind.USE_NOT_EQ_NULL, | |
4129 ''' | |
4130 main(p) { | 3776 main(p) { |
4131 p != null; | 3777 p != null; |
4132 } | 3778 } |
4133 '''); | 3779 '''); |
4134 } | 3780 } |
4135 | 3781 |
4136 test_isNull() async { | 3782 test_isNull() async { |
4137 await resolveTestUnit(''' | 3783 await resolveTestUnit(''' |
4138 main(p) { | 3784 main(p) { |
4139 p is Null; | 3785 p is Null; |
4140 } | 3786 } |
4141 '''); | 3787 '''); |
4142 await assertHasFix( | 3788 await assertHasFix(DartFixKind.USE_EQ_EQ_NULL, ''' |
4143 DartFixKind.USE_EQ_EQ_NULL, | |
4144 ''' | |
4145 main(p) { | 3789 main(p) { |
4146 p == null; | 3790 p == null; |
4147 } | 3791 } |
4148 '''); | 3792 '''); |
4149 } | 3793 } |
4150 | 3794 |
4151 test_makeEnclosingClassAbstract_declaresAbstractMethod() async { | 3795 test_makeEnclosingClassAbstract_declaresAbstractMethod() async { |
4152 await resolveTestUnit(''' | 3796 await resolveTestUnit(''' |
4153 class A { | 3797 class A { |
4154 m(); | 3798 m(); |
4155 } | 3799 } |
4156 '''); | 3800 '''); |
4157 await assertHasFix( | 3801 await assertHasFix(DartFixKind.MAKE_CLASS_ABSTRACT, ''' |
4158 DartFixKind.MAKE_CLASS_ABSTRACT, | |
4159 ''' | |
4160 abstract class A { | 3802 abstract class A { |
4161 m(); | 3803 m(); |
4162 } | 3804 } |
4163 '''); | 3805 '''); |
4164 } | 3806 } |
4165 | 3807 |
4166 test_makeEnclosingClassAbstract_inheritsAbstractMethod() async { | 3808 test_makeEnclosingClassAbstract_inheritsAbstractMethod() async { |
4167 await resolveTestUnit(''' | 3809 await resolveTestUnit(''' |
4168 abstract class A { | 3810 abstract class A { |
4169 m(); | 3811 m(); |
4170 } | 3812 } |
4171 class B extends A { | 3813 class B extends A { |
4172 } | 3814 } |
4173 '''); | 3815 '''); |
4174 await assertHasFix( | 3816 await assertHasFix(DartFixKind.MAKE_CLASS_ABSTRACT, ''' |
4175 DartFixKind.MAKE_CLASS_ABSTRACT, | |
4176 ''' | |
4177 abstract class A { | 3817 abstract class A { |
4178 m(); | 3818 m(); |
4179 } | 3819 } |
4180 abstract class B extends A { | 3820 abstract class B extends A { |
4181 } | 3821 } |
4182 '''); | 3822 '''); |
4183 } | 3823 } |
4184 | 3824 |
4185 test_makeFieldNotFinal_hasType() async { | 3825 test_makeFieldNotFinal_hasType() async { |
4186 await resolveTestUnit(''' | 3826 await resolveTestUnit(''' |
4187 class A { | 3827 class A { |
4188 final int fff = 1; | 3828 final int fff = 1; |
4189 main() { | 3829 main() { |
4190 fff = 2; | 3830 fff = 2; |
4191 } | 3831 } |
4192 } | 3832 } |
4193 '''); | 3833 '''); |
4194 await assertHasFix( | 3834 await assertHasFix(DartFixKind.MAKE_FIELD_NOT_FINAL, ''' |
4195 DartFixKind.MAKE_FIELD_NOT_FINAL, | |
4196 ''' | |
4197 class A { | 3835 class A { |
4198 int fff = 1; | 3836 int fff = 1; |
4199 main() { | 3837 main() { |
4200 fff = 2; | 3838 fff = 2; |
4201 } | 3839 } |
4202 } | 3840 } |
4203 '''); | 3841 '''); |
4204 } | 3842 } |
4205 | 3843 |
4206 test_makeFieldNotFinal_noType() async { | 3844 test_makeFieldNotFinal_noType() async { |
4207 await resolveTestUnit(''' | 3845 await resolveTestUnit(''' |
4208 class A { | 3846 class A { |
4209 final fff = 1; | 3847 final fff = 1; |
4210 main() { | 3848 main() { |
4211 fff = 2; | 3849 fff = 2; |
4212 } | 3850 } |
4213 } | 3851 } |
4214 '''); | 3852 '''); |
4215 await assertHasFix( | 3853 await assertHasFix(DartFixKind.MAKE_FIELD_NOT_FINAL, ''' |
4216 DartFixKind.MAKE_FIELD_NOT_FINAL, | |
4217 ''' | |
4218 class A { | 3854 class A { |
4219 var fff = 1; | 3855 var fff = 1; |
4220 main() { | 3856 main() { |
4221 fff = 2; | 3857 fff = 2; |
4222 } | 3858 } |
4223 } | 3859 } |
4224 '''); | 3860 '''); |
4225 } | 3861 } |
4226 | 3862 |
4227 test_noException_1() async { | 3863 test_noException_1() async { |
4228 await resolveTestUnit(''' | 3864 await resolveTestUnit(''' |
4229 main(p) { | 3865 main(p) { |
4230 p i s Null; | 3866 p i s Null; |
4231 }'''); | 3867 }'''); |
4232 List<AnalysisError> errors = await _computeErrors(); | 3868 List<AnalysisError> errors = await _computeErrors(); |
4233 for (var error in errors) { | 3869 for (var error in errors) { |
4234 await _computeFixes(error); | 3870 await _computeFixes(error); |
4235 } | 3871 } |
4236 } | 3872 } |
4237 | 3873 |
4238 test_nonBoolCondition_addNotNull() async { | 3874 test_nonBoolCondition_addNotNull() async { |
4239 await resolveTestUnit(''' | 3875 await resolveTestUnit(''' |
4240 main(String p) { | 3876 main(String p) { |
4241 if (p) { | 3877 if (p) { |
4242 print(p); | 3878 print(p); |
4243 } | 3879 } |
4244 } | 3880 } |
4245 '''); | 3881 '''); |
4246 await assertHasFix( | 3882 await assertHasFix(DartFixKind.ADD_NE_NULL, ''' |
4247 DartFixKind.ADD_NE_NULL, | |
4248 ''' | |
4249 main(String p) { | 3883 main(String p) { |
4250 if (p != null) { | 3884 if (p != null) { |
4251 print(p); | 3885 print(p); |
4252 } | 3886 } |
4253 } | 3887 } |
4254 '''); | 3888 '''); |
4255 } | 3889 } |
4256 | 3890 |
4257 test_removeDeadCode_condition() async { | 3891 test_removeDeadCode_condition() async { |
4258 await resolveTestUnit(''' | 3892 await resolveTestUnit(''' |
4259 main(int p) { | 3893 main(int p) { |
4260 if (true || p > 5) { | 3894 if (true || p > 5) { |
4261 print(1); | 3895 print(1); |
4262 } | 3896 } |
4263 } | 3897 } |
4264 '''); | 3898 '''); |
4265 await assertHasFix( | 3899 await assertHasFix(DartFixKind.REMOVE_DEAD_CODE, ''' |
4266 DartFixKind.REMOVE_DEAD_CODE, | |
4267 ''' | |
4268 main(int p) { | 3900 main(int p) { |
4269 if (true) { | 3901 if (true) { |
4270 print(1); | 3902 print(1); |
4271 } | 3903 } |
4272 } | 3904 } |
4273 '''); | 3905 '''); |
4274 } | 3906 } |
4275 | 3907 |
4276 test_removeDeadCode_statements_one() async { | 3908 test_removeDeadCode_statements_one() async { |
4277 await resolveTestUnit(''' | 3909 await resolveTestUnit(''' |
4278 int main() { | 3910 int main() { |
4279 print(0); | 3911 print(0); |
4280 return 42; | 3912 return 42; |
4281 print(1); | 3913 print(1); |
4282 } | 3914 } |
4283 '''); | 3915 '''); |
4284 await assertHasFix( | 3916 await assertHasFix(DartFixKind.REMOVE_DEAD_CODE, ''' |
4285 DartFixKind.REMOVE_DEAD_CODE, | |
4286 ''' | |
4287 int main() { | 3917 int main() { |
4288 print(0); | 3918 print(0); |
4289 return 42; | 3919 return 42; |
4290 } | 3920 } |
4291 '''); | 3921 '''); |
4292 } | 3922 } |
4293 | 3923 |
4294 test_removeDeadCode_statements_two() async { | 3924 test_removeDeadCode_statements_two() async { |
4295 await resolveTestUnit(''' | 3925 await resolveTestUnit(''' |
4296 int main() { | 3926 int main() { |
4297 print(0); | 3927 print(0); |
4298 return 42; | 3928 return 42; |
4299 print(1); | 3929 print(1); |
4300 print(2); | 3930 print(2); |
4301 } | 3931 } |
4302 '''); | 3932 '''); |
4303 await assertHasFix( | 3933 await assertHasFix(DartFixKind.REMOVE_DEAD_CODE, ''' |
4304 DartFixKind.REMOVE_DEAD_CODE, | |
4305 ''' | |
4306 int main() { | 3934 int main() { |
4307 print(0); | 3935 print(0); |
4308 return 42; | 3936 return 42; |
4309 } | 3937 } |
4310 '''); | 3938 '''); |
4311 } | 3939 } |
4312 | 3940 |
4313 test_removeParentheses_inGetterDeclaration() async { | 3941 test_removeParentheses_inGetterDeclaration() async { |
4314 await resolveTestUnit(''' | 3942 await resolveTestUnit(''' |
4315 class A { | 3943 class A { |
4316 int get foo() => 0; | 3944 int get foo() => 0; |
4317 } | 3945 } |
4318 '''); | 3946 '''); |
4319 await assertHasFix( | 3947 await assertHasFix(DartFixKind.REMOVE_PARAMETERS_IN_GETTER_DECLARATION, ''' |
4320 DartFixKind.REMOVE_PARAMETERS_IN_GETTER_DECLARATION, | |
4321 ''' | |
4322 class A { | 3948 class A { |
4323 int get foo => 0; | 3949 int get foo => 0; |
4324 } | 3950 } |
4325 '''); | 3951 '''); |
4326 } | 3952 } |
4327 | 3953 |
4328 test_removeParentheses_inGetterInvocation() async { | 3954 test_removeParentheses_inGetterInvocation() async { |
4329 await resolveTestUnit(''' | 3955 await resolveTestUnit(''' |
4330 class A { | 3956 class A { |
4331 int get foo => 0; | 3957 int get foo => 0; |
4332 } | 3958 } |
4333 main(A a) { | 3959 main(A a) { |
4334 a.foo(); | 3960 a.foo(); |
4335 } | 3961 } |
4336 '''); | 3962 '''); |
4337 await assertHasFix( | 3963 await assertHasFix(DartFixKind.REMOVE_PARENTHESIS_IN_GETTER_INVOCATION, ''' |
4338 DartFixKind.REMOVE_PARENTHESIS_IN_GETTER_INVOCATION, | |
4339 ''' | |
4340 class A { | 3964 class A { |
4341 int get foo => 0; | 3965 int get foo => 0; |
4342 } | 3966 } |
4343 main(A a) { | 3967 main(A a) { |
4344 a.foo; | 3968 a.foo; |
4345 } | 3969 } |
4346 '''); | 3970 '''); |
4347 } | 3971 } |
4348 | 3972 |
4349 test_removeUnnecessaryCast_assignment() async { | 3973 test_removeUnnecessaryCast_assignment() async { |
4350 await resolveTestUnit(''' | 3974 await resolveTestUnit(''' |
4351 main(Object p) { | 3975 main(Object p) { |
4352 if (p is String) { | 3976 if (p is String) { |
4353 String v = ((p as String)); | 3977 String v = ((p as String)); |
4354 } | 3978 } |
4355 } | 3979 } |
4356 '''); | 3980 '''); |
4357 await assertHasFix( | 3981 await assertHasFix(DartFixKind.REMOVE_UNNECESSARY_CAST, ''' |
4358 DartFixKind.REMOVE_UNNECESSARY_CAST, | |
4359 ''' | |
4360 main(Object p) { | 3982 main(Object p) { |
4361 if (p is String) { | 3983 if (p is String) { |
4362 String v = p; | 3984 String v = p; |
4363 } | 3985 } |
4364 } | 3986 } |
4365 '''); | 3987 '''); |
4366 } | 3988 } |
4367 | 3989 |
4368 test_removeUnusedCatchClause() async { | 3990 test_removeUnusedCatchClause() async { |
4369 errorFilter = (AnalysisError error) => true; | 3991 errorFilter = (AnalysisError error) => true; |
4370 await resolveTestUnit(''' | 3992 await resolveTestUnit(''' |
4371 main() { | 3993 main() { |
4372 try { | 3994 try { |
4373 throw 42; | 3995 throw 42; |
4374 } on int catch (e) { | 3996 } on int catch (e) { |
4375 } | 3997 } |
4376 } | 3998 } |
4377 '''); | 3999 '''); |
4378 await assertHasFix( | 4000 await assertHasFix(DartFixKind.REMOVE_UNUSED_CATCH_CLAUSE, ''' |
4379 DartFixKind.REMOVE_UNUSED_CATCH_CLAUSE, | |
4380 ''' | |
4381 main() { | 4001 main() { |
4382 try { | 4002 try { |
4383 throw 42; | 4003 throw 42; |
4384 } on int { | 4004 } on int { |
4385 } | 4005 } |
4386 } | 4006 } |
4387 '''); | 4007 '''); |
4388 } | 4008 } |
4389 | 4009 |
4390 test_removeUnusedCatchStack() async { | 4010 test_removeUnusedCatchStack() async { |
4391 errorFilter = (AnalysisError error) => true; | 4011 errorFilter = (AnalysisError error) => true; |
4392 await resolveTestUnit(''' | 4012 await resolveTestUnit(''' |
4393 main() { | 4013 main() { |
4394 try { | 4014 try { |
4395 throw 42; | 4015 throw 42; |
4396 } catch (e, stack) { | 4016 } catch (e, stack) { |
4397 } | 4017 } |
4398 } | 4018 } |
4399 '''); | 4019 '''); |
4400 await assertHasFix( | 4020 await assertHasFix(DartFixKind.REMOVE_UNUSED_CATCH_STACK, ''' |
4401 DartFixKind.REMOVE_UNUSED_CATCH_STACK, | |
4402 ''' | |
4403 main() { | 4021 main() { |
4404 try { | 4022 try { |
4405 throw 42; | 4023 throw 42; |
4406 } catch (e) { | 4024 } catch (e) { |
4407 } | 4025 } |
4408 } | 4026 } |
4409 '''); | 4027 '''); |
4410 } | 4028 } |
4411 | 4029 |
4412 test_removeUnusedImport() async { | 4030 test_removeUnusedImport() async { |
4413 await resolveTestUnit(''' | 4031 await resolveTestUnit(''' |
4414 import 'dart:math'; | 4032 import 'dart:math'; |
4415 main() { | 4033 main() { |
4416 } | 4034 } |
4417 '''); | 4035 '''); |
4418 await assertHasFix( | 4036 await assertHasFix(DartFixKind.REMOVE_UNUSED_IMPORT, ''' |
4419 DartFixKind.REMOVE_UNUSED_IMPORT, | |
4420 ''' | |
4421 main() { | 4037 main() { |
4422 } | 4038 } |
4423 '''); | 4039 '''); |
4424 } | 4040 } |
4425 | 4041 |
4426 test_removeUnusedImport_anotherImportOnLine() async { | 4042 test_removeUnusedImport_anotherImportOnLine() async { |
4427 await resolveTestUnit(''' | 4043 await resolveTestUnit(''' |
4428 import 'dart:math'; import 'dart:async'; | 4044 import 'dart:math'; import 'dart:async'; |
4429 | 4045 |
4430 main() { | 4046 main() { |
4431 Future f; | 4047 Future f; |
4432 } | 4048 } |
4433 '''); | 4049 '''); |
4434 await assertHasFix( | 4050 await assertHasFix(DartFixKind.REMOVE_UNUSED_IMPORT, ''' |
4435 DartFixKind.REMOVE_UNUSED_IMPORT, | |
4436 ''' | |
4437 import 'dart:async'; | 4051 import 'dart:async'; |
4438 | 4052 |
4439 main() { | 4053 main() { |
4440 Future f; | 4054 Future f; |
4441 } | 4055 } |
4442 '''); | 4056 '''); |
4443 } | 4057 } |
4444 | 4058 |
4445 test_removeUnusedImport_severalLines() async { | 4059 test_removeUnusedImport_severalLines() async { |
4446 await resolveTestUnit(''' | 4060 await resolveTestUnit(''' |
4447 import | 4061 import |
4448 'dart:math'; | 4062 'dart:math'; |
4449 main() { | 4063 main() { |
4450 } | 4064 } |
4451 '''); | 4065 '''); |
4452 await assertHasFix( | 4066 await assertHasFix(DartFixKind.REMOVE_UNUSED_IMPORT, ''' |
4453 DartFixKind.REMOVE_UNUSED_IMPORT, | |
4454 ''' | |
4455 main() { | 4067 main() { |
4456 } | 4068 } |
4457 '''); | 4069 '''); |
4458 } | 4070 } |
4459 | 4071 |
4460 test_replaceVarWithDynamic() async { | 4072 test_replaceVarWithDynamic() async { |
4461 errorFilter = (AnalysisError error) { | 4073 errorFilter = (AnalysisError error) { |
4462 return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME; | 4074 return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME; |
4463 }; | 4075 }; |
4464 await resolveTestUnit(''' | 4076 await resolveTestUnit(''' |
4465 class A { | 4077 class A { |
4466 Map<String, var> m; | 4078 Map<String, var> m; |
4467 } | 4079 } |
4468 '''); | 4080 '''); |
4469 await assertHasFix( | 4081 await assertHasFix(DartFixKind.REPLACE_VAR_WITH_DYNAMIC, ''' |
4470 DartFixKind.REPLACE_VAR_WITH_DYNAMIC, | |
4471 ''' | |
4472 class A { | 4082 class A { |
4473 Map<String, dynamic> m; | 4083 Map<String, dynamic> m; |
4474 } | 4084 } |
4475 '''); | 4085 '''); |
4476 } | 4086 } |
4477 | 4087 |
4478 test_replaceWithConstInstanceCreation() async { | 4088 test_replaceWithConstInstanceCreation() async { |
4479 await resolveTestUnit(''' | 4089 await resolveTestUnit(''' |
4480 class A { | 4090 class A { |
4481 const A(); | 4091 const A(); |
4482 } | 4092 } |
4483 const a = new A(); | 4093 const a = new A(); |
4484 '''); | 4094 '''); |
4485 await assertHasFix( | 4095 await assertHasFix(DartFixKind.USE_CONST, ''' |
4486 DartFixKind.USE_CONST, | |
4487 ''' | |
4488 class A { | 4096 class A { |
4489 const A(); | 4097 const A(); |
4490 } | 4098 } |
4491 const a = const A(); | 4099 const a = const A(); |
4492 '''); | 4100 '''); |
4493 } | 4101 } |
4494 | 4102 |
4495 test_undefinedClass_useSimilar_BAD_prefixed() async { | 4103 test_undefinedClass_useSimilar_BAD_prefixed() async { |
4496 await resolveTestUnit(''' | 4104 await resolveTestUnit(''' |
4497 import 'dart:async' as c; | 4105 import 'dart:async' as c; |
4498 main() { | 4106 main() { |
4499 c.Fture v = null; | 4107 c.Fture v = null; |
4500 } | 4108 } |
4501 '''); | 4109 '''); |
4502 await assertHasFix( | 4110 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
4503 DartFixKind.CHANGE_TO, | |
4504 ''' | |
4505 import 'dart:async' as c; | 4111 import 'dart:async' as c; |
4506 main() { | 4112 main() { |
4507 c.Future v = null; | 4113 c.Future v = null; |
4508 } | 4114 } |
4509 '''); | 4115 '''); |
4510 } | 4116 } |
4511 | 4117 |
4512 test_undefinedClass_useSimilar_fromImport() async { | 4118 test_undefinedClass_useSimilar_fromImport() async { |
4513 await resolveTestUnit(''' | 4119 await resolveTestUnit(''' |
4514 main() { | 4120 main() { |
4515 Stirng s = 'abc'; | 4121 Stirng s = 'abc'; |
4516 } | 4122 } |
4517 '''); | 4123 '''); |
4518 await assertHasFix( | 4124 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
4519 DartFixKind.CHANGE_TO, | |
4520 ''' | |
4521 main() { | 4125 main() { |
4522 String s = 'abc'; | 4126 String s = 'abc'; |
4523 } | 4127 } |
4524 '''); | 4128 '''); |
4525 } | 4129 } |
4526 | 4130 |
4527 test_undefinedClass_useSimilar_fromThisLibrary() async { | 4131 test_undefinedClass_useSimilar_fromThisLibrary() async { |
4528 await resolveTestUnit(''' | 4132 await resolveTestUnit(''' |
4529 class MyClass {} | 4133 class MyClass {} |
4530 main() { | 4134 main() { |
4531 MyCalss v = null; | 4135 MyCalss v = null; |
4532 } | 4136 } |
4533 '''); | 4137 '''); |
4534 await assertHasFix( | 4138 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
4535 DartFixKind.CHANGE_TO, | |
4536 ''' | |
4537 class MyClass {} | 4139 class MyClass {} |
4538 main() { | 4140 main() { |
4539 MyClass v = null; | 4141 MyClass v = null; |
4540 } | 4142 } |
4541 '''); | 4143 '''); |
4542 } | 4144 } |
4543 | 4145 |
4544 test_undefinedFunction_create_bottomArgument() async { | 4146 test_undefinedFunction_create_bottomArgument() async { |
4545 await resolveTestUnit(''' | 4147 await resolveTestUnit(''' |
4546 main() { | 4148 main() { |
4547 test(throw 42); | 4149 test(throw 42); |
4548 } | 4150 } |
4549 '''); | 4151 '''); |
4550 await assertHasFix( | 4152 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4551 DartFixKind.CREATE_FUNCTION, | |
4552 ''' | |
4553 main() { | 4153 main() { |
4554 test(throw 42); | 4154 test(throw 42); |
4555 } | 4155 } |
4556 | 4156 |
4557 void test(param0) { | 4157 void test(param0) { |
4558 } | 4158 } |
4559 '''); | 4159 '''); |
4560 } | 4160 } |
4561 | 4161 |
4562 test_undefinedFunction_create_duplicateArgumentNames() async { | 4162 test_undefinedFunction_create_duplicateArgumentNames() async { |
4563 await resolveTestUnit(''' | 4163 await resolveTestUnit(''' |
4564 class C { | 4164 class C { |
4565 int x; | 4165 int x; |
4566 } | 4166 } |
4567 | 4167 |
4568 foo(C c1, C c2) { | 4168 foo(C c1, C c2) { |
4569 bar(c1.x, c2.x); | 4169 bar(c1.x, c2.x); |
4570 } | 4170 } |
4571 '''); | 4171 '''); |
4572 await assertHasFix( | 4172 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4573 DartFixKind.CREATE_FUNCTION, | |
4574 ''' | |
4575 class C { | 4173 class C { |
4576 int x; | 4174 int x; |
4577 } | 4175 } |
4578 | 4176 |
4579 foo(C c1, C c2) { | 4177 foo(C c1, C c2) { |
4580 bar(c1.x, c2.x); | 4178 bar(c1.x, c2.x); |
4581 } | 4179 } |
4582 | 4180 |
4583 void bar(int x, int x2) { | 4181 void bar(int x, int x2) { |
4584 } | 4182 } |
4585 '''); | 4183 '''); |
4586 } | 4184 } |
4587 | 4185 |
4588 test_undefinedFunction_create_dynamicArgument() async { | 4186 test_undefinedFunction_create_dynamicArgument() async { |
4589 await resolveTestUnit(''' | 4187 await resolveTestUnit(''' |
4590 main() { | 4188 main() { |
4591 dynamic v; | 4189 dynamic v; |
4592 test(v); | 4190 test(v); |
4593 } | 4191 } |
4594 '''); | 4192 '''); |
4595 await assertHasFix( | 4193 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4596 DartFixKind.CREATE_FUNCTION, | |
4597 ''' | |
4598 main() { | 4194 main() { |
4599 dynamic v; | 4195 dynamic v; |
4600 test(v); | 4196 test(v); |
4601 } | 4197 } |
4602 | 4198 |
4603 void test(v) { | 4199 void test(v) { |
4604 } | 4200 } |
4605 '''); | 4201 '''); |
4606 } | 4202 } |
4607 | 4203 |
4608 test_undefinedFunction_create_dynamicReturnType() async { | 4204 test_undefinedFunction_create_dynamicReturnType() async { |
4609 await resolveTestUnit(''' | 4205 await resolveTestUnit(''' |
4610 main() { | 4206 main() { |
4611 dynamic v = test(); | 4207 dynamic v = test(); |
4612 } | 4208 } |
4613 '''); | 4209 '''); |
4614 await assertHasFix( | 4210 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4615 DartFixKind.CREATE_FUNCTION, | |
4616 ''' | |
4617 main() { | 4211 main() { |
4618 dynamic v = test(); | 4212 dynamic v = test(); |
4619 } | 4213 } |
4620 | 4214 |
4621 test() { | 4215 test() { |
4622 } | 4216 } |
4623 '''); | 4217 '''); |
4624 } | 4218 } |
4625 | 4219 |
4626 test_undefinedFunction_create_fromFunction() async { | 4220 test_undefinedFunction_create_fromFunction() async { |
4627 await resolveTestUnit(''' | 4221 await resolveTestUnit(''' |
4628 main() { | 4222 main() { |
4629 int v = myUndefinedFunction(1, 2.0, '3'); | 4223 int v = myUndefinedFunction(1, 2.0, '3'); |
4630 } | 4224 } |
4631 '''); | 4225 '''); |
4632 await assertHasFix( | 4226 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4633 DartFixKind.CREATE_FUNCTION, | |
4634 ''' | |
4635 main() { | 4227 main() { |
4636 int v = myUndefinedFunction(1, 2.0, '3'); | 4228 int v = myUndefinedFunction(1, 2.0, '3'); |
4637 } | 4229 } |
4638 | 4230 |
4639 int myUndefinedFunction(int i, double d, String s) { | 4231 int myUndefinedFunction(int i, double d, String s) { |
4640 } | 4232 } |
4641 '''); | 4233 '''); |
4642 } | 4234 } |
4643 | 4235 |
4644 test_undefinedFunction_create_fromMethod() async { | 4236 test_undefinedFunction_create_fromMethod() async { |
4645 await resolveTestUnit(''' | 4237 await resolveTestUnit(''' |
4646 class A { | 4238 class A { |
4647 main() { | 4239 main() { |
4648 int v = myUndefinedFunction(1, 2.0, '3'); | 4240 int v = myUndefinedFunction(1, 2.0, '3'); |
4649 } | 4241 } |
4650 } | 4242 } |
4651 '''); | 4243 '''); |
4652 await assertHasFix( | 4244 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4653 DartFixKind.CREATE_FUNCTION, | |
4654 ''' | |
4655 class A { | 4245 class A { |
4656 main() { | 4246 main() { |
4657 int v = myUndefinedFunction(1, 2.0, '3'); | 4247 int v = myUndefinedFunction(1, 2.0, '3'); |
4658 } | 4248 } |
4659 } | 4249 } |
4660 | 4250 |
4661 int myUndefinedFunction(int i, double d, String s) { | 4251 int myUndefinedFunction(int i, double d, String s) { |
4662 } | 4252 } |
4663 '''); | 4253 '''); |
4664 } | 4254 } |
4665 | 4255 |
4666 test_undefinedFunction_create_generic_BAD() async { | 4256 test_undefinedFunction_create_generic_BAD() async { |
4667 await resolveTestUnit(''' | 4257 await resolveTestUnit(''' |
4668 class A<T> { | 4258 class A<T> { |
4669 Map<int, T> items; | 4259 Map<int, T> items; |
4670 main() { | 4260 main() { |
4671 process(items); | 4261 process(items); |
4672 } | 4262 } |
4673 } | 4263 } |
4674 '''); | 4264 '''); |
4675 await assertHasFix( | 4265 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4676 DartFixKind.CREATE_FUNCTION, | |
4677 ''' | |
4678 class A<T> { | 4266 class A<T> { |
4679 Map<int, T> items; | 4267 Map<int, T> items; |
4680 main() { | 4268 main() { |
4681 process(items); | 4269 process(items); |
4682 } | 4270 } |
4683 } | 4271 } |
4684 | 4272 |
4685 void process(Map items) { | 4273 void process(Map items) { |
4686 } | 4274 } |
4687 '''); | 4275 '''); |
4688 } | 4276 } |
4689 | 4277 |
4690 test_undefinedFunction_create_generic_OK() async { | 4278 test_undefinedFunction_create_generic_OK() async { |
4691 await resolveTestUnit(''' | 4279 await resolveTestUnit(''' |
4692 class A { | 4280 class A { |
4693 List<int> items; | 4281 List<int> items; |
4694 main() { | 4282 main() { |
4695 process(items); | 4283 process(items); |
4696 } | 4284 } |
4697 } | 4285 } |
4698 '''); | 4286 '''); |
4699 await assertHasFix( | 4287 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4700 DartFixKind.CREATE_FUNCTION, | |
4701 ''' | |
4702 class A { | 4288 class A { |
4703 List<int> items; | 4289 List<int> items; |
4704 main() { | 4290 main() { |
4705 process(items); | 4291 process(items); |
4706 } | 4292 } |
4707 } | 4293 } |
4708 | 4294 |
4709 void process(List<int> items) { | 4295 void process(List<int> items) { |
4710 } | 4296 } |
4711 '''); | 4297 '''); |
4712 _assertLinkedGroup( | 4298 _assertLinkedGroup( |
4713 change.linkedEditGroups[2], | 4299 change.linkedEditGroups[2], |
4714 ['List<int> items) {'], | 4300 ['List<int> items) {'], |
4715 expectedSuggestions(LinkedEditSuggestionKind.TYPE, | 4301 expectedSuggestions(LinkedEditSuggestionKind.TYPE, |
4716 ['List<int>', 'Iterable<int>', 'Object'])); | 4302 ['List<int>', 'Iterable<int>', 'Object'])); |
4717 } | 4303 } |
4718 | 4304 |
4719 test_undefinedFunction_create_importType() async { | 4305 test_undefinedFunction_create_importType() async { |
4720 addSource( | 4306 addSource('/lib.dart', r''' |
4721 '/lib.dart', | |
4722 r''' | |
4723 library lib; | 4307 library lib; |
4724 import 'dart:async'; | 4308 import 'dart:async'; |
4725 Future getFuture() => null; | 4309 Future getFuture() => null; |
4726 '''); | 4310 '''); |
4727 await resolveTestUnit(''' | 4311 await resolveTestUnit(''' |
4728 import 'lib.dart'; | 4312 import 'lib.dart'; |
4729 main() { | 4313 main() { |
4730 test(getFuture()); | 4314 test(getFuture()); |
4731 } | 4315 } |
4732 '''); | 4316 '''); |
4733 await assertHasFix( | 4317 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4734 DartFixKind.CREATE_FUNCTION, | |
4735 ''' | |
4736 import 'dart:async'; | 4318 import 'dart:async'; |
4737 | 4319 |
4738 import 'lib.dart'; | 4320 import 'lib.dart'; |
4739 main() { | 4321 main() { |
4740 test(getFuture()); | 4322 test(getFuture()); |
4741 } | 4323 } |
4742 | 4324 |
4743 void test(Future future) { | 4325 void test(Future future) { |
4744 } | 4326 } |
4745 '''); | 4327 '''); |
4746 } | 4328 } |
4747 | 4329 |
4748 test_undefinedFunction_create_nullArgument() async { | 4330 test_undefinedFunction_create_nullArgument() async { |
4749 await resolveTestUnit(''' | 4331 await resolveTestUnit(''' |
4750 main() { | 4332 main() { |
4751 test(null); | 4333 test(null); |
4752 } | 4334 } |
4753 '''); | 4335 '''); |
4754 await assertHasFix( | 4336 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4755 DartFixKind.CREATE_FUNCTION, | |
4756 ''' | |
4757 main() { | 4337 main() { |
4758 test(null); | 4338 test(null); |
4759 } | 4339 } |
4760 | 4340 |
4761 void test(param0) { | 4341 void test(param0) { |
4762 } | 4342 } |
4763 '''); | 4343 '''); |
4764 } | 4344 } |
4765 | 4345 |
4766 test_undefinedFunction_create_returnType_bool_expressions() async { | 4346 test_undefinedFunction_create_returnType_bool_expressions() async { |
(...skipping 13 matching lines...) Expand all Loading... |
4780 "do {} while ( test() );"); | 4360 "do {} while ( test() );"); |
4781 } | 4361 } |
4782 | 4362 |
4783 test_undefinedFunction_create_returnType_fromAssignment_eq() async { | 4363 test_undefinedFunction_create_returnType_fromAssignment_eq() async { |
4784 await resolveTestUnit(''' | 4364 await resolveTestUnit(''' |
4785 main() { | 4365 main() { |
4786 int v; | 4366 int v; |
4787 v = myUndefinedFunction(); | 4367 v = myUndefinedFunction(); |
4788 } | 4368 } |
4789 '''); | 4369 '''); |
4790 await assertHasFix( | 4370 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4791 DartFixKind.CREATE_FUNCTION, | |
4792 ''' | |
4793 main() { | 4371 main() { |
4794 int v; | 4372 int v; |
4795 v = myUndefinedFunction(); | 4373 v = myUndefinedFunction(); |
4796 } | 4374 } |
4797 | 4375 |
4798 int myUndefinedFunction() { | 4376 int myUndefinedFunction() { |
4799 } | 4377 } |
4800 '''); | 4378 '''); |
4801 } | 4379 } |
4802 | 4380 |
4803 test_undefinedFunction_create_returnType_fromAssignment_plusEq() async { | 4381 test_undefinedFunction_create_returnType_fromAssignment_plusEq() async { |
4804 await resolveTestUnit(''' | 4382 await resolveTestUnit(''' |
4805 main() { | 4383 main() { |
4806 int v; | 4384 int v; |
4807 v += myUndefinedFunction(); | 4385 v += myUndefinedFunction(); |
4808 } | 4386 } |
4809 '''); | 4387 '''); |
4810 await assertHasFix( | 4388 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4811 DartFixKind.CREATE_FUNCTION, | |
4812 ''' | |
4813 main() { | 4389 main() { |
4814 int v; | 4390 int v; |
4815 v += myUndefinedFunction(); | 4391 v += myUndefinedFunction(); |
4816 } | 4392 } |
4817 | 4393 |
4818 num myUndefinedFunction() { | 4394 num myUndefinedFunction() { |
4819 } | 4395 } |
4820 '''); | 4396 '''); |
4821 } | 4397 } |
4822 | 4398 |
4823 test_undefinedFunction_create_returnType_fromBinary_right() async { | 4399 test_undefinedFunction_create_returnType_fromBinary_right() async { |
4824 await resolveTestUnit(''' | 4400 await resolveTestUnit(''' |
4825 main() { | 4401 main() { |
4826 0 + myUndefinedFunction(); | 4402 0 + myUndefinedFunction(); |
4827 } | 4403 } |
4828 '''); | 4404 '''); |
4829 await assertHasFix( | 4405 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4830 DartFixKind.CREATE_FUNCTION, | |
4831 ''' | |
4832 main() { | 4406 main() { |
4833 0 + myUndefinedFunction(); | 4407 0 + myUndefinedFunction(); |
4834 } | 4408 } |
4835 | 4409 |
4836 num myUndefinedFunction() { | 4410 num myUndefinedFunction() { |
4837 } | 4411 } |
4838 '''); | 4412 '''); |
4839 } | 4413 } |
4840 | 4414 |
4841 test_undefinedFunction_create_returnType_fromInitializer() async { | 4415 test_undefinedFunction_create_returnType_fromInitializer() async { |
4842 await resolveTestUnit(''' | 4416 await resolveTestUnit(''' |
4843 main() { | 4417 main() { |
4844 int v = myUndefinedFunction(); | 4418 int v = myUndefinedFunction(); |
4845 } | 4419 } |
4846 '''); | 4420 '''); |
4847 await assertHasFix( | 4421 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4848 DartFixKind.CREATE_FUNCTION, | |
4849 ''' | |
4850 main() { | 4422 main() { |
4851 int v = myUndefinedFunction(); | 4423 int v = myUndefinedFunction(); |
4852 } | 4424 } |
4853 | 4425 |
4854 int myUndefinedFunction() { | 4426 int myUndefinedFunction() { |
4855 } | 4427 } |
4856 '''); | 4428 '''); |
4857 } | 4429 } |
4858 | 4430 |
4859 test_undefinedFunction_create_returnType_fromInvocationArgument() async { | 4431 test_undefinedFunction_create_returnType_fromInvocationArgument() async { |
4860 await resolveTestUnit(''' | 4432 await resolveTestUnit(''' |
4861 foo(int p) {} | 4433 foo(int p) {} |
4862 main() { | 4434 main() { |
4863 foo( myUndefinedFunction() ); | 4435 foo( myUndefinedFunction() ); |
4864 } | 4436 } |
4865 '''); | 4437 '''); |
4866 await assertHasFix( | 4438 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4867 DartFixKind.CREATE_FUNCTION, | |
4868 ''' | |
4869 foo(int p) {} | 4439 foo(int p) {} |
4870 main() { | 4440 main() { |
4871 foo( myUndefinedFunction() ); | 4441 foo( myUndefinedFunction() ); |
4872 } | 4442 } |
4873 | 4443 |
4874 int myUndefinedFunction() { | 4444 int myUndefinedFunction() { |
4875 } | 4445 } |
4876 '''); | 4446 '''); |
4877 } | 4447 } |
4878 | 4448 |
4879 test_undefinedFunction_create_returnType_fromReturn() async { | 4449 test_undefinedFunction_create_returnType_fromReturn() async { |
4880 await resolveTestUnit(''' | 4450 await resolveTestUnit(''' |
4881 int main() { | 4451 int main() { |
4882 return myUndefinedFunction(); | 4452 return myUndefinedFunction(); |
4883 } | 4453 } |
4884 '''); | 4454 '''); |
4885 await assertHasFix( | 4455 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4886 DartFixKind.CREATE_FUNCTION, | |
4887 ''' | |
4888 int main() { | 4456 int main() { |
4889 return myUndefinedFunction(); | 4457 return myUndefinedFunction(); |
4890 } | 4458 } |
4891 | 4459 |
4892 int myUndefinedFunction() { | 4460 int myUndefinedFunction() { |
4893 } | 4461 } |
4894 '''); | 4462 '''); |
4895 } | 4463 } |
4896 | 4464 |
4897 test_undefinedFunction_create_returnType_void() async { | 4465 test_undefinedFunction_create_returnType_void() async { |
4898 await resolveTestUnit(''' | 4466 await resolveTestUnit(''' |
4899 main() { | 4467 main() { |
4900 myUndefinedFunction(); | 4468 myUndefinedFunction(); |
4901 } | 4469 } |
4902 '''); | 4470 '''); |
4903 await assertHasFix( | 4471 await assertHasFix(DartFixKind.CREATE_FUNCTION, ''' |
4904 DartFixKind.CREATE_FUNCTION, | |
4905 ''' | |
4906 main() { | 4472 main() { |
4907 myUndefinedFunction(); | 4473 myUndefinedFunction(); |
4908 } | 4474 } |
4909 | 4475 |
4910 void myUndefinedFunction() { | 4476 void myUndefinedFunction() { |
4911 } | 4477 } |
4912 '''); | 4478 '''); |
4913 } | 4479 } |
4914 | 4480 |
4915 test_undefinedFunction_useSimilar_fromImport() async { | 4481 test_undefinedFunction_useSimilar_fromImport() async { |
4916 await resolveTestUnit(''' | 4482 await resolveTestUnit(''' |
4917 main() { | 4483 main() { |
4918 pritn(0); | 4484 pritn(0); |
4919 } | 4485 } |
4920 '''); | 4486 '''); |
4921 await assertHasFix( | 4487 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
4922 DartFixKind.CHANGE_TO, | |
4923 ''' | |
4924 main() { | 4488 main() { |
4925 print(0); | 4489 print(0); |
4926 } | 4490 } |
4927 '''); | 4491 '''); |
4928 } | 4492 } |
4929 | 4493 |
4930 test_undefinedFunction_useSimilar_prefixed_fromImport() async { | 4494 test_undefinedFunction_useSimilar_prefixed_fromImport() async { |
4931 await resolveTestUnit(''' | 4495 await resolveTestUnit(''' |
4932 import 'dart:core' as c; | 4496 import 'dart:core' as c; |
4933 main() { | 4497 main() { |
4934 c.prnt(42); | 4498 c.prnt(42); |
4935 } | 4499 } |
4936 '''); | 4500 '''); |
4937 await assertHasFix( | 4501 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
4938 DartFixKind.CHANGE_TO, | |
4939 ''' | |
4940 import 'dart:core' as c; | 4502 import 'dart:core' as c; |
4941 main() { | 4503 main() { |
4942 c.print(42); | 4504 c.print(42); |
4943 } | 4505 } |
4944 '''); | 4506 '''); |
4945 } | 4507 } |
4946 | 4508 |
4947 test_undefinedFunction_useSimilar_prefixed_ignoreLocal() async { | 4509 test_undefinedFunction_useSimilar_prefixed_ignoreLocal() async { |
4948 await resolveTestUnit(''' | 4510 await resolveTestUnit(''' |
4949 import 'dart:async' as c; | 4511 import 'dart:async' as c; |
4950 main() { | 4512 main() { |
4951 c.main(); | 4513 c.main(); |
4952 } | 4514 } |
4953 '''); | 4515 '''); |
4954 await assertNoFix(DartFixKind.CHANGE_TO); | 4516 await assertNoFix(DartFixKind.CHANGE_TO); |
4955 } | 4517 } |
4956 | 4518 |
4957 test_undefinedFunction_useSimilar_thisLibrary() async { | 4519 test_undefinedFunction_useSimilar_thisLibrary() async { |
4958 await resolveTestUnit(''' | 4520 await resolveTestUnit(''' |
4959 myFunction() {} | 4521 myFunction() {} |
4960 main() { | 4522 main() { |
4961 myFuntcion(); | 4523 myFuntcion(); |
4962 } | 4524 } |
4963 '''); | 4525 '''); |
4964 await assertHasFix( | 4526 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
4965 DartFixKind.CHANGE_TO, | |
4966 ''' | |
4967 myFunction() {} | 4527 myFunction() {} |
4968 main() { | 4528 main() { |
4969 myFunction(); | 4529 myFunction(); |
4970 } | 4530 } |
4971 '''); | 4531 '''); |
4972 } | 4532 } |
4973 | 4533 |
4974 test_undefinedGetter_useSimilar_hint() async { | 4534 test_undefinedGetter_useSimilar_hint() async { |
4975 await resolveTestUnit(''' | 4535 await resolveTestUnit(''' |
4976 class A { | 4536 class A { |
4977 int myField; | 4537 int myField; |
4978 } | 4538 } |
4979 main(A a) { | 4539 main(A a) { |
4980 var x = a; | 4540 var x = a; |
4981 print(x.myFild); | 4541 print(x.myFild); |
4982 } | 4542 } |
4983 '''); | 4543 '''); |
4984 await assertHasFix( | 4544 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
4985 DartFixKind.CHANGE_TO, | |
4986 ''' | |
4987 class A { | 4545 class A { |
4988 int myField; | 4546 int myField; |
4989 } | 4547 } |
4990 main(A a) { | 4548 main(A a) { |
4991 var x = a; | 4549 var x = a; |
4992 print(x.myField); | 4550 print(x.myField); |
4993 } | 4551 } |
4994 '''); | 4552 '''); |
4995 } | 4553 } |
4996 | 4554 |
4997 test_undefinedGetter_useSimilar_qualified() async { | 4555 test_undefinedGetter_useSimilar_qualified() async { |
4998 await resolveTestUnit(''' | 4556 await resolveTestUnit(''' |
4999 class A { | 4557 class A { |
5000 int myField; | 4558 int myField; |
5001 } | 4559 } |
5002 main(A a) { | 4560 main(A a) { |
5003 print(a.myFild); | 4561 print(a.myFild); |
5004 } | 4562 } |
5005 '''); | 4563 '''); |
5006 await assertHasFix( | 4564 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
5007 DartFixKind.CHANGE_TO, | |
5008 ''' | |
5009 class A { | 4565 class A { |
5010 int myField; | 4566 int myField; |
5011 } | 4567 } |
5012 main(A a) { | 4568 main(A a) { |
5013 print(a.myField); | 4569 print(a.myField); |
5014 } | 4570 } |
5015 '''); | 4571 '''); |
5016 } | 4572 } |
5017 | 4573 |
5018 test_undefinedGetter_useSimilar_qualified_static() async { | 4574 test_undefinedGetter_useSimilar_qualified_static() async { |
5019 await resolveTestUnit(''' | 4575 await resolveTestUnit(''' |
5020 class A { | 4576 class A { |
5021 static int MY_NAME = 1; | 4577 static int MY_NAME = 1; |
5022 } | 4578 } |
5023 main() { | 4579 main() { |
5024 A.MY_NAM; | 4580 A.MY_NAM; |
5025 } | 4581 } |
5026 '''); | 4582 '''); |
5027 await assertHasFix( | 4583 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
5028 DartFixKind.CHANGE_TO, | |
5029 ''' | |
5030 class A { | 4584 class A { |
5031 static int MY_NAME = 1; | 4585 static int MY_NAME = 1; |
5032 } | 4586 } |
5033 main() { | 4587 main() { |
5034 A.MY_NAME; | 4588 A.MY_NAME; |
5035 } | 4589 } |
5036 '''); | 4590 '''); |
5037 } | 4591 } |
5038 | 4592 |
5039 test_undefinedGetter_useSimilar_unqualified() async { | 4593 test_undefinedGetter_useSimilar_unqualified() async { |
5040 await resolveTestUnit(''' | 4594 await resolveTestUnit(''' |
5041 class A { | 4595 class A { |
5042 int myField; | 4596 int myField; |
5043 main() { | 4597 main() { |
5044 print(myFild); | 4598 print(myFild); |
5045 } | 4599 } |
5046 } | 4600 } |
5047 '''); | 4601 '''); |
5048 await assertHasFix( | 4602 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
5049 DartFixKind.CHANGE_TO, | |
5050 ''' | |
5051 class A { | 4603 class A { |
5052 int myField; | 4604 int myField; |
5053 main() { | 4605 main() { |
5054 print(myField); | 4606 print(myField); |
5055 } | 4607 } |
5056 } | 4608 } |
5057 '''); | 4609 '''); |
5058 } | 4610 } |
5059 | 4611 |
5060 test_undefinedMethod_create_BAD_inSDK() async { | 4612 test_undefinedMethod_create_BAD_inSDK() async { |
(...skipping 21 matching lines...) Expand all Loading... |
5082 B b; | 4634 B b; |
5083 Map<int, T> items; | 4635 Map<int, T> items; |
5084 main() { | 4636 main() { |
5085 b.process(items); | 4637 b.process(items); |
5086 } | 4638 } |
5087 } | 4639 } |
5088 | 4640 |
5089 class B { | 4641 class B { |
5090 } | 4642 } |
5091 '''); | 4643 '''); |
5092 await assertHasFix( | 4644 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5093 DartFixKind.CREATE_METHOD, | |
5094 ''' | |
5095 class A<T> { | 4645 class A<T> { |
5096 B b; | 4646 B b; |
5097 Map<int, T> items; | 4647 Map<int, T> items; |
5098 main() { | 4648 main() { |
5099 b.process(items); | 4649 b.process(items); |
5100 } | 4650 } |
5101 } | 4651 } |
5102 | 4652 |
5103 class B { | 4653 class B { |
5104 void process(Map items) {} | 4654 void process(Map items) {} |
5105 } | 4655 } |
5106 '''); | 4656 '''); |
5107 } | 4657 } |
5108 | 4658 |
5109 test_undefinedMethod_create_generic_BAD_returnType() async { | 4659 test_undefinedMethod_create_generic_BAD_returnType() async { |
5110 await resolveTestUnit(''' | 4660 await resolveTestUnit(''' |
5111 class A<T> { | 4661 class A<T> { |
5112 main() { | 4662 main() { |
5113 T t = new B().compute(); | 4663 T t = new B().compute(); |
5114 } | 4664 } |
5115 } | 4665 } |
5116 | 4666 |
5117 class B { | 4667 class B { |
5118 } | 4668 } |
5119 '''); | 4669 '''); |
5120 await assertHasFix( | 4670 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5121 DartFixKind.CREATE_METHOD, | |
5122 ''' | |
5123 class A<T> { | 4671 class A<T> { |
5124 main() { | 4672 main() { |
5125 T t = new B().compute(); | 4673 T t = new B().compute(); |
5126 } | 4674 } |
5127 } | 4675 } |
5128 | 4676 |
5129 class B { | 4677 class B { |
5130 compute() {} | 4678 compute() {} |
5131 } | 4679 } |
5132 '''); | 4680 '''); |
5133 } | 4681 } |
5134 | 4682 |
5135 test_undefinedMethod_create_generic_OK_literal() async { | 4683 test_undefinedMethod_create_generic_OK_literal() async { |
5136 await resolveTestUnit(''' | 4684 await resolveTestUnit(''' |
5137 class A { | 4685 class A { |
5138 B b; | 4686 B b; |
5139 List<int> items; | 4687 List<int> items; |
5140 main() { | 4688 main() { |
5141 b.process(items); | 4689 b.process(items); |
5142 } | 4690 } |
5143 } | 4691 } |
5144 | 4692 |
5145 class B {} | 4693 class B {} |
5146 '''); | 4694 '''); |
5147 await assertHasFix( | 4695 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5148 DartFixKind.CREATE_METHOD, | |
5149 ''' | |
5150 class A { | 4696 class A { |
5151 B b; | 4697 B b; |
5152 List<int> items; | 4698 List<int> items; |
5153 main() { | 4699 main() { |
5154 b.process(items); | 4700 b.process(items); |
5155 } | 4701 } |
5156 } | 4702 } |
5157 | 4703 |
5158 class B { | 4704 class B { |
5159 void process(List<int> items) {} | 4705 void process(List<int> items) {} |
5160 } | 4706 } |
5161 '''); | 4707 '''); |
5162 } | 4708 } |
5163 | 4709 |
5164 test_undefinedMethod_create_generic_OK_local() async { | 4710 test_undefinedMethod_create_generic_OK_local() async { |
5165 await resolveTestUnit(''' | 4711 await resolveTestUnit(''' |
5166 class A<T> { | 4712 class A<T> { |
5167 List<T> items; | 4713 List<T> items; |
5168 main() { | 4714 main() { |
5169 process(items); | 4715 process(items); |
5170 } | 4716 } |
5171 } | 4717 } |
5172 '''); | 4718 '''); |
5173 await assertHasFix( | 4719 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5174 DartFixKind.CREATE_METHOD, | |
5175 ''' | |
5176 class A<T> { | 4720 class A<T> { |
5177 List<T> items; | 4721 List<T> items; |
5178 main() { | 4722 main() { |
5179 process(items); | 4723 process(items); |
5180 } | 4724 } |
5181 | 4725 |
5182 void process(List<T> items) {} | 4726 void process(List<T> items) {} |
5183 } | 4727 } |
5184 '''); | 4728 '''); |
5185 } | 4729 } |
5186 | 4730 |
5187 test_undefinedMethod_createQualified_emptyClassBody() async { | 4731 test_undefinedMethod_createQualified_emptyClassBody() async { |
5188 await resolveTestUnit(''' | 4732 await resolveTestUnit(''' |
5189 class A {} | 4733 class A {} |
5190 main() { | 4734 main() { |
5191 A.myUndefinedMethod(); | 4735 A.myUndefinedMethod(); |
5192 } | 4736 } |
5193 '''); | 4737 '''); |
5194 await assertHasFix( | 4738 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5195 DartFixKind.CREATE_METHOD, | |
5196 ''' | |
5197 class A { | 4739 class A { |
5198 static void myUndefinedMethod() {} | 4740 static void myUndefinedMethod() {} |
5199 } | 4741 } |
5200 main() { | 4742 main() { |
5201 A.myUndefinedMethod(); | 4743 A.myUndefinedMethod(); |
5202 } | 4744 } |
5203 '''); | 4745 '''); |
5204 } | 4746 } |
5205 | 4747 |
5206 test_undefinedMethod_createQualified_fromClass() async { | 4748 test_undefinedMethod_createQualified_fromClass() async { |
5207 await resolveTestUnit(''' | 4749 await resolveTestUnit(''' |
5208 class A { | 4750 class A { |
5209 } | 4751 } |
5210 main() { | 4752 main() { |
5211 A.myUndefinedMethod(); | 4753 A.myUndefinedMethod(); |
5212 } | 4754 } |
5213 '''); | 4755 '''); |
5214 await assertHasFix( | 4756 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5215 DartFixKind.CREATE_METHOD, | |
5216 ''' | |
5217 class A { | 4757 class A { |
5218 static void myUndefinedMethod() {} | 4758 static void myUndefinedMethod() {} |
5219 } | 4759 } |
5220 main() { | 4760 main() { |
5221 A.myUndefinedMethod(); | 4761 A.myUndefinedMethod(); |
5222 } | 4762 } |
5223 '''); | 4763 '''); |
5224 } | 4764 } |
5225 | 4765 |
5226 test_undefinedMethod_createQualified_fromClass_hasOtherMember() async { | 4766 test_undefinedMethod_createQualified_fromClass_hasOtherMember() async { |
5227 await resolveTestUnit(''' | 4767 await resolveTestUnit(''' |
5228 class A { | 4768 class A { |
5229 foo() {} | 4769 foo() {} |
5230 } | 4770 } |
5231 main() { | 4771 main() { |
5232 A.myUndefinedMethod(); | 4772 A.myUndefinedMethod(); |
5233 } | 4773 } |
5234 '''); | 4774 '''); |
5235 await assertHasFix( | 4775 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5236 DartFixKind.CREATE_METHOD, | |
5237 ''' | |
5238 class A { | 4776 class A { |
5239 foo() {} | 4777 foo() {} |
5240 | 4778 |
5241 static void myUndefinedMethod() {} | 4779 static void myUndefinedMethod() {} |
5242 } | 4780 } |
5243 main() { | 4781 main() { |
5244 A.myUndefinedMethod(); | 4782 A.myUndefinedMethod(); |
5245 } | 4783 } |
5246 '''); | 4784 '''); |
5247 } | 4785 } |
5248 | 4786 |
5249 test_undefinedMethod_createQualified_fromInstance() async { | 4787 test_undefinedMethod_createQualified_fromInstance() async { |
5250 await resolveTestUnit(''' | 4788 await resolveTestUnit(''' |
5251 class A { | 4789 class A { |
5252 } | 4790 } |
5253 main(A a) { | 4791 main(A a) { |
5254 a.myUndefinedMethod(); | 4792 a.myUndefinedMethod(); |
5255 } | 4793 } |
5256 '''); | 4794 '''); |
5257 await assertHasFix( | 4795 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5258 DartFixKind.CREATE_METHOD, | |
5259 ''' | |
5260 class A { | 4796 class A { |
5261 void myUndefinedMethod() {} | 4797 void myUndefinedMethod() {} |
5262 } | 4798 } |
5263 main(A a) { | 4799 main(A a) { |
5264 a.myUndefinedMethod(); | 4800 a.myUndefinedMethod(); |
5265 } | 4801 } |
5266 '''); | 4802 '''); |
5267 } | 4803 } |
5268 | 4804 |
5269 test_undefinedMethod_createQualified_targetIsFunctionType() async { | 4805 test_undefinedMethod_createQualified_targetIsFunctionType() async { |
(...skipping 19 matching lines...) Expand all Loading... |
5289 await resolveTestUnit(''' | 4825 await resolveTestUnit(''' |
5290 class C { | 4826 class C { |
5291 int x; | 4827 int x; |
5292 } | 4828 } |
5293 | 4829 |
5294 class D { | 4830 class D { |
5295 foo(C c1, C c2) { | 4831 foo(C c1, C c2) { |
5296 bar(c1.x, c2.x); | 4832 bar(c1.x, c2.x); |
5297 } | 4833 } |
5298 }'''); | 4834 }'''); |
5299 await assertHasFix( | 4835 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5300 DartFixKind.CREATE_METHOD, | |
5301 ''' | |
5302 class C { | 4836 class C { |
5303 int x; | 4837 int x; |
5304 } | 4838 } |
5305 | 4839 |
5306 class D { | 4840 class D { |
5307 foo(C c1, C c2) { | 4841 foo(C c1, C c2) { |
5308 bar(c1.x, c2.x); | 4842 bar(c1.x, c2.x); |
5309 } | 4843 } |
5310 | 4844 |
5311 void bar(int x, int x2) {} | 4845 void bar(int x, int x2) {} |
5312 }'''); | 4846 }'''); |
5313 } | 4847 } |
5314 | 4848 |
5315 test_undefinedMethod_createUnqualified_parameters() async { | 4849 test_undefinedMethod_createUnqualified_parameters() async { |
5316 await resolveTestUnit(''' | 4850 await resolveTestUnit(''' |
5317 class A { | 4851 class A { |
5318 main() { | 4852 main() { |
5319 myUndefinedMethod(0, 1.0, '3'); | 4853 myUndefinedMethod(0, 1.0, '3'); |
5320 } | 4854 } |
5321 } | 4855 } |
5322 '''); | 4856 '''); |
5323 await assertHasFix( | 4857 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5324 DartFixKind.CREATE_METHOD, | |
5325 ''' | |
5326 class A { | 4858 class A { |
5327 main() { | 4859 main() { |
5328 myUndefinedMethod(0, 1.0, '3'); | 4860 myUndefinedMethod(0, 1.0, '3'); |
5329 } | 4861 } |
5330 | 4862 |
5331 void myUndefinedMethod(int i, double d, String s) {} | 4863 void myUndefinedMethod(int i, double d, String s) {} |
5332 } | 4864 } |
5333 '''); | 4865 '''); |
5334 // linked positions | 4866 // linked positions |
5335 int index = 0; | 4867 int index = 0; |
(...skipping 22 matching lines...) Expand all Loading... |
5358 } | 4890 } |
5359 | 4891 |
5360 test_undefinedMethod_createUnqualified_parameters_named() async { | 4892 test_undefinedMethod_createUnqualified_parameters_named() async { |
5361 await resolveTestUnit(''' | 4893 await resolveTestUnit(''' |
5362 class A { | 4894 class A { |
5363 main() { | 4895 main() { |
5364 myUndefinedMethod(0, bbb: 1.0, ccc: '2'); | 4896 myUndefinedMethod(0, bbb: 1.0, ccc: '2'); |
5365 } | 4897 } |
5366 } | 4898 } |
5367 '''); | 4899 '''); |
5368 await assertHasFix( | 4900 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5369 DartFixKind.CREATE_METHOD, | |
5370 ''' | |
5371 class A { | 4901 class A { |
5372 main() { | 4902 main() { |
5373 myUndefinedMethod(0, bbb: 1.0, ccc: '2'); | 4903 myUndefinedMethod(0, bbb: 1.0, ccc: '2'); |
5374 } | 4904 } |
5375 | 4905 |
5376 void myUndefinedMethod(int i, {double bbb, String ccc}) {} | 4906 void myUndefinedMethod(int i, {double bbb, String ccc}) {} |
5377 } | 4907 } |
5378 '''); | 4908 '''); |
5379 // linked positions | 4909 // linked positions |
5380 int index = 0; | 4910 int index = 0; |
(...skipping 20 matching lines...) Expand all Loading... |
5401 } | 4931 } |
5402 | 4932 |
5403 test_undefinedMethod_createUnqualified_returnType() async { | 4933 test_undefinedMethod_createUnqualified_returnType() async { |
5404 await resolveTestUnit(''' | 4934 await resolveTestUnit(''' |
5405 class A { | 4935 class A { |
5406 main() { | 4936 main() { |
5407 int v = myUndefinedMethod(); | 4937 int v = myUndefinedMethod(); |
5408 } | 4938 } |
5409 } | 4939 } |
5410 '''); | 4940 '''); |
5411 await assertHasFix( | 4941 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5412 DartFixKind.CREATE_METHOD, | |
5413 ''' | |
5414 class A { | 4942 class A { |
5415 main() { | 4943 main() { |
5416 int v = myUndefinedMethod(); | 4944 int v = myUndefinedMethod(); |
5417 } | 4945 } |
5418 | 4946 |
5419 int myUndefinedMethod() {} | 4947 int myUndefinedMethod() {} |
5420 } | 4948 } |
5421 '''); | 4949 '''); |
5422 // linked positions | 4950 // linked positions |
5423 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); | 4951 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); |
5424 _assertLinkedGroup(change.linkedEditGroups[1], | 4952 _assertLinkedGroup(change.linkedEditGroups[1], |
5425 ['myUndefinedMethod();', 'myUndefinedMethod() {']); | 4953 ['myUndefinedMethod();', 'myUndefinedMethod() {']); |
5426 } | 4954 } |
5427 | 4955 |
5428 test_undefinedMethod_createUnqualified_staticFromField() async { | 4956 test_undefinedMethod_createUnqualified_staticFromField() async { |
5429 await resolveTestUnit(''' | 4957 await resolveTestUnit(''' |
5430 class A { | 4958 class A { |
5431 static var f = myUndefinedMethod(); | 4959 static var f = myUndefinedMethod(); |
5432 } | 4960 } |
5433 '''); | 4961 '''); |
5434 await assertHasFix( | 4962 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5435 DartFixKind.CREATE_METHOD, | |
5436 ''' | |
5437 class A { | 4963 class A { |
5438 static var f = myUndefinedMethod(); | 4964 static var f = myUndefinedMethod(); |
5439 | 4965 |
5440 static myUndefinedMethod() {} | 4966 static myUndefinedMethod() {} |
5441 } | 4967 } |
5442 '''); | 4968 '''); |
5443 } | 4969 } |
5444 | 4970 |
5445 test_undefinedMethod_createUnqualified_staticFromMethod() async { | 4971 test_undefinedMethod_createUnqualified_staticFromMethod() async { |
5446 await resolveTestUnit(''' | 4972 await resolveTestUnit(''' |
5447 class A { | 4973 class A { |
5448 static main() { | 4974 static main() { |
5449 myUndefinedMethod(); | 4975 myUndefinedMethod(); |
5450 } | 4976 } |
5451 } | 4977 } |
5452 '''); | 4978 '''); |
5453 await assertHasFix( | 4979 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5454 DartFixKind.CREATE_METHOD, | |
5455 ''' | |
5456 class A { | 4980 class A { |
5457 static main() { | 4981 static main() { |
5458 myUndefinedMethod(); | 4982 myUndefinedMethod(); |
5459 } | 4983 } |
5460 | 4984 |
5461 static void myUndefinedMethod() {} | 4985 static void myUndefinedMethod() {} |
5462 } | 4986 } |
5463 '''); | 4987 '''); |
5464 } | 4988 } |
5465 | 4989 |
5466 test_undefinedMethod_hint_createQualified_fromInstance() async { | 4990 test_undefinedMethod_hint_createQualified_fromInstance() async { |
5467 await resolveTestUnit(''' | 4991 await resolveTestUnit(''' |
5468 class A { | 4992 class A { |
5469 } | 4993 } |
5470 main() { | 4994 main() { |
5471 var a = new A(); | 4995 var a = new A(); |
5472 a.myUndefinedMethod(); | 4996 a.myUndefinedMethod(); |
5473 } | 4997 } |
5474 '''); | 4998 '''); |
5475 await assertHasFix( | 4999 await assertHasFix(DartFixKind.CREATE_METHOD, ''' |
5476 DartFixKind.CREATE_METHOD, | |
5477 ''' | |
5478 class A { | 5000 class A { |
5479 void myUndefinedMethod() {} | 5001 void myUndefinedMethod() {} |
5480 } | 5002 } |
5481 main() { | 5003 main() { |
5482 var a = new A(); | 5004 var a = new A(); |
5483 a.myUndefinedMethod(); | 5005 a.myUndefinedMethod(); |
5484 } | 5006 } |
5485 '''); | 5007 '''); |
5486 } | 5008 } |
5487 | 5009 |
5488 test_undefinedMethod_parameterType_differentPrefixInTargetUnit() async { | 5010 test_undefinedMethod_parameterType_differentPrefixInTargetUnit() async { |
5489 String code2 = r''' | 5011 String code2 = r''' |
5490 library test2; | 5012 library test2; |
5491 import 'test3.dart' as bbb; | 5013 import 'test3.dart' as bbb; |
5492 export 'test3.dart'; | 5014 export 'test3.dart'; |
5493 class D { | 5015 class D { |
5494 } | 5016 } |
5495 '''; | 5017 '''; |
5496 addSource('/test2.dart', code2); | 5018 addSource('/test2.dart', code2); |
5497 addSource( | 5019 addSource('/test3.dart', r''' |
5498 '/test3.dart', | |
5499 r''' | |
5500 library test3; | 5020 library test3; |
5501 class E {} | 5021 class E {} |
5502 '''); | 5022 '''); |
5503 await resolveTestUnit(''' | 5023 await resolveTestUnit(''' |
5504 library test; | 5024 library test; |
5505 import 'test2.dart' as aaa; | 5025 import 'test2.dart' as aaa; |
5506 main(aaa.D d, aaa.E e) { | 5026 main(aaa.D d, aaa.E e) { |
5507 d.foo(e); | 5027 d.foo(e); |
5508 } | 5028 } |
5509 '''); | 5029 '''); |
5510 AnalysisError error = await _findErrorToFix(); | 5030 AnalysisError error = await _findErrorToFix(); |
5511 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); | 5031 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); |
5512 change = fix.change; | 5032 change = fix.change; |
5513 // apply to "test2.dart" | 5033 // apply to "test2.dart" |
5514 List<SourceFileEdit> fileEdits = change.edits; | 5034 List<SourceFileEdit> fileEdits = change.edits; |
5515 expect(fileEdits, hasLength(1)); | 5035 expect(fileEdits, hasLength(1)); |
5516 SourceFileEdit fileEdit = change.edits[0]; | 5036 SourceFileEdit fileEdit = change.edits[0]; |
5517 expect(fileEdit.file, '/test2.dart'); | 5037 expect(fileEdit.file, '/test2.dart'); |
5518 expect( | 5038 expect(SourceEdit.applySequence(code2, fileEdit.edits), r''' |
5519 SourceEdit.applySequence(code2, fileEdit.edits), | |
5520 r''' | |
5521 library test2; | 5039 library test2; |
5522 import 'test3.dart' as bbb; | 5040 import 'test3.dart' as bbb; |
5523 export 'test3.dart'; | 5041 export 'test3.dart'; |
5524 class D { | 5042 class D { |
5525 void foo(bbb.E e) {} | 5043 void foo(bbb.E e) {} |
5526 } | 5044 } |
5527 '''); | 5045 '''); |
5528 } | 5046 } |
5529 | 5047 |
5530 test_undefinedMethod_parameterType_inTargetUnit() async { | 5048 test_undefinedMethod_parameterType_inTargetUnit() async { |
(...skipping 12 matching lines...) Expand all Loading... |
5543 } | 5061 } |
5544 '''); | 5062 '''); |
5545 AnalysisError error = await _findErrorToFix(); | 5063 AnalysisError error = await _findErrorToFix(); |
5546 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); | 5064 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); |
5547 change = fix.change; | 5065 change = fix.change; |
5548 // apply to "test2.dart" | 5066 // apply to "test2.dart" |
5549 List<SourceFileEdit> fileEdits = change.edits; | 5067 List<SourceFileEdit> fileEdits = change.edits; |
5550 expect(fileEdits, hasLength(1)); | 5068 expect(fileEdits, hasLength(1)); |
5551 SourceFileEdit fileEdit = change.edits[0]; | 5069 SourceFileEdit fileEdit = change.edits[0]; |
5552 expect(fileEdit.file, '/test2.dart'); | 5070 expect(fileEdit.file, '/test2.dart'); |
5553 expect( | 5071 expect(SourceEdit.applySequence(code2, fileEdit.edits), r''' |
5554 SourceEdit.applySequence(code2, fileEdit.edits), | |
5555 r''' | |
5556 library test2; | 5072 library test2; |
5557 class D { | 5073 class D { |
5558 void foo(E e) {} | 5074 void foo(E e) {} |
5559 } | 5075 } |
5560 class E {} | 5076 class E {} |
5561 '''); | 5077 '''); |
5562 } | 5078 } |
5563 | 5079 |
5564 test_undefinedMethod_useSimilar_ignoreOperators() async { | 5080 test_undefinedMethod_useSimilar_ignoreOperators() async { |
5565 await resolveTestUnit(''' | 5081 await resolveTestUnit(''' |
5566 main(Object object) { | 5082 main(Object object) { |
5567 object.then(); | 5083 object.then(); |
5568 } | 5084 } |
5569 '''); | 5085 '''); |
5570 await assertNoFix(DartFixKind.CHANGE_TO); | 5086 await assertNoFix(DartFixKind.CHANGE_TO); |
5571 } | 5087 } |
5572 | 5088 |
5573 test_undefinedMethod_useSimilar_qualified() async { | 5089 test_undefinedMethod_useSimilar_qualified() async { |
5574 await resolveTestUnit(''' | 5090 await resolveTestUnit(''' |
5575 class A { | 5091 class A { |
5576 myMethod() {} | 5092 myMethod() {} |
5577 } | 5093 } |
5578 main() { | 5094 main() { |
5579 A a = new A(); | 5095 A a = new A(); |
5580 a.myMehtod(); | 5096 a.myMehtod(); |
5581 } | 5097 } |
5582 '''); | 5098 '''); |
5583 await assertHasFix( | 5099 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
5584 DartFixKind.CHANGE_TO, | |
5585 ''' | |
5586 class A { | 5100 class A { |
5587 myMethod() {} | 5101 myMethod() {} |
5588 } | 5102 } |
5589 main() { | 5103 main() { |
5590 A a = new A(); | 5104 A a = new A(); |
5591 a.myMethod(); | 5105 a.myMethod(); |
5592 } | 5106 } |
5593 '''); | 5107 '''); |
5594 } | 5108 } |
5595 | 5109 |
5596 test_undefinedMethod_useSimilar_unqualified_superClass() async { | 5110 test_undefinedMethod_useSimilar_unqualified_superClass() async { |
5597 await resolveTestUnit(''' | 5111 await resolveTestUnit(''' |
5598 class A { | 5112 class A { |
5599 myMethod() {} | 5113 myMethod() {} |
5600 } | 5114 } |
5601 class B extends A { | 5115 class B extends A { |
5602 main() { | 5116 main() { |
5603 myMehtod(); | 5117 myMehtod(); |
5604 } | 5118 } |
5605 } | 5119 } |
5606 '''); | 5120 '''); |
5607 await assertHasFix( | 5121 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
5608 DartFixKind.CHANGE_TO, | |
5609 ''' | |
5610 class A { | 5122 class A { |
5611 myMethod() {} | 5123 myMethod() {} |
5612 } | 5124 } |
5613 class B extends A { | 5125 class B extends A { |
5614 main() { | 5126 main() { |
5615 myMethod(); | 5127 myMethod(); |
5616 } | 5128 } |
5617 } | 5129 } |
5618 '''); | 5130 '''); |
5619 } | 5131 } |
5620 | 5132 |
5621 test_undefinedMethod_useSimilar_unqualified_thisClass() async { | 5133 test_undefinedMethod_useSimilar_unqualified_thisClass() async { |
5622 await resolveTestUnit(''' | 5134 await resolveTestUnit(''' |
5623 class A { | 5135 class A { |
5624 myMethod() {} | 5136 myMethod() {} |
5625 main() { | 5137 main() { |
5626 myMehtod(); | 5138 myMehtod(); |
5627 } | 5139 } |
5628 } | 5140 } |
5629 '''); | 5141 '''); |
5630 await assertHasFix( | 5142 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
5631 DartFixKind.CHANGE_TO, | |
5632 ''' | |
5633 class A { | 5143 class A { |
5634 myMethod() {} | 5144 myMethod() {} |
5635 main() { | 5145 main() { |
5636 myMethod(); | 5146 myMethod(); |
5637 } | 5147 } |
5638 } | 5148 } |
5639 '''); | 5149 '''); |
5640 } | 5150 } |
5641 | 5151 |
5642 test_undefinedParameter_convertFlutterChild_invalidList() async { | 5152 test_undefinedParameter_convertFlutterChild_invalidList() async { |
(...skipping 28 matching lines...) Expand all Loading... |
5671 child: new Row( | 5181 child: new Row( |
5672 child: [ | 5182 child: [ |
5673 new Transform(), | 5183 new Transform(), |
5674 new ClipRect.rect(), | 5184 new ClipRect.rect(), |
5675 new AspectRatio(), | 5185 new AspectRatio(), |
5676 ], | 5186 ], |
5677 ), | 5187 ), |
5678 ); | 5188 ); |
5679 } | 5189 } |
5680 '''); | 5190 '''); |
5681 await assertHasFix( | 5191 await assertHasFix(DartFixKind.CONVERT_FLUTTER_CHILD, ''' |
5682 DartFixKind.CONVERT_FLUTTER_CHILD, | |
5683 ''' | |
5684 import 'package:flutter/src/widgets/framework.dart'; | 5192 import 'package:flutter/src/widgets/framework.dart'; |
5685 build() { | 5193 build() { |
5686 return new Container( | 5194 return new Container( |
5687 child: new Row( | 5195 child: new Row( |
5688 children: <Widget>[ | 5196 children: <Widget>[ |
5689 new Transform(), | 5197 new Transform(), |
5690 new ClipRect.rect(), | 5198 new ClipRect.rect(), |
5691 new AspectRatio(), | 5199 new AspectRatio(), |
5692 ], | 5200 ], |
5693 ), | 5201 ), |
(...skipping 13 matching lines...) Expand all Loading... |
5707 child: new Row( | 5215 child: new Row( |
5708 child: <Widget>[ | 5216 child: <Widget>[ |
5709 new Transform(), | 5217 new Transform(), |
5710 new ClipRect.rect(), | 5218 new ClipRect.rect(), |
5711 new AspectRatio(), | 5219 new AspectRatio(), |
5712 ], | 5220 ], |
5713 ), | 5221 ), |
5714 ); | 5222 ); |
5715 } | 5223 } |
5716 '''); | 5224 '''); |
5717 await assertHasFix( | 5225 await assertHasFix(DartFixKind.CONVERT_FLUTTER_CHILD, ''' |
5718 DartFixKind.CONVERT_FLUTTER_CHILD, | |
5719 ''' | |
5720 import 'package:flutter/src/widgets/framework.dart'; | 5226 import 'package:flutter/src/widgets/framework.dart'; |
5721 build() { | 5227 build() { |
5722 return new Container( | 5228 return new Container( |
5723 child: new Row( | 5229 child: new Row( |
5724 children: <Widget>[ | 5230 children: <Widget>[ |
5725 new Transform(), | 5231 new Transform(), |
5726 new ClipRect.rect(), | 5232 new ClipRect.rect(), |
5727 new AspectRatio(), | 5233 new AspectRatio(), |
5728 ], | 5234 ], |
5729 ), | 5235 ), |
(...skipping 12 matching lines...) Expand all Loading... |
5742 return new Scaffold( | 5248 return new Scaffold( |
5743 body: new Row( | 5249 body: new Row( |
5744 child: new Container( | 5250 child: new Container( |
5745 width: 200.0, | 5251 width: 200.0, |
5746 height: 300.0, | 5252 height: 300.0, |
5747 ), | 5253 ), |
5748 ), | 5254 ), |
5749 ); | 5255 ); |
5750 } | 5256 } |
5751 '''); | 5257 '''); |
5752 await assertHasFix( | 5258 await assertHasFix(DartFixKind.CONVERT_FLUTTER_CHILD, ''' |
5753 DartFixKind.CONVERT_FLUTTER_CHILD, | |
5754 ''' | |
5755 import 'package:flutter/src/widgets/framework.dart'; | 5259 import 'package:flutter/src/widgets/framework.dart'; |
5756 build() { | 5260 build() { |
5757 return new Scaffold( | 5261 return new Scaffold( |
5758 body: new Row( | 5262 body: new Row( |
5759 children: <Widget>[ | 5263 children: <Widget>[ |
5760 new Container( | 5264 new Container( |
5761 width: 200.0, | 5265 width: 200.0, |
5762 height: 300.0, | 5266 height: 300.0, |
5763 ), | 5267 ), |
5764 ], | 5268 ], |
5765 ), | 5269 ), |
5766 ); | 5270 ); |
5767 } | 5271 } |
5768 '''); | 5272 '''); |
5769 } | 5273 } |
5770 | 5274 |
5771 test_undefinedSetter_useSimilar_hint() async { | 5275 test_undefinedSetter_useSimilar_hint() async { |
5772 await resolveTestUnit(''' | 5276 await resolveTestUnit(''' |
5773 class A { | 5277 class A { |
5774 int myField; | 5278 int myField; |
5775 } | 5279 } |
5776 main(A a) { | 5280 main(A a) { |
5777 var x = a; | 5281 var x = a; |
5778 x.myFild = 42; | 5282 x.myFild = 42; |
5779 } | 5283 } |
5780 '''); | 5284 '''); |
5781 await assertHasFix( | 5285 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
5782 DartFixKind.CHANGE_TO, | |
5783 ''' | |
5784 class A { | 5286 class A { |
5785 int myField; | 5287 int myField; |
5786 } | 5288 } |
5787 main(A a) { | 5289 main(A a) { |
5788 var x = a; | 5290 var x = a; |
5789 x.myField = 42; | 5291 x.myField = 42; |
5790 } | 5292 } |
5791 '''); | 5293 '''); |
5792 } | 5294 } |
5793 | 5295 |
5794 test_undefinedSetter_useSimilar_qualified() async { | 5296 test_undefinedSetter_useSimilar_qualified() async { |
5795 await resolveTestUnit(''' | 5297 await resolveTestUnit(''' |
5796 class A { | 5298 class A { |
5797 int myField; | 5299 int myField; |
5798 } | 5300 } |
5799 main(A a) { | 5301 main(A a) { |
5800 a.myFild = 42; | 5302 a.myFild = 42; |
5801 } | 5303 } |
5802 '''); | 5304 '''); |
5803 await assertHasFix( | 5305 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
5804 DartFixKind.CHANGE_TO, | |
5805 ''' | |
5806 class A { | 5306 class A { |
5807 int myField; | 5307 int myField; |
5808 } | 5308 } |
5809 main(A a) { | 5309 main(A a) { |
5810 a.myField = 42; | 5310 a.myField = 42; |
5811 } | 5311 } |
5812 '''); | 5312 '''); |
5813 } | 5313 } |
5814 | 5314 |
5815 test_undefinedSetter_useSimilar_unqualified() async { | 5315 test_undefinedSetter_useSimilar_unqualified() async { |
5816 await resolveTestUnit(''' | 5316 await resolveTestUnit(''' |
5817 class A { | 5317 class A { |
5818 int myField; | 5318 int myField; |
5819 main() { | 5319 main() { |
5820 myFild = 42; | 5320 myFild = 42; |
5821 } | 5321 } |
5822 } | 5322 } |
5823 '''); | 5323 '''); |
5824 await assertHasFix( | 5324 await assertHasFix(DartFixKind.CHANGE_TO, ''' |
5825 DartFixKind.CHANGE_TO, | |
5826 ''' | |
5827 class A { | 5325 class A { |
5828 int myField; | 5326 int myField; |
5829 main() { | 5327 main() { |
5830 myField = 42; | 5328 myField = 42; |
5831 } | 5329 } |
5832 } | 5330 } |
5833 '''); | 5331 '''); |
5834 } | 5332 } |
5835 | 5333 |
5836 test_useEffectiveIntegerDivision() async { | 5334 test_useEffectiveIntegerDivision() async { |
5837 await resolveTestUnit(''' | 5335 await resolveTestUnit(''' |
5838 main() { | 5336 main() { |
5839 var a = 5; | 5337 var a = 5; |
5840 var b = 2; | 5338 var b = 2; |
5841 print((a / b).toInt()); | 5339 print((a / b).toInt()); |
5842 } | 5340 } |
5843 '''); | 5341 '''); |
5844 await assertHasFix( | 5342 await assertHasFix(DartFixKind.USE_EFFECTIVE_INTEGER_DIVISION, ''' |
5845 DartFixKind.USE_EFFECTIVE_INTEGER_DIVISION, | |
5846 ''' | |
5847 main() { | 5343 main() { |
5848 var a = 5; | 5344 var a = 5; |
5849 var b = 2; | 5345 var b = 2; |
5850 print(a ~/ b); | 5346 print(a ~/ b); |
5851 } | 5347 } |
5852 '''); | 5348 '''); |
5853 } | 5349 } |
5854 | 5350 |
5855 test_useImportPrefix_withClass() async { | 5351 test_useImportPrefix_withClass() async { |
5856 await resolveTestUnit(''' | 5352 await resolveTestUnit(''' |
5857 import 'dart:async' as pref; | 5353 import 'dart:async' as pref; |
5858 main() { | 5354 main() { |
5859 pref.Stream s = null; | 5355 pref.Stream s = null; |
5860 Future f = null; | 5356 Future f = null; |
5861 } | 5357 } |
5862 '''); | 5358 '''); |
5863 await assertHasFix( | 5359 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PREFIX, ''' |
5864 DartFixKind.IMPORT_LIBRARY_PREFIX, | |
5865 ''' | |
5866 import 'dart:async' as pref; | 5360 import 'dart:async' as pref; |
5867 main() { | 5361 main() { |
5868 pref.Stream s = null; | 5362 pref.Stream s = null; |
5869 pref.Future f = null; | 5363 pref.Future f = null; |
5870 } | 5364 } |
5871 '''); | 5365 '''); |
5872 } | 5366 } |
5873 | 5367 |
5874 test_useImportPrefix_withTopLevelVariable() async { | 5368 test_useImportPrefix_withTopLevelVariable() async { |
5875 await resolveTestUnit(''' | 5369 await resolveTestUnit(''' |
5876 import 'dart:math' as pref; | 5370 import 'dart:math' as pref; |
5877 main() { | 5371 main() { |
5878 print(pref.E); | 5372 print(pref.E); |
5879 print(PI); | 5373 print(PI); |
5880 } | 5374 } |
5881 '''); | 5375 '''); |
5882 await assertHasFix( | 5376 await assertHasFix(DartFixKind.IMPORT_LIBRARY_PREFIX, ''' |
5883 DartFixKind.IMPORT_LIBRARY_PREFIX, | |
5884 ''' | |
5885 import 'dart:math' as pref; | 5377 import 'dart:math' as pref; |
5886 main() { | 5378 main() { |
5887 print(pref.E); | 5379 print(pref.E); |
5888 print(pref.PI); | 5380 print(pref.PI); |
5889 } | 5381 } |
5890 '''); | 5382 '''); |
5891 } | 5383 } |
5892 | 5384 |
5893 void _addMetaPackageSource() { | 5385 void _addMetaPackageSource() { |
5894 addPackageSource( | 5386 addPackageSource('meta', 'meta.dart', r''' |
5895 'meta', | |
5896 'meta.dart', | |
5897 r''' | |
5898 library meta; | 5387 library meta; |
5899 | 5388 |
5900 const Required required = const Required(); | 5389 const Required required = const Required(); |
5901 | 5390 |
5902 class Required { | 5391 class Required { |
5903 final String reason; | 5392 final String reason; |
5904 const Required([this.reason]); | 5393 const Required([this.reason]); |
5905 } | 5394 } |
5906 '''); | 5395 '''); |
5907 } | 5396 } |
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6924 @override | 6413 @override |
6925 final AnalysisError error; | 6414 final AnalysisError error; |
6926 | 6415 |
6927 _DartFixContextImpl(this.resourceProvider, this.analysisDriver, | 6416 _DartFixContextImpl(this.resourceProvider, this.analysisDriver, |
6928 this.astProvider, this.unit, this.error); | 6417 this.astProvider, this.unit, this.error); |
6929 | 6418 |
6930 @override | 6419 @override |
6931 GetTopLevelDeclarations get getTopLevelDeclarations => | 6420 GetTopLevelDeclarations get getTopLevelDeclarations => |
6932 analysisDriver.getTopLevelNameDeclarations; | 6421 analysisDriver.getTopLevelNameDeclarations; |
6933 } | 6422 } |
OLD | NEW |