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.correction.fix; | 5 library test.services.correction.fix; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; | 10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; |
(...skipping 4583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4594 ''' | 4594 ''' |
4595 class A<T> { | 4595 class A<T> { |
4596 B b; | 4596 B b; |
4597 Map<int, T> items; | 4597 Map<int, T> items; |
4598 main() { | 4598 main() { |
4599 b.process(items); | 4599 b.process(items); |
4600 } | 4600 } |
4601 } | 4601 } |
4602 | 4602 |
4603 class B { | 4603 class B { |
4604 void process(Map items) { | 4604 void process(Map items) {} |
Brian Wilkerson
2016/11/30 18:22:57
It would be good to have some tests in which there
| |
4605 } | |
4606 } | 4605 } |
4607 '''); | 4606 '''); |
4608 } | 4607 } |
4609 | 4608 |
4610 test_undefinedMethod_create_generic_BAD_returnType() async { | 4609 test_undefinedMethod_create_generic_BAD_returnType() async { |
4611 resolveTestUnit(''' | 4610 resolveTestUnit(''' |
4612 class A<T> { | 4611 class A<T> { |
4613 main() { | 4612 main() { |
4614 T t = new B().compute(); | 4613 T t = new B().compute(); |
4615 } | 4614 } |
4616 } | 4615 } |
4617 | 4616 |
4618 class B { | 4617 class B { |
4619 } | 4618 } |
4620 '''); | 4619 '''); |
4621 await assertHasFix( | 4620 await assertHasFix( |
4622 DartFixKind.CREATE_METHOD, | 4621 DartFixKind.CREATE_METHOD, |
4623 ''' | 4622 ''' |
4624 class A<T> { | 4623 class A<T> { |
4625 main() { | 4624 main() { |
4626 T t = new B().compute(); | 4625 T t = new B().compute(); |
4627 } | 4626 } |
4628 } | 4627 } |
4629 | 4628 |
4630 class B { | 4629 class B { |
4631 dynamic compute() { | 4630 dynamic compute() {} |
4632 } | |
4633 } | 4631 } |
4634 '''); | 4632 '''); |
4635 } | 4633 } |
4636 | 4634 |
4637 test_undefinedMethod_create_generic_OK_literal() async { | 4635 test_undefinedMethod_create_generic_OK_literal() async { |
4638 resolveTestUnit(''' | 4636 resolveTestUnit(''' |
4639 class A { | 4637 class A { |
4640 B b; | 4638 B b; |
4641 List<int> items; | 4639 List<int> items; |
4642 main() { | 4640 main() { |
4643 b.process(items); | 4641 b.process(items); |
4644 } | 4642 } |
4645 } | 4643 } |
4646 | 4644 |
4647 class B { | 4645 class B {} |
4648 } | |
4649 '''); | 4646 '''); |
4650 await assertHasFix( | 4647 await assertHasFix( |
4651 DartFixKind.CREATE_METHOD, | 4648 DartFixKind.CREATE_METHOD, |
4652 ''' | 4649 ''' |
4653 class A { | 4650 class A { |
4654 B b; | 4651 B b; |
4655 List<int> items; | 4652 List<int> items; |
4656 main() { | 4653 main() { |
4657 b.process(items); | 4654 b.process(items); |
4658 } | 4655 } |
4659 } | 4656 } |
4660 | 4657 |
4661 class B { | 4658 class B { |
4662 void process(List<int> items) { | 4659 void process(List<int> items) {} |
4663 } | |
4664 } | 4660 } |
4665 '''); | 4661 '''); |
4666 } | 4662 } |
4667 | 4663 |
4668 test_undefinedMethod_create_generic_OK_local() async { | 4664 test_undefinedMethod_create_generic_OK_local() async { |
4669 resolveTestUnit(''' | 4665 resolveTestUnit(''' |
4670 class A<T> { | 4666 class A<T> { |
4671 List<T> items; | 4667 List<T> items; |
4672 main() { | 4668 main() { |
4673 process(items); | 4669 process(items); |
4674 } | 4670 } |
4675 } | 4671 } |
4676 '''); | 4672 '''); |
4677 await assertHasFix( | 4673 await assertHasFix( |
4678 DartFixKind.CREATE_METHOD, | 4674 DartFixKind.CREATE_METHOD, |
4679 ''' | 4675 ''' |
4680 class A<T> { | 4676 class A<T> { |
4681 List<T> items; | 4677 List<T> items; |
4682 main() { | 4678 main() { |
4683 process(items); | 4679 process(items); |
4684 } | 4680 } |
4685 | 4681 |
4686 void process(List<T> items) { | 4682 void process(List<T> items) {} |
4687 } | |
4688 } | 4683 } |
4689 '''); | 4684 '''); |
4690 } | 4685 } |
4686 | |
4687 test_undefinedMethod_createQualified_emptyClassBody() async { | |
4688 resolveTestUnit(''' | |
4689 class A {} | |
4690 main() { | |
4691 A.myUndefinedMethod(); | |
4692 } | |
4693 '''); | |
4694 await assertHasFix( | |
4695 DartFixKind.CREATE_METHOD, | |
4696 ''' | |
4697 class A { | |
4698 static void myUndefinedMethod() {} | |
4699 } | |
4700 main() { | |
4701 A.myUndefinedMethod(); | |
4702 } | |
4703 '''); | |
4704 } | |
4691 | 4705 |
4692 test_undefinedMethod_createQualified_fromClass() async { | 4706 test_undefinedMethod_createQualified_fromClass() async { |
4693 resolveTestUnit(''' | 4707 resolveTestUnit(''' |
4694 class A { | 4708 class A { |
4695 } | 4709 } |
4696 main() { | 4710 main() { |
4697 A.myUndefinedMethod(); | 4711 A.myUndefinedMethod(); |
4698 } | 4712 } |
4699 '''); | 4713 '''); |
4700 await assertHasFix( | 4714 await assertHasFix( |
4701 DartFixKind.CREATE_METHOD, | 4715 DartFixKind.CREATE_METHOD, |
4702 ''' | 4716 ''' |
4703 class A { | 4717 class A { |
4704 static void myUndefinedMethod() { | 4718 static void myUndefinedMethod() {} |
4705 } | |
4706 } | 4719 } |
4707 main() { | 4720 main() { |
4708 A.myUndefinedMethod(); | 4721 A.myUndefinedMethod(); |
4709 } | 4722 } |
4710 '''); | 4723 '''); |
4711 } | 4724 } |
4712 | 4725 |
4713 test_undefinedMethod_createQualified_fromClass_hasOtherMember() async { | 4726 test_undefinedMethod_createQualified_fromClass_hasOtherMember() async { |
4714 resolveTestUnit(''' | 4727 resolveTestUnit(''' |
4715 class A { | 4728 class A { |
4716 foo() {} | 4729 foo() {} |
4717 } | 4730 } |
4718 main() { | 4731 main() { |
4719 A.myUndefinedMethod(); | 4732 A.myUndefinedMethod(); |
4720 } | 4733 } |
4721 '''); | 4734 '''); |
4722 await assertHasFix( | 4735 await assertHasFix( |
4723 DartFixKind.CREATE_METHOD, | 4736 DartFixKind.CREATE_METHOD, |
4724 ''' | 4737 ''' |
4725 class A { | 4738 class A { |
4726 foo() {} | 4739 foo() {} |
4727 | 4740 |
4728 static void myUndefinedMethod() { | 4741 static void myUndefinedMethod() {} |
4729 } | |
4730 } | 4742 } |
4731 main() { | 4743 main() { |
4732 A.myUndefinedMethod(); | 4744 A.myUndefinedMethod(); |
4733 } | 4745 } |
4734 '''); | 4746 '''); |
4735 } | 4747 } |
4736 | 4748 |
4737 test_undefinedMethod_createQualified_fromInstance() async { | 4749 test_undefinedMethod_createQualified_fromInstance() async { |
4738 resolveTestUnit(''' | 4750 resolveTestUnit(''' |
4739 class A { | 4751 class A { |
4740 } | 4752 } |
4741 main(A a) { | 4753 main(A a) { |
4742 a.myUndefinedMethod(); | 4754 a.myUndefinedMethod(); |
4743 } | 4755 } |
4744 '''); | 4756 '''); |
4745 await assertHasFix( | 4757 await assertHasFix( |
4746 DartFixKind.CREATE_METHOD, | 4758 DartFixKind.CREATE_METHOD, |
4747 ''' | 4759 ''' |
4748 class A { | 4760 class A { |
4749 void myUndefinedMethod() { | 4761 void myUndefinedMethod() {} |
4750 } | |
4751 } | 4762 } |
4752 main(A a) { | 4763 main(A a) { |
4753 a.myUndefinedMethod(); | 4764 a.myUndefinedMethod(); |
4754 } | 4765 } |
4755 '''); | 4766 '''); |
4756 } | 4767 } |
4757 | 4768 |
4758 test_undefinedMethod_createQualified_targetIsFunctionType() async { | 4769 test_undefinedMethod_createQualified_targetIsFunctionType() async { |
4759 resolveTestUnit(''' | 4770 resolveTestUnit(''' |
4760 typedef A(); | 4771 typedef A(); |
(...skipping 29 matching lines...) Expand all Loading... | |
4790 ''' | 4801 ''' |
4791 class C { | 4802 class C { |
4792 int x; | 4803 int x; |
4793 } | 4804 } |
4794 | 4805 |
4795 class D { | 4806 class D { |
4796 foo(C c1, C c2) { | 4807 foo(C c1, C c2) { |
4797 bar(c1.x, c2.x); | 4808 bar(c1.x, c2.x); |
4798 } | 4809 } |
4799 | 4810 |
4800 void bar(int x, int x2) { | 4811 void bar(int x, int x2) {} |
4801 } | |
4802 }'''); | 4812 }'''); |
4803 } | 4813 } |
4804 | 4814 |
4805 test_undefinedMethod_createUnqualified_parameters() async { | 4815 test_undefinedMethod_createUnqualified_parameters() async { |
4806 resolveTestUnit(''' | 4816 resolveTestUnit(''' |
4807 class A { | 4817 class A { |
4808 main() { | 4818 main() { |
4809 myUndefinedMethod(0, 1.0, '3'); | 4819 myUndefinedMethod(0, 1.0, '3'); |
4810 } | 4820 } |
4811 } | 4821 } |
4812 '''); | 4822 '''); |
4813 await assertHasFix( | 4823 await assertHasFix( |
4814 DartFixKind.CREATE_METHOD, | 4824 DartFixKind.CREATE_METHOD, |
4815 ''' | 4825 ''' |
4816 class A { | 4826 class A { |
4817 main() { | 4827 main() { |
4818 myUndefinedMethod(0, 1.0, '3'); | 4828 myUndefinedMethod(0, 1.0, '3'); |
4819 } | 4829 } |
4820 | 4830 |
4821 void myUndefinedMethod(int i, double d, String s) { | 4831 void myUndefinedMethod(int i, double d, String s) {} |
4822 } | |
4823 } | 4832 } |
4824 '''); | 4833 '''); |
4825 // linked positions | 4834 // linked positions |
4826 int index = 0; | 4835 int index = 0; |
4827 _assertLinkedGroup( | 4836 _assertLinkedGroup( |
4828 change.linkedEditGroups[index++], ['void myUndefinedMethod(']); | 4837 change.linkedEditGroups[index++], ['void myUndefinedMethod(']); |
4829 _assertLinkedGroup(change.linkedEditGroups[index++], | 4838 _assertLinkedGroup(change.linkedEditGroups[index++], |
4830 ['myUndefinedMethod(0', 'myUndefinedMethod(int']); | 4839 ['myUndefinedMethod(0', 'myUndefinedMethod(int']); |
4831 _assertLinkedGroup( | 4840 _assertLinkedGroup( |
4832 change.linkedEditGroups[index++], | 4841 change.linkedEditGroups[index++], |
(...skipping 24 matching lines...) Expand all Loading... | |
4857 } | 4866 } |
4858 '''); | 4867 '''); |
4859 await assertHasFix( | 4868 await assertHasFix( |
4860 DartFixKind.CREATE_METHOD, | 4869 DartFixKind.CREATE_METHOD, |
4861 ''' | 4870 ''' |
4862 class A { | 4871 class A { |
4863 main() { | 4872 main() { |
4864 myUndefinedMethod(0, bbb: 1.0, ccc: '2'); | 4873 myUndefinedMethod(0, bbb: 1.0, ccc: '2'); |
4865 } | 4874 } |
4866 | 4875 |
4867 void myUndefinedMethod(int i, {double bbb, String ccc}) { | 4876 void myUndefinedMethod(int i, {double bbb, String ccc}) {} |
4868 } | |
4869 } | 4877 } |
4870 '''); | 4878 '''); |
4871 // linked positions | 4879 // linked positions |
4872 int index = 0; | 4880 int index = 0; |
4873 _assertLinkedGroup( | 4881 _assertLinkedGroup( |
4874 change.linkedEditGroups[index++], ['void myUndefinedMethod(']); | 4882 change.linkedEditGroups[index++], ['void myUndefinedMethod(']); |
4875 _assertLinkedGroup(change.linkedEditGroups[index++], | 4883 _assertLinkedGroup(change.linkedEditGroups[index++], |
4876 ['myUndefinedMethod(0', 'myUndefinedMethod(int']); | 4884 ['myUndefinedMethod(0', 'myUndefinedMethod(int']); |
4877 _assertLinkedGroup( | 4885 _assertLinkedGroup( |
4878 change.linkedEditGroups[index++], | 4886 change.linkedEditGroups[index++], |
(...skipping 22 matching lines...) Expand all Loading... | |
4901 } | 4909 } |
4902 '''); | 4910 '''); |
4903 await assertHasFix( | 4911 await assertHasFix( |
4904 DartFixKind.CREATE_METHOD, | 4912 DartFixKind.CREATE_METHOD, |
4905 ''' | 4913 ''' |
4906 class A { | 4914 class A { |
4907 main() { | 4915 main() { |
4908 int v = myUndefinedMethod(); | 4916 int v = myUndefinedMethod(); |
4909 } | 4917 } |
4910 | 4918 |
4911 int myUndefinedMethod() { | 4919 int myUndefinedMethod() {} |
4912 } | |
4913 } | 4920 } |
4914 '''); | 4921 '''); |
4915 // linked positions | 4922 // linked positions |
4916 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); | 4923 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); |
4917 _assertLinkedGroup(change.linkedEditGroups[1], | 4924 _assertLinkedGroup(change.linkedEditGroups[1], |
4918 ['myUndefinedMethod();', 'myUndefinedMethod() {']); | 4925 ['myUndefinedMethod();', 'myUndefinedMethod() {']); |
4919 } | 4926 } |
4920 | 4927 |
4921 test_undefinedMethod_createUnqualified_staticFromField() async { | 4928 test_undefinedMethod_createUnqualified_staticFromField() async { |
4922 resolveTestUnit(''' | 4929 resolveTestUnit(''' |
4923 class A { | 4930 class A { |
4924 static var f = myUndefinedMethod(); | 4931 static var f = myUndefinedMethod(); |
4925 } | 4932 } |
4926 '''); | 4933 '''); |
4927 await assertHasFix( | 4934 await assertHasFix( |
4928 DartFixKind.CREATE_METHOD, | 4935 DartFixKind.CREATE_METHOD, |
4929 ''' | 4936 ''' |
4930 class A { | 4937 class A { |
4931 static var f = myUndefinedMethod(); | 4938 static var f = myUndefinedMethod(); |
4932 | 4939 |
4933 static myUndefinedMethod() { | 4940 static myUndefinedMethod() {} |
4934 } | |
4935 } | 4941 } |
4936 '''); | 4942 '''); |
4937 } | 4943 } |
4938 | 4944 |
4939 test_undefinedMethod_createUnqualified_staticFromMethod() async { | 4945 test_undefinedMethod_createUnqualified_staticFromMethod() async { |
4940 resolveTestUnit(''' | 4946 resolveTestUnit(''' |
4941 class A { | 4947 class A { |
4942 static main() { | 4948 static main() { |
4943 myUndefinedMethod(); | 4949 myUndefinedMethod(); |
4944 } | 4950 } |
4945 } | 4951 } |
4946 '''); | 4952 '''); |
4947 await assertHasFix( | 4953 await assertHasFix( |
4948 DartFixKind.CREATE_METHOD, | 4954 DartFixKind.CREATE_METHOD, |
4949 ''' | 4955 ''' |
4950 class A { | 4956 class A { |
4951 static main() { | 4957 static main() { |
4952 myUndefinedMethod(); | 4958 myUndefinedMethod(); |
4953 } | 4959 } |
4954 | 4960 |
4955 static void myUndefinedMethod() { | 4961 static void myUndefinedMethod() {} |
4956 } | |
4957 } | 4962 } |
4958 '''); | 4963 '''); |
4959 } | 4964 } |
4960 | 4965 |
4961 test_undefinedMethod_hint_createQualified_fromInstance() async { | 4966 test_undefinedMethod_hint_createQualified_fromInstance() async { |
4962 resolveTestUnit(''' | 4967 resolveTestUnit(''' |
4963 class A { | 4968 class A { |
4964 } | 4969 } |
4965 main() { | 4970 main() { |
4966 var a = new A(); | 4971 var a = new A(); |
4967 a.myUndefinedMethod(); | 4972 a.myUndefinedMethod(); |
4968 } | 4973 } |
4969 '''); | 4974 '''); |
4970 await assertHasFix( | 4975 await assertHasFix( |
4971 DartFixKind.CREATE_METHOD, | 4976 DartFixKind.CREATE_METHOD, |
4972 ''' | 4977 ''' |
4973 class A { | 4978 class A { |
4974 void myUndefinedMethod() { | 4979 void myUndefinedMethod() {} |
4975 } | |
4976 } | 4980 } |
4977 main() { | 4981 main() { |
4978 var a = new A(); | 4982 var a = new A(); |
4979 a.myUndefinedMethod(); | 4983 a.myUndefinedMethod(); |
4980 } | 4984 } |
4981 '''); | 4985 '''); |
4982 } | 4986 } |
4983 | 4987 |
4984 test_undefinedMethod_parameterType_differentPrefixInTargetUnit() async { | 4988 test_undefinedMethod_parameterType_differentPrefixInTargetUnit() async { |
4985 String code2 = r''' | 4989 String code2 = r''' |
(...skipping 25 matching lines...) Expand all Loading... | |
5011 expect(fileEdits, hasLength(1)); | 5015 expect(fileEdits, hasLength(1)); |
5012 SourceFileEdit fileEdit = change.edits[0]; | 5016 SourceFileEdit fileEdit = change.edits[0]; |
5013 expect(fileEdit.file, '/test2.dart'); | 5017 expect(fileEdit.file, '/test2.dart'); |
5014 expect( | 5018 expect( |
5015 SourceEdit.applySequence(code2, fileEdit.edits), | 5019 SourceEdit.applySequence(code2, fileEdit.edits), |
5016 r''' | 5020 r''' |
5017 library test2; | 5021 library test2; |
5018 import 'test3.dart' as bbb; | 5022 import 'test3.dart' as bbb; |
5019 export 'test3.dart'; | 5023 export 'test3.dart'; |
5020 class D { | 5024 class D { |
5021 void foo(bbb.E e) { | 5025 void foo(bbb.E e) {} |
5022 } | |
5023 } | 5026 } |
5024 '''); | 5027 '''); |
5025 } | 5028 } |
5026 | 5029 |
5027 test_undefinedMethod_parameterType_inTargetUnit() async { | 5030 test_undefinedMethod_parameterType_inTargetUnit() async { |
5028 String code2 = r''' | 5031 String code2 = r''' |
5029 library test2; | 5032 library test2; |
5030 class D { | 5033 class D { |
5031 } | 5034 } |
5032 class E {} | 5035 class E {} |
(...skipping 12 matching lines...) Expand all Loading... | |
5045 // apply to "test2.dart" | 5048 // apply to "test2.dart" |
5046 List<SourceFileEdit> fileEdits = change.edits; | 5049 List<SourceFileEdit> fileEdits = change.edits; |
5047 expect(fileEdits, hasLength(1)); | 5050 expect(fileEdits, hasLength(1)); |
5048 SourceFileEdit fileEdit = change.edits[0]; | 5051 SourceFileEdit fileEdit = change.edits[0]; |
5049 expect(fileEdit.file, '/test2.dart'); | 5052 expect(fileEdit.file, '/test2.dart'); |
5050 expect( | 5053 expect( |
5051 SourceEdit.applySequence(code2, fileEdit.edits), | 5054 SourceEdit.applySequence(code2, fileEdit.edits), |
5052 r''' | 5055 r''' |
5053 library test2; | 5056 library test2; |
5054 class D { | 5057 class D { |
5055 void foo(E e) { | 5058 void foo(E e) {} |
5056 } | |
5057 } | 5059 } |
5058 class E {} | 5060 class E {} |
5059 '''); | 5061 '''); |
5060 } | 5062 } |
5061 | 5063 |
5062 test_undefinedMethod_useSimilar_ignoreOperators() async { | 5064 test_undefinedMethod_useSimilar_ignoreOperators() async { |
5063 resolveTestUnit(''' | 5065 resolveTestUnit(''' |
5064 main(Object object) { | 5066 main(Object object) { |
5065 object.then(); | 5067 object.then(); |
5066 } | 5068 } |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5476 var v = 42; | 5478 var v = 42; |
5477 print('v: $v'); | 5479 print('v: $v'); |
5478 } | 5480 } |
5479 '''); | 5481 '''); |
5480 } | 5482 } |
5481 | 5483 |
5482 void verifyResult(String expectedResult) { | 5484 void verifyResult(String expectedResult) { |
5483 expect(resultCode, expectedResult); | 5485 expect(resultCode, expectedResult); |
5484 } | 5486 } |
5485 } | 5487 } |
OLD | NEW |