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

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

Issue 2965063002: Add a quick fix for missing new (issue 30077) (Closed)
Patch Set: Created 3 years, 5 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 c2dfd1b7e23ed19bf6f355a9a6f0c61fd7fe79d3..1052c9dd0740725d1b136339385a4de8700467cb 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -348,6 +348,9 @@ class FixProcessor {
await _addFix_importLibrary_withTopLevelVariable();
await _addFix_createLocalVariable();
}
+ if (errorCode == StaticTypeWarningCode.UNDEFINED_METHOD_WITH_CONSTRUCTOR) {
+ await _addFix_undefinedMethodWithContructor();
+ }
if (errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE) {
await _addFix_illegalAsyncReturnType();
}
@@ -2522,6 +2525,20 @@ class FixProcessor {
}
}
+ Future<Null> _addFix_undefinedMethodWithContructor() async {
+ if (node is SimpleIdentifier && node.parent is MethodInvocation) {
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(session);
+ await changeBuilder.addFileEdit(file, (DartFileEditBuilder builder) {
+ builder.addSimpleInsertion(node.parent.offset, 'new ');
+ });
+ _addFixFromBuilder(
+ changeBuilder, DartFixKind.INVOKE_CONSTRUCTOR_USING_NEW);
+ // TODO(brianwilkerson) Figure out whether the constructor is a `const`
+ // constructor and all of the parameters are constant expressions, and
+ // suggest inserting 'const ' if so.
+ }
+ }
+
/**
* Here we handle cases when a constructors does not initialize all of the
* final fields.
« 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