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.edit.refactoring; | 5 library test.edit.refactoring; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/protocol/protocol.dart'; | 9 import 'package:analysis_server/protocol/protocol.dart'; |
10 import 'package:analysis_server/protocol/protocol_generated.dart'; | 10 import 'package:analysis_server/protocol/protocol_generated.dart'; |
(...skipping 16 matching lines...) Expand all Loading... |
27 defineReflectiveTests(GetAvailableRefactoringsTest); | 27 defineReflectiveTests(GetAvailableRefactoringsTest); |
28 defineReflectiveTests(InlineLocalTest); | 28 defineReflectiveTests(InlineLocalTest); |
29 defineReflectiveTests(InlineMethodTest); | 29 defineReflectiveTests(InlineMethodTest); |
30 defineReflectiveTests(MoveFileTest); | 30 defineReflectiveTests(MoveFileTest); |
31 defineReflectiveTests(RenameTest); | 31 defineReflectiveTests(RenameTest); |
32 }); | 32 }); |
33 } | 33 } |
34 | 34 |
35 @reflectiveTest | 35 @reflectiveTest |
36 class ConvertGetterMethodToMethodTest extends _AbstractGetRefactoring_Test { | 36 class ConvertGetterMethodToMethodTest extends _AbstractGetRefactoring_Test { |
37 @override | |
38 void setUp() { | |
39 enableNewAnalysisDriver = true; | |
40 super.setUp(); | |
41 } | |
42 | |
43 test_function() { | 37 test_function() { |
44 addTestFile(''' | 38 addTestFile(''' |
45 int get test => 42; | 39 int get test => 42; |
46 main() { | 40 main() { |
47 var a = 1 + test; | 41 var a = 1 + test; |
48 var b = 2 + test; | 42 var b = 2 + test; |
49 } | 43 } |
50 '''); | 44 '''); |
51 return assertSuccessfulRefactoring(() { | 45 return assertSuccessfulRefactoring(() { |
52 return _sendConvertRequest('test =>'); | 46 return _sendConvertRequest('test =>'); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 findOffset(search), | 124 findOffset(search), |
131 0, | 125 0, |
132 false) | 126 false) |
133 .toRequest('0'); | 127 .toRequest('0'); |
134 return serverChannel.sendRequest(request); | 128 return serverChannel.sendRequest(request); |
135 } | 129 } |
136 } | 130 } |
137 | 131 |
138 @reflectiveTest | 132 @reflectiveTest |
139 class ConvertMethodToGetterTest extends _AbstractGetRefactoring_Test { | 133 class ConvertMethodToGetterTest extends _AbstractGetRefactoring_Test { |
140 @override | |
141 void setUp() { | |
142 enableNewAnalysisDriver = true; | |
143 super.setUp(); | |
144 } | |
145 | |
146 test_function() { | 134 test_function() { |
147 addTestFile(''' | 135 addTestFile(''' |
148 int test() => 42; | 136 int test() => 42; |
149 main() { | 137 main() { |
150 var a = 1 + test(); | 138 var a = 1 + test(); |
151 var b = 2 + test(); | 139 var b = 2 + test(); |
152 } | 140 } |
153 '''); | 141 '''); |
154 return assertSuccessfulRefactoring(() { | 142 return assertSuccessfulRefactoring(() { |
155 return _sendConvertRequest('test() =>'); | 143 return _sendConvertRequest('test() =>'); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 findOffset(search), | 238 findOffset(search), |
251 0, | 239 0, |
252 false) | 240 false) |
253 .toRequest('0'); | 241 .toRequest('0'); |
254 return serverChannel.sendRequest(request); | 242 return serverChannel.sendRequest(request); |
255 } | 243 } |
256 } | 244 } |
257 | 245 |
258 @reflectiveTest | 246 @reflectiveTest |
259 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test { | 247 class ExtractLocalVariableTest extends _AbstractGetRefactoring_Test { |
| 248 @override |
| 249 bool get enableNewAnalysisDriver => false; |
| 250 |
260 Future<Response> sendExtractRequest( | 251 Future<Response> sendExtractRequest( |
261 int offset, int length, String name, bool extractAll) { | 252 int offset, int length, String name, bool extractAll) { |
262 RefactoringKind kind = RefactoringKind.EXTRACT_LOCAL_VARIABLE; | 253 RefactoringKind kind = RefactoringKind.EXTRACT_LOCAL_VARIABLE; |
263 ExtractLocalVariableOptions options = | 254 ExtractLocalVariableOptions options = |
264 name != null ? new ExtractLocalVariableOptions(name, extractAll) : null; | 255 name != null ? new ExtractLocalVariableOptions(name, extractAll) : null; |
265 return sendRequest(kind, offset, length, options, false); | 256 return sendRequest(kind, offset, length, options, false); |
266 } | 257 } |
267 | 258 |
268 Future<Response> sendStringRequest( | 259 Future<Response> sendStringRequest( |
269 String search, String name, bool extractAll) { | 260 String search, String name, bool extractAll) { |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 } | 509 } |
519 } | 510 } |
520 | 511 |
521 @reflectiveTest | 512 @reflectiveTest |
522 class ExtractMethodTest extends _AbstractGetRefactoring_Test { | 513 class ExtractMethodTest extends _AbstractGetRefactoring_Test { |
523 int offset; | 514 int offset; |
524 int length; | 515 int length; |
525 String name = 'res'; | 516 String name = 'res'; |
526 ExtractMethodOptions options; | 517 ExtractMethodOptions options; |
527 | 518 |
528 @override | |
529 void setUp() { | |
530 enableNewAnalysisDriver = true; | |
531 super.setUp(); | |
532 } | |
533 | |
534 test_expression() { | 519 test_expression() { |
535 addTestFile(''' | 520 addTestFile(''' |
536 main() { | 521 main() { |
537 print(1 + 2); | 522 print(1 + 2); |
538 print(1 + 2); | 523 print(1 + 2); |
539 } | 524 } |
540 '''); | 525 '''); |
541 _setOffsetLengthForString('1 + 2'); | 526 _setOffsetLengthForString('1 + 2'); |
542 return assertSuccessfulRefactoring( | 527 return assertSuccessfulRefactoring( |
543 _computeChange, | 528 _computeChange, |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 return getRefactorings(offset, 0); | 776 return getRefactorings(offset, 0); |
792 } | 777 } |
793 | 778 |
794 Future getRefactoringsForString(String search) { | 779 Future getRefactoringsForString(String search) { |
795 int offset = findOffset(search); | 780 int offset = findOffset(search); |
796 return getRefactorings(offset, search.length); | 781 return getRefactorings(offset, search.length); |
797 } | 782 } |
798 | 783 |
799 @override | 784 @override |
800 void setUp() { | 785 void setUp() { |
801 enableNewAnalysisDriver = true; | |
802 super.setUp(); | 786 super.setUp(); |
803 createProject(); | 787 createProject(); |
804 ExtensionManager manager = new ExtensionManager(); | 788 ExtensionManager manager = new ExtensionManager(); |
805 manager.processPlugins([server.serverPlugin]); | 789 manager.processPlugins([server.serverPlugin]); |
806 handler = new EditDomainHandler(server); | 790 handler = new EditDomainHandler(server); |
807 server.handlers = [handler]; | 791 server.handlers = [handler]; |
808 } | 792 } |
809 | 793 |
810 Future test_convertMethodToGetter_hasElement() { | 794 Future test_convertMethodToGetter_hasElement() { |
811 return assertHasKind( | 795 return assertHasKind( |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 } | 947 } |
964 '''); | 948 '''); |
965 await waitForTasksFinished(); | 949 await waitForTasksFinished(); |
966 await getRefactoringsAtString('// not an element'); | 950 await getRefactoringsAtString('// not an element'); |
967 expect(kinds, isNot(contains(RefactoringKind.RENAME))); | 951 expect(kinds, isNot(contains(RefactoringKind.RENAME))); |
968 } | 952 } |
969 } | 953 } |
970 | 954 |
971 @reflectiveTest | 955 @reflectiveTest |
972 class InlineLocalTest extends _AbstractGetRefactoring_Test { | 956 class InlineLocalTest extends _AbstractGetRefactoring_Test { |
| 957 @override |
| 958 bool get enableNewAnalysisDriver => false; |
| 959 |
973 test_analysis_onlyOneFile() async { | 960 test_analysis_onlyOneFile() async { |
974 shouldWaitForFullAnalysis = false; | 961 shouldWaitForFullAnalysis = false; |
975 String otherFile = '$testFolder/other.dart'; | 962 String otherFile = '$testFolder/other.dart'; |
976 addFile( | 963 addFile( |
977 otherFile, | 964 otherFile, |
978 r''' | 965 r''' |
979 foo(int p) {} | 966 foo(int p) {} |
980 '''); | 967 '''); |
981 addTestFile(''' | 968 addTestFile(''' |
982 import 'other.dart'; | 969 import 'other.dart'; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 false) | 1073 false) |
1087 .toRequest('0'); | 1074 .toRequest('0'); |
1088 return serverChannel.sendRequest(request); | 1075 return serverChannel.sendRequest(request); |
1089 } | 1076 } |
1090 } | 1077 } |
1091 | 1078 |
1092 @reflectiveTest | 1079 @reflectiveTest |
1093 class InlineMethodTest extends _AbstractGetRefactoring_Test { | 1080 class InlineMethodTest extends _AbstractGetRefactoring_Test { |
1094 InlineMethodOptions options = new InlineMethodOptions(true, true); | 1081 InlineMethodOptions options = new InlineMethodOptions(true, true); |
1095 | 1082 |
1096 @override | |
1097 void setUp() { | |
1098 enableNewAnalysisDriver = true; | |
1099 super.setUp(); | |
1100 } | |
1101 | |
1102 test_feedback() { | 1083 test_feedback() { |
1103 addTestFile(''' | 1084 addTestFile(''' |
1104 class A { | 1085 class A { |
1105 int f; | 1086 int f; |
1106 test(int p) { | 1087 test(int p) { |
1107 print(f + p); | 1088 print(f + p); |
1108 } | 1089 } |
1109 main() { | 1090 main() { |
1110 test(1); | 1091 test(1); |
1111 } | 1092 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 options: options) | 1202 options: options) |
1222 .toRequest('0'); | 1203 .toRequest('0'); |
1223 return serverChannel.sendRequest(request); | 1204 return serverChannel.sendRequest(request); |
1224 } | 1205 } |
1225 } | 1206 } |
1226 | 1207 |
1227 @reflectiveTest | 1208 @reflectiveTest |
1228 class MoveFileTest extends _AbstractGetRefactoring_Test { | 1209 class MoveFileTest extends _AbstractGetRefactoring_Test { |
1229 MoveFileOptions options; | 1210 MoveFileOptions options; |
1230 | 1211 |
| 1212 @override |
| 1213 bool get enableNewAnalysisDriver => false; |
| 1214 |
1231 test_OK() { | 1215 test_OK() { |
1232 resourceProvider.newFile('/project/bin/lib.dart', ''); | 1216 resourceProvider.newFile('/project/bin/lib.dart', ''); |
1233 addTestFile(''' | 1217 addTestFile(''' |
1234 import 'dart:math'; | 1218 import 'dart:math'; |
1235 import 'lib.dart'; | 1219 import 'lib.dart'; |
1236 '''); | 1220 '''); |
1237 _setOptions('/project/test.dart'); | 1221 _setOptions('/project/test.dart'); |
1238 return assertSuccessfulRefactoring(() { | 1222 return assertSuccessfulRefactoring(() { |
1239 return _sendMoveRequest(); | 1223 return _sendMoveRequest(); |
1240 }, | 1224 }, |
(...skipping 11 matching lines...) Expand all Loading... |
1252 return serverChannel.sendRequest(request); | 1236 return serverChannel.sendRequest(request); |
1253 } | 1237 } |
1254 | 1238 |
1255 void _setOptions(String newFile) { | 1239 void _setOptions(String newFile) { |
1256 options = new MoveFileOptions(newFile); | 1240 options = new MoveFileOptions(newFile); |
1257 } | 1241 } |
1258 } | 1242 } |
1259 | 1243 |
1260 @reflectiveTest | 1244 @reflectiveTest |
1261 class RenameTest extends _AbstractGetRefactoring_Test { | 1245 class RenameTest extends _AbstractGetRefactoring_Test { |
| 1246 @override |
| 1247 bool get enableNewAnalysisDriver => false; |
| 1248 |
1262 Future<Response> sendRenameRequest(String search, String newName, | 1249 Future<Response> sendRenameRequest(String search, String newName, |
1263 {String id: '0', bool validateOnly: false}) { | 1250 {String id: '0', bool validateOnly: false}) { |
1264 RenameOptions options = newName != null ? new RenameOptions(newName) : null; | 1251 RenameOptions options = newName != null ? new RenameOptions(newName) : null; |
1265 Request request = new EditGetRefactoringParams(RefactoringKind.RENAME, | 1252 Request request = new EditGetRefactoringParams(RefactoringKind.RENAME, |
1266 testFile, findOffset(search), 0, validateOnly, | 1253 testFile, findOffset(search), 0, validateOnly, |
1267 options: options) | 1254 options: options) |
1268 .toRequest(id); | 1255 .toRequest(id); |
1269 return serverChannel.sendRequest(request); | 1256 return serverChannel.sendRequest(request); |
1270 } | 1257 } |
1271 | 1258 |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2050 @override | 2037 @override |
2051 void setUp() { | 2038 void setUp() { |
2052 super.setUp(); | 2039 super.setUp(); |
2053 createProject(); | 2040 createProject(); |
2054 ExtensionManager manager = new ExtensionManager(); | 2041 ExtensionManager manager = new ExtensionManager(); |
2055 manager.processPlugins([server.serverPlugin]); | 2042 manager.processPlugins([server.serverPlugin]); |
2056 handler = new EditDomainHandler(server); | 2043 handler = new EditDomainHandler(server); |
2057 server.handlers = [handler]; | 2044 server.handlers = [handler]; |
2058 } | 2045 } |
2059 } | 2046 } |
OLD | NEW |