DAS: Simplify the storage of the fix mappings for assists

This map is a map of _assists_ and the lint rules that can _fix_, when
used as a _fix_ producer. A rather specific set of information. It was
being passed around everywhere, but now with the instance of
`_RegisteredAssistGenerators` to hang onto, we can leave the map there,
and remove it from a handful of other classes which all ultimately just
passed the map back to AssistProcessor.

Change-Id: Ib2aa4ea1fdb23bbaf55b3377232f2205b7f91447
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415460
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart b/pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart
index 11675b0..591ec9b 100644
--- a/pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart
+++ b/pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart
@@ -3,9 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'package:analysis_server_plugin/src/correction/change_workspace.dart';
-import 'package:analysis_server_plugin/src/correction/fix_generators.dart';
 import 'package:analyzer/dart/analysis/results.dart';
-import 'package:analyzer/error/error.dart';
 import 'package:analyzer/instrumentation/service.dart';
 
 /// An object used to provide context information for Dart assist contributors.
@@ -19,10 +17,6 @@
   /// The resolved library result in which assist operates.
   ResolvedLibraryResult get libraryResult;
 
-  /// A mapping of [ProducerGenerator]s to the set of lint names with which they
-  /// are associated (can fix).
-  Map<ProducerGenerator, Set<LintCode>> get producerGeneratorsForLintRules;
-
   /// The length of the selection.
   int get selectionLength;
 
diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart
index 6944025..b28472c 100644
--- a/pkg/analysis_server/lib/src/analysis_server.dart
+++ b/pkg/analysis_server/lib/src/analysis_server.dart
@@ -31,7 +31,6 @@
 import 'package:analysis_server/src/server/message_scheduler.dart';
 import 'package:analysis_server/src/server/performance.dart';
 import 'package:analysis_server/src/services/completion/completion_performance.dart';
-import 'package:analysis_server/src/services/correction/assist_internal.dart';
 import 'package:analysis_server/src/services/correction/assist_performance.dart';
 import 'package:analysis_server/src/services/correction/fix_performance.dart';
 import 'package:analysis_server/src/services/correction/namespace.dart';
@@ -51,12 +50,10 @@
 import 'package:analysis_server/src/utilities/request_statistics.dart';
 import 'package:analysis_server/src/utilities/tee_string_sink.dart';
 import 'package:analysis_server/src/utilities/timing_byte_store.dart';
-import 'package:analysis_server_plugin/src/correction/fix_generators.dart';
 import 'package:analyzer/dart/analysis/results.dart';
 import 'package:analyzer/dart/analysis/session.dart';
 import 'package:analyzer/dart/ast/ast.dart';
 import 'package:analyzer/dart/element/element2.dart';
-import 'package:analyzer/error/error.dart';
 import 'package:analyzer/exception/exception.dart';
 import 'package:analyzer/file_system/file_system.dart';
 import 'package:analyzer/file_system/overlay_file_system.dart';
@@ -254,10 +251,6 @@
   /// the last idle state.
   final Set<String> filesResolvedSinceLastIdle = {};
 
-  /// A mapping of [ProducerGenerator]s to the set of lint names with which they
-  /// are associated (can fix).
-  final Map<ProducerGenerator, Set<LintCode>> producerGeneratorsForLintRules;
-
   /// A completer for [lspUninitialized].
   final Completer<void> _lspUninitializedCompleter = Completer<void>();
 
@@ -292,7 +285,6 @@
          httpClient,
          Platform.environment['PUB_HOSTED_URL'],
        ),
