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

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

Issue 2267893002: Fix for 'Extract Local' in an expression function body. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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/test/services/refactoring/extract_local_test.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/extract_local.dart
diff --git a/pkg/analysis_server/lib/src/services/refactoring/extract_local.dart b/pkg/analysis_server/lib/src/services/refactoring/extract_local.dart
index c7c57763dad26c06675c174f3a77bdab3359ac6a..5c7e2da0449f5b4d4c97db6a51138ab7b41ef281 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/extract_local.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/extract_local.dart
@@ -139,6 +139,7 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl
void addPosition(int offset) {
positions.add(new Position(file, offset));
}
+
// add variable declaration
{
String declarationCode;
@@ -180,8 +181,11 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl
occurrencesShift = target.offset + code.length - expr.offset;
doSourceChange_addElementEdit(change, unitElement, edit);
}
- doSourceChange_addElementEdit(change, unitElement,
- new SourceEdit(expr.end, 0, ';' + eol + prefix + '}'));
+ doSourceChange_addElementEdit(
+ change,
+ unitElement,
+ new SourceEdit(
+ expr.end, target.end - expr.end, ';' + eol + prefix + '}'));
}
}
// prepare replacement
@@ -298,11 +302,14 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl
coveringExpressionOffsets.add(node.offset);
coveringExpressionLengths.add(node.length);
}
- // we need enclosing block to add variable declaration statement
+ // We need an enclosing function.
+ // If it has a block body, we can add a new variable declaration statement
+ // into this block. If it has an expression body, we can convert it into
+ // the block body first.
if (coveringNode == null ||
- coveringNode.getAncestor((node) => node is Block) == null) {
+ coveringNode.getAncestor((node) => node is FunctionBody) == null) {
return new RefactoringStatus.fatal(
- 'Expression inside of function must be selected '
+ 'Expression inside a function must be selected '
Brian Wilkerson 2016/08/22 18:54:38 "Expression" --> "An expression"?
scheglov 2016/08/22 18:57:44 Done.
'to activate this refactoring.');
}
// part of string literal
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/extract_local_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698