[messages] Add lowerCaseName and lowerCaseUniqueName to DiagnosticCode.

Adds the getters `lowerCaseName` and `lowerCaseUniqueName` to the
`DiagnosticCode` class. These getters behave the same as the `name`
and `uniqueName` getters, except that they convert the string to lower
case before returning. These getters should help make it easier for
the analyzer and related packages (as well as analyzer clients) to
treat diagnostic codes in a case-insensitive fashion.

In follow-up CLs, I plan to switch the analyzer and related packages
over to using the new getters, and then I'll deprecate and eventually
remove `name` and `uniqueName` from the analyzer public API.

Change-Id: I6a6a6964e8891fc6f74a9777eae375f1a553c2f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466182
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
diff --git a/pkg/_fe_analyzer_shared/lib/src/base/errors.dart b/pkg/_fe_analyzer_shared/lib/src/base/errors.dart
index f9a2182..8191fab 100644
--- a/pkg/_fe_analyzer_shared/lib/src/base/errors.dart
+++ b/pkg/_fe_analyzer_shared/lib/src/base/errors.dart
@@ -258,6 +258,18 @@
   /// `// ignore:` or `// ignore_for_file:`.
   bool get isIgnorable => severity != DiagnosticSeverity.ERROR;
 
+  /// The name of the error code, converted to all lower case.
+  ///
+  /// This should be used instead of [name] to ensure that diagnostic codes are
+  /// matched in case-insensitive fashion.
+  String get lowerCaseName => name.toLowerCase();
+
+  /// The unique name of this error code, converted to all lower case.
+  ///
+  /// This should be used instead of [uniqueName] to ensure that diagnostic
+  /// codes are matched in case-insensitive fashion.
+  String get lowerCaseUniqueName => uniqueName.toLowerCase();
+
   int get numParameters {
     int result = 0;
     String? correctionMessage = _correctionMessage;
diff --git a/pkg/analysis_server/test/protocol_server_test.dart b/pkg/analysis_server/test/protocol_server_test.dart
index cd77253..866b0c7 100644
--- a/pkg/analysis_server/test/protocol_server_test.dart
+++ b/pkg/analysis_server/test/protocol_server_test.dart
@@ -429,6 +429,9 @@
   bool get isUnresolvedIdentifier => false;
 
   @override
+  String get lowerCaseName => name.toLowerCase();
+
+  @override
   String get problemMessage {
     throw StateError('Unexpected invocation of problemMessage');
   }
diff --git a/pkg/analyzer/api.txt b/pkg/analyzer/api.txt
index 1dcaa35..e80f6e8 100644
--- a/pkg/analyzer/api.txt
+++ b/pkg/analyzer/api.txt
@@ -4579,6 +4579,8 @@
     hasPublishedDocs (getter: bool)
     isIgnorable (getter: bool)
     isUnresolvedIdentifier (getter: bool)
+    lowerCaseName (getter: String)
+    lowerCaseUniqueName (getter: String)
     name (getter: String)
     numParameters (getter: int)
     problemMessage (getter: String)
diff --git a/pkg/analyzer_cli/test/mocks.dart b/pkg/analyzer_cli/test/mocks.dart
index 28e19d9..e2045a2 100644
--- a/pkg/analyzer_cli/test/mocks.dart
+++ b/pkg/analyzer_cli/test/mocks.dart
@@ -97,6 +97,9 @@
   bool get isUnresolvedIdentifier => false;
 
   @override
+  String get lowerCaseName => name.toLowerCase();
+
+  @override
   String get problemMessage {
     throw StateError('Unexpected invocation of message');
   }
diff --git a/pkg/front_end/test/spell_checking_list_code.txt b/pkg/front_end/test/spell_checking_list_code.txt
index 4e13537..957c846 100644
--- a/pkg/front_end/test/spell_checking_list_code.txt
+++ b/pkg/front_end/test/spell_checking_list_code.txt
@@ -907,6 +907,7 @@
 initializer's
 injecting
 inlines
+insensitive
 insertion
 insists
 inspect