| 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 library test.services.refactoring.extract_method; | 5 library test.services.refactoring.extract_method; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:analysis_server/src/services/correction/status.dart'; |
| 10 import 'package:analysis_server/src/services/refactoring/extract_method.dart'; | 11 import 'package:analysis_server/src/services/refactoring/extract_method.dart'; |
| 11 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 12 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 12 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 13 | 14 |
| 14 import '../../reflective_tests.dart'; | 15 import '../../reflective_tests.dart'; |
| 15 import 'abstract_refactoring.dart'; | 16 import 'abstract_refactoring.dart'; |
| 16 | 17 |
| 17 | 18 |
| 18 main() { | 19 main() { |
| 19 groupSep = ' | '; | 20 groupSep = ' | '; |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 } | 356 } |
| 356 print(0); | 357 print(0); |
| 357 // end | 358 // end |
| 358 } | 359 } |
| 359 '''); | 360 '''); |
| 360 _createRefactoringForStartEndComments(); | 361 _createRefactoringForStartEndComments(); |
| 361 return _assertConditionsFatal( | 362 return _assertConditionsFatal( |
| 362 'Not all selected statements are enclosed by the same parent statement.'
); | 363 'Not all selected statements are enclosed by the same parent statement.'
); |
| 363 } | 364 } |
| 364 | 365 |
| 365 test_bad_parameterName_duplicate() { | 366 test_bad_parameterName_duplicate() async { |
| 366 indexTestUnit(''' | 367 indexTestUnit(''' |
| 367 main() { | 368 main() { |
| 368 int v1 = 1; | 369 int v1 = 1; |
| 369 int v2 = 2; | 370 int v2 = 2; |
| 370 // start | 371 // start |
| 371 int a = v1 + v2; // marker | 372 int a = v1 + v2; // marker |
| 372 // end | 373 // end |
| 373 } | 374 } |
| 374 '''); | 375 '''); |
| 375 _createRefactoringForStartEndComments(); | 376 _createRefactoringForStartEndComments(); |
| 376 // update parameters | 377 // update parameters |
| 377 return refactoring.checkInitialConditions().then((_) { | 378 await refactoring.checkInitialConditions(); |
| 378 { | 379 { |
| 379 var parameters = _getParametersCopy(); | 380 List<RefactoringMethodParameter> parameters = _getParametersCopy(); |
| 380 expect(parameters, hasLength(2)); | 381 expect(parameters, hasLength(2)); |
| 381 parameters[0].name = 'dup'; | 382 parameters[0].name = 'dup'; |
| 382 parameters[1].name = 'dup'; | 383 parameters[1].name = 'dup'; |
| 383 refactoring.parameters = parameters; | 384 refactoring.parameters = parameters; |
| 384 } | 385 } |
| 385 return _assertFinalConditionsError("Parameter 'dup' already exists"); | 386 return _assertFinalConditionsError("Parameter 'dup' already exists"); |
| 386 }); | |
| 387 } | 387 } |
| 388 | 388 |
| 389 test_bad_parameterName_inUse() { | 389 test_bad_parameterName_inUse() async { |
| 390 indexTestUnit(''' | 390 indexTestUnit(''' |
| 391 main() { | 391 main() { |
| 392 int v1 = 1; | 392 int v1 = 1; |
| 393 int v2 = 2; | 393 int v2 = 2; |
| 394 // start | 394 // start |
| 395 int a = v1 + v2; // marker | 395 int a = v1 + v2; // marker |
| 396 // end | 396 // end |
| 397 } | 397 } |
| 398 '''); | 398 '''); |
| 399 _createRefactoringForStartEndComments(); | 399 _createRefactoringForStartEndComments(); |
| 400 // update parameters | 400 // update parameters |
| 401 return refactoring.checkInitialConditions().then((_) { | 401 await refactoring.checkInitialConditions(); |
| 402 { | 402 { |
| 403 var parameters = _getParametersCopy(); | 403 List<RefactoringMethodParameter> parameters = _getParametersCopy(); |
| 404 expect(parameters, hasLength(2)); | 404 expect(parameters, hasLength(2)); |
| 405 parameters[0].name = 'a'; | 405 parameters[0].name = 'a'; |
| 406 refactoring.parameters = parameters; | 406 refactoring.parameters = parameters; |
| 407 } | 407 } |
| 408 return _assertFinalConditionsError( | 408 return _assertFinalConditionsError( |
| 409 "'a' is already used as a name in the selected code"); | 409 "'a' is already used as a name in the selected code"); |
| 410 }); | |
| 411 } | 410 } |
| 412 | 411 |
| 413 test_bad_selectionEndsInSomeNode() { | 412 test_bad_selectionEndsInSomeNode() { |
| 414 indexTestUnit(''' | 413 indexTestUnit(''' |
| 415 main() { | 414 main() { |
| 416 // start | 415 // start |
| 417 print(0); | 416 print(0); |
| 418 print(1); | 417 print(1); |
| 419 // end | 418 // end |
| 420 } | 419 } |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 { | 603 { |
| 605 } | 604 } |
| 606 // end | 605 // end |
| 607 } | 606 } |
| 608 '''); | 607 '''); |
| 609 _createRefactoringForStartEndComments(); | 608 _createRefactoringForStartEndComments(); |
| 610 return _assertConditionsFatal( | 609 return _assertConditionsFatal( |
| 611 "Operation not applicable to a while statement's expression and body."); | 610 "Operation not applicable to a while statement's expression and body."); |
| 612 } | 611 } |
| 613 | 612 |
| 614 test_canExtractGetter_false_fieldAssignment() { | 613 test_canExtractGetter_false_fieldAssignment() async { |
| 615 indexTestUnit(''' | 614 indexTestUnit(''' |
| 616 class A { | 615 class A { |
| 617 var f; | 616 var f; |
| 618 main() { | 617 main() { |
| 619 // start | 618 // start |
| 620 f = 1; | 619 f = 1; |
| 621 // end | 620 // end |
| 622 } | 621 } |
| 623 } | 622 } |
| 624 '''); | 623 '''); |
| 625 _createRefactoringForStartEndComments(); | 624 _createRefactoringForStartEndComments(); |
| 626 // apply refactoring | 625 // apply refactoring |
| 627 return assertRefactoringConditionsOK().then((_) { | 626 await assertRefactoringConditionsOK(); |
| 628 expect(refactoring.canCreateGetter, false); | 627 expect(refactoring.canCreateGetter, false); |
| 629 expect(refactoring.createGetter, false); | 628 expect(refactoring.createGetter, false); |
| 630 }); | |
| 631 } | 629 } |
| 632 | 630 |
| 633 test_canExtractGetter_false_hasParameters() { | 631 test_canExtractGetter_false_hasParameters() async { |
| 634 indexTestUnit(''' | 632 indexTestUnit(''' |
| 635 main(int p) { | 633 main(int p) { |
| 636 int a = p + 1; | 634 int a = p + 1; |
| 637 } | 635 } |
| 638 '''); | 636 '''); |
| 639 _createRefactoringForString('p + 1'); | 637 _createRefactoringForString('p + 1'); |
| 640 // apply refactoring | 638 // apply refactoring |
| 641 return assertRefactoringConditionsOK().then((_) { | 639 await assertRefactoringConditionsOK(); |
| 642 expect(refactoring.canCreateGetter, false); | 640 expect(refactoring.canCreateGetter, false); |
| 643 expect(refactoring.createGetter, false); | 641 expect(refactoring.createGetter, false); |
| 644 }); | |
| 645 } | 642 } |
| 646 | 643 |
| 647 test_canExtractGetter_false_returnNotUsed_assignment() { | 644 test_canExtractGetter_false_returnNotUsed_assignment() async { |
| 648 indexTestUnit(''' | 645 indexTestUnit(''' |
| 649 var topVar = 0; | 646 var topVar = 0; |
| 650 f(int p) { | 647 f(int p) { |
| 651 topVar = 5; | 648 topVar = 5; |
| 652 } | 649 } |
| 653 '''); | 650 '''); |
| 654 _createRefactoringForString('topVar = 5'); | 651 _createRefactoringForString('topVar = 5'); |
| 655 // apply refactoring | 652 // apply refactoring |
| 656 return assertRefactoringConditionsOK().then((_) { | 653 await assertRefactoringConditionsOK(); |
| 657 expect(refactoring.canCreateGetter, false); | 654 expect(refactoring.canCreateGetter, false); |
| 658 expect(refactoring.createGetter, false); | 655 expect(refactoring.createGetter, false); |
| 659 }); | |
| 660 } | 656 } |
| 661 | 657 |
| 662 test_canExtractGetter_false_returnNotUsed_noReturn() { | 658 test_canExtractGetter_false_returnNotUsed_noReturn() async { |
| 663 indexTestUnit(''' | 659 indexTestUnit(''' |
| 664 var topVar = 0; | 660 var topVar = 0; |
| 665 main() { | 661 main() { |
| 666 // start | 662 // start |
| 667 int a = 1; | 663 int a = 1; |
| 668 int b = 2; | 664 int b = 2; |
| 669 topVar = a + b; | 665 topVar = a + b; |
| 670 // end | 666 // end |
| 671 } | 667 } |
| 672 '''); | 668 '''); |
| 673 _createRefactoringForStartEndComments(); | 669 _createRefactoringForStartEndComments(); |
| 674 // apply refactoring | 670 // apply refactoring |
| 675 return assertRefactoringConditionsOK().then((_) { | 671 await assertRefactoringConditionsOK(); |
| 676 expect(refactoring.canCreateGetter, false); | 672 expect(refactoring.canCreateGetter, false); |
| 677 expect(refactoring.createGetter, false); | 673 expect(refactoring.createGetter, false); |
| 678 }); | |
| 679 } | 674 } |
| 680 | 675 |
| 681 test_canExtractGetter_true() { | 676 test_canExtractGetter_true() async { |
| 682 indexTestUnit(''' | 677 indexTestUnit(''' |
| 683 main() { | 678 main() { |
| 684 int a = 1 + 2; | 679 int a = 1 + 2; |
| 685 } | 680 } |
| 686 '''); | 681 '''); |
| 687 _createRefactoringForString('1 + 2'); | 682 _createRefactoringForString('1 + 2'); |
| 688 // apply refactoring | 683 // apply refactoring |
| 689 return assertRefactoringConditionsOK().then((_) { | 684 await assertRefactoringConditionsOK(); |
| 690 expect(refactoring.canCreateGetter, true); | 685 expect(refactoring.canCreateGetter, true); |
| 691 expect(refactoring.createGetter, true); | 686 expect(refactoring.createGetter, true); |
| 692 }); | |
| 693 } | 687 } |
| 694 | 688 |
| 695 test_checkName() { | 689 test_checkName() { |
| 696 indexTestUnit(''' | 690 indexTestUnit(''' |
| 697 main() { | 691 main() { |
| 698 int a = 1 + 2; | 692 int a = 1 + 2; |
| 699 } | 693 } |
| 700 '''); | 694 '''); |
| 701 _createRefactoringForString('1 + 2'); | 695 _createRefactoringForString('1 + 2'); |
| 702 // null | 696 // null |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 } | 778 } |
| 785 | 779 |
| 786 res(x) { | 780 res(x) { |
| 787 print(x); | 781 print(x); |
| 788 return x * k; | 782 return x * k; |
| 789 } | 783 } |
| 790 } | 784 } |
| 791 '''); | 785 '''); |
| 792 } | 786 } |
| 793 | 787 |
| 794 test_closure_bad_referencesLocalVariable() { | 788 test_closure_bad_referencesLocalVariable() async { |
| 795 indexTestUnit(''' | 789 indexTestUnit(''' |
| 796 process(f(x)) {} | 790 process(f(x)) {} |
| 797 main() { | 791 main() { |
| 798 int k = 2; | 792 int k = 2; |
| 799 process((x) => x * k); | 793 process((x) => x * k); |
| 800 } | 794 } |
| 801 '''); | 795 '''); |
| 802 _createRefactoringForString('(x) => x * k'); | 796 _createRefactoringForString('(x) => x * k'); |
| 803 // check | 797 // check |
| 804 return refactoring.checkInitialConditions().then((status) { | 798 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 805 assertRefactoringStatus( | 799 assertRefactoringStatus( |
| 806 status, | 800 status, |
| 807 RefactoringProblemSeverity.FATAL, | 801 RefactoringProblemSeverity.FATAL, |
| 808 expectedMessage: | 802 expectedMessage: |
| 809 'Cannot extract closure as method, it references 1 external variab
le(s).'); | 803 'Cannot extract closure as method, it references 1 external variable
(s).'); |
| 810 }); | |
| 811 } | 804 } |
| 812 | 805 |
| 813 test_closure_bad_referencesParameter() { | 806 test_closure_bad_referencesParameter() async { |
| 814 indexTestUnit(''' | 807 indexTestUnit(''' |
| 815 process(f(x)) {} | 808 process(f(x)) {} |
| 816 main(int k) { | 809 main(int k) { |
| 817 process((x) => x * k); | 810 process((x) => x * k); |
| 818 } | 811 } |
| 819 '''); | 812 '''); |
| 820 _createRefactoringForString('(x) => x * k'); | 813 _createRefactoringForString('(x) => x * k'); |
| 821 // check | 814 // check |
| 822 return refactoring.checkInitialConditions().then((status) { | 815 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 823 assertRefactoringStatus( | 816 assertRefactoringStatus( |
| 824 status, | 817 status, |
| 825 RefactoringProblemSeverity.FATAL, | 818 RefactoringProblemSeverity.FATAL, |
| 826 expectedMessage: | 819 expectedMessage: |
| 827 'Cannot extract closure as method, it references 1 external variab
le(s).'); | 820 'Cannot extract closure as method, it references 1 external variable
(s).'); |
| 828 }); | |
| 829 } | 821 } |
| 830 | 822 |
| 831 test_fromTopLevelVariableInitializerClosure() { | 823 test_fromTopLevelVariableInitializerClosure() { |
| 832 indexTestUnit(''' | 824 indexTestUnit(''' |
| 833 var X = 1; | 825 var X = 1; |
| 834 | 826 |
| 835 var Y = () { | 827 var Y = () { |
| 836 return 1 + X; | 828 return 1 + X; |
| 837 }; | 829 }; |
| 838 '''); | 830 '''); |
| 839 _createRefactoringForString('1 + X'); | 831 _createRefactoringForString('1 + X'); |
| 840 // apply refactoring | 832 // apply refactoring |
| 841 return _assertSuccessfulRefactoring(''' | 833 return _assertSuccessfulRefactoring(''' |
| 842 var X = 1; | 834 var X = 1; |
| 843 | 835 |
| 844 var Y = () { | 836 var Y = () { |
| 845 return res(); | 837 return res(); |
| 846 }; | 838 }; |
| 847 | 839 |
| 848 num res() => 1 + X; | 840 num res() => 1 + X; |
| 849 '''); | 841 '''); |
| 850 } | 842 } |
| 851 | 843 |
| 852 test_getExtractGetter_false_do() { | 844 test_getExtractGetter_false_do() async { |
| 853 indexTestUnit(''' | 845 indexTestUnit(''' |
| 854 main() { | 846 main() { |
| 855 // start | 847 // start |
| 856 int v = 0; | 848 int v = 0; |
| 857 do { | 849 do { |
| 858 v++; | 850 v++; |
| 859 } while (v < 10); | 851 } while (v < 10); |
| 860 // end | 852 // end |
| 861 print(v); | 853 print(v); |
| 862 } | 854 } |
| 863 '''); | 855 '''); |
| 864 _createRefactoringForStartEndComments(); | 856 _createRefactoringForStartEndComments(); |
| 865 // apply refactoring | 857 // apply refactoring |
| 866 return assertRefactoringConditionsOK().then((_) { | 858 await assertRefactoringConditionsOK(); |
| 867 expect(refactoring.createGetter, false); | 859 expect(refactoring.createGetter, false); |
| 868 }); | |
| 869 } | 860 } |
| 870 | 861 |
| 871 test_getExtractGetter_false_for() { | 862 test_getExtractGetter_false_for() async { |
| 872 indexTestUnit(''' | 863 indexTestUnit(''' |
| 873 main() { | 864 main() { |
| 874 // start | 865 // start |
| 875 int v = 0; | 866 int v = 0; |
| 876 for (int i = 0; i < 10; i++) { | 867 for (int i = 0; i < 10; i++) { |
| 877 v += i; | 868 v += i; |
| 878 } | 869 } |
| 879 // end | 870 // end |
| 880 print(v); | 871 print(v); |
| 881 } | 872 } |
| 882 '''); | 873 '''); |
| 883 _createRefactoringForStartEndComments(); | 874 _createRefactoringForStartEndComments(); |
| 884 // apply refactoring | 875 // apply refactoring |
| 885 return assertRefactoringConditionsOK().then((_) { | 876 await assertRefactoringConditionsOK(); |
| 886 expect(refactoring.createGetter, false); | 877 expect(refactoring.createGetter, false); |
| 887 }); | |
| 888 } | 878 } |
| 889 | 879 |
| 890 test_getExtractGetter_false_forEach() { | 880 test_getExtractGetter_false_forEach() async { |
| 891 indexTestUnit(''' | 881 indexTestUnit(''' |
| 892 main() { | 882 main() { |
| 893 // start | 883 // start |
| 894 int v = 0; | 884 int v = 0; |
| 895 for (int i in [1, 2, 3]) { | 885 for (int i in [1, 2, 3]) { |
| 896 v += i; | 886 v += i; |
| 897 } | 887 } |
| 898 // end | 888 // end |
| 899 print(v); | 889 print(v); |
| 900 } | 890 } |
| 901 '''); | 891 '''); |
| 902 _createRefactoringForStartEndComments(); | 892 _createRefactoringForStartEndComments(); |
| 903 // apply refactoring | 893 // apply refactoring |
| 904 return assertRefactoringConditionsOK().then((_) { | 894 await assertRefactoringConditionsOK(); |
| 905 expect(refactoring.createGetter, false); | 895 expect(refactoring.createGetter, false); |
| 906 }); | |
| 907 } | 896 } |
| 908 | 897 |
| 909 test_getExtractGetter_false_methodInvocation_expression() { | 898 test_getExtractGetter_false_methodInvocation_expression() async { |
| 910 indexTestUnit(''' | 899 indexTestUnit(''' |
| 911 main() { | 900 main() { |
| 912 int v = calculateSomething() + 5; | 901 int v = calculateSomething() + 5; |
| 913 } | 902 } |
| 914 int calculateSomething() => 42; | 903 int calculateSomething() => 42; |
| 915 '''); | 904 '''); |
| 916 _createRefactoringForString('calculateSomething() + 5'); | 905 _createRefactoringForString('calculateSomething() + 5'); |
| 917 // apply refactoring | 906 // apply refactoring |
| 918 return assertRefactoringConditionsOK().then((_) { | 907 await assertRefactoringConditionsOK(); |
| 919 expect(refactoring.createGetter, false); | 908 expect(refactoring.createGetter, false); |
| 920 }); | |
| 921 } | 909 } |
| 922 | 910 |
| 923 test_getExtractGetter_false_methodInvocation_statements() { | 911 test_getExtractGetter_false_methodInvocation_statements() async { |
| 924 indexTestUnit(''' | 912 indexTestUnit(''' |
| 925 main() { | 913 main() { |
| 926 // start | 914 // start |
| 927 int v = calculateSomething(); | 915 int v = calculateSomething(); |
| 928 // end | 916 // end |
| 929 print(v); | 917 print(v); |
| 930 } | 918 } |
| 931 int calculateSomething() => 42; | 919 int calculateSomething() => 42; |
| 932 '''); | 920 '''); |
| 933 _createRefactoringForStartEndComments(); | 921 _createRefactoringForStartEndComments(); |
| 934 // apply refactoring | 922 // apply refactoring |
| 935 return assertRefactoringConditionsOK().then((_) { | 923 await assertRefactoringConditionsOK(); |
| 936 expect(refactoring.createGetter, false); | 924 expect(refactoring.createGetter, false); |
| 937 }); | |
| 938 } | 925 } |
| 939 | 926 |
| 940 test_getExtractGetter_false_while() { | 927 test_getExtractGetter_false_while() async { |
| 941 indexTestUnit(''' | 928 indexTestUnit(''' |
| 942 main() { | 929 main() { |
| 943 // start | 930 // start |
| 944 int v = 0; | 931 int v = 0; |
| 945 while (v < 10) { | 932 while (v < 10) { |
| 946 v++; | 933 v++; |
| 947 } | 934 } |
| 948 // end | 935 // end |
| 949 print(v); | 936 print(v); |
| 950 } | 937 } |
| 951 '''); | 938 '''); |
| 952 _createRefactoringForStartEndComments(); | 939 _createRefactoringForStartEndComments(); |
| 953 // apply refactoring | 940 // apply refactoring |
| 954 return assertRefactoringConditionsOK().then((_) { | 941 await assertRefactoringConditionsOK(); |
| 955 expect(refactoring.createGetter, false); | 942 expect(refactoring.createGetter, false); |
| 956 }); | |
| 957 } | 943 } |
| 958 | 944 |
| 959 test_getExtractGetter_true_simpleBlock() { | 945 test_getExtractGetter_true_simpleBlock() async { |
| 960 indexTestUnit(''' | 946 indexTestUnit(''' |
| 961 main() { | 947 main() { |
| 962 // start | 948 // start |
| 963 int v = 1 + 2; | 949 int v = 1 + 2; |
| 964 // end | 950 // end |
| 965 print(v); | 951 print(v); |
| 966 } | 952 } |
| 967 '''); | 953 '''); |
| 968 _createRefactoringForStartEndComments(); | 954 _createRefactoringForStartEndComments(); |
| 969 // apply refactoring | 955 // apply refactoring |
| 970 return assertRefactoringConditionsOK().then((_) { | 956 await assertRefactoringConditionsOK(); |
| 971 expect(refactoring.createGetter, true); | 957 expect(refactoring.createGetter, true); |
| 972 }); | |
| 973 } | 958 } |
| 974 | 959 |
| 975 test_getExtractGetter_true_singleExpression() { | 960 test_getExtractGetter_true_singleExpression() async { |
| 976 indexTestUnit(''' | 961 indexTestUnit(''' |
| 977 main() { | 962 main() { |
| 978 // start | 963 // start |
| 979 int v = 1 + 2; | 964 int v = 1 + 2; |
| 980 // end | 965 // end |
| 981 print(v); | 966 print(v); |
| 982 } | 967 } |
| 983 '''); | 968 '''); |
| 984 _createRefactoringForString('1 + 2'); | 969 _createRefactoringForString('1 + 2'); |
| 985 // apply refactoring | 970 // apply refactoring |
| 986 return assertRefactoringConditionsOK().then((_) { | 971 await assertRefactoringConditionsOK(); |
| 987 expect(refactoring.createGetter, true); | 972 expect(refactoring.createGetter, true); |
| 988 }); | |
| 989 } | 973 } |
| 990 | 974 |
| 991 test_getRefactoringName_function() { | 975 test_getRefactoringName_function() { |
| 992 indexTestUnit(''' | 976 indexTestUnit(''' |
| 993 main() { | 977 main() { |
| 994 print(1 + 2); | 978 print(1 + 2); |
| 995 } | 979 } |
| 996 '''); | 980 '''); |
| 997 _createRefactoringForString('1 + 2'); | 981 _createRefactoringForString('1 + 2'); |
| 998 expect(refactoring.refactoringName, 'Extract Function'); | 982 expect(refactoring.refactoringName, 'Extract Function'); |
| 999 } | 983 } |
| 1000 | 984 |
| 1001 test_getRefactoringName_method() { | 985 test_getRefactoringName_method() { |
| 1002 indexTestUnit(''' | 986 indexTestUnit(''' |
| 1003 class A { | 987 class A { |
| 1004 main() { | 988 main() { |
| 1005 print(1 + 2); | 989 print(1 + 2); |
| 1006 } | 990 } |
| 1007 } | 991 } |
| 1008 '''); | 992 '''); |
| 1009 _createRefactoringForString('1 + 2'); | 993 _createRefactoringForString('1 + 2'); |
| 1010 expect(refactoring.refactoringName, 'Extract Method'); | 994 expect(refactoring.refactoringName, 'Extract Method'); |
| 1011 } | 995 } |
| 1012 | 996 |
| 1013 test_names_singleExpression() { | 997 test_names_singleExpression() async { |
| 1014 indexTestUnit(''' | 998 indexTestUnit(''' |
| 1015 class TreeItem {} | 999 class TreeItem {} |
| 1016 TreeItem getSelectedItem() => null; | 1000 TreeItem getSelectedItem() => null; |
| 1017 process(my) {} | 1001 process(my) {} |
| 1018 main() { | 1002 main() { |
| 1019 process(getSelectedItem()); // marker | 1003 process(getSelectedItem()); // marker |
| 1020 int treeItem = 0; | 1004 int treeItem = 0; |
| 1021 } | 1005 } |
| 1022 '''); | 1006 '''); |
| 1023 _createRefactoringWithSuffix('getSelectedItem()', '); // marker'); | 1007 _createRefactoringWithSuffix('getSelectedItem()', '); // marker'); |
| 1024 // check names | 1008 // check names |
| 1025 return refactoring.checkInitialConditions().then((_) { | 1009 await refactoring.checkInitialConditions(); |
| 1026 expect( | 1010 expect( |
| 1027 refactoring.names, | 1011 refactoring.names, |
| 1028 unorderedEquals(['selectedItem', 'item', 'my', 'treeItem2'])); | 1012 unorderedEquals(['selectedItem', 'item', 'my', 'treeItem2'])); |
| 1029 }); | |
| 1030 } | 1013 } |
| 1031 | 1014 |
| 1032 test_offsets_lengths() { | 1015 test_offsets_lengths() async { |
| 1033 indexTestUnit(''' | 1016 indexTestUnit(''' |
| 1034 main() { | 1017 main() { |
| 1035 int a = 1 + 2; | 1018 int a = 1 + 2; |
| 1036 int b = 1 + 2; | 1019 int b = 1 + 2; |
| 1037 } | 1020 } |
| 1038 '''); | 1021 '''); |
| 1039 _createRefactoringForString('1 + 2'); | 1022 _createRefactoringForString('1 + 2'); |
| 1040 // apply refactoring | 1023 // apply refactoring |
| 1041 return refactoring.checkInitialConditions().then((_) { | 1024 await refactoring.checkInitialConditions(); |
| 1042 expect( | 1025 expect( |
| 1043 refactoring.offsets, | 1026 refactoring.offsets, |
| 1044 unorderedEquals([findOffset('1 + 2'), findOffset('1 + 2')])); | 1027 unorderedEquals([findOffset('1 + 2'), findOffset('1 + 2')])); |
| 1045 expect(refactoring.lengths, unorderedEquals([5, 6])); | 1028 expect(refactoring.lengths, unorderedEquals([5, 6])); |
| 1046 }); | |
| 1047 } | 1029 } |
| 1048 | 1030 |
| 1049 test_returnType_expression() { | 1031 test_returnType_expression() async { |
| 1050 indexTestUnit(''' | 1032 indexTestUnit(''' |
| 1051 main() { | 1033 main() { |
| 1052 int a = 1 + 2; | 1034 int a = 1 + 2; |
| 1053 } | 1035 } |
| 1054 '''); | 1036 '''); |
| 1055 _createRefactoringForString('1 + 2'); | 1037 _createRefactoringForString('1 + 2'); |
| 1056 // do check | 1038 // do check |
| 1057 return refactoring.checkInitialConditions().then((_) { | 1039 await refactoring.checkInitialConditions(); |
| 1058 expect(refactoring.returnType, 'int'); | 1040 expect(refactoring.returnType, 'int'); |
| 1059 }); | |
| 1060 } | 1041 } |
| 1061 | 1042 |
| 1062 test_returnType_statements() { | 1043 test_returnType_statements() async { |
| 1063 indexTestUnit(''' | 1044 indexTestUnit(''' |
| 1064 main() { | 1045 main() { |
| 1065 // start | 1046 // start |
| 1066 double v = 5.0; | 1047 double v = 5.0; |
| 1067 // end | 1048 // end |
| 1068 print(v); | 1049 print(v); |
| 1069 } | 1050 } |
| 1070 '''); | 1051 '''); |
| 1071 _createRefactoringForStartEndComments(); | 1052 _createRefactoringForStartEndComments(); |
| 1072 // do check | 1053 // do check |
| 1073 return refactoring.checkInitialConditions().then((_) { | 1054 await refactoring.checkInitialConditions(); |
| 1074 expect(refactoring.returnType, 'double'); | 1055 expect(refactoring.returnType, 'double'); |
| 1075 }); | |
| 1076 } | 1056 } |
| 1077 | 1057 |
| 1078 test_returnType_statements_nullMix() { | 1058 test_returnType_statements_nullMix() async { |
| 1079 indexTestUnit(''' | 1059 indexTestUnit(''' |
| 1080 main(bool p) { | 1060 main(bool p) { |
| 1081 // start | 1061 // start |
| 1082 if (p) { | 1062 if (p) { |
| 1083 return 42; | 1063 return 42; |
| 1084 } | 1064 } |
| 1085 return null; | 1065 return null; |
| 1086 // end | 1066 // end |
| 1087 } | 1067 } |
| 1088 '''); | 1068 '''); |
| 1089 _createRefactoringForStartEndComments(); | 1069 _createRefactoringForStartEndComments(); |
| 1090 // do check | 1070 // do check |
| 1091 return refactoring.checkInitialConditions().then((_) { | 1071 await refactoring.checkInitialConditions(); |
| 1092 expect(refactoring.returnType, 'int'); | 1072 expect(refactoring.returnType, 'int'); |
| 1093 }); | |
| 1094 } | 1073 } |
| 1095 | 1074 |
| 1096 test_returnType_statements_void() { | 1075 test_returnType_statements_void() async { |
| 1097 indexTestUnit(''' | 1076 indexTestUnit(''' |
| 1098 main() { | 1077 main() { |
| 1099 // start | 1078 // start |
| 1100 print(42); | 1079 print(42); |
| 1101 // end | 1080 // end |
| 1102 } | 1081 } |
| 1103 '''); | 1082 '''); |
| 1104 _createRefactoringForStartEndComments(); | 1083 _createRefactoringForStartEndComments(); |
| 1105 // do check | 1084 // do check |
| 1106 return refactoring.checkInitialConditions().then((_) { | 1085 await refactoring.checkInitialConditions(); |
| 1107 expect(refactoring.returnType, 'void'); | 1086 expect(refactoring.returnType, 'void'); |
| 1108 }); | |
| 1109 } | 1087 } |
| 1110 | 1088 |
| 1111 test_setExtractGetter() { | 1089 test_setExtractGetter() async { |
| 1112 indexTestUnit(''' | 1090 indexTestUnit(''' |
| 1113 main() { | 1091 main() { |
| 1114 int a = 1 + 2; | 1092 int a = 1 + 2; |
| 1115 } | 1093 } |
| 1116 '''); | 1094 '''); |
| 1117 _createRefactoringForString('1 + 2'); | 1095 _createRefactoringForString('1 + 2'); |
| 1118 // apply refactoring | 1096 // apply refactoring |
| 1119 return assertRefactoringConditionsOK().then((_) { | 1097 await assertRefactoringConditionsOK(); |
| 1120 expect(refactoring.canCreateGetter, true); | 1098 expect(refactoring.canCreateGetter, true); |
| 1121 expect(refactoring.createGetter, true); | 1099 expect(refactoring.createGetter, true); |
| 1122 return refactoring.createChange().then((SourceChange refactoringChange) { | 1100 refactoringChange = await refactoring.createChange(); |
| 1123 this.refactoringChange = refactoringChange; | 1101 assertTestChangeResult(''' |
| 1124 assertTestChangeResult(''' | |
| 1125 main() { | 1102 main() { |
| 1126 int a = res; | 1103 int a = res; |
| 1127 } | 1104 } |
| 1128 | 1105 |
| 1129 int get res => 1 + 2; | 1106 int get res => 1 + 2; |
| 1130 '''); | 1107 '''); |
| 1131 }); | |
| 1132 }); | |
| 1133 } | 1108 } |
| 1134 | 1109 |
| 1135 test_singleExpression() { | 1110 test_singleExpression() { |
| 1136 indexTestUnit(''' | 1111 indexTestUnit(''' |
| 1137 main() { | 1112 main() { |
| 1138 int a = 1 + 2; | 1113 int a = 1 + 2; |
| 1139 } | 1114 } |
| 1140 '''); | 1115 '''); |
| 1141 _createRefactoringForString('1 + 2'); | 1116 _createRefactoringForString('1 + 2'); |
| 1142 // apply refactoring | 1117 // apply refactoring |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1602 main() { | 1577 main() { |
| 1603 int v1 = 1; | 1578 int v1 = 1; |
| 1604 int v2 = 2; | 1579 int v2 = 2; |
| 1605 int a = res(v1, v2); | 1580 int a = res(v1, v2); |
| 1606 } | 1581 } |
| 1607 | 1582 |
| 1608 int res(int v1, int v2) => v1 + v2 + v1; | 1583 int res(int v1, int v2) => v1 + v2 + v1; |
| 1609 '''); | 1584 '''); |
| 1610 } | 1585 } |
| 1611 | 1586 |
| 1612 test_singleExpression_withVariables_doRename() { | 1587 test_singleExpression_withVariables_doRename() async { |
| 1613 indexTestUnit(''' | 1588 indexTestUnit(''' |
| 1614 main() { | 1589 main() { |
| 1615 int v1 = 1; | 1590 int v1 = 1; |
| 1616 int v2 = 2; | 1591 int v2 = 2; |
| 1617 int v3 = 3; | 1592 int v3 = 3; |
| 1618 int a = v1 + v2 + v1; // marker | 1593 int a = v1 + v2 + v1; // marker |
| 1619 int b = v2 + v3 + v2; | 1594 int b = v2 + v3 + v2; |
| 1620 } | 1595 } |
| 1621 '''); | 1596 '''); |
| 1622 _createRefactoringForString('v1 + v2 + v1'); | 1597 _createRefactoringForString('v1 + v2 + v1'); |
| 1623 // apply refactoring | 1598 // apply refactoring |
| 1624 return refactoring.checkInitialConditions().then((_) { | 1599 await refactoring.checkInitialConditions(); |
| 1625 { | 1600 { |
| 1626 var parameters = _getParametersCopy(); | 1601 List<RefactoringMethodParameter> parameters = _getParametersCopy(); |
| 1627 expect(parameters, hasLength(2)); | 1602 expect(parameters, hasLength(2)); |
| 1628 expect(parameters[0].name, 'v1'); | 1603 expect(parameters[0].name, 'v1'); |
| 1629 expect(parameters[1].name, 'v2'); | 1604 expect(parameters[1].name, 'v2'); |
| 1630 parameters[0].name = 'par1'; | 1605 parameters[0].name = 'par1'; |
| 1631 parameters[1].name = 'param2'; | 1606 parameters[1].name = 'param2'; |
| 1632 refactoring.parameters = parameters; | 1607 refactoring.parameters = parameters; |
| 1633 } | 1608 } |
| 1634 return assertRefactoringFinalConditionsOK().then((_) { | 1609 await assertRefactoringFinalConditionsOK(); |
| 1635 refactoring.createGetter = false; | 1610 refactoring.createGetter = false; |
| 1636 return _assertRefactoringChange(''' | 1611 return _assertRefactoringChange(''' |
| 1637 main() { | 1612 main() { |
| 1638 int v1 = 1; | 1613 int v1 = 1; |
| 1639 int v2 = 2; | 1614 int v2 = 2; |
| 1640 int v3 = 3; | 1615 int v3 = 3; |
| 1641 int a = res(v1, v2); // marker | 1616 int a = res(v1, v2); // marker |
| 1642 int b = res(v2, v3); | 1617 int b = res(v2, v3); |
| 1643 } | 1618 } |
| 1644 | 1619 |
| 1645 int res(int par1, int param2) => par1 + param2 + par1; | 1620 int res(int par1, int param2) => par1 + param2 + par1; |
| 1646 '''); | 1621 '''); |
| 1647 }); | |
| 1648 }); | |
| 1649 } | 1622 } |
| 1650 | 1623 |
| 1651 test_singleExpression_withVariables_doReorder() { | 1624 test_singleExpression_withVariables_doReorder() async { |
| 1652 indexTestUnit(''' | 1625 indexTestUnit(''' |
| 1653 main() { | 1626 main() { |
| 1654 int v1 = 1; | 1627 int v1 = 1; |
| 1655 int v2 = 2; | 1628 int v2 = 2; |
| 1656 int v3 = 3; | 1629 int v3 = 3; |
| 1657 int a = v1 + v2; // marker | 1630 int a = v1 + v2; // marker |
| 1658 int b = v2 + v3; | 1631 int b = v2 + v3; |
| 1659 } | 1632 } |
| 1660 '''); | 1633 '''); |
| 1661 _createRefactoringForString('v1 + v2'); | 1634 _createRefactoringForString('v1 + v2'); |
| 1662 // apply refactoring | 1635 // apply refactoring |
| 1663 return refactoring.checkInitialConditions().then((_) { | 1636 await refactoring.checkInitialConditions(); |
| 1664 { | 1637 { |
| 1665 var parameters = _getParametersCopy(); | 1638 List<RefactoringMethodParameter> parameters = _getParametersCopy(); |
| 1666 expect(parameters, hasLength(2)); | 1639 expect(parameters, hasLength(2)); |
| 1667 expect(parameters[0].name, 'v1'); | 1640 expect(parameters[0].name, 'v1'); |
| 1668 expect(parameters[1].name, 'v2'); | 1641 expect(parameters[1].name, 'v2'); |
| 1669 var parameter = parameters.removeAt(1); | 1642 var parameter = parameters.removeAt(1); |
| 1670 parameters.insert(0, parameter); | 1643 parameters.insert(0, parameter); |
| 1671 refactoring.parameters = parameters; | 1644 refactoring.parameters = parameters; |
| 1672 } | 1645 } |
| 1673 return assertRefactoringFinalConditionsOK().then((_) { | 1646 await assertRefactoringFinalConditionsOK(); |
| 1674 refactoring.createGetter = false; | 1647 refactoring.createGetter = false; |
| 1675 return _assertRefactoringChange(''' | 1648 return _assertRefactoringChange(''' |
| 1676 main() { | 1649 main() { |
| 1677 int v1 = 1; | 1650 int v1 = 1; |
| 1678 int v2 = 2; | 1651 int v2 = 2; |
| 1679 int v3 = 3; | 1652 int v3 = 3; |
| 1680 int a = res(v2, v1); // marker | 1653 int a = res(v2, v1); // marker |
| 1681 int b = res(v3, v2); | 1654 int b = res(v3, v2); |
| 1682 } | 1655 } |
| 1683 | 1656 |
| 1684 int res(int v2, int v1) => v1 + v2; | 1657 int res(int v2, int v1) => v1 + v2; |
| 1685 '''); | 1658 '''); |
| 1686 }); | |
| 1687 }); | |
| 1688 } | 1659 } |
| 1689 | 1660 |
| 1690 test_singleExpression_withVariables_namedExpression() { | 1661 test_singleExpression_withVariables_namedExpression() { |
| 1691 indexTestUnit(''' | 1662 indexTestUnit(''' |
| 1692 main() { | 1663 main() { |
| 1693 int v1 = 1; | 1664 int v1 = 1; |
| 1694 int v2 = 2; | 1665 int v2 = 2; |
| 1695 int a = process(arg: v1 + v2); | 1666 int a = process(arg: v1 + v2); |
| 1696 } | 1667 } |
| 1697 process({arg}) {} | 1668 process({arg}) {} |
| 1698 '''); | 1669 '''); |
| 1699 _createRefactoringForString('process(arg: v1 + v2)'); | 1670 _createRefactoringForString('process(arg: v1 + v2)'); |
| 1700 // apply refactoring | 1671 // apply refactoring |
| 1701 return _assertSuccessfulRefactoring(''' | 1672 return _assertSuccessfulRefactoring(''' |
| 1702 main() { | 1673 main() { |
| 1703 int v1 = 1; | 1674 int v1 = 1; |
| 1704 int v2 = 2; | 1675 int v2 = 2; |
| 1705 int a = res(v1, v2); | 1676 int a = res(v1, v2); |
| 1706 } | 1677 } |
| 1707 | 1678 |
| 1708 res(int v1, int v2) => process(arg: v1 + v2); | 1679 res(int v1, int v2) => process(arg: v1 + v2); |
| 1709 process({arg}) {} | 1680 process({arg}) {} |
| 1710 '''); | 1681 '''); |
| 1711 } | 1682 } |
| 1712 | 1683 |
| 1713 test_singleExpression_withVariables_newType() { | 1684 test_singleExpression_withVariables_newType() async { |
| 1714 indexTestUnit(''' | 1685 indexTestUnit(''' |
| 1715 main() { | 1686 main() { |
| 1716 int v1 = 1; | 1687 int v1 = 1; |
| 1717 int v2 = 2; | 1688 int v2 = 2; |
| 1718 int v3 = 3; | 1689 int v3 = 3; |
| 1719 int a = v1 + v2 + v3; | 1690 int a = v1 + v2 + v3; |
| 1720 } | 1691 } |
| 1721 '''); | 1692 '''); |
| 1722 _createRefactoringForString('v1 + v2 + v3'); | 1693 _createRefactoringForString('v1 + v2 + v3'); |
| 1723 // apply refactoring | 1694 // apply refactoring |
| 1724 return refactoring.checkInitialConditions().then((_) { | 1695 await refactoring.checkInitialConditions(); |
| 1725 { | 1696 { |
| 1726 var parameters = _getParametersCopy(); | 1697 List<RefactoringMethodParameter> parameters = _getParametersCopy(); |
| 1727 expect(parameters, hasLength(3)); | 1698 expect(parameters, hasLength(3)); |
| 1728 expect(parameters[0].name, 'v1'); | 1699 expect(parameters[0].name, 'v1'); |
| 1729 expect(parameters[1].name, 'v2'); | 1700 expect(parameters[1].name, 'v2'); |
| 1730 expect(parameters[2].name, 'v3'); | 1701 expect(parameters[2].name, 'v3'); |
| 1731 parameters[0].type = 'num'; | 1702 parameters[0].type = 'num'; |
| 1732 parameters[1].type = 'dynamic'; | 1703 parameters[1].type = 'dynamic'; |
| 1733 parameters[2].type = ''; | 1704 parameters[2].type = ''; |
| 1734 refactoring.parameters = parameters; | 1705 refactoring.parameters = parameters; |
| 1735 } | 1706 } |
| 1736 return assertRefactoringFinalConditionsOK().then((_) { | 1707 await assertRefactoringFinalConditionsOK(); |
| 1737 refactoring.createGetter = false; | 1708 refactoring.createGetter = false; |
| 1738 return _assertRefactoringChange(''' | 1709 return _assertRefactoringChange(''' |
| 1739 main() { | 1710 main() { |
| 1740 int v1 = 1; | 1711 int v1 = 1; |
| 1741 int v2 = 2; | 1712 int v2 = 2; |
| 1742 int v3 = 3; | 1713 int v3 = 3; |
| 1743 int a = res(v1, v2, v3); | 1714 int a = res(v1, v2, v3); |
| 1744 } | 1715 } |
| 1745 | 1716 |
| 1746 int res(num v1, v2, v3) => v1 + v2 + v3; | 1717 int res(num v1, v2, v3) => v1 + v2 + v3; |
| 1747 '''); | 1718 '''); |
| 1748 }); | |
| 1749 }); | |
| 1750 } | 1719 } |
| 1751 | 1720 |
| 1752 test_singleExpression_withVariables_useBestType() { | 1721 test_singleExpression_withVariables_useBestType() { |
| 1753 indexTestUnit(''' | 1722 indexTestUnit(''' |
| 1754 main() { | 1723 main() { |
| 1755 var v1 = 1; | 1724 var v1 = 1; |
| 1756 var v2 = 2; | 1725 var v2 = 2; |
| 1757 var a = v1 + v2 + v1; // marker | 1726 var a = v1 + v2 + v1; // marker |
| 1758 } | 1727 } |
| 1759 '''); | 1728 '''); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1964 } | 1933 } |
| 1965 myFunctionB() { | 1934 myFunctionB() { |
| 1966 int a = 3; | 1935 int a = 3; |
| 1967 int b = 4; | 1936 int b = 4; |
| 1968 int v2 = res(a, b); | 1937 int v2 = res(a, b); |
| 1969 print(v2); | 1938 print(v2); |
| 1970 } | 1939 } |
| 1971 '''); | 1940 '''); |
| 1972 } | 1941 } |
| 1973 | 1942 |
| 1974 test_statements_definesVariable_twoUsedOutside() { | 1943 test_statements_definesVariable_twoUsedOutside() async { |
| 1975 indexTestUnit(''' | 1944 indexTestUnit(''' |
| 1976 main() { | 1945 main() { |
| 1977 // start | 1946 // start |
| 1978 int varA = 1; | 1947 int varA = 1; |
| 1979 int varB = 2; | 1948 int varB = 2; |
| 1980 // end | 1949 // end |
| 1981 int v = varA + varB; | 1950 int v = varA + varB; |
| 1982 } | 1951 } |
| 1983 '''); | 1952 '''); |
| 1984 _createRefactoringForStartEndComments(); | 1953 _createRefactoringForStartEndComments(); |
| 1985 // check conditions | 1954 // check conditions |
| 1986 return refactoring.checkInitialConditions().then((status) { | 1955 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 1987 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); | 1956 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); |
| 1988 }); | |
| 1989 } | 1957 } |
| 1990 | 1958 |
| 1991 test_statements_duplicate_absolutelySame() { | 1959 test_statements_duplicate_absolutelySame() { |
| 1992 indexTestUnit(''' | 1960 indexTestUnit(''' |
| 1993 myFunctionA() { | 1961 myFunctionA() { |
| 1994 print(0); | 1962 print(0); |
| 1995 print(1); | 1963 print(1); |
| 1996 } | 1964 } |
| 1997 myFunctionB() { | 1965 myFunctionB() { |
| 1998 // start | 1966 // start |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2397 print(0); | 2365 print(0); |
| 2398 } | 2366 } |
| 2399 | 2367 |
| 2400 void res() { | 2368 void res() { |
| 2401 print(0); | 2369 print(0); |
| 2402 print(0); | 2370 print(0); |
| 2403 } | 2371 } |
| 2404 '''); | 2372 '''); |
| 2405 } | 2373 } |
| 2406 | 2374 |
| 2407 Future _assertConditionsError(String message) { | 2375 Future _assertConditionsError(String message) async { |
| 2408 return refactoring.checkAllConditions().then((status) { | 2376 RefactoringStatus status = await refactoring.checkAllConditions(); |
| 2409 assertRefactoringStatus( | 2377 assertRefactoringStatus( |
| 2410 status, | 2378 status, |
| 2411 RefactoringProblemSeverity.ERROR, | 2379 RefactoringProblemSeverity.ERROR, |
| 2412 expectedMessage: message); | 2380 expectedMessage: message); |
| 2413 }); | |
| 2414 } | 2381 } |
| 2415 | 2382 |
| 2416 Future _assertConditionsFatal(String message) { | 2383 Future _assertConditionsFatal(String message) async { |
| 2417 return refactoring.checkAllConditions().then((status) { | 2384 RefactoringStatus status = await refactoring.checkAllConditions(); |
| 2418 assertRefactoringStatus( | 2385 assertRefactoringStatus( |
| 2419 status, | 2386 status, |
| 2420 RefactoringProblemSeverity.FATAL, | 2387 RefactoringProblemSeverity.FATAL, |
| 2421 expectedMessage: message); | 2388 expectedMessage: message); |
| 2422 }); | |
| 2423 } | 2389 } |
| 2424 | 2390 |
| 2425 Future _assertFinalConditionsError(String message) { | 2391 Future _assertFinalConditionsError(String message) async { |
| 2426 return refactoring.checkFinalConditions().then((status) { | 2392 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 2427 assertRefactoringStatus( | 2393 assertRefactoringStatus( |
| 2428 status, | 2394 status, |
| 2429 RefactoringProblemSeverity.ERROR, | 2395 RefactoringProblemSeverity.ERROR, |
| 2430 expectedMessage: message); | 2396 expectedMessage: message); |
| 2431 }); | |
| 2432 } | 2397 } |
| 2433 | 2398 |
| 2434 Future _assertRefactoringChange(String expectedCode) { | 2399 Future _assertRefactoringChange(String expectedCode) async { |
| 2435 return refactoring.createChange().then((SourceChange refactoringChange) { | 2400 SourceChange refactoringChange = await refactoring.createChange(); |
| 2436 this.refactoringChange = refactoringChange; | 2401 this.refactoringChange = refactoringChange; |
| 2437 assertTestChangeResult(expectedCode); | 2402 assertTestChangeResult(expectedCode); |
| 2438 }); | |
| 2439 } | 2403 } |
| 2440 | 2404 |
| 2441 /** | 2405 /** |
| 2442 * Checks that all conditions are OK and the result of applying the [Change] | 2406 * Checks that all conditions are OK and the result of applying the [Change] |
| 2443 * to [testUnit] is [expectedCode]. | 2407 * to [testUnit] is [expectedCode]. |
| 2444 */ | 2408 */ |
| 2445 Future _assertSuccessfulRefactoring(String expectedCode) { | 2409 Future _assertSuccessfulRefactoring(String expectedCode) async { |
| 2446 return assertRefactoringConditionsOK().then((_) { | 2410 await assertRefactoringConditionsOK(); |
| 2447 refactoring.createGetter = false; | 2411 refactoring.createGetter = false; |
| 2448 return _assertRefactoringChange(expectedCode); | 2412 return _assertRefactoringChange(expectedCode); |
| 2449 }); | |
| 2450 } | 2413 } |
| 2451 | 2414 |
| 2452 void _createRefactoring(int offset, int length) { | 2415 void _createRefactoring(int offset, int length) { |
| 2453 refactoring = | 2416 refactoring = |
| 2454 new ExtractMethodRefactoring(searchEngine, testUnit, offset, length); | 2417 new ExtractMethodRefactoring(searchEngine, testUnit, offset, length); |
| 2455 refactoring.name = 'res'; | 2418 refactoring.name = 'res'; |
| 2456 } | 2419 } |
| 2457 | 2420 |
| 2458 void _createRefactoringForStartEndComments() { | 2421 void _createRefactoringForStartEndComments() { |
| 2459 int offset = findEnd('// start') + '\n'.length; | 2422 int offset = findEnd('// start') + '\n'.length; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2488 * Returns a deep copy of [refactoring] parameters. | 2451 * Returns a deep copy of [refactoring] parameters. |
| 2489 * There was a bug masked by updating parameter instances shared between the | 2452 * There was a bug masked by updating parameter instances shared between the |
| 2490 * refactoring and the test. | 2453 * refactoring and the test. |
| 2491 */ | 2454 */ |
| 2492 List<RefactoringMethodParameter> _getParametersCopy() { | 2455 List<RefactoringMethodParameter> _getParametersCopy() { |
| 2493 return refactoring.parameters.map((p) { | 2456 return refactoring.parameters.map((p) { |
| 2494 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id); | 2457 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id); |
| 2495 }).toList(); | 2458 }).toList(); |
| 2496 } | 2459 } |
| 2497 } | 2460 } |
| OLD | NEW |