| 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/src/edit/edit_domain.dart'; | 9 import 'package:analysis_server/src/edit/edit_domain.dart'; |
| 10 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 }, ''' | 1019 }, ''' |
| 1020 class A { | 1020 class A { |
| 1021 get newName => 0; | 1021 get newName => 0; |
| 1022 main() { | 1022 main() { |
| 1023 print(newName); | 1023 print(newName); |
| 1024 } | 1024 } |
| 1025 } | 1025 } |
| 1026 '''); | 1026 '''); |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 test_classMember_method() { |
| 1030 addTestFile(''' |
| 1031 class A { |
| 1032 test() {} |
| 1033 main() { |
| 1034 test(); |
| 1035 } |
| 1036 } |
| 1037 main(A a) { |
| 1038 a.test(); |
| 1039 } |
| 1040 '''); |
| 1041 return assertSuccessfulRefactoring(() { |
| 1042 return sendRenameRequest('test() {}', 'newName'); |
| 1043 }, ''' |
| 1044 class A { |
| 1045 newName() {} |
| 1046 main() { |
| 1047 newName(); |
| 1048 } |
| 1049 } |
| 1050 main(A a) { |
| 1051 a.newName(); |
| 1052 } |
| 1053 '''); |
| 1054 } |
| 1055 |
| 1056 test_classMember_method_potential() { |
| 1057 addTestFile(''' |
| 1058 class A { |
| 1059 test() {} |
| 1060 } |
| 1061 main(A a, a2) { |
| 1062 a.test(); |
| 1063 a2.test(); // a2 |
| 1064 } |
| 1065 '''); |
| 1066 return getRefactoringResult(() { |
| 1067 return sendRenameRequest('test() {}', 'newName'); |
| 1068 }).then((result) { |
| 1069 assertResultProblemsOK(result); |
| 1070 // prepare potential edit ID |
| 1071 List<String> potentialIds = result.potentialEdits; |
| 1072 expect(potentialIds, hasLength(1)); |
| 1073 String potentialId = potentialIds[0]; |
| 1074 // find potential edit |
| 1075 SourceChange change = result.change; |
| 1076 SourceEdit potentialEdit = _findEditWithId(change, potentialId); |
| 1077 expect(potentialEdit, isNotNull); |
| 1078 expect(potentialEdit.offset, findOffset('test(); // a2')); |
| 1079 expect(potentialEdit.length, 4); |
| 1080 }); |
| 1081 } |
| 1082 |
| 1029 test_classMember_setter() { | 1083 test_classMember_setter() { |
| 1030 addTestFile(''' | 1084 addTestFile(''' |
| 1031 class A { | 1085 class A { |
| 1032 set test(x) {} | 1086 set test(x) {} |
| 1033 main() { | 1087 main() { |
| 1034 test = 0; | 1088 test = 0; |
| 1035 } | 1089 } |
| 1036 } | 1090 } |
| 1037 '''); | 1091 '''); |
| 1038 return assertSuccessfulRefactoring(() { | 1092 return assertSuccessfulRefactoring(() { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 return getRefactoringResult(() { | 1336 return getRefactoringResult(() { |
| 1283 return sendRenameRequest('otherName =', 'newName', true); | 1337 return sendRenameRequest('otherName =', 'newName', true); |
| 1284 }).then((result) { | 1338 }).then((result) { |
| 1285 RenameFeedback feedback = result.feedback; | 1339 RenameFeedback feedback = result.feedback; |
| 1286 // the refactoring was reset, so we don't get a stale result | 1340 // the refactoring was reset, so we don't get a stale result |
| 1287 expect(feedback.oldName, 'otherName'); | 1341 expect(feedback.oldName, 'otherName'); |
| 1288 }); | 1342 }); |
| 1289 }); | 1343 }); |
| 1290 }); | 1344 }); |
| 1291 } | 1345 } |
| 1346 |
| 1347 SourceEdit _findEditWithId(SourceChange change, String id) { |
| 1348 SourceEdit potentialEdit; |
| 1349 change.edits.forEach((fileEdit) { |
| 1350 fileEdit.edits.forEach((edit) { |
| 1351 if (edit.id == id) { |
| 1352 potentialEdit = edit; |
| 1353 } |
| 1354 }); |
| 1355 }); |
| 1356 return potentialEdit; |
| 1357 } |
| 1292 } | 1358 } |
| 1293 | 1359 |
| 1294 | 1360 |
| 1295 @ReflectiveTestCase() | 1361 @ReflectiveTestCase() |
| 1296 class _AbstractGetRefactoring_Test extends AbstractAnalysisTest { | 1362 class _AbstractGetRefactoring_Test extends AbstractAnalysisTest { |
| 1297 /** | 1363 /** |
| 1298 * Asserts that [problems] has a single ERROR problem. | 1364 * Asserts that [problems] has a single ERROR problem. |
| 1299 */ | 1365 */ |
| 1300 void assertResultProblemsError(List<RefactoringProblem> problems, | 1366 void assertResultProblemsError(List<RefactoringProblem> problems, |
| 1301 [String message]) { | 1367 [String message]) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 } | 1469 } |
| 1404 | 1470 |
| 1405 @override | 1471 @override |
| 1406 void setUp() { | 1472 void setUp() { |
| 1407 super.setUp(); | 1473 super.setUp(); |
| 1408 server.handlers = [new EditDomainHandler(server),]; | 1474 server.handlers = [new EditDomainHandler(server),]; |
| 1409 createProject(); | 1475 createProject(); |
| 1410 handler = new EditDomainHandler(server); | 1476 handler = new EditDomainHandler(server); |
| 1411 } | 1477 } |
| 1412 } | 1478 } |
| OLD | NEW |