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

Unified Diff: pkg/analysis_server/lib/src/services/correction/assist_internal.dart

Issue 1267333003: Issue 23963. Improve to/from block/expression body with void expressions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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/correction/assist_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/correction/assist_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
index 9c5e9ba5d5bb7fca3270ad7e74d6cbe2b25b335d..cf87d270a58f4ed33e404d631a69df76a6fd865f 100644
--- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
@@ -399,13 +399,19 @@ class AssistProcessor {
return;
}
Expression returnValue = (body as ExpressionFunctionBody).expression;
+ DartType returnValueType = returnValue.staticType;
+ String returnValueCode = _getNodeText(returnValue);
// prepare prefix
String prefix = utils.getNodePrefix(body.parent);
- // add change
String indent = utils.getIndent(1);
- String returnSource = 'return ' + _getNodeText(returnValue);
- String newBodySource = '{$eol$prefix$indent$returnSource;$eol$prefix}';
- _addReplaceEdit(rangeNode(body), newBodySource);
+ // add change
+ String statementCode =
+ (returnValueType.isVoid ? '' : 'return ') + returnValueCode;
+ SourceBuilder sb = new SourceBuilder(file, body.offset);
+ sb.append('{$eol$prefix$indent$statementCode;');
+ sb.setExitOffset();
+ sb.append('$eol$prefix}');
+ _insertBuilder(sb, body.length);
// add proposal
_addAssist(DartAssistKind.CONVERT_INTO_BLOCK_BODY, []);
}
@@ -423,13 +429,14 @@ class AssistProcessor {
_coverageMarker();
return;
}
- if (statements[0] is! ReturnStatement) {
- _coverageMarker();
- return;
- }
- ReturnStatement returnStatement = statements[0] as ReturnStatement;
+ Statement onlyStatement = statements.first;
// prepare returned expression
- Expression returnExpression = returnStatement.expression;
+ Expression returnExpression;
+ if (onlyStatement is ReturnStatement) {
+ returnExpression = onlyStatement.expression;
+ } else if (onlyStatement is ExpressionStatement) {
+ returnExpression = onlyStatement.expression;
+ }
if (returnExpression == null) {
_coverageMarker();
return;
@@ -484,8 +491,8 @@ class AssistProcessor {
// check number of references
{
int numOfReferences = 0;
- AstVisitor visitor = new _SimpleIdentifierRecursiveAstVisitor(
- (SimpleIdentifier node) {
+ AstVisitor visitor =
+ new _SimpleIdentifierRecursiveAstVisitor((SimpleIdentifier node) {
if (node.staticElement == parameterElement) {
numOfReferences++;
}
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/correction/assist_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698