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

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

Issue 1652963003: Issue 25623. When adding the 'async' modifier, change the return type. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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/fix_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/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) {
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/correction/fix_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698