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

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

Issue 780653005: Issue 21740. Allow inlining local variables declared in SwitchCase. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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/inline_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/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 fdee7212086a1f5d03bf5c75a44d7442b1a68f34..2c4e11525fad771a3ea62a9c8d88765fda0ff705 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/inline_local.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/inline_local.dart
@@ -79,18 +79,11 @@ class InlineLocalRefactoringImpl extends RefactoringImpl implements
}
}
}
- 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 ||
- _variableNode.parent.parent is! VariableDeclarationStatement ||
- _variableNode.parent.parent.parent is! Block) {
+ // validate node declaration
+ if (!_isVariableDeclaredInStatement()) {
result = new RefactoringStatus.fatal(
- 'Local variable declared in '
- 'statement should be selected to activate this refactoring.');
+ 'Local variable declaration or reference must be selected '
+ 'to activate this refactoring.');
return new Future.value(result);
}
// should have initializer at declaration
@@ -188,6 +181,21 @@ class InlineLocalRefactoringImpl extends RefactoringImpl implements
@override
bool requiresPreview() => false;
+ bool _isVariableDeclaredInStatement() {
+ if (_variableNode == null) {
+ return false;
+ }
+ AstNode parent = _variableNode.parent;
+ if (parent is VariableDeclarationList) {
+ parent = parent.parent;
+ if (parent is VariableDeclarationStatement) {
+ parent = parent.parent;
+ return parent is Block || parent is SwitchCase;
+ }
+ }
+ return false;
+ }
+
static bool _shouldBeExpressionInterpolation(InterpolationExpression target,
Expression expression) {
TokenType targetType = target.beginToken.type;
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/inline_local_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698