| OLD | NEW |
| 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 } | 587 } |
| 588 // verify that none or all execution flows end with a "return" | 588 // verify that none or all execution flows end with a "return" |
| 589 if (_selectionStatements != null) { | 589 if (_selectionStatements != null) { |
| 590 bool hasReturn = _selectionStatements.any(_mayEndWithReturnStatement); | 590 bool hasReturn = _selectionStatements.any(_mayEndWithReturnStatement); |
| 591 if (hasReturn && !ExitDetector.exits(_selectionStatements.last)) { | 591 if (hasReturn && !ExitDetector.exits(_selectionStatements.last)) { |
| 592 result.addError(ERROR_EXITS); | 592 result.addError(ERROR_EXITS); |
| 593 } | 593 } |
| 594 } | 594 } |
| 595 // maybe ends with "return" statement | 595 // maybe ends with "return" statement |
| 596 if (_selectionStatements != null) { | 596 if (_selectionStatements != null) { |
| 597 _ReturnTypeComputer returnTypeComputer = new _ReturnTypeComputer(); | 597 _ReturnTypeComputer returnTypeComputer = new _ReturnTypeComputer(context); |
| 598 _selectionStatements.forEach((statement) { | 598 _selectionStatements.forEach((statement) { |
| 599 statement.accept(returnTypeComputer); | 599 statement.accept(returnTypeComputer); |
| 600 }); | 600 }); |
| 601 _returnType = returnTypeComputer.returnType; | 601 _returnType = returnTypeComputer.returnType; |
| 602 } | 602 } |
| 603 // maybe single variable to return | 603 // maybe single variable to return |
| 604 if (assignedUsedVariables.length == 1) { | 604 if (assignedUsedVariables.length == 1) { |
| 605 // we cannot both return variable and have explicit return statement | 605 // we cannot both return variable and have explicit return statement |
| 606 if (_returnType != null) { | 606 if (_returnType != null) { |
| 607 result.addFatalError( | 607 result.addFatalError( |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 class _Occurrence { | 1151 class _Occurrence { |
| 1152 final SourceRange range; | 1152 final SourceRange range; |
| 1153 final bool isSelection; | 1153 final bool isSelection; |
| 1154 | 1154 |
| 1155 Map<String, String> _parameterOldToOccurrenceName = <String, String>{}; | 1155 Map<String, String> _parameterOldToOccurrenceName = <String, String>{}; |
| 1156 | 1156 |
| 1157 _Occurrence(this.range, this.isSelection); | 1157 _Occurrence(this.range, this.isSelection); |
| 1158 } | 1158 } |
| 1159 | 1159 |
| 1160 class _ReturnTypeComputer extends RecursiveAstVisitor { | 1160 class _ReturnTypeComputer extends RecursiveAstVisitor { |
| 1161 final AnalysisContext context; |
| 1162 |
| 1161 DartType returnType; | 1163 DartType returnType; |
| 1162 | 1164 |
| 1165 _ReturnTypeComputer(this.context); |
| 1166 |
| 1163 @override | 1167 @override |
| 1164 visitBlockFunctionBody(BlockFunctionBody node) {} | 1168 visitBlockFunctionBody(BlockFunctionBody node) {} |
| 1165 | 1169 |
| 1166 @override | 1170 @override |
| 1167 visitReturnStatement(ReturnStatement node) { | 1171 visitReturnStatement(ReturnStatement node) { |
| 1168 // prepare expression | 1172 // prepare expression |
| 1169 Expression expression = node.expression; | 1173 Expression expression = node.expression; |
| 1170 if (expression == null) { | 1174 if (expression == null) { |
| 1171 return; | 1175 return; |
| 1172 } | 1176 } |
| 1173 // prepare type | 1177 // prepare type |
| 1174 DartType type = expression.bestType; | 1178 DartType type = expression.bestType; |
| 1175 if (type.isBottom) { | 1179 if (type.isBottom) { |
| 1176 return; | 1180 return; |
| 1177 } | 1181 } |
| 1178 // combine types | 1182 // combine types |
| 1179 if (returnType == null) { | 1183 if (returnType == null) { |
| 1180 returnType = type; | 1184 returnType = type; |
| 1181 } else { | 1185 } else { |
| 1182 if (returnType is InterfaceType && type is InterfaceType) { | 1186 if (returnType is InterfaceType && type is InterfaceType) { |
| 1183 returnType = InterfaceType.getSmartLeastUpperBound(returnType, type); | 1187 returnType = InterfaceType.getSmartLeastUpperBound(returnType, type); |
| 1184 } else { | 1188 } else { |
| 1185 returnType = returnType.getLeastUpperBound(type); | 1189 returnType = context.typeSystem |
| 1190 .getLeastUpperBound(context.typeProvider, returnType, type); |
| 1186 } | 1191 } |
| 1187 } | 1192 } |
| 1188 } | 1193 } |
| 1189 } | 1194 } |
| 1190 | 1195 |
| 1191 /** | 1196 /** |
| 1192 * Generalized version of some source, in which references to the specific | 1197 * Generalized version of some source, in which references to the specific |
| 1193 * variables are replaced with pattern variables, with back mapping from the | 1198 * variables are replaced with pattern variables, with back mapping from the |
| 1194 * pattern to the original variable names. | 1199 * pattern to the original variable names. |
| 1195 */ | 1200 */ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1206 return false; | 1211 return false; |
| 1207 } | 1212 } |
| 1208 for (int i = 0; i < parameterTypes.length; i++) { | 1213 for (int i = 0; i < parameterTypes.length; i++) { |
| 1209 if (other.parameterTypes[i] != parameterTypes[i]) { | 1214 if (other.parameterTypes[i] != parameterTypes[i]) { |
| 1210 return false; | 1215 return false; |
| 1211 } | 1216 } |
| 1212 } | 1217 } |
| 1213 return true; | 1218 return true; |
| 1214 } | 1219 } |
| 1215 } | 1220 } |
| OLD | NEW |