| 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_constructor; | 5 library test.services.refactoring.rename_constructor; |
| 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:analysis_server/src/services/refactoring/refactoring.dart'; | 9 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 class B extends A { | 125 class B extends A { |
| 126 B() : super.newName() {} | 126 B() : super.newName() {} |
| 127 factory B._() = A.newName; | 127 factory B._() = A.newName; |
| 128 } | 128 } |
| 129 main() { | 129 main() { |
| 130 new A.newName(); | 130 new A.newName(); |
| 131 } | 131 } |
| 132 '''); | 132 '''); |
| 133 } | 133 } |
| 134 | 134 |
| 135 test_createChange_add_toSynthetic() { |
| 136 indexTestUnit(''' |
| 137 class A { |
| 138 } |
| 139 class B extends A { |
| 140 B() : super() {} |
| 141 factory B._() = A; |
| 142 } |
| 143 main() { |
| 144 new A(); |
| 145 } |
| 146 '''); |
| 147 // configure refactoring |
| 148 _createConstructorInvocationRefactoring('new A();'); |
| 149 expect(refactoring.refactoringName, 'Rename Constructor'); |
| 150 expect(refactoring.elementKindName, 'constructor'); |
| 151 expect(refactoring.oldName, ''); |
| 152 // validate change |
| 153 refactoring.newName = 'newName'; |
| 154 return assertSuccessfulRefactoring(''' |
| 155 class A { |
| 156 A.newName(); |
| 157 } |
| 158 class B extends A { |
| 159 B() : super.newName() {} |
| 160 factory B._() = A.newName; |
| 161 } |
| 162 main() { |
| 163 new A.newName(); |
| 164 } |
| 165 '''); |
| 166 } |
| 167 |
| 135 test_createChange_change() { | 168 test_createChange_change() { |
| 136 indexTestUnit(''' | 169 indexTestUnit(''' |
| 137 class A { | 170 class A { |
| 138 A.test() {} // marker | 171 A.test() {} // marker |
| 139 } | 172 } |
| 140 class B extends A { | 173 class B extends A { |
| 141 B() : super.test() {} | 174 B() : super.test() {} |
| 142 factory B._() = A.test; | 175 factory B._() = A.test; |
| 143 } | 176 } |
| 144 main() { | 177 main() { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 void test_newInstance_nullElement() { | 236 void test_newInstance_nullElement() { |
| 204 RenameRefactoring refactoring = new RenameRefactoring(searchEngine, null); | 237 RenameRefactoring refactoring = new RenameRefactoring(searchEngine, null); |
| 205 expect(refactoring, isNull); | 238 expect(refactoring, isNull); |
| 206 } | 239 } |
| 207 | 240 |
| 208 void _createConstructorDeclarationRefactoring(String search) { | 241 void _createConstructorDeclarationRefactoring(String search) { |
| 209 ConstructorElement element = findNodeElementAtString( | 242 ConstructorElement element = findNodeElementAtString( |
| 210 search, (node) => node is ConstructorDeclaration); | 243 search, (node) => node is ConstructorDeclaration); |
| 211 createRenameRefactoringForElement(element); | 244 createRenameRefactoringForElement(element); |
| 212 } | 245 } |
| 246 |
| 247 void _createConstructorInvocationRefactoring(String search) { |
| 248 ConstructorElement element = findNodeElementAtString( |
| 249 search, (node) => node is InstanceCreationExpression); |
| 250 createRenameRefactoringForElement(element); |
| 251 } |
| 213 } | 252 } |
| OLD | NEW |