From 388a92b1606534eed06faaf2131e7b5af6e28fa2 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Tue, 25 Nov 2025 16:12:00 -0800 Subject: [PATCH] analyzer: Remove deprecated DiagnosticOrErrorListener and friends Change-Id: I06d91cd3e10e27afd10056dfac978d918f594c6e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464601 Reviewed-by: Konstantin Shcheglov Commit-Queue: Samuel Rawlins --- pkg/analyzer/CHANGELOG.md | 4 ++++ pkg/analyzer/api.txt | 9 ++------- pkg/analyzer/lib/error/listener.dart | 19 +------------------ pkg/analyzer/lib/src/error/listener.dart | 3 +-- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md index 6ec6da35f65..7d2f452233e 100644 --- a/pkg/analyzer/CHANGELOG.md +++ b/pkg/analyzer/CHANGELOG.md @@ -14,6 +14,10 @@ * **Breaking Change:** While the deprecated members mentioned above still exist in the AST, their parent nodes have changed. This means that code relying on specific parent-child relationships for these nodes might break. +* **Breaking Change:** Remove deprecated `DiagnosticOrErrorListener` and the + `DiagnosticOrErrorListenerExtension` extension. +* **Breaking Change:** Remove deprecated `RecordingDiagnosticListener.onError` + and `BooleanDiagnosticListener.onError` methods. * Deprecate `LintCode.new`'s `hasPublishedDocs` parameter. * Add `RemovedAnalysisRule` as the preferred way to represent removed lint rules. Deprecated `RuleState.removed` (which was the previous way to do so). diff --git a/pkg/analyzer/api.txt b/pkg/analyzer/api.txt index 2578fc82f9a..446f20ccd87 100644 --- a/pkg/analyzer/api.txt +++ b/pkg/analyzer/api.txt @@ -4612,14 +4612,12 @@ package:analyzer/error/listener.dart: new (constructor: BooleanDiagnosticListener Function()) errorReported (getter: bool) onDiagnostic (method: void Function(Diagnostic)) - onError (method: void Function(Diagnostic), deprecated) - DiagnosticListener (class extends Object implements DiagnosticOrErrorListener): + DiagnosticListener (class extends Object): nullListener (static getter: DiagnosticListener) new (constructor: DiagnosticListener Function()) onDiagnostic (method: void Function(Diagnostic)) - DiagnosticOrErrorListener (class extends Object, sealed (immediate subtypes: DiagnosticListener), deprecated) DiagnosticReporter (class extends Object): - new (constructor: DiagnosticReporter Function(DiagnosticOrErrorListener, Source)) + new (constructor: DiagnosticReporter Function(DiagnosticListener, Source)) lockLevel (getter: int) lockLevel= (setter: int) source (getter: Source) @@ -4635,9 +4633,6 @@ package:analyzer/error/listener.dart: new (constructor: RecordingDiagnosticListener Function()) diagnostics (getter: List) onDiagnostic (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) package:analyzer/exception/exception.dart: AnalysisException (class extends Object implements Exception): diff --git a/pkg/analyzer/lib/error/listener.dart b/pkg/analyzer/lib/error/listener.dart index fa2cfaf4c5f..64737186ff5 100644 --- a/pkg/analyzer/lib/error/listener.dart +++ b/pkg/analyzer/lib/error/listener.dart @@ -24,22 +24,15 @@ class BooleanDiagnosticListener implements DiagnosticListener { void onDiagnostic(Diagnostic diagnostic) { _diagnosticReported = true; } - - @Deprecated("Call 'onDiagnostic' instead") - void onError(Diagnostic diagnostic) => onDiagnostic(diagnostic); } -// ignore: deprecated_member_use_from_same_package -abstract class DiagnosticListener implements DiagnosticOrErrorListener { +abstract class DiagnosticListener { /// A diagnostic listener that ignores diagnostics that are reported to it. static const DiagnosticListener nullListener = _NullDiagnosticListener(); 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. @@ -58,9 +51,6 @@ class RecordingDiagnosticListener implements DiagnosticListener { void onDiagnostic(Diagnostic diagnostic) { (_diagnostics ??= {}).add(diagnostic); } - - @Deprecated("Call 'onDiagnostic' instead") - void onError(Diagnostic diagnostic) => onDiagnostic(diagnostic); } /// A [DiagnosticListener] that ignores everything. @@ -72,10 +62,3 @@ class _NullDiagnosticListener implements DiagnosticListener { // Ignore diagnostics. } } - -// ignore: deprecated_member_use_from_same_package -extension DiagnosticOrErrorListenerExtension on DiagnosticOrErrorListener { - void onDiagnostic(Diagnostic diagnostic) => switch (this) { - DiagnosticListener self => self.onDiagnostic(diagnostic), - }; -} diff --git a/pkg/analyzer/lib/src/error/listener.dart b/pkg/analyzer/lib/src/error/listener.dart index 3228993efe2..bad503c001f 100644 --- a/pkg/analyzer/lib/src/error/listener.dart +++ b/pkg/analyzer/lib/src/error/listener.dart @@ -145,8 +145,7 @@ Expected types: $expectedTypes'''); @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; + final DiagnosticListener _diagnosticListener; /// The source to be used when reporting diagnostics. final Source _source;