| 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 services.refactoring; | 5 library services.refactoring; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart' | 9 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 10 show RefactoringMethodParameter, SourceChange; | 10 show RefactoringMethodParameter, SourceChange; |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 if (element is ImportElement) { | 390 if (element is ImportElement) { |
| 391 return new RenameImportRefactoringImpl(searchEngine, element); | 391 return new RenameImportRefactoringImpl(searchEngine, element); |
| 392 } | 392 } |
| 393 if (element is LabelElement) { | 393 if (element is LabelElement) { |
| 394 return new RenameLabelRefactoringImpl(searchEngine, element); | 394 return new RenameLabelRefactoringImpl(searchEngine, element); |
| 395 } | 395 } |
| 396 if (element is LibraryElement) { | 396 if (element is LibraryElement) { |
| 397 return new RenameLibraryRefactoringImpl(searchEngine, element); | 397 return new RenameLibraryRefactoringImpl(searchEngine, element); |
| 398 } | 398 } |
| 399 if (element is LocalElement) { | 399 if (element is LocalElement) { |
| 400 return new RenameLocalRefactoringImpl(searchEngine, element); | 400 return new RenameLocalRefactoringImpl(searchEngine, astProvider, element); |
| 401 } | 401 } |
| 402 if (element.enclosingElement is ClassElement) { | 402 if (element.enclosingElement is ClassElement) { |
| 403 return new RenameClassMemberRefactoringImpl(searchEngine, element); | 403 return new RenameClassMemberRefactoringImpl(searchEngine, element); |
| 404 } | 404 } |
| 405 return null; | 405 return null; |
| 406 } | 406 } |
| 407 | 407 |
| 408 /** | 408 /** |
| 409 * Returns the human-readable description of the kind of element being renamed | 409 * Returns the human-readable description of the kind of element being renamed |
| 410 * (such as “class” or “function type alias”). | 410 * (such as “class” or “function type alias”). |
| (...skipping 14 matching lines...) Expand all Loading... |
| 425 * Validates that the [newName] is a valid identifier and is appropriate for | 425 * Validates that the [newName] is a valid identifier and is appropriate for |
| 426 * the type of the [Element] being renamed. | 426 * the type of the [Element] being renamed. |
| 427 * | 427 * |
| 428 * It does not perform all the checks (such as checking for conflicts with any | 428 * It does not perform all the checks (such as checking for conflicts with any |
| 429 * existing names in any of the scopes containing the current name), as many | 429 * existing names in any of the scopes containing the current name), as many |
| 430 * of these checkes require search engine. Use [checkFinalConditions] for this | 430 * of these checkes require search engine. Use [checkFinalConditions] for this |
| 431 * level of checking. | 431 * level of checking. |
| 432 */ | 432 */ |
| 433 RefactoringStatus checkNewName(); | 433 RefactoringStatus checkNewName(); |
| 434 } | 434 } |
| 435 |
| 436 /** |
| 437 * Cache for accessing resolved [CompilationUnit]s by [Element]s. |
| 438 * |
| 439 * Must by short-lived. |
| 440 * |
| 441 * TODO(scheglov) consider moving to request-bound object. |
| 442 */ |
| 443 class ResolvedUnitCache { |
| 444 final AstProvider _astProvider; |
| 445 final Map<CompilationUnitElement, CompilationUnit> _map = {}; |
| 446 |
| 447 ResolvedUnitCache(this._astProvider, [CompilationUnit unit]) { |
| 448 if (unit != null) { |
| 449 _map[unit.element] = unit; |
| 450 } |
| 451 } |
| 452 |
| 453 Future<CompilationUnit> getUnit(Element element) async { |
| 454 CompilationUnitElement unitElement = |
| 455 element.getAncestor((e) => e is CompilationUnitElement) |
| 456 as CompilationUnitElement; |
| 457 CompilationUnit unit = _map[unitElement]; |
| 458 if (unit == null) { |
| 459 unit = await _astProvider.getResolvedUnitForElement(element); |
| 460 _map[unitElement] = unit; |
| 461 } |
| 462 return unit; |
| 463 } |
| 464 } |
| OLD | NEW |