analyzer: Remove AnalysisErrorListener and friends

* Remove AnalysisErrorListener, `RecordingDiagnosticListener.errors`,
  and `RecordingDiagnosticListener.getErrorsForSource`.
* Deprecate `BooleanDiagnosticListener.onError` and
  `RecordingDiagnosticListener.onError` in favor of `.onDiagnostic`.
* Deprecate DiagnosticOrErrorListener. Where this class is used in
  private API, replace it with DiagnosticListener. Where this class is
  used in public API, keep it and ignore the deprecation lint.

Change-Id: Ie9c89008269db8f42e4ebd161df2764d27dfe0da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456100
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md
index bdc7c9e..a7e8fc0 100644
--- a/pkg/analyzer/CHANGELOG.md
+++ b/pkg/analyzer/CHANGELOG.md
@@ -17,6 +17,12 @@
 * Remove deprecated `ErrorCode`.
 * Remove deprecated `ErrorSeverity`.
 * Remove deprecated `ErrorType`.
+* Remove deprecated `AnalysisErrorListener`.
+* Remove deprecated `RecordingDiagnosticListener.errors`.
+* Remove deprecated `RecordingDiagnosticListener.getErrorForSource`.
+* Deprecate `BooleanDiagnosticListener.onError` in favor of `.onDiagnostic`.
+* Deprecate `RecordingDiagnosticListener.onError` in favor of `.onDiagnostic`.
+* Deprecate `DiagnosticOrErrorListener` in favor of `DiagnosticListener`.
 
 ## 8.4.0
 * Add the `experimental_member_use` warning, which warns about any reference to
diff --git a/pkg/analyzer/api.txt b/pkg/analyzer/api.txt
index f3dcdcb..a623100 100644
--- a/pkg/analyzer/api.txt
+++ b/pkg/analyzer/api.txt
@@ -4575,19 +4575,16 @@
     == (method: bool Function(Object))
   AnalysisError (type alias for Diagnostic, deprecated)
 package:analyzer/error/listener.dart:
-  AnalysisErrorListener (class extends Object implements DiagnosticOrErrorListener, deprecated):
-    new (constructor: AnalysisErrorListener Function())
-    onError (method: void Function(Diagnostic))
-  BooleanDiagnosticListener (class extends Object implements AnalysisErrorListener, DiagnosticListener):
+  BooleanDiagnosticListener (class extends Object implements DiagnosticListener):
     new (constructor: BooleanDiagnosticListener Function())
     errorReported (getter: bool)
     onDiagnostic (method: void Function(Diagnostic))
-    onError (method: void Function(Diagnostic))
+    onError (method: void Function(Diagnostic), deprecated)
   DiagnosticListener (class extends Object implements DiagnosticOrErrorListener):
     nullListener (static getter: DiagnosticListener)
     new (constructor: DiagnosticListener Function())
     onDiagnostic (method: void Function(Diagnostic))
-  DiagnosticOrErrorListener (class extends Object, sealed (immediate subtypes: AnalysisErrorListener, DiagnosticListener))
+  DiagnosticOrErrorListener (class extends Object, sealed (immediate subtypes: DiagnosticListener), deprecated)
   DiagnosticReporter (class extends Object):
     new (constructor: DiagnosticReporter Function(DiagnosticOrErrorListener, Source))
     lockLevel (getter: int)
@@ -4601,13 +4598,11 @@
     atSourceSpan (method: Diagnostic Function(SourceSpan, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages}))
     atToken (method: Diagnostic Function(Token, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages}))
     reportError (method: void Function(Diagnostic))
-  RecordingDiagnosticListener (class extends Object implements AnalysisErrorListener, DiagnosticListener):
+  RecordingDiagnosticListener (class extends Object implements DiagnosticListener):
     new (constructor: RecordingDiagnosticListener Function())
     diagnostics (getter: List<Diagnostic>)
-    errors (getter: List<Diagnostic>, deprecated)
-    getErrorsForSource (method: List<Diagnostic> Function(Source), deprecated)
     onDiagnostic (method: void Function(Diagnostic))
-    onError (method: void Function(Diagnostic))
+    onError (method: void Function(Diagnostic), deprecated)
   DiagnosticOrErrorListenerExtension (extension on DiagnosticOrErrorListener):
     onDiagnostic (method: void Function(Diagnostic))
   ErrorReporter (type alias for DiagnosticReporter, deprecated)
diff --git a/pkg/analyzer/lib/error/listener.dart b/pkg/analyzer/lib/error/listener.dart
index 6408da2..fa2cfaf 100644
--- a/pkg/analyzer/lib/error/listener.dart
+++ b/pkg/analyzer/lib/error/listener.dart
@@ -4,7 +4,6 @@
 
 import 'package:_fe_analyzer_shared/src/base/errors.dart';
 import 'package:analyzer/diagnostic/diagnostic.dart';
