Chromium Code Reviews| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 main() { | 280 main() { |
| 281 Test v = null; | 281 Test v = null; |
| 282 } | 282 } |
| 283 | 283 |
| 284 class Test { | 284 class Test { |
| 285 } | 285 } |
| 286 '''); | 286 '''); |
| 287 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); | 287 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void test_createConstructor_forFinalFields() { | |
|
Brian Wilkerson
2015/03/16 13:17:55
Does this handle the case where there is already a
scheglov
2015/03/16 14:55:22
No, not this fix.
I plan to add a separate one for
| |
| 291 errorFilter = (AnalysisError error) { | |
| 292 return error.message.contains("'a'"); | |
| 293 }; | |
| 294 resolveTestUnit(''' | |
| 295 class Test { | |
| 296 final int a; | |
| 297 final int b = 2; | |
| 298 final int c; | |
| 299 } | |
| 300 '''); | |
| 301 assertHasFix(FixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS, ''' | |
| 302 class Test { | |
| 303 final int a; | |
| 304 final int b = 2; | |
| 305 final int c; | |
| 306 | |
| 307 Test(this.a, this.c); | |
| 308 } | |
| 309 '''); | |
| 310 } | |
| 311 | |
| 290 void test_createConstructor_insteadOfSyntheticDefault() { | 312 void test_createConstructor_insteadOfSyntheticDefault() { |
| 291 resolveTestUnit(''' | 313 resolveTestUnit(''' |
| 292 class A { | 314 class A { |
| 293 int field; | 315 int field; |
| 294 | 316 |
| 295 method() {} | 317 method() {} |
| 296 } | 318 } |
| 297 main() { | 319 main() { |
| 298 new A(1, 2.0); | 320 new A(1, 2.0); |
| 299 } | 321 } |
| (...skipping 2667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2967 } | 2989 } |
| 2968 | 2990 |
| 2969 void myUndefinedMethod(int i, double d, String s) { | 2991 void myUndefinedMethod(int i, double d, String s) { |
| 2970 } | 2992 } |
| 2971 } | 2993 } |
| 2972 '''); | 2994 '''); |
| 2973 // linked positions | 2995 // linked positions |
| 2974 int index = 0; | 2996 int index = 0; |
| 2975 _assertLinkedGroup( | 2997 _assertLinkedGroup( |
| 2976 change.linkedEditGroups[index++], ['void myUndefinedMethod(']); | 2998 change.linkedEditGroups[index++], ['void myUndefinedMethod(']); |
| 2977 _assertLinkedGroup(change.linkedEditGroups[index++], | 2999 _assertLinkedGroup(change.linkedEditGroups[index++], [ |
| 2978 ['myUndefinedMethod(0', 'myUndefinedMethod(int']); | 3000 'myUndefinedMethod(0', |
| 3001 'myUndefinedMethod(int' | |
| 3002 ]); | |
| 2979 _assertLinkedGroup(change.linkedEditGroups[index++], [ | 3003 _assertLinkedGroup(change.linkedEditGroups[index++], [ |
| 2980 'int i' | 3004 'int i' |
| 2981 ], expectedSuggestions( | 3005 ], expectedSuggestions( |
| 2982 LinkedEditSuggestionKind.TYPE, ['int', 'num', 'Object', 'Comparable'])); | 3006 LinkedEditSuggestionKind.TYPE, ['int', 'num', 'Object', 'Comparable'])); |
| 2983 _assertLinkedGroup(change.linkedEditGroups[index++], ['i,']); | 3007 _assertLinkedGroup(change.linkedEditGroups[index++], ['i,']); |
| 2984 _assertLinkedGroup(change.linkedEditGroups[index++], [ | 3008 _assertLinkedGroup(change.linkedEditGroups[index++], ['double d'], |
| 2985 'double d' | 3009 expectedSuggestions(LinkedEditSuggestionKind.TYPE, [ |
| 2986 ], expectedSuggestions(LinkedEditSuggestionKind.TYPE, [ | |
| 2987 'double', | 3010 'double', |
| 2988 'num', | 3011 'num', |
| 2989 'Object', | 3012 'Object', |
| 2990 'Comparable' | 3013 'Comparable' |
| 2991 ])); | 3014 ])); |
| 2992 _assertLinkedGroup(change.linkedEditGroups[index++], ['d,']); | 3015 _assertLinkedGroup(change.linkedEditGroups[index++], ['d,']); |
| 2993 _assertLinkedGroup(change.linkedEditGroups[index++], [ | 3016 _assertLinkedGroup(change.linkedEditGroups[index++], ['String s'], |
| 2994 'String s' | 3017 expectedSuggestions( |
| 2995 ], expectedSuggestions( | 3018 LinkedEditSuggestionKind.TYPE, ['String', 'Object', 'Comparable'])); |
| 2996 LinkedEditSuggestionKind.TYPE, ['String', 'Object', 'Comparable'])); | |
| 2997 _assertLinkedGroup(change.linkedEditGroups[index++], ['s)']); | 3019 _assertLinkedGroup(change.linkedEditGroups[index++], ['s)']); |
| 2998 } | 3020 } |
| 2999 | 3021 |
| 3000 void test_undefinedMethod_createUnqualified_returnType() { | 3022 void test_undefinedMethod_createUnqualified_returnType() { |
| 3001 resolveTestUnit(''' | 3023 resolveTestUnit(''' |
| 3002 class A { | 3024 class A { |
| 3003 main() { | 3025 main() { |
| 3004 int v = myUndefinedMethod(); | 3026 int v = myUndefinedMethod(); |
| 3005 } | 3027 } |
| 3006 } | 3028 } |
| 3007 '''); | 3029 '''); |
| 3008 assertHasFix(FixKind.CREATE_METHOD, ''' | 3030 assertHasFix(FixKind.CREATE_METHOD, ''' |
| 3009 class A { | 3031 class A { |
| 3010 main() { | 3032 main() { |
| 3011 int v = myUndefinedMethod(); | 3033 int v = myUndefinedMethod(); |
| 3012 } | 3034 } |
| 3013 | 3035 |
| 3014 int myUndefinedMethod() { | 3036 int myUndefinedMethod() { |
| 3015 } | 3037 } |
| 3016 } | 3038 } |
| 3017 '''); | 3039 '''); |
| 3018 // linked positions | 3040 // linked positions |
| 3019 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); | 3041 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); |
| 3020 _assertLinkedGroup(change.linkedEditGroups[1], | 3042 _assertLinkedGroup(change.linkedEditGroups[1], [ |
| 3021 ['myUndefinedMethod();', 'myUndefinedMethod() {']); | 3043 'myUndefinedMethod();', |
| 3044 'myUndefinedMethod() {' | |
| 3045 ]); | |
| 3022 } | 3046 } |
| 3023 | 3047 |
| 3024 void test_undefinedMethod_createUnqualified_staticFromField() { | 3048 void test_undefinedMethod_createUnqualified_staticFromField() { |
| 3025 resolveTestUnit(''' | 3049 resolveTestUnit(''' |
| 3026 class A { | 3050 class A { |
| 3027 static var f = myUndefinedMethod(); | 3051 static var f = myUndefinedMethod(); |
| 3028 } | 3052 } |
| 3029 '''); | 3053 '''); |
| 3030 assertHasFix(FixKind.CREATE_METHOD, ''' | 3054 assertHasFix(FixKind.CREATE_METHOD, ''' |
| 3031 class A { | 3055 class A { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3240 | 3264 |
| 3241 List<Position> _findResultPositions(List<String> searchStrings) { | 3265 List<Position> _findResultPositions(List<String> searchStrings) { |
| 3242 List<Position> positions = <Position>[]; | 3266 List<Position> positions = <Position>[]; |
| 3243 for (String search in searchStrings) { | 3267 for (String search in searchStrings) { |
| 3244 int offset = resultCode.indexOf(search); | 3268 int offset = resultCode.indexOf(search); |
| 3245 positions.add(new Position(testFile, offset)); | 3269 positions.add(new Position(testFile, offset)); |
| 3246 } | 3270 } |
| 3247 return positions; | 3271 return positions; |
| 3248 } | 3272 } |
| 3249 } | 3273 } |
| OLD | NEW |