Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: pkg/analysis_server/test/services/correction/fix_test.dart

Issue 1024573002: Issue 22886. Quick fixes create getter' and 'create field' for hints. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:analyzer/file_system/file_system.dart'; 9 import 'package:analyzer/file_system/file_system.dart';
10 import 'package:analyzer/source/package_map_resolver.dart'; 10 import 'package:analyzer/source/package_map_resolver.dart';
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 class A { 745 class A {
746 var test; 746 var test;
747 747
748 main() { 748 main() {
749 test; 749 test;
750 } 750 }
751 } 751 }
752 '''); 752 ''');
753 } 753 }
754 754
755 void test_createField_hint() {
756 resolveTestUnit('''
757 class A {
758 }
759 main(A a) {
760 var x = a;
761 int v = x.test;
762 }
763 ''');
764 assertHasFix(FixKind.CREATE_FIELD, '''
765 class A {
766 int test;
767 }
768 main(A a) {
769 var x = a;
770 int v = x.test;
771 }
772 ''');
773 }
774
775 void test_createField_hint_setter() {
776 resolveTestUnit('''
777 class A {
778 }
779 main(A a) {
780 var x = a;
781 x.test = 0;
782 }
783 ''');
784 assertHasFix(FixKind.CREATE_FIELD, '''
785 class A {
786 int test;
787 }
788 main(A a) {
789 var x = a;
790 x.test = 0;
791 }
792 ''');
793 }
794
755 void test_createField_importType() { 795 void test_createField_importType() {
756 addSource('/libA.dart', r''' 796 addSource('/libA.dart', r'''
757 library libA; 797 library libA;
758 class A {} 798 class A {}
759 '''); 799 ''');
760 addSource('/libB.dart', r''' 800 addSource('/libB.dart', r'''
761 library libB; 801 library libB;
762 import 'libA.dart'; 802 import 'libA.dart';
763 A getA() => null; 803 A getA() => null;
764 '''); 804 ''');
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 1010
971 void test_createGetter_BAD_inSDK() { 1011 void test_createGetter_BAD_inSDK() {
972 resolveTestUnit(''' 1012 resolveTestUnit('''
973 main(List p) { 1013 main(List p) {
974 int v = p.foo; 1014 int v = p.foo;
975 } 1015 }
976 '''); 1016 ''');
977 assertNoFix(FixKind.CREATE_GETTER); 1017 assertNoFix(FixKind.CREATE_GETTER);
978 } 1018 }
979 1019
1020 void test_createGetter_hint_getter() {
1021 resolveTestUnit('''
1022 class A {
1023 }
1024 main(A a) {
1025 var x = a;
1026 int v = x.test;
1027 }
1028 ''');
1029 assertHasFix(FixKind.CREATE_GETTER, '''
1030 class A {
1031 int get test => null;
1032 }
1033 main(A a) {
1034 var x = a;
1035 int v = x.test;
1036 }
1037 ''');
1038 }
1039
980 void test_createGetter_multiLevel() { 1040 void test_createGetter_multiLevel() {
981 resolveTestUnit(''' 1041 resolveTestUnit('''
982 class A { 1042 class A {
983 } 1043 }
984 class B { 1044 class B {
985 A a; 1045 A a;
986 } 1046 }
987 class C { 1047 class C {
988 B b; 1048 B b;
989 } 1049 }
(...skipping 1821 matching lines...) Expand 10 before | Expand all | Expand 10 after
2811 } 2871 }
2812 '''); 2872 ''');
2813 assertHasFix(FixKind.CHANGE_TO, ''' 2873 assertHasFix(FixKind.CHANGE_TO, '''
2814 myFunction() {} 2874 myFunction() {}
2815 main() { 2875 main() {
2816 myFunction(); 2876 myFunction();
2817 } 2877 }
2818 '''); 2878 ''');
2819 } 2879 }
2820 2880
2881 void test_undefinedGetter_useSimilar_hint() {
2882 resolveTestUnit('''
2883 class A {
2884 int myField;
2885 }
2886 main(A a) {
2887 var x = a;
2888 print(x.myFild);
2889 }
2890 ''');
2891 assertHasFix(FixKind.CHANGE_TO, '''
2892 class A {
2893 int myField;
2894 }
2895 main(A a) {
2896 var x = a;
2897 print(x.myField);
2898 }
2899 ''');
2900 }
2901
2821 void test_undefinedGetter_useSimilar_qualified() { 2902 void test_undefinedGetter_useSimilar_qualified() {
2822 resolveTestUnit(''' 2903 resolveTestUnit('''
2823 class A { 2904 class A {
2824 int myField; 2905 int myField;
2825 } 2906 }
2826 main(A a) { 2907 main(A a) {
2827 print(a.myFild); 2908 print(a.myFild);
2828 } 2909 }
2829 '''); 2910 ''');
2830 assertHasFix(FixKind.CHANGE_TO, ''' 2911 assertHasFix(FixKind.CHANGE_TO, '''
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
3236 assertHasFix(FixKind.CHANGE_TO, ''' 3317 assertHasFix(FixKind.CHANGE_TO, '''
3237 class A { 3318 class A {
3238 myMethod() {} 3319 myMethod() {}
3239 main() { 3320 main() {
3240 myMethod(); 3321 myMethod();
3241 } 3322 }
3242 } 3323 }
3243 '''); 3324 ''');
3244 } 3325 }
3245 3326
3327 void test_undefinedSetter_useSimilar_hint() {
3328 resolveTestUnit('''
3329 class A {
3330 int myField;
3331 }
3332 main(A a) {
3333 var x = a;
3334 x.myFild = 42;
3335 }
3336 ''');
3337 assertHasFix(FixKind.CHANGE_TO, '''
3338 class A {
3339 int myField;
3340 }
3341 main(A a) {
3342 var x = a;
3343 x.myField = 42;
3344 }
3345 ''');
3346 }
3347
3348 void test_undefinedSetter_useSimilar_qualified() {
3349 resolveTestUnit('''
3350 class A {
3351 int myField;
3352 }
3353 main(A a) {
3354 a.myFild = 42;
3355 }
3356 ''');
3357 assertHasFix(FixKind.CHANGE_TO, '''
3358 class A {
3359 int myField;
3360 }
3361 main(A a) {
3362 a.myField = 42;
3363 }
3364 ''');
3365 }
3366
3246 void test_undefinedSetter_useSimilar_unqualified() { 3367 void test_undefinedSetter_useSimilar_unqualified() {
3247 resolveTestUnit(''' 3368 resolveTestUnit('''
3248 class A { 3369 class A {
3249 int myField; 3370 int myField;
3250 main() { 3371 main() {
3251 myFild = 42; 3372 myFild = 42;
3252 } 3373 }
3253 } 3374 }
3254 '''); 3375 ''');
3255 assertHasFix(FixKind.CHANGE_TO, ''' 3376 assertHasFix(FixKind.CHANGE_TO, '''
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3333 3454
3334 List<Position> _findResultPositions(List<String> searchStrings) { 3455 List<Position> _findResultPositions(List<String> searchStrings) {
3335 List<Position> positions = <Position>[]; 3456 List<Position> positions = <Position>[];
3336 for (String search in searchStrings) { 3457 for (String search in searchStrings) {
3337 int offset = resultCode.indexOf(search); 3458 int offset = resultCode.indexOf(search);
3338 positions.add(new Position(testFile, offset)); 3459 positions.add(new Position(testFile, offset));
3339 } 3460 }
3340 return positions; 3461 return positions;
3341 } 3462 }
3342 } 3463 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698