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

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

Issue 725393002: Issue 21612. Support for multiple returns in the 'Extract Method' refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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_method_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_method.dart
diff --git a/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart b/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
index 15b4ab6a95bbda3c026689f8de3b64cfda08c92f..2673fef385dca2c2248a3b7076982a7fa7bcb434 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
@@ -576,14 +576,11 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl implements
}
// may be ends with "return" statement
if (_selectionStatements != null) {
- Statement lastStatement =
- _selectionStatements[_selectionStatements.length - 1];
- if (lastStatement is ReturnStatement) {
- Expression expression = lastStatement.expression;
- if (expression != null) {
- _returnType = expression.bestType;
- }
- }
+ _ReturnTypeComputer returnTypeComputer = new _ReturnTypeComputer();
+ _selectionStatements.forEach((statement) {
+ statement.accept(returnTypeComputer);
+ });
+ _returnType = returnTypeComputer.returnType;
}
// may be single variable to return
if (assignedUsedVariables.length == 1) {
@@ -1101,6 +1098,28 @@ class _ResetCanCreateGetterVisitor extends RecursiveAstVisitor {
}
+class _ReturnTypeComputer extends RecursiveAstVisitor {
+ DartType returnType;
+
+ @override
+ visitBlockFunctionBody(BlockFunctionBody node) {
+ }
+
+ @override
+ visitReturnStatement(ReturnStatement node) {
+ Expression expression = node.expression;
+ if (expression != null) {
+ DartType type = expression.bestType;
+ if (returnType == null) {
+ returnType = type;
+ } else {
+ returnType = returnType.getLeastUpperBound(type);
Brian Wilkerson 2014/11/15 01:32:38 I'm going to guess that this doesn't work very wel
scheglov 2014/11/15 02:26:16 OK https://codereview.chromium.org/730803003
+ }
+ }
+ }
+}
+
+
/**
* Generalized version of some source, in which references to the specific
* variables are replaced with pattern variables, with back mapping from the
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/extract_method_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698