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

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

Issue 533273003: Use unit + offset as 'Inline Local' arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/refactoring/refactoring.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/refactoring/inline_local.dart
diff --git a/pkg/analysis_server/lib/src/services/refactoring/inline_local.dart b/pkg/analysis_server/lib/src/services/refactoring/inline_local.dart
index f9aea0ceccb220679d9e2727ad9fafc7a5d0a528..c04d9e53bae2807672f9ee5a782edb0331a2576d 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/inline_local.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/inline_local.dart
@@ -29,14 +29,15 @@ class InlineLocalRefactoringImpl extends RefactoringImpl implements
InlineLocalRefactoring {
final SearchEngine searchEngine;
final CompilationUnit unit;
- final LocalVariableElement element;
+ final int offset;
String file;
CorrectionUtils utils;
+ Element _variableElement;
VariableDeclaration _variableNode;
List<SearchMatch> _references;
- InlineLocalRefactoringImpl(this.searchEngine, this.unit, this.element) {
+ InlineLocalRefactoringImpl(this.searchEngine, this.unit, this.offset) {
file = unit.element.source.fullName;
utils = new CorrectionUtils(unit);
}
@@ -60,10 +61,19 @@ class InlineLocalRefactoringImpl extends RefactoringImpl implements
RefactoringStatus result = new RefactoringStatus();
// prepare variable
{
- AstNode elementNode = utils.findNode(element.nameOffset);
- _variableNode = elementNode != null ?
- elementNode.getAncestor((node) => node is VariableDeclaration) :
- null;
+ AstNode offsetNode = new NodeLocator.con1(offset).searchWithin(unit);
+ if (offsetNode is SimpleIdentifier) {
+ Element element = offsetNode.staticElement;
+ if (element is LocalVariableElement) {
+ _variableElement = element;
+ _variableNode = element.node;
+ }
+ }
+ }
+ if (_variableNode == null) {
+ result = new RefactoringStatus.fatal(
+ 'Local variable declaration or reference must be selected to activate this refactoring.');
+ return new Future.value(result);
}
// should be normal variable declaration statement
if (_variableNode.parent is! VariableDeclarationList ||
@@ -78,20 +88,20 @@ class InlineLocalRefactoringImpl extends RefactoringImpl implements
if (_variableNode.initializer == null) {
String message = format(
"Local variable '{0}' is not initialized at declaration.",
- element.displayName);
+ _variableElement.displayName);
result =
new RefactoringStatus.fatal(message, new Location.fromNode(_variableNode));
return new Future.value(result);
}
// prepare references
- return searchEngine.searchReferences(element).then((references) {
+ return searchEngine.searchReferences(_variableElement).then((references) {
this._references = references;
// should not have assignments
for (SearchMatch reference in _references) {
if (reference.kind != MatchKind.READ) {
String message = format(
"Local variable '{0}' is assigned more than once.",
- [element.displayName]);
+ [_variableElement.displayName]);
return new RefactoringStatus.fatal(
message,
new Location.fromMatch(reference));
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/refactoring/refactoring.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698