quick fix for `CLASS_INSTANTIATION_ACCESS_TO_STATIC_MEMBER`
Change-Id: Id39b57597f8d34084f6b931526dd31b85207da41
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367983
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_type_arguments.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_type_arguments.dart
index c84f914..0e512a9 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/remove_type_arguments.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_type_arguments.dart
@@ -20,13 +20,15 @@
@override
Future<void> compute(ChangeBuilder builder) async {
- var typeArguments = coveringNode;
- if (typeArguments is! TypeArgumentList) {
- return;
+ var node = coveringNode;
+ // A<int>.i;
+ if (node is ConstructorName) {
+ node = node.type.typeArguments;
}
+ if (node is! TypeArgumentList) return;
await builder.addDartFileEdit(file, (builder) {
- builder.addDeletion(range.node(typeArguments));
+ builder.addDeletion(range.node(node!));
});
}
}
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 41d0f73..ccc5c18 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
@@ -45,8 +45,8 @@
#
# Stats:
# - 42 "needsEvaluation"
-# - 362 "needsFix"
-# - 389 "hasFix"
+# - 361 "needsFix"
+# - 390 "hasFix"
# - 516 "noFix"
AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR:
@@ -291,10 +291,7 @@
status: noFix
since: 2.15
CompileTimeErrorCode.CLASS_INSTANTIATION_ACCESS_TO_STATIC_MEMBER:
- status: needsFix
- notes: |-
- The fix is to remove the type arguments.
- since: 2.15
+ status: hasFix
CompileTimeErrorCode.CLASS_INSTANTIATION_ACCESS_TO_UNKNOWN_MEMBER:
status: noFix
notes: |-
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 9ef02b0..4ced115 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -889,6 +889,9 @@
CreateClass.new,
CreateMixin.new,
],
+ CompileTimeErrorCode.CLASS_INSTANTIATION_ACCESS_TO_STATIC_MEMBER: [
+ RemoveTypeArguments.new,
+ ],
CompileTimeErrorCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER: [
ConvertIntoBlockBody.missingBody,
CreateNoSuchMethod.new,
diff --git a/pkg/analysis_server/test/src/services/correction/fix/remove_type_arguments_test.dart b/pkg/analysis_server/test/src/services/correction/fix/remove_type_arguments_test.dart
index 472127c..a9575cd 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/remove_type_arguments_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/remove_type_arguments_test.dart
@@ -19,6 +19,23 @@
@override
FixKind get kind => DartFixKind.REMOVE_TYPE_ARGUMENTS;
+ Future<void> test_classInstantiationAccessToStaticMember() async {
+ await resolveTestCode('''
+class A<T> {
+ static int i = 1;
+}
+
+var x = A<int>.i;
+''');
+ await assertHasFix('''
+class A<T> {
+ static int i = 1;
+}
+
+var x = A.i;
+''');
+ }
+
Future<void> test_explicitConst() async {
await resolveTestCode('''
void f() {