-import 'package:analyzer/source/source.dart';
 import 'package:analyzer/src/error/listener.dart';
 
 export 'package:analyzer/src/error/listener.dart' show DiagnosticReporter;
@@ -12,22 +11,9 @@
 @Deprecated("Use 'DiagnosticReporter' instead")
 typedef ErrorReporter = DiagnosticReporter;
 
-/// An object that listens for [Diagnostic]s being produced by the analysis
-/// engine.
-@Deprecated("Use 'DiagnosticListener' instead")
-abstract class AnalysisErrorListener implements DiagnosticOrErrorListener {
-  /// This method is invoked when a [diagnostic] has been found by the analysis
-  /// engine.
-  void onError(Diagnostic diagnostic);
-}
-
 /// A [DiagnosticListener] that keeps track of whether any diagnostic has been
 /// reported to it.
-class BooleanDiagnosticListener
-    implements
-        // ignore: deprecated_member_use_from_same_package
-        AnalysisErrorListener,
-        DiagnosticListener {
+class BooleanDiagnosticListener implements DiagnosticListener {
   /// A flag indicating whether a diagnostic has been reported to this listener.
   bool _diagnosticReported = false;
 
@@ -39,10 +25,11 @@
     _diagnosticReported = true;
   }
 
-  @override
+  @Deprecated("Call 'onDiagnostic' instead")
   void onError(Diagnostic diagnostic) => onDiagnostic(diagnostic);
 }
 
+// ignore: deprecated_member_use_from_same_package
 abstract class DiagnosticListener implements DiagnosticOrErrorListener {
   /// A diagnostic listener that ignores diagnostics that are reported to it.
   static const DiagnosticListener nullListener = _NullDiagnosticListener();
@@ -50,16 +37,13 @@
   void onDiagnostic(Diagnostic diagnostic);
 }
 
+@Deprecated("Use 'DiagnosticListener' instead")
 sealed class DiagnosticOrErrorListener {}
 
 /// A diagnostic listener that records the diagnostics that are reported to it
 /// in a way that is appropriate for caching those diagnostic within an
 /// analysis context.
-class RecordingDiagnosticListener
-    implements
-        // ignore: deprecated_member_use_from_same_package
-        AnalysisErrorListener,
-        DiagnosticListener {
+class RecordingDiagnosticListener implements DiagnosticListener {
   Set<Diagnostic>? _diagnostics;
 
   /// The diagnostics collected by the listener.
@@ -70,24 +54,12 @@
     return _diagnostics!.toList();
   }
 
-  @Deprecated("Use 'diagnostics' instead")
-  List<Diagnostic> get errors => diagnostics;
-
-  /// Return the errors collected by the listener for the given [source].
-  @Deprecated('No longer supported')
-  List<Diagnostic> getErrorsForSource(Source source) {
-    if (_diagnostics == null) {
-      return const [];
-    }
-    return _diagnostics!.where((d) => d.source == source).toList();
-  }
-
   @override
   void onDiagnostic(Diagnostic diagnostic) {
     (_diagnostics ??= {}).add(diagnostic);
   }
 
-  @override
+  @Deprecated("Call 'onDiagnostic' instead")
   void onError(Diagnostic diagnostic) => onDiagnostic(diagnostic);
 }
 
@@ -101,10 +73,9 @@
   }
 }
 