-       producerGeneratorsForLintRules = AssistProcessor.computeLintRuleMap(),
        messageScheduler = MessageScheduler(
          testView: retainDataForTesting ? MessageSchedulerTestView() : null,
        ) {
diff --git a/pkg/analysis_server/lib/src/cider/assists.dart b/pkg/analysis_server/lib/src/cider/assists.dart
index 548341a..fccffcd8 100644
--- a/pkg/analysis_server/lib/src/cider/assists.dart
+++ b/pkg/analysis_server/lib/src/cider/assists.dart
@@ -6,9 +6,7 @@
 import 'package:analysis_server/src/services/correction/assist.dart';
 import 'package:analysis_server/src/services/correction/assist_internal.dart';
 import 'package:analysis_server_plugin/src/correction/dart_change_workspace.dart';
-import 'package:analysis_server_plugin/src/correction/fix_generators.dart';
 import 'package:analyzer/dart/analysis/session.dart';
-import 'package:analyzer/error/error.dart';
 import 'package:analyzer/instrumentation/service.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:analyzer/src/dart/micro/resolve_file.dart';
@@ -17,15 +15,7 @@
   final PerformanceLog _logger;
   final FileResolver _fileResolver;
 
-  /// A mapping of [ProducerGenerator]s to the set of lint names with which they
-  /// are associated (can fix).
-  final Map<ProducerGenerator, Set<LintCode>> _producerGeneratorsForLintRules;
-
-  CiderAssistsComputer(
-    this._logger,
-    this._fileResolver,
-    this._producerGeneratorsForLintRules,
-  );
+  CiderAssistsComputer(this._logger, this._fileResolver);
 
   /// Compute quick assists on the line and character position.
   Future<List<Assist>> compute(
@@ -49,7 +39,6 @@
           workspace,
           resolvedLibrary,
           resolvedUnit,
-          _producerGeneratorsForLintRules,
           offset,
           length,
         );
diff --git a/pkg/analysis_server/lib/src/handler/legacy/edit_get_assists.dart b/pkg/analysis_server/lib/src/handler/legacy/edit_get_assists.dart
index c25daac..b3ef636 100644
--- a/pkg/analysis_server/lib/src/handler/legacy/edit_get_assists.dart
+++ b/pkg/analysis_server/lib/src/handler/legacy/edit_get_assists.dart
@@ -106,7 +106,6 @@
         DartChangeWorkspace(await server.currentSessions),
         libraryResult,
         unitResult,
-        server.producerGeneratorsForLintRules,
         offset,
         length,
       );
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart
index cce7137..aa52be7 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart
@@ -133,7 +133,6 @@
         workspace,
         libraryResult,
         unitResult,
-        server.producerGeneratorsForLintRules,
         offset,
         length,
       );
diff --git a/pkg/analysis_server/lib/src/services/correction/assist.dart b/pkg/analysis_server/lib/src/services/correction/assist.dart
index b92f972..b5bdcdc 100644
--- a/pkg/analysis_server/lib/src/services/correction/assist.dart
+++ b/pkg/analysis_server/lib/src/services/correction/assist.dart
@@ -4,9 +4,7 @@
 
 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart';
 import 'package:analysis_server_plugin/src/correction/change_workspace.dart';
-import 'package:analysis_server_plugin/src/correction/fix_generators.dart';
 import 'package:analyzer/dart/analysis/results.dart';
-import 'package:analyzer/error/error.dart';
 import 'package:analyzer/instrumentation/service.dart';
 import 'package:analyzer_plugin/utilities/assist/assist.dart';
 
@@ -25,9 +23,6 @@
   final ResolvedUnitResult unitResult;
 
   @override
-  final Map<ProducerGenerator, Set<LintCode>> producerGeneratorsForLintRules;
-
-  @override
   final int selectionOffset;
 
   @override
@@ -38,7 +33,6 @@
     this.workspace,
     this.libraryResult,
     this.unitResult,
-    this.producerGeneratorsForLintRules,
     this.selectionOffset,
     this.selectionLength,
   );
diff --git a/pkg/analysis_server/lib/src/services/correction/assist_generators.dart b/pkg/analysis_server/lib/src/services/correction/assist_generators.dart
index da0cdcd..b2d4695 100644
--- a/pkg/analysis_server/lib/src/services/correction/assist_generators.dart
+++ b/pkg/analysis_server/lib/src/services/correction/assist_generators.dart
@@ -4,6 +4,7 @@
 
 import 'package:analysis_server_plugin/edit/dart/correction_producer.dart';
 import 'package:analysis_server_plugin/src/correction/fix_generators.dart';
+import 'package:analyzer/error/error.dart';
 
 final registeredAssistGenerators = _RegisteredAssistGenerators();
 
@@ -18,6 +19,17 @@
   /// assists.
   final Set<MultiProducerGenerator> multiProducerGenerators = {};
 
+  /// A mapping from registered _assist_ producer generators to the [LintCode]s
+  /// for which they may also act as a _fix_ producer generator.
+  late Map<ProducerGenerator, Set<LintCode>> lintRuleMap = {
+    for (var generator in producerGenerators)
+      generator: {
+        for (var MapEntry(key: lintName, value: generators)
+            in registeredFixGenerators.lintProducers.entries)
+          if (generators.contains(generator)) lintName,
+      },
+  };
+
   void registerGenerator(ProducerGenerator generator) {
     producerGenerators.add(generator);
   }
diff --git a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
index 3208fc5..8754a40 100644
--- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
@@ -264,7 +264,7 @@
     for (var generator in registeredAssistGenerators.producerGenerators) {
       if (!_generatorAppliesToAnyLintRule(
         generator,
-        _assistContext.producerGeneratorsForLintRules[generator] ?? {},
+        registeredAssistGenerators.lintRuleMap[generator] ?? {},
       )) {
         var producer = generator(context: context);
         await compute(producer);
@@ -285,6 +285,10 @@
     ProducerGenerator generator,
     Set<LintCode> errorCodes,
   ) {
+    if (errorCodes.isEmpty) {
+      return false;
+    }
+
     var selectionEnd =
         _assistContext.selectionOffset + _assistContext.selectionLength;
     var locator = NodeLocator(_assistContext.selectionOffset, selectionEnd);
@@ -307,15 +311,4 @@
     }
     return false;
   }
