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

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

Issue 2946093002: Fix invalid initializing formal by adding a field (Closed)
Patch Set: cleanup Created 3 years, 6 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 7b0f8a179eed9b414a9379e03523e84e1627e82f..cd4fd648633ad9b3353289bf7f69156a6c2a8b68 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -396,6 +396,10 @@ class FixProcessor {
await _addFix_convertFlutterChild();
await _addFix_convertFlutterChildren();
}
+ if (errorCode ==
+ CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD) {
+ await _addFix_createField_initializingFormal();
+ }
// lints
if (errorCode is LintCode) {
if (errorCode.name == LintNames.annotate_overrides) {
@@ -1181,7 +1185,7 @@ class FixProcessor {
// prepare location
ClassMemberLocation targetLocation =
utils.prepareNewFieldLocation(targetClassNode);
- // build method source
+ // build field source
Source targetSource = targetClassElement.source;
String targetFile = targetSource.fullName;
DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
@@ -1202,6 +1206,41 @@ class FixProcessor {
_addFixFromBuilder(changeBuilder, DartFixKind.CREATE_FIELD, args: [name]);
}
+ Future<Null> _addFix_createField_initializingFormal() async {
+ //
+ // Ensure that we are in an initializing formal parameter.
+ //
+ FieldFormalParameter parameter =
+ node.getAncestor((node) => node is FieldFormalParameter);
+ if (parameter == null) {
+ return;
+ }
+ ClassDeclaration targetClassNode =
+ parameter.getAncestor((node) => node is ClassDeclaration);
+ if (targetClassNode == null) {
+ return;
+ }
+ SimpleIdentifier nameNode = parameter.identifier;
+ String name = nameNode.name;
+ ClassMemberLocation targetLocation =
+ utils.prepareNewFieldLocation(targetClassNode);
+ //
+ // Add proposal.
+ //
+ DartChangeBuilder changeBuilder = new DartChangeBuilder(driver);
+ await changeBuilder.addFileEdit(file, fileStamp,
+ (DartFileEditBuilder builder) {
+ DartType fieldType = parameter.type?.type;
+ builder.addInsertion(targetLocation.offset, (DartEditBuilder builder) {
+ builder.write(targetLocation.prefix);
+ builder.writeFieldDeclaration(name,
+ nameGroupName: 'NAME', type: fieldType, typeGroupName: 'TYPE');
+ builder.write(targetLocation.suffix);
+ });
+ });
+ _addFixFromBuilder(changeBuilder, DartFixKind.CREATE_FIELD, args: [name]);
+ }
+
Future<Null> _addFix_createFunction_forFunctionType() async {
if (node is SimpleIdentifier) {
SimpleIdentifier nameNode = node as SimpleIdentifier;
« 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