+// ignore: deprecated_member_use_from_same_package
 extension DiagnosticOrErrorListenerExtension on DiagnosticOrErrorListener {
   void onDiagnostic(Diagnostic diagnostic) => switch (this) {
     DiagnosticListener self => self.onDiagnostic(diagnostic),
-    // ignore: deprecated_member_use_from_same_package
-    AnalysisErrorListener self => self.onError(diagnostic),
   };
 }
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index e1b901a..50d5ae3 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -591,8 +591,7 @@
 
   /// Return a new parsed unresolved [CompilationUnit].
   CompilationUnitImpl parse({
-    DiagnosticOrErrorListener diagnosticListener =
-        DiagnosticListener.nullListener,
+    DiagnosticListener diagnosticListener = DiagnosticListener.nullListener,
     required OperationPerformanceImpl performance,
   }) {
     try {
@@ -609,7 +608,7 @@
   /// Parses given [code] with the same features as this file.
   CompilationUnitImpl parseCode({
     required String code,
-    required DiagnosticOrErrorListener diagnosticListener,
+    required DiagnosticListener diagnosticListener,
     required OperationPerformanceImpl performance,
   }) {
     return performance.run('parseCode', (performance) {
diff --git a/pkg/analyzer/lib/src/dart/scanner/scanner.dart b/pkg/analyzer/lib/src/dart/scanner/scanner.dart
index b349b3d..2ae5ee4 100644
--- a/pkg/analyzer/lib/src/dart/scanner/scanner.dart
+++ b/pkg/analyzer/lib/src/dart/scanner/scanner.dart
@@ -48,7 +48,7 @@
 
   /// The diagnostic listener that will be informed of any diagnostics that are
   /// found during the scan.
-  final DiagnosticOrErrorListener _diagnosticListener;
+  final DiagnosticListener _diagnosticListener;
 
   /// If the file has [fasta.LanguageVersionToken], it is allowed to use the
   /// language version greater than the one specified in the package config.
@@ -71,7 +71,7 @@
   factory Scanner(
     Source source,
     CharacterReader reader,
-    DiagnosticOrErrorListener diagnosticListener,
+    DiagnosticListener diagnosticListener,
   ) => Scanner.fasta(
     source,
     diagnosticListener,
@@ -81,7 +81,7 @@
 
   factory Scanner.fasta(
     Source source,
-    DiagnosticOrErrorListener diagnosticListener, {
+    DiagnosticListener diagnosticListener, {
     String? contents,
     int offset = -1,
   }) {
diff --git a/pkg/analyzer/lib/src/error/listener.dart b/pkg/analyzer/lib/src/error/listener.dart
index fd44191..8a17f0b 100644
--- a/pkg/analyzer/lib/src/error/listener.dart
+++ b/pkg/analyzer/lib/src/error/listener.dart
@@ -144,6 +144,7 @@
 @AnalyzerPublicApi(message: 'Exported by package:analyzer/error/listener.dart')
 class DiagnosticReporter {
   /// The diagnostic listener to which diagnostics are reported.
+  // ignore: deprecated_member_use_from_same_package
   final DiagnosticOrErrorListener _diagnosticListener;
 
   /// The source to be used when reporting diagnostics.
diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart
index 7a4f1ed..e3fdd42 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -32,7 +32,7 @@
 
   Parser(
     Source source,
-    DiagnosticOrErrorListener diagnosticListener, {
+    DiagnosticListener diagnosticListener, {
     required FeatureSet featureSet,
     bool allowNativeClause = true,
     required LibraryLanguageVersion languageVersion,
diff --git a/pkg/analyzer/test/error/error_listener_test.dart b/pkg/analyzer/test/error/error_listener_test.dart
index b947e6f..54f0c1a 100644
--- a/pkg/analyzer/test/error/error_listener_test.dart
+++ b/pkg/analyzer/test/error/error_listener_test.dart
@@ -9,19 +9,19 @@
 
 main() {
   defineReflectiveSuite(() {
-    defineReflectiveTests(RecordingErrorListenerTest);
+    defineReflectiveTests(RecordingDiagnosticListenerTest);
   });
 }
 
 @reflectiveTest
-class RecordingErrorListenerTest {
+class RecordingDiagnosticListenerTest {
   test_orderedAsReported() {
     var listener = RecordingDiagnosticListener();
-    listener.onError(_MockDiagnostic(expectedIndex: 0, hashCode: 1));
-    listener.onError(_MockDiagnostic(expectedIndex: 1, hashCode: 10));
-    listener.onError(_MockDiagnostic(expectedIndex: 2, hashCode: -50));
-    listener.onError(_MockDiagnostic(expectedIndex: 3, hashCode: 20));
-    listener.onError(_MockDiagnostic(expectedIndex: 4, hashCode: 1));
+    listener.onDiagnostic(_MockDiagnostic(expectedIndex: 0, hashCode: 1));
+    listener.onDiagnostic(_MockDiagnostic(expectedIndex: 1, hashCode: 10));
+    listener.onDiagnostic(_MockDiagnostic(expectedIndex: 2, hashCode: -50));
+    listener.onDiagnostic(_MockDiagnostic(expectedIndex: 3, hashCode: 20));
+    listener.onDiagnostic(_MockDiagnostic(expectedIndex: 4, hashCode: 1));
 
     // Expect the errors are returned in the order they are reported, and not
     // affected by their hashcodes.
diff --git a/pkg/analyzer/test/generated/parser_test_base.dart b/pkg/analyzer/test/generated/parser_test_base.dart
index a0c093d..74b613d 100644
--- a/pkg/analyzer/test/generated/parser_test_base.dart
+++ b/pkg/analyzer/test/generated/parser_test_base.dart
@@ -1287,7 +1287,7 @@
   /// Parse the given [content] as a compilation unit.
   CompilationUnit parseCompilationUnit2(
     String content, {
-    DiagnosticOrErrorListener listener = DiagnosticListener.nullListener,
+    DiagnosticListener listener = DiagnosticListener.nullListener,
   }) {
     Source source = NonExistingSource.unknown;