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

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

Issue 533913002: Fix for 'returnType' when extract a method with a single expression. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months 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 f3373c4991e6fd20ce052ed94eb5b9e8287ee5f0..87a4bf29be00bb0c4654bae166b1c9245b74e751 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
@@ -106,7 +106,7 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl implements
}
}
if (_selectionStatements != null) {
- return returnType != null;
+ return returnType != 'void';
}
return true;
}
@@ -226,7 +226,7 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl implements
} else {
StringBuffer sb = new StringBuffer();
// may be returns value
- if (returnType != null) {
+ if (_selectionStatements != null && returnType != 'void') {
// single variable assignment / return statement
if (_returnVariableName != null) {
String occurrenceName =
@@ -316,12 +316,8 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl implements
}
// statements
if (_selectionStatements != null) {
- if (returnType != null) {
- if (returnType.isNotEmpty) {
- annotations += returnType + ' ';
- }
- } else {
- annotations += 'void ';
+ if (returnType.isNotEmpty) {
+ annotations += returnType + ' ';
}
declarationSource = '${annotations}${signature} {${eol}';
declarationSource += returnExpressionSource;
@@ -572,6 +568,10 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl implements
RefactoringStatus result = new RefactoringStatus();
List<VariableElement> assignedUsedVariables = [];
unit.accept(new _InitializeParametersVisitor(this, assignedUsedVariables));
+ // single expression
+ if (_selectionExpression != null) {
+ _returnType = _selectionExpression.bestType;
+ }
// may be ends with "return" statement
if (_selectionStatements != null) {
Statement lastStatement =
@@ -616,12 +616,12 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl implements
void _initializeReturnType() {
if (_returnType == null) {
- returnType = null;
+ returnType = 'void';
} else {
returnType = utils.getTypeSource(_returnType);
- if (returnType == 'dynamic') {
- returnType = '';
- }
+ }
+ if (returnType == 'dynamic') {
+ returnType = '';
}
}
« 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