quick fix for `REDECLARE_ON_NON_REDECLARING_MEMBER`
See: https://github.com/dart-lang/sdk/issues/53121
Change-Id: I324f8a14820da2e9e5b714f9f1d88c647f9cfebc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/321424
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/remove_annotation.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_annotation.dart
index b17eb75..df318ad 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/remove_annotation.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_annotation.dart
@@ -56,6 +56,7 @@
await addFix(findAnnotation(node.metadata, 'required'));
} else if (node is MethodDeclaration) {
await addFix(findAnnotation(node.metadata, 'override'));
+ await addFix(findAnnotation(node.metadata, 'redeclare'));
} else if (node is VariableDeclaration) {
var fieldDeclaration = node.thisOrAncestorOfType<FieldDeclaration>();
if (fieldDeclaration != null) {
diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
index 7442859..370573e 100644
--- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
+++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
@@ -3612,9 +3612,7 @@
WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA:
status: hasFix
WarningCode.REDECLARE_ON_NON_REDECLARING_MEMBER:
- status: needsFix
- notes: |-
- The fix is to remove the annotation.
+ status: hasFix
WarningCode.REMOVED_LINT_USE:
status: needsFix
WarningCode.REPLACED_LINT_USE:
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 ab47a57..bc51e83 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -1640,6 +1640,9 @@
WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA: [
AddTrailingComma.new,
],
+ WarningCode.REDECLARE_ON_NON_REDECLARING_MEMBER: [
+ RemoveAnnotation.new,
+ ],
WarningCode.SDK_VERSION_GT_GT_GT_OPERATOR: [
UpdateSdkConstraints.version_2_14_0,
],
diff --git a/pkg/analysis_server/test/src/services/correction/fix/remove_annotation_test.dart b/pkg/analysis_server/test/src/services/correction/fix/remove_annotation_test.dart
index b047e36..3c59433 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/remove_annotation_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/remove_annotation_test.dart
@@ -200,6 +200,46 @@
''');
}
+ Future<void> test_redeclare_invalidTarget() async {
+ await resolveTestCode('''
+import 'package:meta/meta.dart';
+
+class C {
+ @redeclare
+ void m() {}
+}
+''');
+ await assertHasFix('''
+import 'package:meta/meta.dart';
+
+class C {
+ void m() {}
+}
+''');
+ }
+
+ Future<void> test_redeclare_notRedeclaring() async {
+ await resolveTestCode('''
+import 'package:meta/meta.dart';
+
+class C {}
+
+extension type E(C c) implements C {
+ @redeclare
+ int get i => 0;
+}
+''');
+ await assertHasFix('''
+import 'package:meta/meta.dart';
+
+class C {}
+
+extension type E(C c) implements C {
+ int get i => 0;
+}
+''');
+ }
+
Future<void> test_required_namedWithDefault() async {
await resolveTestCode('''
import 'package:meta/meta.dart';