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

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

Issue 1324323004: Issue 24298. Fix for 'async' function body conversion. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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/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 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].
*/
« 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