| 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_unit_member; | 5 library test.services.refactoring.rename_unit_member; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol.dart'; | 7 import 'package:analysis_server/src/protocol.dart'; |
| 8 import 'package:analysis_server/src/services/correction/status.dart'; |
| 8 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 9 | 10 |
| 10 import '../../reflective_tests.dart'; | 11 import '../../reflective_tests.dart'; |
| 11 import 'abstract_rename.dart'; | 12 import 'abstract_rename.dart'; |
| 12 | 13 |
| 13 | 14 |
| 14 main() { | 15 main() { |
| 15 groupSep = ' | '; | 16 groupSep = ' | '; |
| 16 runReflectiveTests(RenameUnitMemberTest); | 17 runReflectiveTests(RenameUnitMemberTest); |
| 17 } | 18 } |
| 18 | 19 |
| 19 | 20 |
| 20 @reflectiveTest | 21 @reflectiveTest |
| 21 class RenameUnitMemberTest extends RenameRefactoringTest { | 22 class RenameUnitMemberTest extends RenameRefactoringTest { |
| 22 test_checkFinalConditions_hasTopLevel_ClassElement() { | 23 test_checkFinalConditions_hasTopLevel_ClassElement() async { |
| 23 indexTestUnit(''' | 24 indexTestUnit(''' |
| 24 class Test {} | 25 class Test {} |
| 25 class NewName {} // existing | 26 class NewName {} // existing |
| 26 '''); | 27 '''); |
| 27 createRenameRefactoringAtString('Test {}'); | 28 createRenameRefactoringAtString('Test {}'); |
| 28 // check status | 29 // check status |
| 29 refactoring.newName = 'NewName'; | 30 refactoring.newName = 'NewName'; |
| 30 return refactoring.checkFinalConditions().then((status) { | 31 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 31 assertRefactoringStatus( | 32 assertRefactoringStatus( |
| 32 status, | 33 status, |
| 33 RefactoringProblemSeverity.ERROR, | 34 RefactoringProblemSeverity.ERROR, |
| 34 expectedMessage: "Library already declares class with name 'NewName'."
, | 35 expectedMessage: "Library already declares class with name 'NewName'.", |
| 35 expectedContextSearch: 'NewName {} // existing'); | 36 expectedContextSearch: 'NewName {} // existing'); |
| 36 }); | |
| 37 } | 37 } |
| 38 | 38 |
| 39 test_checkFinalConditions_hasTopLevel_FunctionTypeAliasElement() { | 39 test_checkFinalConditions_hasTopLevel_FunctionTypeAliasElement() async { |
| 40 indexTestUnit(''' | 40 indexTestUnit(''' |
| 41 class Test {} | 41 class Test {} |
| 42 typedef NewName(); // existing | 42 typedef NewName(); // existing |
| 43 '''); | 43 '''); |
| 44 createRenameRefactoringAtString('Test {}'); | 44 createRenameRefactoringAtString('Test {}'); |
| 45 // check status | 45 // check status |
| 46 refactoring.newName = 'NewName'; | 46 refactoring.newName = 'NewName'; |
| 47 return refactoring.checkFinalConditions().then((status) { | 47 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 48 assertRefactoringStatus( | 48 assertRefactoringStatus( |
| 49 status, | 49 status, |
| 50 RefactoringProblemSeverity.ERROR, | 50 RefactoringProblemSeverity.ERROR, |
| 51 expectedMessage: | 51 expectedMessage: |
| 52 "Library already declares function type alias with name 'NewName'.
", | 52 "Library already declares function type alias with name 'NewName'.", |
| 53 expectedContextSearch: 'NewName(); // existing'); | 53 expectedContextSearch: 'NewName(); // existing'); |
| 54 }); | |
| 55 } | 54 } |
| 56 | 55 |
| 57 test_checkFinalConditions_OK_qualifiedSuper_MethodElement() { | 56 test_checkFinalConditions_OK_qualifiedSuper_MethodElement() async { |
| 58 indexTestUnit(''' | 57 indexTestUnit(''' |
| 59 class Test {} | 58 class Test {} |
| 60 class A { | 59 class A { |
| 61 NewName() {} | 60 NewName() {} |
| 62 } | 61 } |
| 63 class B extends A { | 62 class B extends A { |
| 64 main() { | 63 main() { |
| 65 super.NewName(); // super-ref | 64 super.NewName(); // super-ref |
| 66 } | 65 } |
| 67 } | 66 } |
| 68 '''); | 67 '''); |
| 69 createRenameRefactoringAtString('Test {}'); | 68 createRenameRefactoringAtString('Test {}'); |
| 70 // check status | 69 // check status |
| 71 refactoring.newName = 'NewName'; | 70 refactoring.newName = 'NewName'; |
| 72 return refactoring.checkFinalConditions().then((status) { | 71 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 73 assertRefactoringStatusOK(status); | 72 assertRefactoringStatusOK(status); |
| 74 }); | |
| 75 } | 73 } |
| 76 | 74 |
| 77 test_checkFinalConditions_shadowedBy_MethodElement() { | 75 test_checkFinalConditions_shadowedBy_MethodElement() async { |
| 78 indexTestUnit(''' | 76 indexTestUnit(''' |
| 79 class Test {} | 77 class Test {} |
| 80 class A { | 78 class A { |
| 81 void NewName() {} | 79 void NewName() {} |
| 82 main() { | 80 main() { |
| 83 new Test(); | 81 new Test(); |
| 84 } | 82 } |
| 85 } | 83 } |
| 86 '''); | 84 '''); |
| 87 createRenameRefactoringAtString('Test {}'); | 85 createRenameRefactoringAtString('Test {}'); |
| 88 // check status | 86 // check status |
| 89 refactoring.newName = 'NewName'; | 87 refactoring.newName = 'NewName'; |
| 90 return refactoring.checkFinalConditions().then((status) { | 88 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 91 assertRefactoringStatus( | 89 assertRefactoringStatus( |
| 92 status, | 90 status, |
| 93 RefactoringProblemSeverity.ERROR, | 91 RefactoringProblemSeverity.ERROR, |
| 94 expectedMessage: | 92 expectedMessage: |
| 95 "Reference to renamed class will be shadowed by method 'A.NewName'
.", | 93 "Reference to renamed class will be shadowed by method 'A.NewName'."
, |
| 96 expectedContextSearch: 'NewName() {}'); | 94 expectedContextSearch: 'NewName() {}'); |
| 97 }); | |
| 98 } | 95 } |
| 99 | 96 |
| 100 test_checkFinalConditions_shadowsInSubClass_importedLib() { | 97 test_checkFinalConditions_shadowsInSubClass_importedLib() async { |
| 101 indexTestUnit(''' | 98 indexTestUnit(''' |
| 102 class Test {} | 99 class Test {} |
| 103 '''); | 100 '''); |
| 104 indexUnit('/lib.dart', ''' | 101 indexUnit('/lib.dart', ''' |
| 105 library my.lib; | 102 library my.lib; |
| 106 import 'test.dart'; | 103 import 'test.dart'; |
| 107 class A { | 104 class A { |
| 108 NewName() {} | 105 NewName() {} |
| 109 } | 106 } |
| 110 class B extends A { | 107 class B extends A { |
| 111 main() { | 108 main() { |
| 112 NewName(); // super-ref | 109 NewName(); // super-ref |
| 113 }", | 110 }", |
| 114 } | 111 } |
| 115 '''); | 112 '''); |
| 116 createRenameRefactoringAtString('Test {}'); | 113 createRenameRefactoringAtString('Test {}'); |
| 117 // check status | 114 // check status |
| 118 refactoring.newName = 'NewName'; | 115 refactoring.newName = 'NewName'; |
| 119 return refactoring.checkFinalConditions().then((status) { | 116 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 120 assertRefactoringStatus( | 117 assertRefactoringStatus( |
| 121 status, | 118 status, |
| 122 RefactoringProblemSeverity.ERROR, | 119 RefactoringProblemSeverity.ERROR, |
| 123 expectedMessage: "Renamed class will shadow method 'A.NewName'."); | 120 expectedMessage: "Renamed class will shadow method 'A.NewName'."); |
| 124 }); | |
| 125 } | 121 } |
| 126 | 122 |
| 127 test_checkFinalConditions_shadowsInSubClass_importedLib_hideCombinator() { | 123 |
| 124 |
| 125 |
| 126 |
| 127 test_checkFinalConditions_shadowsInSubClass_importedLib_hideCombinator() a
sync { |
| 128 indexTestUnit(''' | 128 indexTestUnit(''' |
| 129 class Test {} | 129 class Test {} |
| 130 '''); | 130 '''); |
| 131 indexUnit('/lib.dart', ''' | 131 indexUnit('/lib.dart', ''' |
| 132 library my.lib; | 132 library my.lib; |
| 133 import 'test.dart' hide Test; | 133 import 'test.dart' hide Test; |
| 134 class A { | 134 class A { |
| 135 NewName() {} | 135 NewName() {} |
| 136 } | 136 } |
| 137 class B extends A { | 137 class B extends A { |
| 138 main() { | 138 main() { |
| 139 NewName(); // super-ref | 139 NewName(); // super-ref |
| 140 }", | 140 }", |
| 141 } | 141 } |
| 142 '''); | 142 '''); |
| 143 createRenameRefactoringAtString('Test {}'); | 143 createRenameRefactoringAtString('Test {}'); |
| 144 // check status | 144 // check status |
| 145 refactoring.newName = 'NewName'; | 145 refactoring.newName = 'NewName'; |
| 146 return refactoring.checkFinalConditions().then((status) { | 146 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 147 assertRefactoringStatusOK(status); | 147 assertRefactoringStatusOK(status); |
| 148 }); | |
| 149 } | 148 } |
| 150 | 149 |
| 151 test_checkFinalConditions_shadowsInSubClass_MethodElement() { | 150 test_checkFinalConditions_shadowsInSubClass_MethodElement() async { |
| 152 indexTestUnit(''' | 151 indexTestUnit(''' |
| 153 class Test {} | 152 class Test {} |
| 154 class A { | 153 class A { |
| 155 NewName() {} | 154 NewName() {} |
| 156 } | 155 } |
| 157 class B extends A { | 156 class B extends A { |
| 158 main() { | 157 main() { |
| 159 NewName(); // super-ref | 158 NewName(); // super-ref |
| 160 } | 159 } |
| 161 } | 160 } |
| 162 '''); | 161 '''); |
| 163 createRenameRefactoringAtString('Test {}'); | 162 createRenameRefactoringAtString('Test {}'); |
| 164 // check status | 163 // check status |
| 165 refactoring.newName = 'NewName'; | 164 refactoring.newName = 'NewName'; |
| 166 return refactoring.checkFinalConditions().then((status) { | 165 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 167 assertRefactoringStatus( | 166 assertRefactoringStatus( |
| 168 status, | 167 status, |
| 169 RefactoringProblemSeverity.ERROR, | 168 RefactoringProblemSeverity.ERROR, |
| 170 expectedMessage: "Renamed class will shadow method 'A.NewName'.", | 169 expectedMessage: "Renamed class will shadow method 'A.NewName'.", |
| 171 expectedContextSearch: 'NewName(); // super-ref'); | 170 expectedContextSearch: 'NewName(); // super-ref'); |
| 172 }); | |
| 173 } | 171 } |
| 174 | 172 |
| 175 test_checkFinalConditions_shadowsInSubClass_notImportedLib() { | 173 test_checkFinalConditions_shadowsInSubClass_notImportedLib() async { |
| 176 indexUnit('/lib.dart', ''' | 174 indexUnit('/lib.dart', ''' |
| 177 library my.lib; | 175 library my.lib; |
| 178 class A { | 176 class A { |
| 179 NewName() {} | 177 NewName() {} |
| 180 } | 178 } |
| 181 class B extends A { | 179 class B extends A { |
| 182 main() { | 180 main() { |
| 183 NewName(); // super-ref | 181 NewName(); // super-ref |
| 184 }", | 182 }", |
| 185 } | 183 } |
| 186 '''); | 184 '''); |
| 187 indexTestUnit(''' | 185 indexTestUnit(''' |
| 188 class Test {} | 186 class Test {} |
| 189 '''); | 187 '''); |
| 190 createRenameRefactoringAtString('Test {}'); | 188 createRenameRefactoringAtString('Test {}'); |
| 191 // check status | 189 // check status |
| 192 refactoring.newName = 'NewName'; | 190 refactoring.newName = 'NewName'; |
| 193 return refactoring.checkFinalConditions().then((status) { | 191 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 194 assertRefactoringStatusOK(status); | 192 assertRefactoringStatusOK(status); |
| 195 }); | |
| 196 } | 193 } |
| 197 | 194 |
| 198 test_checkFinalConditions_shadowsInSubClass_notSubClass() { | 195 test_checkFinalConditions_shadowsInSubClass_notSubClass() async { |
| 199 indexTestUnit(''' | 196 indexTestUnit(''' |
| 200 class Test {} | 197 class Test {} |
| 201 class A { | 198 class A { |
| 202 NewName() {} | 199 NewName() {} |
| 203 } | 200 } |
| 204 class B { | 201 class B { |
| 205 main(A a) { | 202 main(A a) { |
| 206 a.NewName(); | 203 a.NewName(); |
| 207 } | 204 } |
| 208 } | 205 } |
| 209 '''); | 206 '''); |
| 210 createRenameRefactoringAtString('Test {}'); | 207 createRenameRefactoringAtString('Test {}'); |
| 211 // check status | 208 // check status |
| 212 refactoring.newName = 'NewName'; | 209 refactoring.newName = 'NewName'; |
| 213 return refactoring.checkFinalConditions().then((status) { | 210 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 214 assertRefactoringStatusOK(status); | 211 assertRefactoringStatusOK(status); |
| 215 }); | |
| 216 } | 212 } |
| 217 | 213 |
| 218 test_checkNewName_ClassElement() { | 214 test_checkNewName_ClassElement() { |
| 219 indexTestUnit(''' | 215 indexTestUnit(''' |
| 220 class Test {} | 216 class Test {} |
| 221 '''); | 217 '''); |
| 222 createRenameRefactoringAtString('Test {}'); | 218 createRenameRefactoringAtString('Test {}'); |
| 223 // null | 219 // null |
| 224 refactoring.newName = null; | 220 refactoring.newName = null; |
| 225 assertRefactoringStatus( | 221 assertRefactoringStatus( |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 return assertSuccessfulRefactoring(''' | 490 return assertSuccessfulRefactoring(''' |
| 495 int newName = 0; | 491 int newName = 0; |
| 496 main() { | 492 main() { |
| 497 print(newName); | 493 print(newName); |
| 498 newName = 1; | 494 newName = 1; |
| 499 newName += 2; | 495 newName += 2; |
| 500 } | 496 } |
| 501 '''); | 497 '''); |
| 502 } | 498 } |
| 503 } | 499 } |
| OLD | NEW |