-
-  /// Returns a map from registered _assist_ producer generators to the
-  /// [LintCode]s for which they may also act as a _fix_ producer generator.
-  static Map<ProducerGenerator, Set<LintCode>> computeLintRuleMap() => {
-    for (var generator in registeredAssistGenerators.producerGenerators)
-      generator: {
-        for (var MapEntry(key: lintName, value: generators)
-            in registeredFixGenerators.lintProducers.entries)
-          if (generators.contains(generator)) lintName,
-      },
-  };
 }
diff --git a/pkg/analysis_server/test/src/cider/assists_test.dart b/pkg/analysis_server/test/src/cider/assists_test.dart
index 39365f1..61ca57a 100644
--- a/pkg/analysis_server/test/src/cider/assists_test.dart
+++ b/pkg/analysis_server/test/src/cider/assists_test.dart
@@ -6,8 +6,6 @@
 import 'package:analysis_server/src/cider/assists.dart';
 import 'package:analysis_server/src/services/correction/assist.dart';
 import 'package:analysis_server/src/services/correction/assist_internal.dart';
-import 'package:analysis_server_plugin/src/correction/fix_generators.dart';
-import 'package:analyzer/error/error.dart';
 import 'package:analyzer/source/line_info.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart' show SourceEdit;
 import 'package:analyzer_plugin/utilities/assist/assist.dart';
@@ -28,10 +26,6 @@
   late _CorrectionContext _correctionContext;
   late List<Assist> _assists;
 
-  /// A mapping of [ProducerGenerator]s to the set of lint names with which they
-  /// are associated (can fix).
-  late Map<ProducerGenerator, Set<LintCode>> _producerGeneratorsForLintRules;
-
   void assertHasAssist(AssistKind kind, String expected) {
     var assist = _getAssist(kind);
 
@@ -50,7 +44,6 @@
     super.setUp();
     registerBuiltInAssistGenerators();
     BlazeMockPackages.instance.addFlutter(resourceProvider);
-    _producerGeneratorsForLintRules = AssistProcessor.computeLintRuleMap();
   }
 
   Future<void> test_addReturnType() async {
@@ -111,11 +104,7 @@
   Future<void> _compute(String content) async {
     _updateFile(content);
 
-    var result = await CiderAssistsComputer(
-      logger,
-      fileResolver,
-      _producerGeneratorsForLintRules,
-    ).compute(
+    var result = await CiderAssistsComputer(logger, fileResolver).compute(
       convertPath(testPath),
       _correctionContext.line,
       _correctionContext.character,
diff --git a/pkg/analysis_server/test/src/services/correction/assist/assist_processor.dart b/pkg/analysis_server/test/src/services/correction/assist/assist_processor.dart
index aefe3c6..3103a53 100644
--- a/pkg/analysis_server/test/src/services/correction/assist/assist_processor.dart
+++ b/pkg/analysis_server/test/src/services/correction/assist/assist_processor.dart
@@ -7,8 +7,6 @@
 import 'package:analysis_server/src/services/correction/assist_internal.dart';
 import 'package:analysis_server_plugin/src/correction/change_workspace.dart';
 import 'package:analysis_server_plugin/src/correction/dart_change_workspace.dart';
-import 'package:analysis_server_plugin/src/correction/fix_generators.dart';
-import 'package:analyzer/error/error.dart';
 import 'package:analyzer/src/test_utilities/platform.dart';
 import 'package:analyzer/src/test_utilities/test_code_format.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart'
@@ -30,10 +28,6 @@
   late SourceChange _change;
   late String _resultCode;
 
-  /// A mapping of [ProducerGenerator]s to the set of lint names with which they
-  /// are associated (can fix).
-  late Map<ProducerGenerator, Set<LintCode>> _producerGeneratorsForLintRules;
-
   /// Return the kind of assist expected by this class.
   AssistKind get kind;
 
@@ -203,7 +197,6 @@
   void setUp() {
     super.setUp();
     useLineEndingsForPlatform = true;
-    _producerGeneratorsForLintRules = AssistProcessor.computeLintRuleMap();
   }
 
   /// Computes assists and verifies that there is an assist of the given kind.
@@ -227,7 +220,6 @@
       await workspace,
       libraryResult,
       testAnalysisResult,
-      _producerGeneratorsForLintRules,
       _offset,
       _length,
     );