| 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 'package:analysis_server/src/protocol.dart' hide AnalysisError; | 7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; |
| 8 import 'package:analysis_server/src/services/correction/fix.dart'; | 8 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 9 import 'package:analysis_server/src/services/index/index.dart'; | 9 import 'package:analysis_server/src/services/index/index.dart'; |
| 10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; | 10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 String test; | 481 String test; |
| 482 | 482 |
| 483 main() { | 483 main() { |
| 484 f(test); | 484 f(test); |
| 485 } | 485 } |
| 486 } | 486 } |
| 487 f(String s) {} | 487 f(String s) {} |
| 488 '''); | 488 '''); |
| 489 } | 489 } |
| 490 | 490 |
| 491 void test_createField_getter_unqualified_instance_assignmentLhs() { | 491 void test_createField_getter_unqualified_instance_assignmentRhs() { |
| 492 _indexTestUnit(''' | 492 _indexTestUnit(''' |
| 493 class A { | 493 class A { |
| 494 main() { | 494 main() { |
| 495 int v = test; | 495 int v = test; |
| 496 } | 496 } |
| 497 } | 497 } |
| 498 '''); | 498 '''); |
| 499 assertHasFix(FixKind.CREATE_FIELD, ''' | 499 assertHasFix(FixKind.CREATE_FIELD, ''' |
| 500 class A { | 500 class A { |
| 501 int test; | 501 int test; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 change = fix.change; | 687 change = fix.change; |
| 688 // validate change | 688 // validate change |
| 689 List<SourceFileEdit> fileEdits = change.edits; | 689 List<SourceFileEdit> fileEdits = change.edits; |
| 690 expect(fileEdits, hasLength(1)); | 690 expect(fileEdits, hasLength(1)); |
| 691 SourceFileEdit fileEdit = change.edits[0]; | 691 SourceFileEdit fileEdit = change.edits[0]; |
| 692 expect(fileEdit.file, '/my/project/bin/my_file.dart'); | 692 expect(fileEdit.file, '/my/project/bin/my_file.dart'); |
| 693 expect(fileEdit.fileStamp, -1); | 693 expect(fileEdit.fileStamp, -1); |
| 694 expect(fileEdit.edits[0].replacement, contains('library my.file;')); | 694 expect(fileEdit.edits[0].replacement, contains('library my.file;')); |
| 695 } | 695 } |
| 696 | 696 |
| 697 void test_createGetter_multiLevel() { |
| 698 _indexTestUnit(''' |
| 699 class A { |
| 700 } |
| 701 class B { |
| 702 A a; |
| 703 } |
| 704 class C { |
| 705 B b; |
| 706 } |
| 707 main(C c) { |
| 708 int v = c.b.a.test; |
| 709 } |
| 710 '''); |
| 711 assertHasFix(FixKind.CREATE_GETTER, ''' |
| 712 class A { |
| 713 int get test => null; |
| 714 } |
| 715 class B { |
| 716 A a; |
| 717 } |
| 718 class C { |
| 719 B b; |
| 720 } |
| 721 main(C c) { |
| 722 int v = c.b.a.test; |
| 723 } |
| 724 '''); |
| 725 } |
| 726 |
| 727 void test_createGetter_qualified_instance() { |
| 728 _indexTestUnit(''' |
| 729 class A { |
| 730 } |
| 731 main(A a) { |
| 732 int v = a.test; |
| 733 } |
| 734 '''); |
| 735 assertHasFix(FixKind.CREATE_GETTER, ''' |
| 736 class A { |
| 737 int get test => null; |
| 738 } |
| 739 main(A a) { |
| 740 int v = a.test; |
| 741 } |
| 742 '''); |
| 743 } |
| 744 |
| 745 void test_createGetter_qualified_instance_dynamicType() { |
| 746 _indexTestUnit(''' |
| 747 class A { |
| 748 B b; |
| 749 void f(Object p) { |
| 750 p == b.test; |
| 751 } |
| 752 } |
| 753 class B { |
| 754 } |
| 755 '''); |
| 756 assertHasFix(FixKind.CREATE_GETTER, ''' |
| 757 class A { |
| 758 B b; |
| 759 void f(Object p) { |
| 760 p == b.test; |
| 761 } |
| 762 } |
| 763 class B { |
| 764 get test => null; |
| 765 } |
| 766 '''); |
| 767 } |
| 768 |
| 769 void test_createGetter_setterContext() { |
| 770 _indexTestUnit(''' |
| 771 class A { |
| 772 } |
| 773 main(A a) { |
| 774 a.test = 42; |
| 775 } |
| 776 '''); |
| 777 assertNoFix(FixKind.CREATE_GETTER); |
| 778 } |
| 779 |
| 780 void test_createGetter_unqualified_instance_asInvocationArgument() { |
| 781 _indexTestUnit(''' |
| 782 class A { |
| 783 main() { |
| 784 f(test); |
| 785 } |
| 786 } |
| 787 f(String s) {} |
| 788 '''); |
| 789 assertHasFix(FixKind.CREATE_GETTER, ''' |
| 790 class A { |
| 791 String get test => null; |
| 792 |
| 793 main() { |
| 794 f(test); |
| 795 } |
| 796 } |
| 797 f(String s) {} |
| 798 '''); |
| 799 } |
| 800 |
| 801 void test_createGetter_unqualified_instance_assignmentLhs() { |
| 802 _indexTestUnit(''' |
| 803 class A { |
| 804 main() { |
| 805 test = 42; |
| 806 } |
| 807 } |
| 808 '''); |
| 809 assertNoFix(FixKind.CREATE_GETTER); |
| 810 } |
| 811 |
| 812 void test_createGetter_unqualified_instance_assignmentRhs() { |
| 813 _indexTestUnit(''' |
| 814 class A { |
| 815 main() { |
| 816 int v = test; |
| 817 } |
| 818 } |
| 819 '''); |
| 820 assertHasFix(FixKind.CREATE_GETTER, ''' |
| 821 class A { |
| 822 int get test => null; |
| 823 |
| 824 main() { |
| 825 int v = test; |
| 826 } |
| 827 } |
| 828 '''); |
| 829 } |
| 830 |
| 831 void test_createGetter_unqualified_instance_asStatement() { |
| 832 _indexTestUnit(''' |
| 833 class A { |
| 834 main() { |
| 835 test; |
| 836 } |
| 837 } |
| 838 '''); |
| 839 // TODO |
| 840 assertHasFix(FixKind.CREATE_GETTER, ''' |
| 841 class A { |
| 842 get test => null; |
| 843 |
| 844 main() { |
| 845 test; |
| 846 } |
| 847 } |
| 848 '''); |
| 849 } |
| 850 |
| 697 void test_createLocalVariable_read_typeAssignment() { | 851 void test_createLocalVariable_read_typeAssignment() { |
| 698 _indexTestUnit(''' | 852 _indexTestUnit(''' |
| 699 main() { | 853 main() { |
| 700 int a = test; | 854 int a = test; |
| 701 } | 855 } |
| 702 '''); | 856 '''); |
| 703 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' | 857 assertHasFix(FixKind.CREATE_LOCAL_VARIABLE, ''' |
| 704 main() { | 858 main() { |
| 705 int test; | 859 int test; |
| 706 int a = test; | 860 int a = test; |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 } | 1243 } |
| 1090 | 1244 |
| 1091 class B extends A { | 1245 class B extends A { |
| 1092 existing() {} | 1246 existing() {} |
| 1093 | 1247 |
| 1094 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1248 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 1095 } | 1249 } |
| 1096 '''); | 1250 '''); |
| 1097 } | 1251 } |
| 1098 | 1252 |
| 1253 void test_creatGetter_location_afterLastGetter() { |
| 1254 _indexTestUnit(''' |
| 1255 class A { |
| 1256 int existingField; |
| 1257 |
| 1258 int get existingGetter => null; |
| 1259 |
| 1260 existingMethod() {} |
| 1261 } |
| 1262 main(A a) { |
| 1263 int v = a.test; |
| 1264 } |
| 1265 '''); |
| 1266 assertHasFix(FixKind.CREATE_GETTER, ''' |
| 1267 class A { |
| 1268 int existingField; |
| 1269 |
| 1270 int get existingGetter => null; |
| 1271 |
| 1272 int get test => null; |
| 1273 |
| 1274 existingMethod() {} |
| 1275 } |
| 1276 main(A a) { |
| 1277 int v = a.test; |
| 1278 } |
| 1279 '''); |
| 1280 } |
| 1281 |
| 1099 void test_creationFunction_forFunctionType_cascadeSecond() { | 1282 void test_creationFunction_forFunctionType_cascadeSecond() { |
| 1100 _indexTestUnit(''' | 1283 _indexTestUnit(''' |
| 1101 class A { | 1284 class A { |
| 1102 B ma() => null; | 1285 B ma() => null; |
| 1103 } | 1286 } |
| 1104 class B { | 1287 class B { |
| 1105 useFunction(int g(double a, String b)) {} | 1288 useFunction(int g(double a, String b)) {} |
| 1106 } | 1289 } |
| 1107 | 1290 |
| 1108 main() { | 1291 main() { |
| (...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2544 positions.add(new Position(testFile, offset)); | 2727 positions.add(new Position(testFile, offset)); |
| 2545 } | 2728 } |
| 2546 return positions; | 2729 return positions; |
| 2547 } | 2730 } |
| 2548 | 2731 |
| 2549 void _indexTestUnit(String code) { | 2732 void _indexTestUnit(String code) { |
| 2550 resolveTestUnit(code); | 2733 resolveTestUnit(code); |
| 2551 index.indexUnit(context, testUnit); | 2734 index.indexUnit(context, testUnit); |
| 2552 } | 2735 } |
| 2553 } | 2736 } |
| OLD | NEW |