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

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

Issue 987173002: Quick Fix for returning Future from 'async' functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
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 d7939f2e4f8831fe479183124453c90db61b0ac7..ec0fb0332b7472bd021f2c58174a9c9c1c34a650 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -209,6 +209,9 @@ class FixProcessor {
_addFix_createLocalVariable();
}
}
+ if (errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE) {
+ _addFix_illegalAsyncReturnType();
+ }
if (errorCode == StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER) {
_addFix_useStaticAccess_method();
_addFix_useStaticAccess_property();
@@ -1003,6 +1006,24 @@ class FixProcessor {
_addFix(FixKind.CREATE_NO_SUCH_METHOD, []);
}
+ 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);
+ // add proposal
+ _addFix(FixKind.REPLACE_RETURN_TYPE_FUTURE, []);
+ }
+
void _addFix_importLibrary(FixKind kind, String importPath) {
CompilationUnitElement libraryUnitElement =
unitLibraryElement.definingCompilationUnit;
@@ -1876,7 +1897,7 @@ class FixProcessor {
}
/**
- * Returns the [Type] with given name from the `dart:core` library.
+ * Returns the [DartType] with given name from the `dart:core` library.
*/
DartType _getCoreType(String name) {
List<LibraryElement> libraries = unitLibraryElement.importedLibraries;

Powered by Google App Engine
This is Rietveld 408576698