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

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

Issue 894373005: Quick Fix for adding 'async' to fix invalid 'await'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 c46ee05bf9cd47c09a9c2318bdd6e25849acff74..cc4311647f8e294f6e5c0d6f7c63ed2400ac678b 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -198,12 +198,15 @@ class FixProcessor {
_addFix_undefinedClass_useSimilar();
}
if (errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER) {
- _addFix_createField();
- _addFix_createGetter();
- _addFix_createFunction_forFunctionType();
- _addFix_importLibrary_withType();
- _addFix_importLibrary_withTopLevelVariable();
- _addFix_createLocalVariable();
+ bool isAsync = _addFix_addAsync();
+ if (!isAsync) {
+ _addFix_createField();
+ _addFix_createGetter();
+ _addFix_createFunction_forFunctionType();
+ _addFix_importLibrary_withType();
+ _addFix_importLibrary_withTopLevelVariable();
+ _addFix_createLocalVariable();
+ }
}
if (errorCode == StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER) {
_addFix_useStaticAccess_method();
@@ -264,6 +267,22 @@ class FixProcessor {
exitPosition = null;
}
+ /**
+ * Returns `true` if the `async` proposal was added.
+ */
+ bool _addFix_addAsync() {
+ AstNode node = this.node;
+ if (_isAwaitNode()) {
+ FunctionBody body = node.getAncestor((n) => n is FunctionBody);
+ if (body.keyword == null) {
+ _addReplaceEdit(rf.rangeStartLength(body, 0), 'async ');
+ _addFix(FixKind.ADD_ASYNC, []);
+ return true;
+ }
+ }
+ return false;
+ }
+
void _addFix_boolInsteadOfBoolean() {
SourceRange range = rf.rangeError(error);
_addReplaceEdit(range, 'bool');
@@ -1164,6 +1183,9 @@ class FixProcessor {
void _addFix_insertSemicolon() {
if (error.message.contains("';'")) {
+ if (_isAwaitNode()) {
+ return;
+ }
int insertOffset = error.offset + error.length;
_addInsertEdit(insertOffset, ';');
_addFix(FixKind.INSERT_SEMICOLON, []);
@@ -2065,6 +2087,11 @@ class FixProcessor {
return method != null && method.isStatic;
}
+ bool _isAwaitNode() {
+ AstNode node = this.node;
+ return node is SimpleIdentifier && node.name == 'await';
+ }
+
_ConstructorLocation
_prepareNewConstructorLocation(ClassDeclaration classDeclaration) {
List<ClassMember> members = classDeclaration.members;
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix.dart ('k') | pkg/analysis_server/test/services/correction/fix_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698