| 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: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 2691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2702 } | 2702 } |
| 2703 '''); | 2703 '''); |
| 2704 assertHasFix(FixKind.CHANGE_TO, ''' | 2704 assertHasFix(FixKind.CHANGE_TO, ''' |
| 2705 myFunction() {} | 2705 myFunction() {} |
| 2706 main() { | 2706 main() { |
| 2707 myFunction(); | 2707 myFunction(); |
| 2708 } | 2708 } |
| 2709 '''); | 2709 '''); |
| 2710 } | 2710 } |
| 2711 | 2711 |
| 2712 void test_undefinedGetter_useSimilar_qualified() { |
| 2713 resolveTestUnit(''' |
| 2714 class A { |
| 2715 int myField; |
| 2716 } |
| 2717 main(A a) { |
| 2718 print(a.myFild); |
| 2719 } |
| 2720 '''); |
| 2721 assertHasFix(FixKind.CHANGE_TO, ''' |
| 2722 class A { |
| 2723 int myField; |
| 2724 } |
| 2725 main(A a) { |
| 2726 print(a.myField); |
| 2727 } |
| 2728 '''); |
| 2729 } |
| 2730 |
| 2731 void test_undefinedGetter_useSimilar_qualified_static() { |
| 2732 resolveTestUnit(''' |
| 2733 class A { |
| 2734 static int MY_NAME = 1; |
| 2735 } |
| 2736 main() { |
| 2737 A.MY_NAM; |
| 2738 } |
| 2739 '''); |
| 2740 assertHasFix(FixKind.CHANGE_TO, ''' |
| 2741 class A { |
| 2742 static int MY_NAME = 1; |
| 2743 } |
| 2744 main() { |
| 2745 A.MY_NAME; |
| 2746 } |
| 2747 '''); |
| 2748 } |
| 2749 |
| 2750 void test_undefinedGetter_useSimilar_unqualified() { |
| 2751 resolveTestUnit(''' |
| 2752 class A { |
| 2753 int myField; |
| 2754 main() { |
| 2755 print(myFild); |
| 2756 } |
| 2757 } |
| 2758 '''); |
| 2759 assertHasFix(FixKind.CHANGE_TO, ''' |
| 2760 class A { |
| 2761 int myField; |
| 2762 main() { |
| 2763 print(myField); |
| 2764 } |
| 2765 } |
| 2766 '''); |
| 2767 } |
| 2768 |
| 2712 void test_undefinedMethod_create_BAD_inSDK() { | 2769 void test_undefinedMethod_create_BAD_inSDK() { |
| 2713 resolveTestUnit(''' | 2770 resolveTestUnit(''' |
| 2714 main() { | 2771 main() { |
| 2715 List.foo(); | 2772 List.foo(); |
| 2716 } | 2773 } |
| 2717 '''); | 2774 '''); |
| 2718 assertNoFix(FixKind.CREATE_METHOD); | 2775 assertNoFix(FixKind.CREATE_METHOD); |
| 2719 } | 2776 } |
| 2720 | 2777 |
| 2721 void test_undefinedMethod_create_generic_BAD() { | 2778 void test_undefinedMethod_create_generic_BAD() { |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3068 assertHasFix(FixKind.CHANGE_TO, ''' | 3125 assertHasFix(FixKind.CHANGE_TO, ''' |
| 3069 class A { | 3126 class A { |
| 3070 myMethod() {} | 3127 myMethod() {} |
| 3071 main() { | 3128 main() { |
| 3072 myMethod(); | 3129 myMethod(); |
| 3073 } | 3130 } |
| 3074 } | 3131 } |
| 3075 '''); | 3132 '''); |
| 3076 } | 3133 } |
| 3077 | 3134 |
| 3135 void test_undefinedSetter_useSimilar_unqualified() { |
| 3136 resolveTestUnit(''' |
| 3137 class A { |
| 3138 int myField; |
| 3139 main() { |
| 3140 myFild = 42; |
| 3141 } |
| 3142 } |
| 3143 '''); |
| 3144 assertHasFix(FixKind.CHANGE_TO, ''' |
| 3145 class A { |
| 3146 int myField; |
| 3147 main() { |
| 3148 myField = 42; |
| 3149 } |
| 3150 } |
| 3151 '''); |
| 3152 } |
| 3153 |
| 3078 void test_useEffectiveIntegerDivision() { | 3154 void test_useEffectiveIntegerDivision() { |
| 3079 resolveTestUnit(''' | 3155 resolveTestUnit(''' |
| 3080 main() { | 3156 main() { |
| 3081 var a = 5; | 3157 var a = 5; |
| 3082 var b = 2; | 3158 var b = 2; |
| 3083 print((a / b).toInt()); | 3159 print((a / b).toInt()); |
| 3084 } | 3160 } |
| 3085 '''); | 3161 '''); |
| 3086 assertHasFix(FixKind.USE_EFFECTIVE_INTEGER_DIVISION, ''' | 3162 assertHasFix(FixKind.USE_EFFECTIVE_INTEGER_DIVISION, ''' |
| 3087 main() { | 3163 main() { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3146 | 3222 |
| 3147 List<Position> _findResultPositions(List<String> searchStrings) { | 3223 List<Position> _findResultPositions(List<String> searchStrings) { |
| 3148 List<Position> positions = <Position>[]; | 3224 List<Position> positions = <Position>[]; |
| 3149 for (String search in searchStrings) { | 3225 for (String search in searchStrings) { |
| 3150 int offset = resultCode.indexOf(search); | 3226 int offset = resultCode.indexOf(search); |
| 3151 positions.add(new Position(testFile, offset)); | 3227 positions.add(new Position(testFile, offset)); |
| 3152 } | 3228 } |
| 3153 return positions; | 3229 return positions; |
| 3154 } | 3230 } |
| 3155 } | 3231 } |
| OLD | NEW |