| 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/src/services/correction/status.dart'; | 7 import 'package:analysis_server/src/protocol2.dart'; |
| 8 import 'package:analysis_testing/reflective_tests.dart'; | 8 import 'package:analysis_testing/reflective_tests.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| 11 import 'abstract_rename.dart'; | 11 import 'abstract_rename.dart'; |
| 12 | 12 |
| 13 | 13 |
| 14 main() { | 14 main() { |
| 15 groupSep = ' | '; | 15 groupSep = ' | '; |
| 16 runReflectiveTests(RenameClassMemberTest); | 16 runReflectiveTests(RenameClassMemberTest); |
| 17 } | 17 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 47 test() {} | 47 test() {} |
| 48 newName() {} // existing | 48 newName() {} // existing |
| 49 } | 49 } |
| 50 '''); | 50 '''); |
| 51 createRenameRefactoringAtString('test() {}'); | 51 createRenameRefactoringAtString('test() {}'); |
| 52 // check status | 52 // check status |
| 53 refactoring.newName = 'newName'; | 53 refactoring.newName = 'newName'; |
| 54 return refactoring.checkFinalConditions().then((status) { | 54 return refactoring.checkFinalConditions().then((status) { |
| 55 assertRefactoringStatus( | 55 assertRefactoringStatus( |
| 56 status, | 56 status, |
| 57 RefactoringStatusSeverity.ERROR, | 57 RefactoringProblemSeverity.ERROR, |
| 58 expectedMessage: "Class 'A' already declares method with name 'newName
'.", | 58 expectedMessage: "Class 'A' already declares method with name 'newName
'.", |
| 59 expectedContextSearch: 'newName() {} // existing'); | 59 expectedContextSearch: 'newName() {} // existing'); |
| 60 }); | 60 }); |
| 61 } | 61 } |
| 62 | 62 |
| 63 test_checkFinalConditions_shadowed_byLocal_OK_qualifiedReference() { | 63 test_checkFinalConditions_shadowed_byLocal_OK_qualifiedReference() { |
| 64 indexTestUnit(''' | 64 indexTestUnit(''' |
| 65 class A { | 65 class A { |
| 66 test() {} | 66 test() {} |
| 67 main() { | 67 main() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 test(); // marker | 104 test(); // marker |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 '''); | 107 '''); |
| 108 createRenameRefactoringAtString('test() {}'); | 108 createRenameRefactoringAtString('test() {}'); |
| 109 // check status | 109 // check status |
| 110 refactoring.newName = 'newName'; | 110 refactoring.newName = 'newName'; |
| 111 return refactoring.checkFinalConditions().then((status) { | 111 return refactoring.checkFinalConditions().then((status) { |
| 112 assertRefactoringStatus( | 112 assertRefactoringStatus( |
| 113 status, | 113 status, |
| 114 RefactoringStatusSeverity.ERROR, | 114 RefactoringProblemSeverity.ERROR, |
| 115 expectedMessage: | 115 expectedMessage: |
| 116 "Usage of renamed method will be shadowed by local variable 'newNa
me'.", | 116 "Usage of renamed method will be shadowed by local variable 'newNa
me'.", |
| 117 expectedContextSearch: 'test(); // marker'); | 117 expectedContextSearch: 'test(); // marker'); |
| 118 }); | 118 }); |
| 119 } | 119 } |
| 120 | 120 |
| 121 test_checkFinalConditions_shadowed_byLocal_inSubClass() { | 121 test_checkFinalConditions_shadowed_byLocal_inSubClass() { |
| 122 indexTestUnit(''' | 122 indexTestUnit(''' |
| 123 class A { | 123 class A { |
| 124 test() {} | 124 test() {} |
| 125 } | 125 } |
| 126 class B extends A { | 126 class B extends A { |
| 127 main() { | 127 main() { |
| 128 var newName; | 128 var newName; |
| 129 test(); // marker | 129 test(); // marker |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 '''); | 132 '''); |
| 133 createRenameRefactoringAtString('test() {}'); | 133 createRenameRefactoringAtString('test() {}'); |
| 134 // check status | 134 // check status |
| 135 refactoring.newName = 'newName'; | 135 refactoring.newName = 'newName'; |
| 136 return refactoring.checkFinalConditions().then((status) { | 136 return refactoring.checkFinalConditions().then((status) { |
| 137 assertRefactoringStatus( | 137 assertRefactoringStatus( |
| 138 status, | 138 status, |
| 139 RefactoringStatusSeverity.ERROR, | 139 RefactoringProblemSeverity.ERROR, |
| 140 expectedMessage: | 140 expectedMessage: |
| 141 "Usage of renamed method will be shadowed by local variable 'newNa
me'.", | 141 "Usage of renamed method will be shadowed by local variable 'newNa
me'.", |
| 142 expectedContextSearch: 'test(); // marker'); | 142 expectedContextSearch: 'test(); // marker'); |
| 143 }); | 143 }); |
| 144 } | 144 } |
| 145 | 145 |
| 146 test_checkFinalConditions_shadowed_byParameter_inSameClass() { | 146 test_checkFinalConditions_shadowed_byParameter_inSameClass() { |
| 147 indexTestUnit(''' | 147 indexTestUnit(''' |
| 148 class A { | 148 class A { |
| 149 test() {} | 149 test() {} |
| 150 main(newName) { | 150 main(newName) { |
| 151 test(); // marker | 151 test(); // marker |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 '''); | 154 '''); |
| 155 createRenameRefactoringAtString('test() {}'); | 155 createRenameRefactoringAtString('test() {}'); |
| 156 // check status | 156 // check status |
| 157 refactoring.newName = 'newName'; | 157 refactoring.newName = 'newName'; |
| 158 return refactoring.checkFinalConditions().then((status) { | 158 return refactoring.checkFinalConditions().then((status) { |
| 159 assertRefactoringStatus( | 159 assertRefactoringStatus( |
| 160 status, | 160 status, |
| 161 RefactoringStatusSeverity.ERROR, | 161 RefactoringProblemSeverity.ERROR, |
| 162 expectedMessage: | 162 expectedMessage: |
| 163 "Usage of renamed method will be shadowed by parameter 'newName'."
, | 163 "Usage of renamed method will be shadowed by parameter 'newName'."
, |
| 164 expectedContextSearch: 'test(); // marker'); | 164 expectedContextSearch: 'test(); // marker'); |
| 165 }); | 165 }); |
| 166 } | 166 } |
| 167 | 167 |
| 168 test_checkFinalConditions_shadowed_inSubClass() { | 168 test_checkFinalConditions_shadowed_inSubClass() { |
| 169 indexTestUnit(''' | 169 indexTestUnit(''' |
| 170 class A { | 170 class A { |
| 171 newName() {} // marker | 171 newName() {} // marker |
| 172 } | 172 } |
| 173 class B extends A { | 173 class B extends A { |
| 174 test() {} | 174 test() {} |
| 175 main() { | 175 main() { |
| 176 newName(); | 176 newName(); |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 '''); | 179 '''); |
| 180 createRenameRefactoringAtString('test() {}'); | 180 createRenameRefactoringAtString('test() {}'); |
| 181 // check status | 181 // check status |
| 182 refactoring.newName = 'newName'; | 182 refactoring.newName = 'newName'; |
| 183 return refactoring.checkFinalConditions().then((status) { | 183 return refactoring.checkFinalConditions().then((status) { |
| 184 assertRefactoringStatus( | 184 assertRefactoringStatus( |
| 185 status, | 185 status, |
| 186 RefactoringStatusSeverity.ERROR, | 186 RefactoringProblemSeverity.ERROR, |
| 187 expectedMessage: "Renamed method will shadow method 'A.newName'.", | 187 expectedMessage: "Renamed method will shadow method 'A.newName'.", |
| 188 expectedContextSearch: 'newName() {} // marker'); | 188 expectedContextSearch: 'newName() {} // marker'); |
| 189 }); | 189 }); |
| 190 } | 190 } |
| 191 | 191 |
| 192 test_checkFinalConditions_shadowsSuper_MethodElement() { | 192 test_checkFinalConditions_shadowsSuper_MethodElement() { |
| 193 indexTestUnit(''' | 193 indexTestUnit(''' |
| 194 class A { | 194 class A { |
| 195 test() {} | 195 test() {} |
| 196 } | 196 } |
| 197 class B extends A { | 197 class B extends A { |
| 198 newName() {} // marker | 198 newName() {} // marker |
| 199 main() { | 199 main() { |
| 200 test(); | 200 test(); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 '''); | 203 '''); |
| 204 createRenameRefactoringAtString('test() {}'); | 204 createRenameRefactoringAtString('test() {}'); |
| 205 // check status | 205 // check status |
| 206 refactoring.newName = 'newName'; | 206 refactoring.newName = 'newName'; |
| 207 return refactoring.checkFinalConditions().then((status) { | 207 return refactoring.checkFinalConditions().then((status) { |
| 208 assertRefactoringStatus( | 208 assertRefactoringStatus( |
| 209 status, | 209 status, |
| 210 RefactoringStatusSeverity.ERROR, | 210 RefactoringProblemSeverity.ERROR, |
| 211 expectedMessage: "Renamed method will be shadowed by method 'B.newName
'.", | 211 expectedMessage: "Renamed method will be shadowed by method 'B.newName
'.", |
| 212 expectedContextSearch: 'newName() {} // marker'); | 212 expectedContextSearch: 'newName() {} // marker'); |
| 213 }); | 213 }); |
| 214 } | 214 } |
| 215 | 215 |
| 216 test_checkFinalConditions_shadowsSuper_inSubClass_FieldElement() { | 216 test_checkFinalConditions_shadowsSuper_inSubClass_FieldElement() { |
| 217 indexTestUnit(''' | 217 indexTestUnit(''' |
| 218 class A { | 218 class A { |
| 219 int newName; // marker | 219 int newName; // marker |
| 220 } | 220 } |
| 221 class B extends A { | 221 class B extends A { |
| 222 test() {} | 222 test() {} |
| 223 } | 223 } |
| 224 class C extends B { | 224 class C extends B { |
| 225 main() { | 225 main() { |
| 226 print(newName); | 226 print(newName); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 '''); | 229 '''); |
| 230 createRenameRefactoringAtString('test() {}'); | 230 createRenameRefactoringAtString('test() {}'); |
| 231 // check status | 231 // check status |
| 232 refactoring.newName = 'newName'; | 232 refactoring.newName = 'newName'; |
| 233 return refactoring.checkFinalConditions().then((status) { | 233 return refactoring.checkFinalConditions().then((status) { |
| 234 assertRefactoringStatus( | 234 assertRefactoringStatus( |
| 235 status, | 235 status, |
| 236 RefactoringStatusSeverity.ERROR, | 236 RefactoringProblemSeverity.ERROR, |
| 237 expectedMessage: "Renamed method will shadow field 'A.newName'.", | 237 expectedMessage: "Renamed method will shadow field 'A.newName'.", |
| 238 expectedContextSearch: 'newName; // marker'); | 238 expectedContextSearch: 'newName; // marker'); |
| 239 }); | 239 }); |
| 240 } | 240 } |
| 241 | 241 |
| 242 test_checkInitialConditions_operator() { | 242 test_checkInitialConditions_operator() { |
| 243 indexTestUnit(''' | 243 indexTestUnit(''' |
| 244 class A { | 244 class A { |
| 245 operator -(other) => this; | 245 operator -(other) => this; |
| 246 } | 246 } |
| 247 '''); | 247 '''); |
| 248 createRenameRefactoringAtString('-(other)'); | 248 createRenameRefactoringAtString('-(other)'); |
| 249 // check status | 249 // check status |
| 250 refactoring.newName = 'newName'; | 250 refactoring.newName = 'newName'; |
| 251 return refactoring.checkInitialConditions().then((status) { | 251 return refactoring.checkInitialConditions().then((status) { |
| 252 assertRefactoringStatus(status, RefactoringStatusSeverity.FATAL); | 252 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); |
| 253 }); | 253 }); |
| 254 } | 254 } |
| 255 | 255 |
| 256 test_checkNewName_FieldElement() { | 256 test_checkNewName_FieldElement() { |
| 257 indexTestUnit(''' | 257 indexTestUnit(''' |
| 258 class A { | 258 class A { |
| 259 int test; | 259 int test; |
| 260 } | 260 } |
| 261 '''); | 261 '''); |
| 262 createRenameRefactoringAtString('test;'); | 262 createRenameRefactoringAtString('test;'); |
| 263 // null | 263 // null |
| 264 refactoring.newName = null; | 264 refactoring.newName = null; |
| 265 assertRefactoringStatus( | 265 assertRefactoringStatus( |
| 266 refactoring.checkNewName(), | 266 refactoring.checkNewName(), |
| 267 RefactoringStatusSeverity.ERROR, | 267 RefactoringProblemSeverity.ERROR, |
| 268 expectedMessage: "Field name must not be null."); | 268 expectedMessage: "Field name must not be null."); |
| 269 // OK | 269 // OK |
| 270 refactoring.newName = 'newName'; | 270 refactoring.newName = 'newName'; |
| 271 assertRefactoringStatusOK(refactoring.checkNewName()); | 271 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 272 } | 272 } |
| 273 | 273 |
| 274 test_checkNewName_FieldElement_const() { | 274 test_checkNewName_FieldElement_const() { |
| 275 indexTestUnit(''' | 275 indexTestUnit(''' |
| 276 class A { | 276 class A { |
| 277 static const int TEST = 0; | 277 static const int TEST = 0; |
| 278 } | 278 } |
| 279 '''); | 279 '''); |
| 280 createRenameRefactoringAtString('TEST ='); | 280 createRenameRefactoringAtString('TEST ='); |
| 281 // null | 281 // null |
| 282 refactoring.newName = null; | 282 refactoring.newName = null; |
| 283 assertRefactoringStatus( | 283 assertRefactoringStatus( |
| 284 refactoring.checkNewName(), | 284 refactoring.checkNewName(), |
| 285 RefactoringStatusSeverity.ERROR, | 285 RefactoringProblemSeverity.ERROR, |
| 286 expectedMessage: "Constant name must not be null."); | 286 expectedMessage: "Constant name must not be null."); |
| 287 // not upper case | 287 // not upper case |
| 288 refactoring.newName = 'newName'; | 288 refactoring.newName = 'newName'; |
| 289 assertRefactoringStatus( | 289 assertRefactoringStatus( |
| 290 refactoring.checkNewName(), | 290 refactoring.checkNewName(), |
| 291 RefactoringStatusSeverity.WARNING); | 291 RefactoringProblemSeverity.WARNING); |
| 292 // OK | 292 // OK |
| 293 refactoring.newName = 'NEW_NAME'; | 293 refactoring.newName = 'NEW_NAME'; |
| 294 assertRefactoringStatusOK(refactoring.checkNewName()); | 294 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 295 } | 295 } |
| 296 | 296 |
| 297 test_checkNewName_MethodElement() { | 297 test_checkNewName_MethodElement() { |
| 298 indexTestUnit(''' | 298 indexTestUnit(''' |
| 299 class A { | 299 class A { |
| 300 test() {} | 300 test() {} |
| 301 } | 301 } |
| 302 '''); | 302 '''); |
| 303 createRenameRefactoringAtString('test() {}'); | 303 createRenameRefactoringAtString('test() {}'); |
| 304 // null | 304 // null |
| 305 refactoring.newName = null; | 305 refactoring.newName = null; |
| 306 assertRefactoringStatus( | 306 assertRefactoringStatus( |
| 307 refactoring.checkNewName(), | 307 refactoring.checkNewName(), |
| 308 RefactoringStatusSeverity.ERROR, | 308 RefactoringProblemSeverity.ERROR, |
| 309 expectedMessage: "Method name must not be null."); | 309 expectedMessage: "Method name must not be null."); |
| 310 // empty | 310 // empty |
| 311 refactoring.newName = ''; | 311 refactoring.newName = ''; |
| 312 assertRefactoringStatus( | 312 assertRefactoringStatus( |
| 313 refactoring.checkNewName(), | 313 refactoring.checkNewName(), |
| 314 RefactoringStatusSeverity.ERROR, | 314 RefactoringProblemSeverity.ERROR, |
| 315 expectedMessage: "Method name must not be empty."); | 315 expectedMessage: "Method name must not be empty."); |
| 316 // same | 316 // same |
| 317 refactoring.newName = 'test'; | 317 refactoring.newName = 'test'; |
| 318 assertRefactoringStatus( | 318 assertRefactoringStatus( |
| 319 refactoring.checkNewName(), | 319 refactoring.checkNewName(), |
| 320 RefactoringStatusSeverity.FATAL, | 320 RefactoringProblemSeverity.FATAL, |
| 321 expectedMessage: "The new name must be different than the current name."
); | 321 expectedMessage: "The new name must be different than the current name."
); |
| 322 // OK | 322 // OK |
| 323 refactoring.newName = 'newName'; | 323 refactoring.newName = 'newName'; |
| 324 assertRefactoringStatusOK(refactoring.checkNewName()); | 324 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 325 } | 325 } |
| 326 | 326 |
| 327 test_createChange_FieldElement() { | 327 test_createChange_FieldElement() { |
| 328 indexTestUnit(''' | 328 indexTestUnit(''' |
| 329 class A { | 329 class A { |
| 330 int test; // marker | 330 int test; // marker |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 // validate change | 725 // validate change |
| 726 return assertSuccessfulRename(''' | 726 return assertSuccessfulRename(''' |
| 727 class A<NewName> { | 727 class A<NewName> { |
| 728 NewName field; | 728 NewName field; |
| 729 List<NewName> items; | 729 List<NewName> items; |
| 730 NewName method(NewName p) => null; | 730 NewName method(NewName p) => null; |
| 731 } | 731 } |
| 732 '''); | 732 '''); |
| 733 } | 733 } |
| 734 } | 734 } |
| OLD | NEW |