Use the unique names of lint codes in FixProcessor

Some lint rules produce more than one lint code and sometimes the fixes
that should be associated with those codes is different. This change
will allow us to use the unique names of those codes to produce the
right fix.

Change-Id: Ib6fc69decb664c1224e33e2a78b28ce91594d826
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/225582
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
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 7abed7a..0186ba9 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -312,7 +312,7 @@
 
   List<ProducerGenerator> _getGenerators(ErrorCode errorCode) {
     if (errorCode is LintCode) {
-      return FixProcessor.lintProducerMap[errorCode.name] ?? [];
+      return FixProcessor.lintProducerMap[errorCode.uniqueLintName] ?? [];
     } else {
       // todo (pq): consider support for multiGenerators
       return FixProcessor.nonLintProducerMap[errorCode] ?? [];
@@ -326,6 +326,12 @@
   /// used to create correction producers. The generators are then used to build
   /// fixes for those diagnostics. The generators used for non-lint diagnostics
   /// are in the [nonLintProducerMap].
+  ///
+  /// The keys of the map are the unique names of the lint codes without the
+  /// `LintCode.` prefix. Generally the unique name is the same as the name of
+  /// the lint, so most of the keys are constants defined by [LintNames]. But
+  /// when a lint produces multiple codes, each with a different unique name,
+  /// the unique name must be used here.
   static final Map<String, List<ProducerGenerator>> lintProducerMap = {
     LintNames.always_declare_return_types: [
       AddReturnType.newInstance,
@@ -1355,7 +1361,7 @@
 
     var errorCode = error.errorCode;
     if (errorCode is LintCode) {
-      var generators = lintProducerMap[errorCode.name] ?? [];
+      var generators = lintProducerMap[errorCode.uniqueLintName] ?? [];
       for (var generator in generators) {
         await compute(generator());
       }
@@ -1428,3 +1434,12 @@
     required this.fixCount,
   });
 }
+
+extension on LintCode {
+  String get uniqueLintName {
+    if (uniqueName.startsWith('LintCode.')) {
+      return uniqueName.substring(9);
+    }
+    return uniqueName;
+  }
+}