Chromium Code Reviews| 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 cf87d270a58f4ed33e404d631a69df76a6fd865f..42f7299ac0c0221dc5dc5cbf2750f79c17f8fa54 100644 |
| --- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart |
| +++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart |
| @@ -405,10 +405,14 @@ class AssistProcessor { |
| String prefix = utils.getNodePrefix(body.parent); |
| String indent = utils.getIndent(1); |
| // add change |
| - String statementCode = |
| - (returnValueType.isVoid ? '' : 'return ') + returnValueCode; |
| SourceBuilder sb = new SourceBuilder(file, body.offset); |
| - sb.append('{$eol$prefix$indent$statementCode;'); |
| + _appendBodyModifiers(sb, body); |
| + sb.append('{$eol$prefix$indent'); |
| + if (!returnValueType.isVoid) { |
| + sb.append('return '); |
| + } |
| + sb.append(returnValueCode); |
| + sb.append(';'); |
| sb.setExitOffset(); |
| sb.append('$eol$prefix}'); |
| _insertBuilder(sb, body.length); |
| @@ -442,12 +446,15 @@ class AssistProcessor { |
| return; |
| } |
| // add change |
| - String newBodySource = '=> ${_getNodeText(returnExpression)}'; |
| + SourceBuilder sb = new SourceBuilder(file, body.offset); |
| + _appendBodyModifiers(sb, body); |
| + sb.append('=> '); |
| + sb.append(_getNodeText(returnExpression)); |
| if (body.parent is! FunctionExpression || |
| body.parent.parent is FunctionDeclaration) { |
| - newBodySource += ';'; |
| + sb.append(';'); |
| } |
| - _addReplaceEdit(rangeNode(body), newBodySource); |
| + _insertBuilder(sb, body.length); |
| // add proposal |
| _addAssist(DartAssistKind.CONVERT_INTO_EXPRESSION_BODY, []); |
| } |
| @@ -1912,6 +1919,16 @@ class AssistProcessor { |
| doSourceChange_addElementEdit(change, unitElement, edit); |
| } |
| + void _appendBodyModifiers(SourceBuilder sb, FunctionBody body) { |
| + if (body.isAsynchronous) { |
| + sb.append('async'); |
| + if (body.isGenerator) { |
| + sb.append('*'); |
| + } |
| + sb.append(' '); |
| + } |
|
Paul Berry
2015/09/05 03:42:35
I don't think "sync*" or "async*" functions will e
scheglov
2015/09/05 04:38:13
Good idea.
I will disable converting for generator
|
| + } |
| + |
| /** |
| * Configures [utils] using given [target]. |
| */ |