| 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 import 'package:analysis_server/src/services/correction/status.dart'; | 5 import 'package:analysis_server/src/services/correction/status.dart'; |
| 6 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 6 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 7 import 'package:test/test.dart'; | 7 import 'package:test/test.dart'; |
| 8 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 8 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 9 | 9 |
| 10 import 'abstract_rename.dart'; | 10 import 'abstract_rename.dart'; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // check status | 62 // check status |
| 63 refactoring.newName = 'NewName'; | 63 refactoring.newName = 'NewName'; |
| 64 RefactoringStatus status = await refactoring.checkFinalConditions(); | 64 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 65 assertRefactoringStatusOK(status); | 65 assertRefactoringStatusOK(status); |
| 66 } | 66 } |
| 67 | 67 |
| 68 test_checkFinalConditions_publicToPrivate_usedInOtherLibrary() async { | 68 test_checkFinalConditions_publicToPrivate_usedInOtherLibrary() async { |
| 69 await indexTestUnit(''' | 69 await indexTestUnit(''' |
| 70 class Test {} | 70 class Test {} |
| 71 '''); | 71 '''); |
| 72 await indexUnit( | 72 await indexUnit('/lib.dart', ''' |
| 73 '/lib.dart', | |
| 74 ''' | |
| 75 library my.lib; | 73 library my.lib; |
| 76 import 'test.dart'; | 74 import 'test.dart'; |
| 77 | 75 |
| 78 main() { | 76 main() { |
| 79 new Test(); | 77 new Test(); |
| 80 } | 78 } |
| 81 '''); | 79 '''); |
| 82 createRenameRefactoringAtString('Test {}'); | 80 createRenameRefactoringAtString('Test {}'); |
| 83 // check status | 81 // check status |
| 84 refactoring.newName = '_NewName'; | 82 refactoring.newName = '_NewName'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 104 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 102 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 105 expectedMessage: | 103 expectedMessage: |
| 106 "Reference to renamed class will be shadowed by method 'A.NewName'."
, | 104 "Reference to renamed class will be shadowed by method 'A.NewName'."
, |
| 107 expectedContextSearch: 'NewName() {}'); | 105 expectedContextSearch: 'NewName() {}'); |
| 108 } | 106 } |
| 109 | 107 |
| 110 test_checkFinalConditions_shadowsInSubClass_importedLib() async { | 108 test_checkFinalConditions_shadowsInSubClass_importedLib() async { |
| 111 await indexTestUnit(''' | 109 await indexTestUnit(''' |
| 112 class Test {} | 110 class Test {} |
| 113 '''); | 111 '''); |
| 114 await indexUnit( | 112 await indexUnit('/lib.dart', ''' |
| 115 '/lib.dart', | |
| 116 ''' | |
| 117 library my.lib; | 113 library my.lib; |
| 118 import 'test.dart'; | 114 import 'test.dart'; |
| 119 class A { | 115 class A { |
| 120 NewName() {} | 116 NewName() {} |
| 121 } | 117 } |
| 122 class B extends A { | 118 class B extends A { |
| 123 main() { | 119 main() { |
| 124 NewName(); // super-ref | 120 NewName(); // super-ref |
| 125 }", | 121 }", |
| 126 } | 122 } |
| 127 '''); | 123 '''); |
| 128 createRenameRefactoringAtString('Test {}'); | 124 createRenameRefactoringAtString('Test {}'); |
| 129 // check status | 125 // check status |
| 130 refactoring.newName = 'NewName'; | 126 refactoring.newName = 'NewName'; |
| 131 RefactoringStatus status = await refactoring.checkFinalConditions(); | 127 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 132 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 128 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 133 expectedMessage: "Renamed class will shadow method 'A.NewName'."); | 129 expectedMessage: "Renamed class will shadow method 'A.NewName'."); |
| 134 } | 130 } |
| 135 | 131 |
| 136 test_checkFinalConditions_shadowsInSubClass_importedLib_hideCombinator() async
{ | 132 test_checkFinalConditions_shadowsInSubClass_importedLib_hideCombinator() async
{ |
| 137 await indexTestUnit(''' | 133 await indexTestUnit(''' |
| 138 class Test {} | 134 class Test {} |
| 139 '''); | 135 '''); |
| 140 await indexUnit( | 136 await indexUnit('/lib.dart', ''' |
| 141 '/lib.dart', | |
| 142 ''' | |
| 143 library my.lib; | 137 library my.lib; |
| 144 import 'test.dart' hide Test; | 138 import 'test.dart' hide Test; |
| 145 class A { | 139 class A { |
| 146 NewName() {} | 140 NewName() {} |
| 147 } | 141 } |
| 148 class B extends A { | 142 class B extends A { |
| 149 main() { | 143 main() { |
| 150 NewName(); // super-ref | 144 NewName(); // super-ref |
| 151 }", | 145 }", |
| 152 } | 146 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 173 createRenameRefactoringAtString('Test {}'); | 167 createRenameRefactoringAtString('Test {}'); |
| 174 // check status | 168 // check status |
| 175 refactoring.newName = 'NewName'; | 169 refactoring.newName = 'NewName'; |
| 176 RefactoringStatus status = await refactoring.checkFinalConditions(); | 170 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 177 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 171 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 178 expectedMessage: "Renamed class will shadow method 'A.NewName'.", | 172 expectedMessage: "Renamed class will shadow method 'A.NewName'.", |
| 179 expectedContextSearch: 'NewName(); // super-ref'); | 173 expectedContextSearch: 'NewName(); // super-ref'); |
| 180 } | 174 } |
| 181 | 175 |
| 182 test_checkFinalConditions_shadowsInSubClass_notImportedLib() async { | 176 test_checkFinalConditions_shadowsInSubClass_notImportedLib() async { |
| 183 await indexUnit( | 177 await indexUnit('/lib.dart', ''' |
| 184 '/lib.dart', | |
| 185 ''' | |
| 186 library my.lib; | 178 library my.lib; |
| 187 class A { | 179 class A { |
| 188 NewName() {} | 180 NewName() {} |
| 189 } | 181 } |
| 190 class B extends A { | 182 class B extends A { |
| 191 main() { | 183 main() { |
| 192 NewName(); // super-ref | 184 NewName(); // super-ref |
| 193 }", | 185 }", |
| 194 } | 186 } |
| 195 '''); | 187 '''); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 216 } | 208 } |
| 217 '''); | 209 '''); |
| 218 createRenameRefactoringAtString('Test {}'); | 210 createRenameRefactoringAtString('Test {}'); |
| 219 // check status | 211 // check status |
| 220 refactoring.newName = 'NewName'; | 212 refactoring.newName = 'NewName'; |
| 221 RefactoringStatus status = await refactoring.checkFinalConditions(); | 213 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 222 assertRefactoringStatusOK(status); | 214 assertRefactoringStatusOK(status); |
| 223 } | 215 } |
| 224 | 216 |
| 225 test_checkInitialConditions_inPubCache_posix() async { | 217 test_checkInitialConditions_inPubCache_posix() async { |
| 226 addSource( | 218 addSource('/.pub-cache/lib.dart', r''' |
| 227 '/.pub-cache/lib.dart', | |
| 228 r''' | |
| 229 class A {} | 219 class A {} |
| 230 '''); | 220 '''); |
| 231 await indexTestUnit(''' | 221 await indexTestUnit(''' |
| 232 import '/.pub-cache/lib.dart'; | 222 import '/.pub-cache/lib.dart'; |
| 233 main() { | 223 main() { |
| 234 A a; | 224 A a; |
| 235 } | 225 } |
| 236 '''); | 226 '''); |
| 237 createRenameRefactoringAtString('A a'); | 227 createRenameRefactoringAtString('A a'); |
| 238 // check status | 228 // check status |
| 239 refactoring.newName = 'NewName'; | 229 refactoring.newName = 'NewName'; |
| 240 RefactoringStatus status = await refactoring.checkInitialConditions(); | 230 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 241 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 231 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 242 expectedMessage: | 232 expectedMessage: |
| 243 "The class 'A' is defined in a pub package, so cannot be renamed."); | 233 "The class 'A' is defined in a pub package, so cannot be renamed."); |
| 244 } | 234 } |
| 245 | 235 |
| 246 test_checkInitialConditions_inPubCache_windows() async { | 236 test_checkInitialConditions_inPubCache_windows() async { |
| 247 addSource( | 237 addSource('/Pub/Cache/lib.dart', r''' |
| 248 '/Pub/Cache/lib.dart', | |
| 249 r''' | |
| 250 class A {} | 238 class A {} |
| 251 '''); | 239 '''); |
| 252 await indexTestUnit(''' | 240 await indexTestUnit(''' |
| 253 import '/Pub/Cache/lib.dart'; | 241 import '/Pub/Cache/lib.dart'; |
| 254 main() { | 242 main() { |
| 255 A a; | 243 A a; |
| 256 } | 244 } |
| 257 '''); | 245 '''); |
| 258 createRenameRefactoringAtString('A a'); | 246 createRenameRefactoringAtString('A a'); |
| 259 // check status | 247 // check status |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 foo() {} | 476 foo() {} |
| 489 main() { | 477 main() { |
| 490 print(newName); | 478 print(newName); |
| 491 print(newName()); | 479 print(newName()); |
| 492 foo(); | 480 foo(); |
| 493 } | 481 } |
| 494 '''); | 482 '''); |
| 495 } | 483 } |
| 496 | 484 |
| 497 test_createChange_FunctionElement_imported() async { | 485 test_createChange_FunctionElement_imported() async { |
| 498 await indexUnit( | 486 await indexUnit('/foo.dart', r''' |
| 499 '/foo.dart', | |
| 500 r''' | |
| 501 test() {} | 487 test() {} |
| 502 foo() {} | 488 foo() {} |
| 503 '''); | 489 '''); |
| 504 await indexTestUnit(''' | 490 await indexTestUnit(''' |
| 505 import 'foo.dart'; | 491 import 'foo.dart'; |
| 506 main() { | 492 main() { |
| 507 print(test); | 493 print(test); |
| 508 print(test()); | 494 print(test()); |
| 509 foo(); | 495 foo(); |
| 510 } | 496 } |
| 511 '''); | 497 '''); |
| 512 // configure refactoring | 498 // configure refactoring |
| 513 createRenameRefactoringAtString('test);'); | 499 createRenameRefactoringAtString('test);'); |
| 514 expect(refactoring.refactoringName, 'Rename Top-Level Function'); | 500 expect(refactoring.refactoringName, 'Rename Top-Level Function'); |
| 515 expect(refactoring.elementKindName, 'function'); | 501 expect(refactoring.elementKindName, 'function'); |
| 516 expect(refactoring.oldName, 'test'); | 502 expect(refactoring.oldName, 'test'); |
| 517 refactoring.newName = 'newName'; | 503 refactoring.newName = 'newName'; |
| 518 // validate change | 504 // validate change |
| 519 await assertSuccessfulRefactoring(''' | 505 await assertSuccessfulRefactoring(''' |
| 520 import 'foo.dart'; | 506 import 'foo.dart'; |
| 521 main() { | 507 main() { |
| 522 print(newName); | 508 print(newName); |
| 523 print(newName()); | 509 print(newName()); |
| 524 foo(); | 510 foo(); |
| 525 } | 511 } |
| 526 '''); | 512 '''); |
| 527 assertFileChangeResult( | 513 assertFileChangeResult('/foo.dart', ''' |
| 528 '/foo.dart', | |
| 529 ''' | |
| 530 newName() {} | 514 newName() {} |
| 531 foo() {} | 515 foo() {} |
| 532 '''); | 516 '''); |
| 533 } | 517 } |
| 534 | 518 |
| 535 test_createChange_PropertyAccessorElement_getter_declaration() async { | 519 test_createChange_PropertyAccessorElement_getter_declaration() async { |
| 536 await _test_createChange_PropertyAccessorElement("test {}"); | 520 await _test_createChange_PropertyAccessorElement("test {}"); |
| 537 } | 521 } |
| 538 | 522 |
| 539 test_createChange_PropertyAccessorElement_getter_usage() async { | 523 test_createChange_PropertyAccessorElement_getter_usage() async { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 return assertSuccessfulRefactoring(''' | 598 return assertSuccessfulRefactoring(''' |
| 615 int newName = 0; | 599 int newName = 0; |
| 616 main() { | 600 main() { |
| 617 print(newName); | 601 print(newName); |
| 618 newName = 1; | 602 newName = 1; |
| 619 newName += 2; | 603 newName += 2; |
| 620 } | 604 } |
| 621 '''); | 605 '''); |
| 622 } | 606 } |
| 623 } | 607 } |
| OLD | NEW |