Chromium Code Reviews| 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 |