mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:36:59 +00:00
Issue 2558. Fixes for 'convert to async function body'.
R=brianwilkerson@google.com Bug: https://github.com/flutter/flutter-intellij/issues/2558 Change-Id: I6e1931a226732b922c2c1695f378d3b59ae09c09 Reviewed-on: https://dart-review.googlesource.com/71560 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
8b5a2b01e7
commit
8b3a0a8476
|
@ -1013,6 +1013,21 @@ Future<String> f() async => '';
|
|||
''');
|
||||
}
|
||||
|
||||
test_convertToAsyncBody_OK_getter_expression_noSpace() async {
|
||||
await resolveTestUnit('''
|
||||
class C {
|
||||
int get g=>0;
|
||||
}
|
||||
''');
|
||||
await assertHasAssistAt('get g', DartAssistKind.CONVERT_INTO_ASYNC_BODY, '''
|
||||
import 'dart:async';
|
||||
|
||||
class C {
|
||||
Future<int> get g async =>0;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_convertToAsyncBody_OK_method() async {
|
||||
await resolveTestUnit('''
|
||||
class C {
|
||||
|
@ -1029,6 +1044,21 @@ class C {
|
|||
''');
|
||||
}
|
||||
|
||||
test_convertToAsyncBody_OK_method_abstract() async {
|
||||
await resolveTestUnit('''
|
||||
abstract class C {
|
||||
int m();
|
||||
}
|
||||
''');
|
||||
await assertHasAssistAt('m()', DartAssistKind.CONVERT_INTO_ASYNC_BODY, '''
|
||||
import 'dart:async';
|
||||
|
||||
abstract class C {
|
||||
Future<int> m();
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_convertToAsyncBody_OK_method_noReturnType() async {
|
||||
await resolveTestUnit('''
|
||||
class C {
|
||||
|
|
|
@ -1142,9 +1142,14 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl
|
|||
throw new ArgumentError(
|
||||
'The function must have a synchronous, non-generator body.');
|
||||
}
|
||||
addInsertion(body.offset, (EditBuilder builder) {
|
||||
builder.write('async ');
|
||||
});
|
||||
if (body is! EmptyFunctionBody) {
|
||||
addInsertion(body.offset, (EditBuilder builder) {
|
||||
if (_isFusedWithPreviousToken(body.beginToken)) {
|
||||
builder.write(' ');
|
||||
}
|
||||
builder.write('async ');
|
||||
});
|
||||
}
|
||||
_replaceReturnTypeWithFuture(body, typeProvider);
|
||||
}
|
||||
|
||||
|
@ -1449,6 +1454,10 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool _isFusedWithPreviousToken(Token token) {
|
||||
return token.previous.end == token.offset;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue