| Index: pkg/analysis_server/lib/src/services/correction/fix_internal.dart
|
| diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
|
| index e223f815dab08891a41125cfcca482448ea17c56..c04bd7569d6887b913c1f023c83ff1687dce53f7 100644
|
| --- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
|
| +++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
|
| @@ -390,6 +390,7 @@ class FixProcessor {
|
| FunctionBody body = node.getAncestor((n) => n is FunctionBody);
|
| if (body != null && body.keyword == null) {
|
| _addReplaceEdit(rf.rangeStartLength(body, 0), 'async ');
|
| + _replaceReturnTypeWithFuture(body);
|
| _addFix(DartFixKind.ADD_ASYNC, []);
|
| return true;
|
| }
|
| @@ -401,6 +402,7 @@ class FixProcessor {
|
| FunctionBody body = node.getAncestor((n) => n is FunctionBody);
|
| if (body != null && body.keyword == null) {
|
| _addReplaceEdit(rf.rangeStartLength(body, 0), 'async ');
|
| + _replaceReturnTypeWithFuture(body);
|
| _addFix(DartFixKind.ADD_ASYNC, []);
|
| }
|
| }
|
| @@ -1357,19 +1359,9 @@ class FixProcessor {
|
| }
|
|
|
| void _addFix_illegalAsyncReturnType() {
|
| - InterfaceType futureType = context.typeProvider.futureType;
|
| - String futureTypeCode = utils.getTypeSource(futureType, librariesToImport);
|
| // prepare the existing type
|
| TypeName typeName = node.getAncestor((n) => n is TypeName);
|
| - String nodeCode = utils.getNodeText(typeName);
|
| - // wrap the existing type with Future
|
| - String returnTypeCode;
|
| - if (nodeCode == 'void') {
|
| - returnTypeCode = futureTypeCode;
|
| - } else {
|
| - returnTypeCode = '$futureTypeCode<$nodeCode>';
|
| - }
|
| - _addReplaceEdit(rf.rangeNode(typeName), returnTypeCode);
|
| + _replaceTypeWithFuture(typeName);
|
| // add proposal
|
| _addFix(DartFixKind.REPLACE_RETURN_TYPE_FUTURE, []);
|
| }
|
| @@ -2787,6 +2779,40 @@ class FixProcessor {
|
| }
|
| }
|
|
|
| + void _replaceReturnTypeWithFuture(AstNode node) {
|
| + for (; node != null; node = node.parent) {
|
| + if (node is FunctionDeclaration) {
|
| + _replaceTypeWithFuture(node.returnType);
|
| + return;
|
| + } else if (node is MethodDeclaration) {
|
| + _replaceTypeWithFuture(node.returnType);
|
| + return;
|
| + }
|
| + }
|
| + }
|
| +
|
| + void _replaceTypeWithFuture(TypeName typeName) {
|
| + InterfaceType futureType = context.typeProvider.futureType;
|
| + // validate the type
|
| + DartType type = typeName?.type;
|
| + if (type == null ||
|
| + type.isDynamic ||
|
| + type is InterfaceType && type.element == futureType.element) {
|
| + return;
|
| + }
|
| + // prepare code for the types
|
| + String futureTypeCode = utils.getTypeSource(futureType, librariesToImport);
|
| + String nodeCode = utils.getNodeText(typeName);
|
| + // wrap the existing type with Future
|
| + String returnTypeCode;
|
| + if (nodeCode == 'void') {
|
| + returnTypeCode = futureTypeCode;
|
| + } else {
|
| + returnTypeCode = '$futureTypeCode<$nodeCode>';
|
| + }
|
| + _addReplaceEdit(rf.rangeNode(typeName), returnTypeCode);
|
| + }
|
| +
|
| void _updateFinderWithClassMembers(
|
| _ClosestElementFinder finder, ClassElement clazz) {
|
| if (clazz != null) {
|
|
|