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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 server.sendResponse( | 393 server.sendResponse( |
394 new Response.serverError(_request, exception, stackTrace)); | 394 new Response.serverError(_request, exception, stackTrace)); |
395 _reset(); | 395 _reset(); |
396 }); | 396 }); |
397 } | 397 } |
398 | 398 |
399 /** | 399 /** |
400 * Initializes this context to perform a refactoring with the specified | 400 * Initializes this context to perform a refactoring with the specified |
401 * parameters. The existing [Refactoring] is reused or created as needed. | 401 * parameters. The existing [Refactoring] is reused or created as needed. |
402 */ | 402 */ |
403 Future _init(RefactoringKind kind, String file, | 403 Future _init(RefactoringKind kind, String file, int offset, |
404 int offset, int length) async { | 404 int length) async { |
405 await server.onAnalysisComplete; | 405 await server.onAnalysisComplete; |
406 // check if we can continue with the existing Refactoring instance | 406 // check if we can continue with the existing Refactoring instance |
407 if (this.kind == kind && | 407 if (this.kind == kind && |
408 this.file == file && | 408 this.file == file && |
409 this.offset == offset && | 409 this.offset == offset && |
410 this.length == length) { | 410 this.length == length) { |
411 return; | 411 return; |
412 } | 412 } |
413 _reset(); | 413 _reset(); |
414 this.kind = kind; | 414 this.kind = kind; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 } | 481 } |
482 if (kind == RefactoringKind.RENAME) { | 482 if (kind == RefactoringKind.RENAME) { |
483 List<AstNode> nodes = server.getNodesAtOffset(file, offset); | 483 List<AstNode> nodes = server.getNodesAtOffset(file, offset); |
484 List<Element> elements = server.getElementsOfNodes(nodes, offset); | 484 List<Element> elements = server.getElementsOfNodes(nodes, offset); |
485 if (nodes.isNotEmpty && elements.isNotEmpty) { | 485 if (nodes.isNotEmpty && elements.isNotEmpty) { |
486 AstNode node = nodes[0]; | 486 AstNode node = nodes[0]; |
487 Element element = elements[0]; | 487 Element element = elements[0]; |
488 if (element is FieldFormalParameterElement) { | 488 if (element is FieldFormalParameterElement) { |
489 element = (element as FieldFormalParameterElement).field; | 489 element = (element as FieldFormalParameterElement).field; |
490 } | 490 } |
491 // climb from "Class" in "new Class()" to "new Class()" | 491 // climb from "Class" in "new Class.named()" to "Class.named" |
492 if (node.parent is TypeName && | 492 if (node.parent is TypeName && node.parent.parent is ConstructorName) { |
493 node.parent.parent is ConstructorName && | 493 ConstructorName constructor = node.parent.parent; |
494 node.parent.parent.parent is InstanceCreationExpression) { | 494 node = constructor; |
495 InstanceCreationExpression creation = node.parent.parent.parent; | 495 element = constructor.staticElement; |
496 node = creation; | |
497 element = creation.staticElement; | |
498 } | 496 } |
499 // do create the refactoring | 497 // do create the refactoring |
500 refactoring = new RenameRefactoring(searchEngine, element); | 498 refactoring = new RenameRefactoring(searchEngine, element); |
501 feedback = | 499 feedback = |
502 new RenameFeedback(node.offset, node.length, 'kind', 'oldName'); | 500 new RenameFeedback(node.offset, node.length, 'kind', 'oldName'); |
503 } | 501 } |
504 } | 502 } |
505 if (refactoring == null) { | 503 if (refactoring == null) { |
506 initStatus = | 504 initStatus = |
507 new RefactoringStatus.fatal('Unable to create a refactoring'); | 505 new RefactoringStatus.fatal('Unable to create a refactoring'); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 } | 613 } |
616 if (refactoring is RenameRefactoring) { | 614 if (refactoring is RenameRefactoring) { |
617 RenameRefactoring renameRefactoring = refactoring; | 615 RenameRefactoring renameRefactoring = refactoring; |
618 RenameOptions renameOptions = params.options; | 616 RenameOptions renameOptions = params.options; |
619 renameRefactoring.newName = renameOptions.newName; | 617 renameRefactoring.newName = renameOptions.newName; |
620 return renameRefactoring.checkNewName(); | 618 return renameRefactoring.checkNewName(); |
621 } | 619 } |
622 return new RefactoringStatus(); | 620 return new RefactoringStatus(); |
623 } | 621 } |
624 } | 622 } |
OLD | NEW |