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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/extract_method_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library services.src.refactoring.extract_method; 5 library services.src.refactoring.extract_method;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol_server.dart' hide Element; 9 import 'package:analysis_server/src/protocol_server.dart' hide Element;
10 import 'package:analysis_server/src/services/correction/name_suggestion.dart'; 10 import 'package:analysis_server/src/services/correction/name_suggestion.dart';
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 _parameterReferencesMap.clear(); 569 _parameterReferencesMap.clear();
570 RefactoringStatus result = new RefactoringStatus(); 570 RefactoringStatus result = new RefactoringStatus();
571 List<VariableElement> assignedUsedVariables = []; 571 List<VariableElement> assignedUsedVariables = [];
572 unit.accept(new _InitializeParametersVisitor(this, assignedUsedVariables)); 572 unit.accept(new _InitializeParametersVisitor(this, assignedUsedVariables));
573 // single expression 573 // single expression
574 if (_selectionExpression != null) { 574 if (_selectionExpression != null) {
575 _returnType = _selectionExpression.bestType; 575 _returnType = _selectionExpression.bestType;
576 } 576 }
577 // may be ends with "return" statement 577 // may be ends with "return" statement
578 if (_selectionStatements != null) { 578 if (_selectionStatements != null) {
579 Statement lastStatement = 579 _ReturnTypeComputer returnTypeComputer = new _ReturnTypeComputer();
580 _selectionStatements[_selectionStatements.length - 1]; 580 _selectionStatements.forEach((statement) {
581 if (lastStatement is ReturnStatement) { 581 statement.accept(returnTypeComputer);
582 Expression expression = lastStatement.expression; 582 });
583 if (expression != null) { 583 _returnType = returnTypeComputer.returnType;
584 _returnType = expression.bestType;
585 }
586 }
587 } 584 }
588 // may be single variable to return 585 // may be single variable to return
589 if (assignedUsedVariables.length == 1) { 586 if (assignedUsedVariables.length == 1) {
590 // we cannot both return variable and have explicit return statement 587 // we cannot both return variable and have explicit return statement
591 if (_returnType != null) { 588 if (_returnType != null) {
592 result.addFatalError( 589 result.addFatalError(
593 'Ambiguous return value: Selected block contains assignment(s) to ' 590 'Ambiguous return value: Selected block contains assignment(s) to '
594 'local variables and return statement.'); 591 'local variables and return statement.');
595 return result; 592 return result;
596 } 593 }
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 } 1091 }
1095 1092
1096 @override 1093 @override
1097 visitWhileStatement(WhileStatement node) { 1094 visitWhileStatement(WhileStatement node) {
1098 ref.createGetter = false; 1095 ref.createGetter = false;
1099 super.visitWhileStatement(node); 1096 super.visitWhileStatement(node);
1100 } 1097 }
1101 } 1098 }
1102 1099
1103 1100
1101 class _ReturnTypeComputer extends RecursiveAstVisitor {
1102 DartType returnType;
1103
1104 @override
1105 visitBlockFunctionBody(BlockFunctionBody node) {
1106 }
1107
1108 @override
1109 visitReturnStatement(ReturnStatement node) {
1110 Expression expression = node.expression;
1111 if (expression != null) {
1112 DartType type = expression.bestType;
1113 if (returnType == null) {
1114 returnType = type;
1115 } else {
1116 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
1117 }
1118 }
1119 }
1120 }
1121
1122
1104 /** 1123 /**
1105 * Generalized version of some source, in which references to the specific 1124 * Generalized version of some source, in which references to the specific
1106 * variables are replaced with pattern variables, with back mapping from the 1125 * variables are replaced with pattern variables, with back mapping from the
1107 * pattern to the original variable names. 1126 * pattern to the original variable names.
1108 */ 1127 */
1109 class _SourcePattern { 1128 class _SourcePattern {
1110 String patternSource; 1129 String patternSource;
1111 Map<String, String> originalToPatternNames = {}; 1130 Map<String, String> originalToPatternNames = {};
1112 } 1131 }
OLDNEW
« 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