Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Unified Diff: pkg/analysis_server/lib/src/services/refactoring/refactoring.dart

Issue 2685783012: Fix for 'Rename Local' refactoring without tasks. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/refactoring/refactoring.dart
diff --git a/pkg/analysis_server/lib/src/services/refactoring/refactoring.dart b/pkg/analysis_server/lib/src/services/refactoring/refactoring.dart
index 115d937b3c321a331a1dc7021a107c59c138828c..480d1c94beec41ce0c986362ec791ba60ac65582 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/refactoring.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/refactoring.dart
@@ -397,7 +397,7 @@ abstract class RenameRefactoring implements Refactoring {
return new RenameLibraryRefactoringImpl(searchEngine, element);
}
if (element is LocalElement) {
- return new RenameLocalRefactoringImpl(searchEngine, element);
+ return new RenameLocalRefactoringImpl(searchEngine, astProvider, element);
}
if (element.enclosingElement is ClassElement) {
return new RenameClassMemberRefactoringImpl(searchEngine, element);
@@ -432,3 +432,33 @@ abstract class RenameRefactoring implements Refactoring {
*/
RefactoringStatus checkNewName();
}
+
+/**
+ * Cache for accessing resolved [CompilationUnit]s by [Element]s.
+ *
+ * Must by short-lived.
+ *
+ * TODO(scheglov) consider moving to request-bound object.
+ */
+class ResolvedUnitCache {
+ final AstProvider _astProvider;
+ final Map<CompilationUnitElement, CompilationUnit> _map = {};
+
+ ResolvedUnitCache(this._astProvider, [CompilationUnit unit]) {
+ if (unit != null) {
+ _map[unit.element] = unit;
+ }
+ }
+
+ Future<CompilationUnit> getUnit(Element element) async {
+ CompilationUnitElement unitElement =
+ element.getAncestor((e) => e is CompilationUnitElement)
+ as CompilationUnitElement;
+ CompilationUnit unit = _map[unitElement];
+ if (unit == null) {
+ unit = await _astProvider.getResolvedUnitForElement(element);
+ _map[unitElement] = unit;
+ }
+ return unit;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698