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/protocol/protocol_generated.dart' | 9 import 'package:analysis_server/protocol/protocol_generated.dart' |
10 hide AnalysisError; | 10 hide AnalysisError; |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 ''' | 459 ''' |
460 import 'libA.dart'; | 460 import 'libA.dart'; |
461 | 461 |
462 main() { | 462 main() { |
463 A a = new A(a: null); | 463 A a = new A(a: null); |
464 } | 464 } |
465 ''', | 465 ''', |
466 target: '/test.dart'); | 466 target: '/test.dart'); |
467 } | 467 } |
468 | 468 |
| 469 test_addMissingRequiredArg_cons_single_closure() async { |
| 470 _addMetaPackageSource(); |
| 471 |
| 472 addSource( |
| 473 '/libA.dart', |
| 474 r''' |
| 475 library libA; |
| 476 import 'package:meta/meta.dart'; |
| 477 |
| 478 typedef void VoidCallback(); |
| 479 |
| 480 class A { |
| 481 A({@required VoidCallback onPressed}) {} |
| 482 } |
| 483 '''); |
| 484 |
| 485 await resolveTestUnit(''' |
| 486 import 'libA.dart'; |
| 487 |
| 488 main() { |
| 489 A a = new A(); |
| 490 } |
| 491 '''); |
| 492 await assertHasFix( |
| 493 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, |
| 494 ''' |
| 495 import 'libA.dart'; |
| 496 |
| 497 main() { |
| 498 A a = new A(onPressed: () {}); |
| 499 } |
| 500 ''', |
| 501 target: '/test.dart'); |
| 502 } |
| 503 |
| 504 test_addMissingRequiredArg_cons_single_closure_2() async { |
| 505 _addMetaPackageSource(); |
| 506 |
| 507 addSource( |
| 508 '/libA.dart', |
| 509 r''' |
| 510 library libA; |
| 511 import 'package:meta/meta.dart'; |
| 512 |
| 513 typedef void Callback(e); |
| 514 |
| 515 class A { |
| 516 A({@required Callback callback}) {} |
| 517 } |
| 518 '''); |
| 519 |
| 520 await resolveTestUnit(''' |
| 521 import 'libA.dart'; |
| 522 |
| 523 main() { |
| 524 A a = new A(); |
| 525 } |
| 526 '''); |
| 527 await assertHasFix( |
| 528 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, |
| 529 ''' |
| 530 import 'libA.dart'; |
| 531 |
| 532 main() { |
| 533 A a = new A(callback: (e) {}); |
| 534 } |
| 535 ''', |
| 536 target: '/test.dart'); |
| 537 } |
| 538 |
| 539 test_addMissingRequiredArg_cons_single_closure_3() async { |
| 540 _addMetaPackageSource(); |
| 541 |
| 542 addSource( |
| 543 '/libA.dart', |
| 544 r''' |
| 545 library libA; |
| 546 import 'package:meta/meta.dart'; |
| 547 |
| 548 typedef void Callback(a,b,c); |
| 549 |
| 550 class A { |
| 551 A({@required Callback callback}) {} |
| 552 } |
| 553 '''); |
| 554 |
| 555 await resolveTestUnit(''' |
| 556 import 'libA.dart'; |
| 557 |
| 558 main() { |
| 559 A a = new A(); |
| 560 } |
| 561 '''); |
| 562 await assertHasFix( |
| 563 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, |
| 564 ''' |
| 565 import 'libA.dart'; |
| 566 |
| 567 main() { |
| 568 A a = new A(callback: (a, b, c) {}); |
| 569 } |
| 570 ''', |
| 571 target: '/test.dart'); |
| 572 } |
| 573 |
| 574 test_addMissingRequiredArg_cons_single_closure_4() async { |
| 575 _addMetaPackageSource(); |
| 576 |
| 577 addSource( |
| 578 '/libA.dart', |
| 579 r''' |
| 580 library libA; |
| 581 import 'package:meta/meta.dart'; |
| 582 |
| 583 typedef int Callback(a,b,c); |
| 584 |
| 585 class A { |
| 586 A({@required Callback callback}) {} |
| 587 } |
| 588 '''); |
| 589 |
| 590 await resolveTestUnit(''' |
| 591 import 'libA.dart'; |
| 592 |
| 593 main() { |
| 594 A a = new A(); |
| 595 } |
| 596 '''); |
| 597 await assertHasFix( |
| 598 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, |
| 599 ''' |
| 600 import 'libA.dart'; |
| 601 |
| 602 main() { |
| 603 A a = new A(callback: (a, b, c) {}); |
| 604 } |
| 605 ''', |
| 606 target: '/test.dart'); |
| 607 } |
| 608 |
| 609 test_addMissingRequiredArg_cons_single_list() async { |
| 610 _addMetaPackageSource(); |
| 611 |
| 612 addSource( |
| 613 '/libA.dart', |
| 614 r''' |
| 615 library libA; |
| 616 import 'package:meta/meta.dart'; |
| 617 |
| 618 class A { |
| 619 A({@required List<String> names}) {} |
| 620 } |
| 621 '''); |
| 622 |
| 623 await resolveTestUnit(''' |
| 624 import 'libA.dart'; |
| 625 |
| 626 main() { |
| 627 A a = new A(); |
| 628 } |
| 629 '''); |
| 630 await assertHasFix( |
| 631 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, |
| 632 ''' |
| 633 import 'libA.dart'; |
| 634 |
| 635 main() { |
| 636 A a = new A(names: <String>[]); |
| 637 } |
| 638 ''', |
| 639 target: '/test.dart'); |
| 640 } |
| 641 |
469 test_addMissingRequiredArg_multiple() async { | 642 test_addMissingRequiredArg_multiple() async { |
470 _addMetaPackageSource(); | 643 _addMetaPackageSource(); |
471 | 644 |
472 await resolveTestUnit(''' | 645 await resolveTestUnit(''' |
473 import 'package:meta/meta.dart'; | 646 import 'package:meta/meta.dart'; |
474 | 647 |
475 test({@required int a, @required int bcd}) {} | 648 test({@required int a, @required int bcd}) {} |
476 main() { | 649 main() { |
477 test(a: 3); | 650 test(a: 3); |
478 } | 651 } |
(...skipping 6237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6716 | 6889 |
6717 @override | 6890 @override |
6718 final CompilationUnit unit; | 6891 final CompilationUnit unit; |
6719 | 6892 |
6720 @override | 6893 @override |
6721 final AnalysisError error; | 6894 final AnalysisError error; |
6722 | 6895 |
6723 _DartFixContextImpl(this.resourceProvider, this.getTopLevelDeclarations, | 6896 _DartFixContextImpl(this.resourceProvider, this.getTopLevelDeclarations, |
6724 this.analysisContext, this.astProvider, this.unit, this.error); | 6897 this.analysisContext, this.astProvider, this.unit, this.error); |
6725 } | 6898 } |
OLD | NEW |