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 edit.domain; | 5 library edit.domain; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
10 import 'package:analysis_server/src/collections.dart'; | 10 import 'package:analysis_server/src/collections.dart'; |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 searchEngine, | 365 searchEngine, |
366 context, | 366 context, |
367 source); | 367 source); |
368 } | 368 } |
369 if (kind == RefactoringKind.RENAME) { | 369 if (kind == RefactoringKind.RENAME) { |
370 List<AstNode> nodes = server.getNodesAtOffset(file, offset); | 370 List<AstNode> nodes = server.getNodesAtOffset(file, offset); |
371 List<Element> elements = server.getElementsOfNodes(nodes, offset); | 371 List<Element> elements = server.getElementsOfNodes(nodes, offset); |
372 if (nodes.isNotEmpty && elements.isNotEmpty) { | 372 if (nodes.isNotEmpty && elements.isNotEmpty) { |
373 AstNode node = nodes[0]; | 373 AstNode node = nodes[0]; |
374 Element element = elements[0]; | 374 Element element = elements[0]; |
| 375 // climb from "Class" in "new Class()" to "new Class()" |
| 376 if (node.parent is TypeName && |
| 377 node.parent.parent is ConstructorName && |
| 378 node.parent.parent.parent is InstanceCreationExpression) { |
| 379 InstanceCreationExpression creation = node.parent.parent.parent; |
| 380 node = creation; |
| 381 element = creation.staticElement; |
| 382 } |
| 383 // do create the refactoring |
375 refactoring = new RenameRefactoring(searchEngine, element); | 384 refactoring = new RenameRefactoring(searchEngine, element); |
376 feedback = | 385 feedback = |
377 new RenameFeedback(node.offset, node.length, 'kind', 'oldName'); | 386 new RenameFeedback(node.offset, node.length, 'kind', 'oldName'); |
378 } | 387 } |
379 } | 388 } |
380 if (refactoring == null) { | 389 if (refactoring == null) { |
381 initStatus = | 390 initStatus = |
382 new RefactoringStatus.fatal('Unable to create a refactoring'); | 391 new RefactoringStatus.fatal('Unable to create a refactoring'); |
383 return new Future.value(initStatus); | 392 return new Future.value(initStatus); |
384 } | 393 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 } | 499 } |
491 if (refactoring is RenameRefactoring) { | 500 if (refactoring is RenameRefactoring) { |
492 RenameRefactoring renameRefactoring = refactoring; | 501 RenameRefactoring renameRefactoring = refactoring; |
493 RenameOptions renameOptions = params.options; | 502 RenameOptions renameOptions = params.options; |
494 renameRefactoring.newName = renameOptions.newName; | 503 renameRefactoring.newName = renameOptions.newName; |
495 return renameRefactoring.checkNewName(); | 504 return renameRefactoring.checkNewName(); |
496 } | 505 } |
497 return new RefactoringStatus(); | 506 return new RefactoringStatus(); |
498 } | 507 } |
499 } | 508 } |
OLD | NEW |