| 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.refactoring.rename_class_member; | 5 library test.services.refactoring.rename_class_member; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 8 import 'package:analysis_server/src/services/correction/status.dart'; | 8 import 'package:analysis_server/src/services/correction/status.dart'; |
| 9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
| 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 12 | 12 |
| 13 import 'abstract_rename.dart'; | 13 import 'abstract_rename.dart'; |
| 14 | 14 |
| 15 main() { | 15 main() { |
| 16 defineReflectiveSuite(() { | 16 defineReflectiveSuite(() { |
| 17 defineReflectiveTests(RenameClassMemberTest); | 17 defineReflectiveTests(RenameClassMemberTest); |
| 18 }); | 18 }); |
| 19 } | 19 } |
| 20 | 20 |
| 21 @reflectiveTest | 21 @reflectiveTest |
| 22 class RenameClassMemberTest extends RenameRefactoringTest { | 22 class RenameClassMemberTest extends RenameRefactoringTest { |
| 23 test_checkFinalConditions_classNameConflict_sameClass() async { | 23 test_checkFinalConditions_classNameConflict_sameClass() async { |
| 24 indexTestUnit(''' | 24 await indexTestUnit(''' |
| 25 class NewName { | 25 class NewName { |
| 26 void test() {} | 26 void test() {} |
| 27 } | 27 } |
| 28 '''); | 28 '''); |
| 29 createRenameRefactoringAtString('test() {}'); | 29 createRenameRefactoringAtString('test() {}'); |
| 30 // check status | 30 // check status |
| 31 refactoring.newName = 'NewName'; | 31 refactoring.newName = 'NewName'; |
| 32 RefactoringStatus status = await refactoring.checkFinalConditions(); | 32 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 33 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 33 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 34 expectedMessage: | 34 expectedMessage: |
| 35 "Renamed method has the same name as the declaring class 'NewName'."
, | 35 "Renamed method has the same name as the declaring class 'NewName'."
, |
| 36 expectedContextSearch: 'test() {}'); | 36 expectedContextSearch: 'test() {}'); |
| 37 } | 37 } |
| 38 | 38 |
| 39 test_checkFinalConditions_classNameConflict_subClass() async { | 39 test_checkFinalConditions_classNameConflict_subClass() async { |
| 40 indexTestUnit(''' | 40 await indexTestUnit(''' |
| 41 class A { | 41 class A { |
| 42 void test() {} // 1 | 42 void test() {} // 1 |
| 43 } | 43 } |
| 44 class NewName extends A { | 44 class NewName extends A { |
| 45 void test() {} // 2 | 45 void test() {} // 2 |
| 46 } | 46 } |
| 47 '''); | 47 '''); |
| 48 createRenameRefactoringAtString('test() {} // 1'); | 48 createRenameRefactoringAtString('test() {} // 1'); |
| 49 // check status | 49 // check status |
| 50 refactoring.newName = 'NewName'; | 50 refactoring.newName = 'NewName'; |
| 51 RefactoringStatus status = await refactoring.checkFinalConditions(); | 51 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 52 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 52 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 53 expectedMessage: | 53 expectedMessage: |
| 54 "Renamed method has the same name as the declaring class 'NewName'."
, | 54 "Renamed method has the same name as the declaring class 'NewName'."
, |
| 55 expectedContextSearch: 'test() {} // 2'); | 55 expectedContextSearch: 'test() {} // 2'); |
| 56 } | 56 } |
| 57 | 57 |
| 58 test_checkFinalConditions_classNameConflict_superClass() async { | 58 test_checkFinalConditions_classNameConflict_superClass() async { |
| 59 indexTestUnit(''' | 59 await indexTestUnit(''' |
| 60 class NewName { | 60 class NewName { |
| 61 void test() {} // 1 | 61 void test() {} // 1 |
| 62 } | 62 } |
| 63 class B extends NewName { | 63 class B extends NewName { |
| 64 void test() {} // 2 | 64 void test() {} // 2 |
| 65 } | 65 } |
| 66 '''); | 66 '''); |
| 67 createRenameRefactoringAtString('test() {} // 2'); | 67 createRenameRefactoringAtString('test() {} // 2'); |
| 68 // check status | 68 // check status |
| 69 refactoring.newName = 'NewName'; | 69 refactoring.newName = 'NewName'; |
| 70 RefactoringStatus status = await refactoring.checkFinalConditions(); | 70 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 71 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 71 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 72 expectedMessage: | 72 expectedMessage: |
| 73 "Renamed method has the same name as the declaring class 'NewName'."
, | 73 "Renamed method has the same name as the declaring class 'NewName'."
, |
| 74 expectedContextSearch: 'test() {} // 1'); | 74 expectedContextSearch: 'test() {} // 1'); |
| 75 } | 75 } |
| 76 | 76 |
| 77 test_checkFinalConditions_hasMember_MethodElement() async { | 77 test_checkFinalConditions_hasMember_MethodElement() async { |
| 78 indexTestUnit(''' | 78 await indexTestUnit(''' |
| 79 class A { | 79 class A { |
| 80 test() {} | 80 test() {} |
| 81 newName() {} // existing | 81 newName() {} // existing |
| 82 } | 82 } |
| 83 '''); | 83 '''); |
| 84 createRenameRefactoringAtString('test() {}'); | 84 createRenameRefactoringAtString('test() {}'); |
| 85 // check status | 85 // check status |
| 86 refactoring.newName = 'newName'; | 86 refactoring.newName = 'newName'; |
| 87 RefactoringStatus status = await refactoring.checkFinalConditions(); | 87 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 88 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 88 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 89 expectedMessage: | 89 expectedMessage: |
| 90 "Class 'A' already declares method with name 'newName'.", | 90 "Class 'A' already declares method with name 'newName'.", |
| 91 expectedContextSearch: 'newName() {} // existing'); | 91 expectedContextSearch: 'newName() {} // existing'); |
| 92 } | 92 } |
| 93 | 93 |
| 94 test_checkFinalConditions_OK_dropSuffix() async { | 94 test_checkFinalConditions_OK_dropSuffix() async { |
| 95 indexTestUnit(r''' | 95 await indexTestUnit(r''' |
| 96 abstract class A { | 96 abstract class A { |
| 97 void testOld(); | 97 void testOld(); |
| 98 } | 98 } |
| 99 class B implements A { | 99 class B implements A { |
| 100 void testOld() {} | 100 void testOld() {} |
| 101 } | 101 } |
| 102 '''); | 102 '''); |
| 103 createRenameRefactoringAtString('testOld() {}'); | 103 createRenameRefactoringAtString('testOld() {}'); |
| 104 // check status | 104 // check status |
| 105 refactoring.newName = 'test'; | 105 refactoring.newName = 'test'; |
| 106 RefactoringStatus status = await refactoring.checkFinalConditions(); | 106 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 107 assertRefactoringStatusOK(status); | 107 assertRefactoringStatusOK(status); |
| 108 } | 108 } |
| 109 | 109 |
| 110 test_checkFinalConditions_OK_noShadow() async { | 110 test_checkFinalConditions_OK_noShadow() async { |
| 111 indexTestUnit(''' | 111 await indexTestUnit(''' |
| 112 class A { | 112 class A { |
| 113 int newName; | 113 int newName; |
| 114 } | 114 } |
| 115 class B { | 115 class B { |
| 116 test() {} | 116 test() {} |
| 117 } | 117 } |
| 118 class C extends A { | 118 class C extends A { |
| 119 main() { | 119 main() { |
| 120 print(newName); | 120 print(newName); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 '''); | 123 '''); |
| 124 createRenameRefactoringAtString('test() {}'); | 124 createRenameRefactoringAtString('test() {}'); |
| 125 // check status | 125 // check status |
| 126 refactoring.newName = 'newName'; | 126 refactoring.newName = 'newName'; |
| 127 RefactoringStatus status = await refactoring.checkFinalConditions(); | 127 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 128 assertRefactoringStatusOK(status); | 128 assertRefactoringStatusOK(status); |
| 129 } | 129 } |
| 130 | 130 |
| 131 test_checkFinalConditions_publicToPrivate_usedInOtherLibrary() async { | 131 test_checkFinalConditions_publicToPrivate_usedInOtherLibrary() async { |
| 132 indexTestUnit(''' | 132 await indexTestUnit(''' |
| 133 class A { | 133 class A { |
| 134 test() {} | 134 test() {} |
| 135 } | 135 } |
| 136 '''); | 136 '''); |
| 137 indexUnit( | 137 await indexUnit( |
| 138 '/lib.dart', | 138 '/lib.dart', |
| 139 ''' | 139 ''' |
| 140 library my.lib; | 140 library my.lib; |
| 141 import 'test.dart'; | 141 import 'test.dart'; |
| 142 | 142 |
| 143 main(A a) { | 143 main(A a) { |
| 144 a.test(); | 144 a.test(); |
| 145 } | 145 } |
| 146 '''); | 146 '''); |
| 147 createRenameRefactoringAtString('test() {}'); | 147 createRenameRefactoringAtString('test() {}'); |
| 148 // check status | 148 // check status |
| 149 refactoring.newName = '_newName'; | 149 refactoring.newName = '_newName'; |
| 150 RefactoringStatus status = await refactoring.checkFinalConditions(); | 150 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 151 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 151 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 152 expectedMessage: "Renamed method will be invisible in 'my.lib'."); | 152 expectedMessage: "Renamed method will be invisible in 'my.lib'."); |
| 153 } | 153 } |
| 154 | 154 |
| 155 test_checkFinalConditions_shadowed_byLocalFunction_inSameClass() async { | 155 test_checkFinalConditions_shadowed_byLocalFunction_inSameClass() async { |
| 156 indexTestUnit(''' | 156 await indexTestUnit(''' |
| 157 class A { | 157 class A { |
| 158 test() {} | 158 test() {} |
| 159 main() { | 159 main() { |
| 160 newName() {} | 160 newName() {} |
| 161 test(); // marker | 161 test(); // marker |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 '''); | 164 '''); |
| 165 createRenameRefactoringAtString('test() {}'); | 165 createRenameRefactoringAtString('test() {}'); |
| 166 // check status | 166 // check status |
| 167 refactoring.newName = 'newName'; | 167 refactoring.newName = 'newName'; |
| 168 RefactoringStatus status = await refactoring.checkFinalConditions(); | 168 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 169 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 169 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 170 expectedMessage: | 170 expectedMessage: |
| 171 "Usage of renamed method will be shadowed by function 'newName'.", | 171 "Usage of renamed method will be shadowed by function 'newName'.", |
| 172 expectedContextSearch: 'test(); // marker'); | 172 expectedContextSearch: 'test(); // marker'); |
| 173 } | 173 } |
| 174 | 174 |
| 175 test_checkFinalConditions_shadowed_byLocalVariable_inSameClass() async { | 175 test_checkFinalConditions_shadowed_byLocalVariable_inSameClass() async { |
| 176 indexTestUnit(''' | 176 await indexTestUnit(''' |
| 177 class A { | 177 class A { |
| 178 test() {} | 178 test() {} |
| 179 main() { | 179 main() { |
| 180 var newName; | 180 var newName; |
| 181 test(); // marker | 181 test(); // marker |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 '''); | 184 '''); |
| 185 createRenameRefactoringAtString('test() {}'); | 185 createRenameRefactoringAtString('test() {}'); |
| 186 // check status | 186 // check status |
| 187 refactoring.newName = 'newName'; | 187 refactoring.newName = 'newName'; |
| 188 RefactoringStatus status = await refactoring.checkFinalConditions(); | 188 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 189 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 189 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 190 expectedMessage: | 190 expectedMessage: |
| 191 "Usage of renamed method will be shadowed by local variable 'newName
'.", | 191 "Usage of renamed method will be shadowed by local variable 'newName
'.", |
| 192 expectedContextSearch: 'test(); // marker'); | 192 expectedContextSearch: 'test(); // marker'); |
| 193 } | 193 } |
| 194 | 194 |
| 195 test_checkFinalConditions_shadowed_byLocalVariable_inSubClass() async { | 195 test_checkFinalConditions_shadowed_byLocalVariable_inSubClass() async { |
| 196 indexTestUnit(''' | 196 await indexTestUnit(''' |
| 197 class A { | 197 class A { |
| 198 test() {} | 198 test() {} |
| 199 } | 199 } |
| 200 class B extends A { | 200 class B extends A { |
| 201 main() { | 201 main() { |
| 202 var newName; | 202 var newName; |
| 203 test(); // marker | 203 test(); // marker |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 '''); | 206 '''); |
| 207 createRenameRefactoringAtString('test() {}'); | 207 createRenameRefactoringAtString('test() {}'); |
| 208 // check status | 208 // check status |
| 209 refactoring.newName = 'newName'; | 209 refactoring.newName = 'newName'; |
| 210 RefactoringStatus status = await refactoring.checkFinalConditions(); | 210 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 211 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 211 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 212 expectedMessage: | 212 expectedMessage: |
| 213 "Usage of renamed method will be shadowed by local variable 'newName
'.", | 213 "Usage of renamed method will be shadowed by local variable 'newName
'.", |
| 214 expectedContextSearch: 'test(); // marker'); | 214 expectedContextSearch: 'test(); // marker'); |
| 215 } | 215 } |
| 216 | 216 |
| 217 test_checkFinalConditions_shadowed_byLocalVariable_OK_qualifiedReference() asy
nc { | 217 test_checkFinalConditions_shadowed_byLocalVariable_OK_qualifiedReference() asy
nc { |
| 218 indexTestUnit(''' | 218 await indexTestUnit(''' |
| 219 class A { | 219 class A { |
| 220 test() {} | 220 test() {} |
| 221 main() { | 221 main() { |
| 222 var newName; | 222 var newName; |
| 223 this.test(); // marker | 223 this.test(); // marker |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 '''); | 226 '''); |
| 227 createRenameRefactoringAtString('test() {}'); | 227 createRenameRefactoringAtString('test() {}'); |
| 228 // check status | 228 // check status |
| 229 refactoring.newName = 'newName'; | 229 refactoring.newName = 'newName'; |
| 230 RefactoringStatus status = await refactoring.checkFinalConditions(); | 230 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 231 assertRefactoringStatusOK(status); | 231 assertRefactoringStatusOK(status); |
| 232 } | 232 } |
| 233 | 233 |
| 234 test_checkFinalConditions_shadowed_byLocalVariable_OK_renamedNotUsed() async { | 234 test_checkFinalConditions_shadowed_byLocalVariable_OK_renamedNotUsed() async { |
| 235 indexTestUnit(''' | 235 await indexTestUnit(''' |
| 236 class A { | 236 class A { |
| 237 test() {} | 237 test() {} |
| 238 main() { | 238 main() { |
| 239 var newName; | 239 var newName; |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 '''); | 242 '''); |
| 243 createRenameRefactoringAtString('test() {}'); | 243 createRenameRefactoringAtString('test() {}'); |
| 244 // check status | 244 // check status |
| 245 refactoring.newName = 'newName'; | 245 refactoring.newName = 'newName'; |
| 246 RefactoringStatus status = await refactoring.checkFinalConditions(); | 246 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 247 assertRefactoringStatusOK(status); | 247 assertRefactoringStatusOK(status); |
| 248 } | 248 } |
| 249 | 249 |
| 250 test_checkFinalConditions_shadowed_byParameter_inSameClass() async { | 250 test_checkFinalConditions_shadowed_byParameter_inSameClass() async { |
| 251 indexTestUnit(''' | 251 await indexTestUnit(''' |
| 252 class A { | 252 class A { |
| 253 test() {} | 253 test() {} |
| 254 main(newName) { | 254 main(newName) { |
| 255 test(); // marker | 255 test(); // marker |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 '''); | 258 '''); |
| 259 createRenameRefactoringAtString('test() {}'); | 259 createRenameRefactoringAtString('test() {}'); |
| 260 // check status | 260 // check status |
| 261 refactoring.newName = 'newName'; | 261 refactoring.newName = 'newName'; |
| 262 RefactoringStatus status = await refactoring.checkFinalConditions(); | 262 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 263 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 263 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 264 expectedMessage: | 264 expectedMessage: |
| 265 "Usage of renamed method will be shadowed by parameter 'newName'.", | 265 "Usage of renamed method will be shadowed by parameter 'newName'.", |
| 266 expectedContextSearch: 'test(); // marker'); | 266 expectedContextSearch: 'test(); // marker'); |
| 267 } | 267 } |
| 268 | 268 |
| 269 test_checkFinalConditions_shadowedBySub_MethodElement() async { | 269 test_checkFinalConditions_shadowedBySub_MethodElement() async { |
| 270 indexTestUnit(''' | 270 await indexTestUnit(''' |
| 271 class A { | 271 class A { |
| 272 test() {} | 272 test() {} |
| 273 } | 273 } |
| 274 class B extends A { | 274 class B extends A { |
| 275 newName() {} // marker | 275 newName() {} // marker |
| 276 main() { | 276 main() { |
| 277 test(); | 277 test(); |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 '''); | 280 '''); |
| 281 createRenameRefactoringAtString('test() {}'); | 281 createRenameRefactoringAtString('test() {}'); |
| 282 // check status | 282 // check status |
| 283 refactoring.newName = 'newName'; | 283 refactoring.newName = 'newName'; |
| 284 RefactoringStatus status = await refactoring.checkFinalConditions(); | 284 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 285 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 285 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 286 expectedMessage: | 286 expectedMessage: |
| 287 "Renamed method will be shadowed by method 'B.newName'.", | 287 "Renamed method will be shadowed by method 'B.newName'.", |
| 288 expectedContextSearch: 'newName() {} // marker'); | 288 expectedContextSearch: 'newName() {} // marker'); |
| 289 } | 289 } |
| 290 | 290 |
| 291 test_checkFinalConditions_shadowsSuper_FieldElement() async { | 291 test_checkFinalConditions_shadowsSuper_FieldElement() async { |
| 292 indexTestUnit(''' | 292 await indexTestUnit(''' |
| 293 class A { | 293 class A { |
| 294 int newName; // marker | 294 int newName; // marker |
| 295 } | 295 } |
| 296 class B extends A { | 296 class B extends A { |
| 297 test() {} | 297 test() {} |
| 298 } | 298 } |
| 299 class C extends B { | 299 class C extends B { |
| 300 main() { | 300 main() { |
| 301 print(newName); | 301 print(newName); |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 '''); | 304 '''); |
| 305 createRenameRefactoringAtString('test() {}'); | 305 createRenameRefactoringAtString('test() {}'); |
| 306 // check status | 306 // check status |
| 307 refactoring.newName = 'newName'; | 307 refactoring.newName = 'newName'; |
| 308 RefactoringStatus status = await refactoring.checkFinalConditions(); | 308 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 309 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 309 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 310 expectedMessage: "Renamed method will shadow field 'A.newName'.", | 310 expectedMessage: "Renamed method will shadow field 'A.newName'.", |
| 311 expectedContextSearch: 'newName; // marker'); | 311 expectedContextSearch: 'newName; // marker'); |
| 312 } | 312 } |
| 313 | 313 |
| 314 test_checkFinalConditions_shadowsSuper_MethodElement() async { | 314 test_checkFinalConditions_shadowsSuper_MethodElement() async { |
| 315 indexTestUnit(''' | 315 await indexTestUnit(''' |
| 316 class A { | 316 class A { |
| 317 newName() {} // marker | 317 newName() {} // marker |
| 318 } | 318 } |
| 319 class B extends A { | 319 class B extends A { |
| 320 test() {} | 320 test() {} |
| 321 } | 321 } |
| 322 '''); | 322 '''); |
| 323 createRenameRefactoringAtString('test() {}'); | 323 createRenameRefactoringAtString('test() {}'); |
| 324 // check status | 324 // check status |
| 325 refactoring.newName = 'newName'; | 325 refactoring.newName = 'newName'; |
| 326 RefactoringStatus status = await refactoring.checkFinalConditions(); | 326 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 327 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 327 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 328 expectedMessage: "Renamed method will shadow method 'A.newName'.", | 328 expectedMessage: "Renamed method will shadow method 'A.newName'.", |
| 329 expectedContextSearch: 'newName() {} // marker'); | 329 expectedContextSearch: 'newName() {} // marker'); |
| 330 } | 330 } |
| 331 | 331 |
| 332 test_checkFinalConditions_shadowsSuper_MethodElement_otherLib() async { | 332 test_checkFinalConditions_shadowsSuper_MethodElement_otherLib() async { |
| 333 var libCode = r''' | 333 var libCode = r''' |
| 334 class A { | 334 class A { |
| 335 newName() {} // marker | 335 newName() {} // marker |
| 336 } | 336 } |
| 337 '''; | 337 '''; |
| 338 indexUnit('/lib.dart', libCode); | 338 await indexUnit('/lib.dart', libCode); |
| 339 indexTestUnit(''' | 339 await indexTestUnit(''' |
| 340 import 'lib.dart'; | 340 import 'lib.dart'; |
| 341 class B extends A { | 341 class B extends A { |
| 342 test() {} | 342 test() {} |
| 343 } | 343 } |
| 344 '''); | 344 '''); |
| 345 createRenameRefactoringAtString('test() {}'); | 345 createRenameRefactoringAtString('test() {}'); |
| 346 // check status | 346 // check status |
| 347 refactoring.newName = 'newName'; | 347 refactoring.newName = 'newName'; |
| 348 RefactoringStatus status = await refactoring.checkFinalConditions(); | 348 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 349 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 349 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 350 expectedMessage: "Renamed method will shadow method 'A.newName'.", | 350 expectedMessage: "Renamed method will shadow method 'A.newName'.", |
| 351 expectedContextRange: new SourceRange( | 351 expectedContextRange: new SourceRange( |
| 352 libCode.indexOf('newName() {} // marker'), 'newName'.length)); | 352 libCode.indexOf('newName() {} // marker'), 'newName'.length)); |
| 353 } | 353 } |
| 354 | 354 |
| 355 test_checkInitialConditions_inSDK() async { | 355 test_checkInitialConditions_inSDK() async { |
| 356 indexTestUnit(''' | 356 await indexTestUnit(''' |
| 357 main() { | 357 main() { |
| 358 'abc'.toUpperCase(); | 358 'abc'.toUpperCase(); |
| 359 } | 359 } |
| 360 '''); | 360 '''); |
| 361 createRenameRefactoringAtString('toUpperCase()'); | 361 createRenameRefactoringAtString('toUpperCase()'); |
| 362 // check status | 362 // check status |
| 363 refactoring.newName = 'NewName'; | 363 refactoring.newName = 'NewName'; |
| 364 RefactoringStatus status = await refactoring.checkInitialConditions(); | 364 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 365 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 365 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 366 expectedMessage: | 366 expectedMessage: |
| 367 "The method 'String.toUpperCase' is defined in the SDK, so cannot be
renamed."); | 367 "The method 'String.toUpperCase' is defined in the SDK, so cannot be
renamed."); |
| 368 } | 368 } |
| 369 | 369 |
| 370 test_checkInitialConditions_operator() async { | 370 test_checkInitialConditions_operator() async { |
| 371 indexTestUnit(''' | 371 await indexTestUnit(''' |
| 372 class A { | 372 class A { |
| 373 operator -(other) => this; | 373 operator -(other) => this; |
| 374 } | 374 } |
| 375 '''); | 375 '''); |
| 376 createRenameRefactoringAtString('-(other)'); | 376 createRenameRefactoringAtString('-(other)'); |
| 377 // check status | 377 // check status |
| 378 refactoring.newName = 'newName'; | 378 refactoring.newName = 'newName'; |
| 379 RefactoringStatus status = await refactoring.checkInitialConditions(); | 379 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 380 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); | 380 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); |
| 381 } | 381 } |
| 382 | 382 |
| 383 test_checkNewName_FieldElement() { | 383 test_checkNewName_FieldElement() async { |
| 384 indexTestUnit(''' | 384 await indexTestUnit(''' |
| 385 class A { | 385 class A { |
| 386 int test; | 386 int test; |
| 387 } | 387 } |
| 388 '''); | 388 '''); |
| 389 createRenameRefactoringAtString('test;'); | 389 createRenameRefactoringAtString('test;'); |
| 390 // null | 390 // null |
| 391 refactoring.newName = null; | 391 refactoring.newName = null; |
| 392 assertRefactoringStatus( | 392 assertRefactoringStatus( |
| 393 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 393 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| 394 expectedMessage: "Field name must not be null."); | 394 expectedMessage: "Field name must not be null."); |
| 395 // OK | 395 // OK |
| 396 refactoring.newName = 'newName'; | 396 refactoring.newName = 'newName'; |
| 397 assertRefactoringStatusOK(refactoring.checkNewName()); | 397 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 398 } | 398 } |
| 399 | 399 |
| 400 test_checkNewName_MethodElement() { | 400 test_checkNewName_MethodElement() async { |
| 401 indexTestUnit(''' | 401 await indexTestUnit(''' |
| 402 class A { | 402 class A { |
| 403 test() {} | 403 test() {} |
| 404 } | 404 } |
| 405 '''); | 405 '''); |
| 406 createRenameRefactoringAtString('test() {}'); | 406 createRenameRefactoringAtString('test() {}'); |
| 407 // null | 407 // null |
| 408 refactoring.newName = null; | 408 refactoring.newName = null; |
| 409 assertRefactoringStatus( | 409 assertRefactoringStatus( |
| 410 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 410 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| 411 expectedMessage: "Method name must not be null."); | 411 expectedMessage: "Method name must not be null."); |
| 412 // empty | 412 // empty |
| 413 refactoring.newName = ''; | 413 refactoring.newName = ''; |
| 414 assertRefactoringStatus( | 414 assertRefactoringStatus( |
| 415 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 415 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| 416 expectedMessage: "Method name must not be empty."); | 416 expectedMessage: "Method name must not be empty."); |
| 417 // same | 417 // same |
| 418 refactoring.newName = 'test'; | 418 refactoring.newName = 'test'; |
| 419 assertRefactoringStatus( | 419 assertRefactoringStatus( |
| 420 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 420 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| 421 expectedMessage: | 421 expectedMessage: |
| 422 "The new name must be different than the current name."); | 422 "The new name must be different than the current name."); |
| 423 // OK | 423 // OK |
| 424 refactoring.newName = 'newName'; | 424 refactoring.newName = 'newName'; |
| 425 assertRefactoringStatusOK(refactoring.checkNewName()); | 425 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 426 } | 426 } |
| 427 | 427 |
| 428 test_createChange_FieldElement() { | 428 test_createChange_FieldElement() async { |
| 429 indexTestUnit(''' | 429 await indexTestUnit(''' |
| 430 class A { | 430 class A { |
| 431 int test; // marker | 431 int test; // marker |
| 432 main() { | 432 main() { |
| 433 print(test); | 433 print(test); |
| 434 test = 1; | 434 test = 1; |
| 435 test += 2; | 435 test += 2; |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 class B extends A { | 438 class B extends A { |
| 439 } | 439 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 a.newName = 1; | 484 a.newName = 1; |
| 485 a.newName += 2; | 485 a.newName += 2; |
| 486 print(b.newName); | 486 print(b.newName); |
| 487 b.newName = 1; | 487 b.newName = 1; |
| 488 print(c.newName); | 488 print(c.newName); |
| 489 c.newName = 1; | 489 c.newName = 1; |
| 490 } | 490 } |
| 491 '''); | 491 '''); |
| 492 } | 492 } |
| 493 | 493 |
| 494 test_createChange_FieldElement_constructorFieldInitializer() { | 494 test_createChange_FieldElement_constructorFieldInitializer() async { |
| 495 indexTestUnit(''' | 495 await indexTestUnit(''' |
| 496 class A { | 496 class A { |
| 497 final test; | 497 final test; |
| 498 A() : test = 5; | 498 A() : test = 5; |
| 499 } | 499 } |
| 500 '''); | 500 '''); |
| 501 // configure refactoring | 501 // configure refactoring |
| 502 createRenameRefactoringAtString('test;'); | 502 createRenameRefactoringAtString('test;'); |
| 503 expect(refactoring.refactoringName, 'Rename Field'); | 503 expect(refactoring.refactoringName, 'Rename Field'); |
| 504 expect(refactoring.oldName, 'test'); | 504 expect(refactoring.oldName, 'test'); |
| 505 refactoring.newName = 'newName'; | 505 refactoring.newName = 'newName'; |
| 506 // validate change | 506 // validate change |
| 507 return assertSuccessfulRefactoring(''' | 507 return assertSuccessfulRefactoring(''' |
| 508 class A { | 508 class A { |
| 509 final newName; | 509 final newName; |
| 510 A() : newName = 5; | 510 A() : newName = 5; |
| 511 } | 511 } |
| 512 '''); | 512 '''); |
| 513 } | 513 } |
| 514 | 514 |
| 515 test_createChange_FieldElement_fieldFormalParameter() { | 515 test_createChange_FieldElement_fieldFormalParameter() async { |
| 516 indexTestUnit(''' | 516 await indexTestUnit(''' |
| 517 class A { | 517 class A { |
| 518 final test; | 518 final test; |
| 519 A(this.test); | 519 A(this.test); |
| 520 } | 520 } |
| 521 '''); | 521 '''); |
| 522 // configure refactoring | 522 // configure refactoring |
| 523 createRenameRefactoringAtString('test;'); | 523 createRenameRefactoringAtString('test;'); |
| 524 expect(refactoring.refactoringName, 'Rename Field'); | 524 expect(refactoring.refactoringName, 'Rename Field'); |
| 525 expect(refactoring.oldName, 'test'); | 525 expect(refactoring.oldName, 'test'); |
| 526 refactoring.newName = 'newName'; | 526 refactoring.newName = 'newName'; |
| 527 // validate change | 527 // validate change |
| 528 return assertSuccessfulRefactoring(''' | 528 return assertSuccessfulRefactoring(''' |
| 529 class A { | 529 class A { |
| 530 final newName; | 530 final newName; |
| 531 A(this.newName); | 531 A(this.newName); |
| 532 } | 532 } |
| 533 '''); | 533 '''); |
| 534 } | 534 } |
| 535 | 535 |
| 536 test_createChange_FieldElement_fieldFormalParameter_named() { | 536 test_createChange_FieldElement_fieldFormalParameter_named() async { |
| 537 indexTestUnit(''' | 537 await indexTestUnit(''' |
| 538 class A { | 538 class A { |
| 539 final test; | 539 final test; |
| 540 A({this.test}); | 540 A({this.test}); |
| 541 } | 541 } |
| 542 main() { | 542 main() { |
| 543 new A(test: 42); | 543 new A(test: 42); |
| 544 } | 544 } |
| 545 '''); | 545 '''); |
| 546 // configure refactoring | 546 // configure refactoring |
| 547 createRenameRefactoringAtString('test;'); | 547 createRenameRefactoringAtString('test;'); |
| 548 expect(refactoring.refactoringName, 'Rename Field'); | 548 expect(refactoring.refactoringName, 'Rename Field'); |
| 549 expect(refactoring.oldName, 'test'); | 549 expect(refactoring.oldName, 'test'); |
| 550 refactoring.newName = 'newName'; | 550 refactoring.newName = 'newName'; |
| 551 // validate change | 551 // validate change |
| 552 return assertSuccessfulRefactoring(''' | 552 return assertSuccessfulRefactoring(''' |
| 553 class A { | 553 class A { |
| 554 final newName; | 554 final newName; |
| 555 A({this.newName}); | 555 A({this.newName}); |
| 556 } | 556 } |
| 557 main() { | 557 main() { |
| 558 new A(newName: 42); | 558 new A(newName: 42); |
| 559 } | 559 } |
| 560 '''); | 560 '''); |
| 561 } | 561 } |
| 562 | 562 |
| 563 test_createChange_FieldElement_invocation() { | 563 test_createChange_FieldElement_invocation() async { |
| 564 indexTestUnit(''' | 564 await indexTestUnit(''' |
| 565 typedef F(a); | 565 typedef F(a); |
| 566 class A { | 566 class A { |
| 567 F test; | 567 F test; |
| 568 main() { | 568 main() { |
| 569 test(1); | 569 test(1); |
| 570 } | 570 } |
| 571 } | 571 } |
| 572 main() { | 572 main() { |
| 573 A a = new A(); | 573 A a = new A(); |
| 574 a.test(2); | 574 a.test(2); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 588 newName(1); | 588 newName(1); |
| 589 } | 589 } |
| 590 } | 590 } |
| 591 main() { | 591 main() { |
| 592 A a = new A(); | 592 A a = new A(); |
| 593 a.newName(2); | 593 a.newName(2); |
| 594 } | 594 } |
| 595 '''); | 595 '''); |
| 596 } | 596 } |
| 597 | 597 |
| 598 test_createChange_MethodElement() { | 598 test_createChange_MethodElement() async { |
| 599 indexTestUnit(''' | 599 await indexTestUnit(''' |
| 600 class A { | 600 class A { |
| 601 test() {} | 601 test() {} |
| 602 } | 602 } |
| 603 class B extends A { | 603 class B extends A { |
| 604 test() {} // marker | 604 test() {} // marker |
| 605 } | 605 } |
| 606 class C extends B { | 606 class C extends B { |
| 607 test() {} | 607 test() {} |
| 608 } | 608 } |
| 609 class D implements A { | 609 class D implements A { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 a.newName(); | 657 a.newName(); |
| 658 b.newName(); | 658 b.newName(); |
| 659 c.newName(); | 659 c.newName(); |
| 660 d.newName(); | 660 d.newName(); |
| 661 e.test(); | 661 e.test(); |
| 662 } | 662 } |
| 663 '''); | 663 '''); |
| 664 } | 664 } |
| 665 | 665 |
| 666 test_createChange_MethodElement_potential() async { | 666 test_createChange_MethodElement_potential() async { |
| 667 indexTestUnit(''' | 667 await indexTestUnit(''' |
| 668 class A { | 668 class A { |
| 669 test() {} | 669 test() {} |
| 670 } | 670 } |
| 671 main(var a) { | 671 main(var a) { |
| 672 a.test(); // 1 | 672 a.test(); // 1 |
| 673 new A().test(); | 673 new A().test(); |
| 674 a.test(); // 2 | 674 a.test(); // 2 |
| 675 } | 675 } |
| 676 '''); | 676 '''); |
| 677 // configure refactoring | 677 // configure refactoring |
| (...skipping 10 matching lines...) Expand all Loading... |
| 688 a.newName(); // 1 | 688 a.newName(); // 1 |
| 689 new A().newName(); | 689 new A().newName(); |
| 690 a.newName(); // 2 | 690 a.newName(); // 2 |
| 691 } | 691 } |
| 692 '''); | 692 '''); |
| 693 assertPotentialEdits(['test(); // 1', 'test(); // 2']); | 693 assertPotentialEdits(['test(); // 1', 'test(); // 2']); |
| 694 } | 694 } |
| 695 | 695 |
| 696 test_createChange_MethodElement_potential_inPubCache() async { | 696 test_createChange_MethodElement_potential_inPubCache() async { |
| 697 String pkgLib = '/.pub-cache/lib.dart'; | 697 String pkgLib = '/.pub-cache/lib.dart'; |
| 698 indexUnit( | 698 await indexUnit( |
| 699 pkgLib, | 699 pkgLib, |
| 700 r''' | 700 r''' |
| 701 processObj(p) { | 701 processObj(p) { |
| 702 p.test(); | 702 p.test(); |
| 703 } | 703 } |
| 704 '''); | 704 '''); |
| 705 indexTestUnit(''' | 705 await indexTestUnit(''' |
| 706 import '$pkgLib'; | 706 import '$pkgLib'; |
| 707 class A { | 707 class A { |
| 708 test() {} | 708 test() {} |
| 709 } | 709 } |
| 710 main(var a) { | 710 main(var a) { |
| 711 a.test(); | 711 a.test(); |
| 712 } | 712 } |
| 713 '''); | 713 '''); |
| 714 // configure refactoring | 714 // configure refactoring |
| 715 createRenameRefactoringAtString('test() {}'); | 715 createRenameRefactoringAtString('test() {}'); |
| 716 expect(refactoring.refactoringName, 'Rename Method'); | 716 expect(refactoring.refactoringName, 'Rename Method'); |
| 717 expect(refactoring.oldName, 'test'); | 717 expect(refactoring.oldName, 'test'); |
| 718 refactoring.newName = 'newName'; | 718 refactoring.newName = 'newName'; |
| 719 // validate change | 719 // validate change |
| 720 await assertSuccessfulRefactoring(''' | 720 await assertSuccessfulRefactoring(''' |
| 721 import '/.pub-cache/lib.dart'; | 721 import '/.pub-cache/lib.dart'; |
| 722 class A { | 722 class A { |
| 723 newName() {} | 723 newName() {} |
| 724 } | 724 } |
| 725 main(var a) { | 725 main(var a) { |
| 726 a.newName(); | 726 a.newName(); |
| 727 } | 727 } |
| 728 '''); | 728 '''); |
| 729 SourceFileEdit fileEdit = refactoringChange.getFileEdit(pkgLib); | 729 SourceFileEdit fileEdit = refactoringChange.getFileEdit(pkgLib); |
| 730 expect(fileEdit, isNull); | 730 expect(fileEdit, isNull); |
| 731 } | 731 } |
| 732 | 732 |
| 733 test_createChange_MethodElement_potential_private_otherLibrary() async { | 733 test_createChange_MethodElement_potential_private_otherLibrary() async { |
| 734 indexUnit( | 734 await indexUnit( |
| 735 '/lib.dart', | 735 '/lib.dart', |
| 736 ''' | 736 ''' |
| 737 library lib; | 737 library lib; |
| 738 main(p) { | 738 main(p) { |
| 739 p._test(); | 739 p._test(); |
| 740 } | 740 } |
| 741 '''); | 741 '''); |
| 742 indexTestUnit(''' | 742 await indexTestUnit(''' |
| 743 class A { | 743 class A { |
| 744 _test() {} | 744 _test() {} |
| 745 } | 745 } |
| 746 main(var a) { | 746 main(var a) { |
| 747 a._test(); | 747 a._test(); |
| 748 new A()._test(); | 748 new A()._test(); |
| 749 } | 749 } |
| 750 '''); | 750 '''); |
| 751 // configure refactoring | 751 // configure refactoring |
| 752 createRenameRefactoringAtString('_test() {}'); | 752 createRenameRefactoringAtString('_test() {}'); |
| 753 expect(refactoring.refactoringName, 'Rename Method'); | 753 expect(refactoring.refactoringName, 'Rename Method'); |
| 754 expect(refactoring.oldName, '_test'); | 754 expect(refactoring.oldName, '_test'); |
| 755 refactoring.newName = 'newName'; | 755 refactoring.newName = 'newName'; |
| 756 // validate change | 756 // validate change |
| 757 await assertSuccessfulRefactoring(''' | 757 await assertSuccessfulRefactoring(''' |
| 758 class A { | 758 class A { |
| 759 newName() {} | 759 newName() {} |
| 760 } | 760 } |
| 761 main(var a) { | 761 main(var a) { |
| 762 a.newName(); | 762 a.newName(); |
| 763 new A().newName(); | 763 new A().newName(); |
| 764 } | 764 } |
| 765 '''); | 765 '''); |
| 766 assertNoFileChange('/lib.dart'); | 766 assertNoFileChange('/lib.dart'); |
| 767 } | 767 } |
| 768 | 768 |
| 769 test_createChange_PropertyAccessorElement_getter() { | 769 test_createChange_PropertyAccessorElement_getter() async { |
| 770 indexTestUnit(''' | 770 await indexTestUnit(''' |
| 771 class A { | 771 class A { |
| 772 get test {} // marker | 772 get test {} // marker |
| 773 set test(x) {} | 773 set test(x) {} |
| 774 main() { | 774 main() { |
| 775 print(test); | 775 print(test); |
| 776 test = 1; | 776 test = 1; |
| 777 } | 777 } |
| 778 } | 778 } |
| 779 class B extends A { | 779 class B extends A { |
| 780 get test {} | 780 get test {} |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 print(a.newName); | 814 print(a.newName); |
| 815 a.newName = 2; | 815 a.newName = 2; |
| 816 | 816 |
| 817 B b = new B(); | 817 B b = new B(); |
| 818 print(b.newName); | 818 print(b.newName); |
| 819 b.newName = 2; | 819 b.newName = 2; |
| 820 } | 820 } |
| 821 '''); | 821 '''); |
| 822 } | 822 } |
| 823 | 823 |
| 824 test_createChange_PropertyAccessorElement_setter() { | 824 test_createChange_PropertyAccessorElement_setter() async { |
| 825 indexTestUnit(''' | 825 await indexTestUnit(''' |
| 826 class A { | 826 class A { |
| 827 get test {} | 827 get test {} |
| 828 set test(x) {} // marker | 828 set test(x) {} // marker |
| 829 main() { | 829 main() { |
| 830 print(test); | 830 print(test); |
| 831 test = 1; | 831 test = 1; |
| 832 } | 832 } |
| 833 } | 833 } |
| 834 class B extends A { | 834 class B extends A { |
| 835 get test {} | 835 get test {} |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 print(a.newName); | 869 print(a.newName); |
| 870 a.newName = 2; | 870 a.newName = 2; |
| 871 | 871 |
| 872 B b = new B(); | 872 B b = new B(); |
| 873 print(b.newName); | 873 print(b.newName); |
| 874 b.newName = 2; | 874 b.newName = 2; |
| 875 } | 875 } |
| 876 '''); | 876 '''); |
| 877 } | 877 } |
| 878 | 878 |
| 879 test_createChange_TypeParameterElement() { | 879 test_createChange_TypeParameterElement() async { |
| 880 indexTestUnit(''' | 880 await indexTestUnit(''' |
| 881 class A<Test> { | 881 class A<Test> { |
| 882 Test field; | 882 Test field; |
| 883 List<Test> items; | 883 List<Test> items; |
| 884 Test method(Test p) => null; | 884 Test method(Test p) => null; |
| 885 } | 885 } |
| 886 '''); | 886 '''); |
| 887 // configure refactoring | 887 // configure refactoring |
| 888 createRenameRefactoringAtString('Test> {'); | 888 createRenameRefactoringAtString('Test> {'); |
| 889 expect(refactoring.refactoringName, 'Rename Type Parameter'); | 889 expect(refactoring.refactoringName, 'Rename Type Parameter'); |
| 890 expect(refactoring.elementKindName, 'type parameter'); | 890 expect(refactoring.elementKindName, 'type parameter'); |
| 891 expect(refactoring.oldName, 'Test'); | 891 expect(refactoring.oldName, 'Test'); |
| 892 refactoring.newName = 'NewName'; | 892 refactoring.newName = 'NewName'; |
| 893 // validate change | 893 // validate change |
| 894 return assertSuccessfulRefactoring(''' | 894 return assertSuccessfulRefactoring(''' |
| 895 class A<NewName> { | 895 class A<NewName> { |
| 896 NewName field; | 896 NewName field; |
| 897 List<NewName> items; | 897 List<NewName> items; |
| 898 NewName method(NewName p) => null; | 898 NewName method(NewName p) => null; |
| 899 } | 899 } |
| 900 '''); | 900 '''); |
| 901 } | 901 } |
| 902 } | 902 } |
| OLD | NEW |