From ee69f45a1ffafea3490c19ccf3587fa93c6fa432 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Wed, 25 Jun 2025 06:54:20 -0700 Subject: [PATCH] analyzer: rework AnalysisErrorListener deprecation Work towards #60635 In this change, we rework the AnalysisErrorListener deprecation to better support users who have their own class that implements AnalysisErrorListener. This change introduces a sealed supertype, DiagnosticOrErrorListener, with the old implementation, AnalysisErrorListener, and the new implementation, DiagnosticListener, as its sole direct subclasses. Users who have implemented AnalysisErrorListener should be able to instead implement DiagnosticListener, and their class is an acceptable instance of DiagnosticOrErrorListener, wherever that is needed. In a breaking change we can drop AnalysisErrorListener and deprecate DiagnosticOrErrorListener, and in the next breaking change, we can drop DiagnosticOrErrorListener. For reference, see the first API difference when deprecating AnalysisErrorListener and introducing DiagnosticListener: https://github.com/dart-lang/sdk/commit/903d77cc8229972a424941dcb7b7b79741e833eb#diff-dec15868961d7eadcd009f49d129bebcdb747aaa8dbfde5f5a08884e0cf11e32 Change-Id: I3ccf11d54b41fbca98d020d89978d250c16b4c04 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436480 Reviewed-by: Paul Berry Commit-Queue: Samuel Rawlins --- .../lib/src/lsp/source_edits.dart | 2 +- .../data_driven/transform_set_manager.dart | 2 +- .../correction/statement_analyzer.dart | 2 +- .../test/stress/replay/replay.dart | 2 +- .../test/utils/test_support.dart | 4 +- .../lib/edit/correction_utils.dart | 2 +- pkg/analyzer/CHANGELOG.md | 8 +- pkg/analyzer/api.txt | 22 +++-- pkg/analyzer/lib/error/listener.dart | 87 ++++++++++++++----- .../lib/src/dart/analysis/file_state.dart | 5 +- .../src/dart/constant/constant_verifier.dart | 2 +- .../lib/src/dart/scanner/scanner.dart | 10 +-- .../error/unused_local_elements_verifier.dart | 2 +- pkg/analyzer/lib/src/generated/parser.dart | 2 +- pkg/analyzer/lib/src/lint/constants.dart | 2 +- .../lib/src/summary2/ast_resolver.dart | 2 +- .../test/generated/parser_test_base.dart | 2 +- pkg/analyzer/test/generated/test_support.dart | 4 +- .../test/src/summary/test_strategies.dart | 4 +- pkg/analyzer_cli/tool/perf.dart | 6 +- pkg/front_end/tool/perf.dart | 6 +- .../lib/src/test_utilities/test_linter.dart | 2 +- pkg/scrape/lib/src/error_listener.dart | 2 +- 23 files changed, 119 insertions(+), 63 deletions(-) diff --git a/pkg/analysis_server/lib/src/lsp/source_edits.dart b/pkg/analysis_server/lib/src/lsp/source_edits.dart index ddda192a7b0..6fb1e67e4cf 100644 --- a/pkg/analysis_server/lib/src/lsp/source_edits.dart +++ b/pkg/analysis_server/lib/src/lsp/source_edits.dart @@ -678,7 +678,7 @@ class _MinimalEditComputer { var scanner = Scanner( _SourceMock.instance, CharSequenceReader(s), - DiagnosticListener.NULL_LISTENER, + DiagnosticListener.nullListener, )..configureFeatures( featureSetForOverriding: featureSet, featureSet: featureSet, diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_manager.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_manager.dart index d12f708ba0d..a2b73bfca16 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_manager.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_manager.dart @@ -115,7 +115,7 @@ class TransformSetManager { try { var content = file.readAsStringSync(); var parser = TransformSetParser( - DiagnosticReporter(DiagnosticListener.NULL_LISTENER, FileSource(file)), + DiagnosticReporter(DiagnosticListener.nullListener, FileSource(file)), packageName, ); return parser.parse(content); diff --git a/pkg/analysis_server/lib/src/services/correction/statement_analyzer.dart b/pkg/analysis_server/lib/src/services/correction/statement_analyzer.dart index edce3e60cc1..96a9132af08 100644 --- a/pkg/analysis_server/lib/src/services/correction/statement_analyzer.dart +++ b/pkg/analysis_server/lib/src/services/correction/statement_analyzer.dart @@ -26,7 +26,7 @@ List _getTokens(String text, FeatureSet featureSet) { var scanner = Scanner( _SourceMock.instance, CharSequenceReader(text), - DiagnosticListener.NULL_LISTENER, + DiagnosticListener.nullListener, )..configureFeatures( featureSetForOverriding: featureSet, featureSet: featureSet, diff --git a/pkg/analysis_server/test/stress/replay/replay.dart b/pkg/analysis_server/test/stress/replay/replay.dart index d04b4ef818b..a051f85ee57 100644 --- a/pkg/analysis_server/test/stress/replay/replay.dart +++ b/pkg/analysis_server/test/stress/replay/replay.dart @@ -226,7 +226,7 @@ class Driver { var scanner = Scanner( _TestSource(), CharSequenceReader(text), - error.DiagnosticListener.NULL_LISTENER, + error.DiagnosticListener.nullListener, )..configureFeatures( featureSetForOverriding: featureSet, featureSet: featureSet, diff --git a/pkg/analysis_server/test/utils/test_support.dart b/pkg/analysis_server/test/utils/test_support.dart index 76e63dbda27..95cf35eee6d 100644 --- a/pkg/analysis_server/test/utils/test_support.dart +++ b/pkg/analysis_server/test/utils/test_support.dart @@ -137,7 +137,7 @@ class GatheringDiagnosticListener implements DiagnosticListener { /// Adds the given [diagnostics] to this listener. void addAll(List diagnostics) { for (var diagnostic in diagnostics) { - onError(diagnostic); + onDiagnostic(diagnostic); } } @@ -388,7 +388,7 @@ class GatheringDiagnosticListener implements DiagnosticListener { } @override - void onError(Diagnostic diagnostic) { + void onDiagnostic(Diagnostic diagnostic) { _diagnostics.add(diagnostic); } diff --git a/pkg/analysis_server_plugin/lib/edit/correction_utils.dart b/pkg/analysis_server_plugin/lib/edit/correction_utils.dart index 62d26e91f49..138a26853f9 100644 --- a/pkg/analysis_server_plugin/lib/edit/correction_utils.dart +++ b/pkg/analysis_server_plugin/lib/edit/correction_utils.dart @@ -443,7 +443,7 @@ class TokenUtils { var scanner = Scanner( _SourceMock(), CharSequenceReader(s), - DiagnosticListener.NULL_LISTENER, + DiagnosticListener.nullListener, )..configureFeatures( featureSetForOverriding: featureSet, featureSet: featureSet, diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md index 4b9d719df89..bc990f56ce3 100644 --- a/pkg/analyzer/CHANGELOG.md +++ b/pkg/analyzer/CHANGELOG.md @@ -17,8 +17,12 @@ * Deprecate `ErrorSeverity`; use `DiagnosticSeverity` instead. * Deprecate `DiagnosticCode.errorSeverity`; use `DiagnosticCode.diagnosticSeverity` instead. -* Deprecate `ErrorListener` and `RecordingErrorListener`; use - `DiagnosticListener` and `RecordingDiagnosticListener` instead. +* Deprecate `AnalysisErrorListener`, `BooleanErrorListener`, and + `RecordingErrorListener`; use `DiagnosticListener`, + `BooleanDiagnosticListener`, and `RecordingDiagnosticListener` respectively, + instead. Instead of calling or overriding `AnalysisErrorListener.onError`, + call or override `DiagnosticListener.onDiagnostic`. Instead of using + `AnalysisErrorListener.NULL_LISTENER`, use `DiagnosticListener.nullListener`. * Deprecate `RecordingErrorListener.errors`; use `RecordingDiagnosticListener.diagnostics` instead. * Deprecate `RecordingErrorListener.getErrorsForSource`; no longer supported. diff --git a/pkg/analyzer/api.txt b/pkg/analyzer/api.txt index 9dfed6b16c2..318bb3fb238 100644 --- a/pkg/analyzer/api.txt +++ b/pkg/analyzer/api.txt @@ -4770,16 +4770,22 @@ package:analyzer/error/error.dart: ErrorSeverity (type alias for DiagnosticSeverity, deprecated) ErrorType (type alias for DiagnosticType, deprecated) package:analyzer/error/listener.dart: - BooleanDiagnosticListener (class extends Object implements DiagnosticListener): + AnalysisErrorListener (class extends Object implements DiagnosticOrErrorListener, deprecated): + NULL_LISTENER (static getter: AnalysisErrorListener) + new (constructor: AnalysisErrorListener Function()) + onError (method: void Function(Diagnostic)) + BooleanDiagnosticListener (class extends Object implements AnalysisErrorListener, DiagnosticListener): new (constructor: BooleanDiagnosticListener Function()) errorReported (getter: bool) + onDiagnostic (method: void Function(Diagnostic)) onError (method: void Function(Diagnostic)) - DiagnosticListener (class extends Object): - NULL_LISTENER (static getter: DiagnosticListener) + DiagnosticListener (class extends Object implements DiagnosticOrErrorListener): + nullListener (static getter: DiagnosticListener) new (constructor: DiagnosticListener Function()) - onError (method: void Function(Diagnostic)) + onDiagnostic (method: void Function(Diagnostic)) + DiagnosticOrErrorListener (class extends Object, sealed (immediate subtypes: AnalysisErrorListener, DiagnosticListener)) DiagnosticReporter (class extends Object): - new (constructor: DiagnosticReporter Function(DiagnosticListener, Source)) + new (constructor: DiagnosticReporter Function(DiagnosticOrErrorListener, Source)) lockLevel (getter: int) lockLevel= (setter: int) source (getter: Source) @@ -4791,13 +4797,15 @@ package:analyzer/error/listener.dart: atSourceSpan (method: void Function(SourceSpan, DiagnosticCode, {List? arguments, List? contextMessages, Object? data})) atToken (method: void Function(Token, DiagnosticCode, {List? arguments, List? contextMessages, Object? data})) reportError (method: void Function(Diagnostic)) - RecordingDiagnosticListener (class extends Object implements DiagnosticListener): + RecordingDiagnosticListener (class extends Object implements AnalysisErrorListener, DiagnosticListener): new (constructor: RecordingDiagnosticListener Function()) diagnostics (getter: List) errors (getter: List, deprecated) getErrorsForSource (method: List Function(Source), deprecated) + onDiagnostic (method: void Function(Diagnostic)) onError (method: void Function(Diagnostic)) - AnalysisErrorListener (type alias for DiagnosticListener, deprecated) + DiagnosticOrErrorListenerExtension (extension on DiagnosticOrErrorListener): + onDiagnostic (method: void Function(Diagnostic)) BooleanErrorListener (type alias for BooleanDiagnosticListener, deprecated) ErrorReporter (type alias for DiagnosticReporter, deprecated) RecorderingErrorListener (type alias for RecordingDiagnosticListener, deprecated) diff --git a/pkg/analyzer/lib/error/listener.dart b/pkg/analyzer/lib/error/listener.dart index 05f516177c4..672f4ee45f9 100644 --- a/pkg/analyzer/lib/error/listener.dart +++ b/pkg/analyzer/lib/error/listener.dart @@ -16,9 +16,6 @@ import 'package:analyzer/src/utilities/extensions/collection.dart'; import 'package:meta/meta.dart'; import 'package:source_span/source_span.dart'; -@Deprecated("Use 'DiagnosticListener' instead") -typedef AnalysisErrorListener = DiagnosticListener; - @Deprecated("Use 'BooleanDiagnosticListener' instead") typedef BooleanErrorListener = BooleanDiagnosticListener; @@ -28,9 +25,26 @@ typedef ErrorReporter = DiagnosticReporter; @Deprecated("Use 'RecordingDiagnosticListener' instead") typedef RecorderingErrorListener = RecordingDiagnosticListener; -/// An [DiagnosticListener] that keeps track of whether any diagnostic has been +/// An object that listens for [Diagnostic]s being produced by the analysis +/// engine. +@Deprecated("Use 'DiagnosticListener' instead") +abstract class AnalysisErrorListener implements DiagnosticOrErrorListener { + /// A diagnostic listener that ignores diagnostics that are reported to it. + @Deprecated("Use 'DiagnosticListener.nullListener' instead") + static const AnalysisErrorListener NULL_LISTENER = _NullErrorListener(); + + /// 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 DiagnosticListener { +class BooleanDiagnosticListener + implements + // ignore: deprecated_member_use_from_same_package + AnalysisErrorListener, + DiagnosticListener { /// A flag indicating whether a diagnostic has been reported to this listener. bool _diagnosticReported = false; @@ -38,28 +52,28 @@ class BooleanDiagnosticListener implements DiagnosticListener { bool get errorReported => _diagnosticReported; @override - void onError(Diagnostic diagnostic) { + void onDiagnostic(Diagnostic diagnostic) { _diagnosticReported = true; } + + @override + void onError(Diagnostic diagnostic) => onDiagnostic(diagnostic); } -/// An object that listens for [Diagnostic]s being produced by the analysis -/// engine. -abstract class DiagnosticListener { +abstract class DiagnosticListener implements DiagnosticOrErrorListener { /// A diagnostic listener that ignores diagnostics that are reported to it. - static const DiagnosticListener NULL_LISTENER = _NullDiagnosticListener(); + static const DiagnosticListener nullListener = _NullDiagnosticListener(); - /// This method is invoked when a [diagnostic] has been found by the analysis - /// engine. - // TODO(srawlins): Rename to 'onDiagnostic'. - void onError(Diagnostic diagnostic); + void onDiagnostic(Diagnostic diagnostic); } +sealed class DiagnosticOrErrorListener {} + /// An object used to create diagnostics and report them to a diagnostic /// listener. class DiagnosticReporter { /// The diagnostic listener to which diagnostics are reported. - final DiagnosticListener _diagnosticListener; + final DiagnosticOrErrorListener _diagnosticListener; /// The source to be used when reporting diagnostics. final Source _source; @@ -211,7 +225,7 @@ class DiagnosticReporter { contextMessages ??= []; contextMessages.addAll(convertTypeNames(arguments)); - _diagnosticListener.onError( + _diagnosticListener.onDiagnostic( Diagnostic.tmp( source: _source, offset: offset, @@ -266,14 +280,18 @@ class DiagnosticReporter { /// Report the given [diagnostic]. void reportError(Diagnostic diagnostic) { - _diagnosticListener.onError(diagnostic); + _diagnosticListener.onDiagnostic(diagnostic); } } /// 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 DiagnosticListener { +class RecordingDiagnosticListener + implements + // ignore: deprecated_member_use_from_same_package + AnalysisErrorListener, + DiagnosticListener { Set? _diagnostics; /// The diagnostics collected by the listener. @@ -297,17 +315,42 @@ class RecordingDiagnosticListener implements DiagnosticListener { } @override - void onError(Diagnostic diagnostic) { + void onDiagnostic(Diagnostic diagnostic) { (_diagnostics ??= {}).add(diagnostic); } + + @override + void onError(Diagnostic diagnostic) => onDiagnostic(diagnostic); +} + +/// A [DiagnosticListener] that ignores everything. +class _NullDiagnosticListener implements DiagnosticListener { + const _NullDiagnosticListener(); + + @override + void onDiagnostic(Diagnostic diagnostic) { + // Ignore diagnostics. + } } -/// An [DiagnosticListener] that ignores everything. -class _NullDiagnosticListener implements DiagnosticListener { - const _NullDiagnosticListener(); +// ignore: deprecated_member_use_from_same_package +/// An [AnalysisErrorListener] that ignores everything. +class _NullErrorListener + implements + // ignore: deprecated_member_use_from_same_package + AnalysisErrorListener { + const _NullErrorListener(); @override void onError(Diagnostic diagnostic) { // Ignore diagnostics. } } + +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 098443e877a..3e006c81d85 100644 --- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart +++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart @@ -591,7 +591,8 @@ class FileState { /// Return a new parsed unresolved [CompilationUnit]. CompilationUnitImpl parse({ - DiagnosticListener diagnosticListener = DiagnosticListener.NULL_LISTENER, + DiagnosticOrErrorListener diagnosticListener = + DiagnosticListener.nullListener, required OperationPerformanceImpl performance, }) { try { @@ -608,7 +609,7 @@ class FileState { /// Parses given [code] with the same features as this file. CompilationUnitImpl parseCode({ required String code, - required DiagnosticListener diagnosticListener, + required DiagnosticOrErrorListener diagnosticListener, required OperationPerformanceImpl performance, }) { return performance.run('parseCode', (performance) { diff --git a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart index 7b2c942da93..3fa1804b3f6 100644 --- a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart +++ b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart @@ -975,7 +975,7 @@ class ConstantVerifier extends RecursiveAstVisitor { // Ignore any diagnostics produced during validation--if the // constant can't be evaluated we'll just report a single error. DiagnosticReporter subDiagnosticReporter = DiagnosticReporter( - DiagnosticListener.NULL_LISTENER, + DiagnosticListener.nullListener, _diagnosticReporter.source, ); var result = initializer.accept( diff --git a/pkg/analyzer/lib/src/dart/scanner/scanner.dart b/pkg/analyzer/lib/src/dart/scanner/scanner.dart index be0559f554c..8dbeebef90d 100644 --- a/pkg/analyzer/lib/src/dart/scanner/scanner.dart +++ b/pkg/analyzer/lib/src/dart/scanner/scanner.dart @@ -42,7 +42,7 @@ class Scanner { /// The diagnostic listener that will be informed of any diagnostics that are /// found during the scan. - final DiagnosticListener _diagnosticListener; + final DiagnosticOrErrorListener _diagnosticListener; /// If the file has [fasta.LanguageVersionToken], it is allowed to use the /// language version greater than the one specified in the package config. @@ -65,7 +65,7 @@ class Scanner { factory Scanner( Source source, CharacterReader reader, - DiagnosticListener diagnosticListener, + DiagnosticOrErrorListener diagnosticListener, ) => Scanner.fasta( source, diagnosticListener, @@ -75,7 +75,7 @@ class Scanner { factory Scanner.fasta( Source source, - DiagnosticListener diagnosticListener, { + DiagnosticOrErrorListener diagnosticListener, { String? contents, int offset = -1, }) { @@ -128,7 +128,7 @@ class Scanner { int offset, List? arguments, ) { - _diagnosticListener.onError( + _diagnosticListener.onDiagnostic( Diagnostic.tmp( source: source, offset: offset, @@ -201,7 +201,7 @@ class Scanner { var latestVersion = ExperimentStatus.currentVersion; if (overrideVersion > latestVersion) { - _diagnosticListener.onError( + _diagnosticListener.onDiagnostic( Diagnostic.tmp( source: source, offset: versionToken.offset, diff --git a/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart b/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart index df15b09642d..f16d93c9feb 100644 --- a/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart +++ b/pkg/analyzer/lib/src/error/unused_local_elements_verifier.dart @@ -1011,7 +1011,7 @@ class UnusedLocalElementsVerifier extends RecursiveAstVisitor { ) { if (element != null) { var fragment = element.firstFragment; - _diagnosticListener.onError( + _diagnosticListener.onDiagnostic( Diagnostic.tmp( source: fragment.libraryFragment!.source, offset: diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart index 153593437f7..3654e0508b1 100644 --- a/pkg/analyzer/lib/src/generated/parser.dart +++ b/pkg/analyzer/lib/src/generated/parser.dart @@ -30,7 +30,7 @@ class Parser { Parser( Source source, - DiagnosticListener diagnosticListener, { + DiagnosticOrErrorListener diagnosticListener, { required FeatureSet featureSet, bool allowNativeClause = true, required LibraryLanguageVersion languageVersion, diff --git a/pkg/analyzer/lib/src/lint/constants.dart b/pkg/analyzer/lib/src/lint/constants.dart index 12d0ddec7fd..b59f9a78868 100644 --- a/pkg/analyzer/lib/src/lint/constants.dart +++ b/pkg/analyzer/lib/src/lint/constants.dart @@ -24,7 +24,7 @@ class _ConstantDiagnosticListener extends DiagnosticListener { bool hasConstError = false; @override - void onError(Diagnostic diagnostic) { + void onDiagnostic(Diagnostic diagnostic) { DiagnosticCode diagnosticCode = diagnostic.diagnosticCode; if (diagnosticCode is CompileTimeErrorCode) { switch (diagnosticCode) { diff --git a/pkg/analyzer/lib/src/summary2/ast_resolver.dart b/pkg/analyzer/lib/src/summary2/ast_resolver.dart index 95289d62942..849be993d69 100644 --- a/pkg/analyzer/lib/src/summary2/ast_resolver.dart +++ b/pkg/analyzer/lib/src/summary2/ast_resolver.dart @@ -24,7 +24,7 @@ class AstResolver { final Scope _nameScope; final FeatureSet _featureSet; final DiagnosticListener _diagnosticListener = - DiagnosticListener.NULL_LISTENER; + DiagnosticListener.nullListener; final AnalysisOptions analysisOptions; final InterfaceElementImpl? enclosingClassElement; final ExecutableElementImpl? enclosingExecutableElement; diff --git a/pkg/analyzer/test/generated/parser_test_base.dart b/pkg/analyzer/test/generated/parser_test_base.dart index 8d3e234d774..c3117edf863 100644 --- a/pkg/analyzer/test/generated/parser_test_base.dart +++ b/pkg/analyzer/test/generated/parser_test_base.dart @@ -1294,7 +1294,7 @@ class ParserTestCase with ParserTestHelpers implements AbstractParserTestCase { /// Parse the given [content] as a compilation unit. CompilationUnit parseCompilationUnit2( String content, { - DiagnosticListener listener = DiagnosticListener.NULL_LISTENER, + DiagnosticOrErrorListener listener = DiagnosticListener.nullListener, }) { Source source = NonExistingSource.unknown; diff --git a/pkg/analyzer/test/generated/test_support.dart b/pkg/analyzer/test/generated/test_support.dart index 1119be55e37..6bd3ca6fab0 100644 --- a/pkg/analyzer/test/generated/test_support.dart +++ b/pkg/analyzer/test/generated/test_support.dart @@ -168,7 +168,7 @@ class GatheringDiagnosticListener implements DiagnosticListener { /// Adds the given [diagnostics] to this listener. void addAll(List diagnostics) { for (Diagnostic diagnostic in diagnostics) { - onError(diagnostic); + onDiagnostic(diagnostic); } } @@ -439,7 +439,7 @@ class GatheringDiagnosticListener implements DiagnosticListener { LineInfo? getLineInfo(Source source) => _lineInfoMap[source]; @override - void onError(Diagnostic diagnostic) { + void onDiagnostic(Diagnostic diagnostic) { _diagnostics.add(diagnostic); } diff --git a/pkg/analyzer/test/src/summary/test_strategies.dart b/pkg/analyzer/test/src/summary/test_strategies.dart index f9e4e657f78..ef16571990a 100644 --- a/pkg/analyzer/test/src/summary/test_strategies.dart +++ b/pkg/analyzer/test/src/summary/test_strategies.dart @@ -16,7 +16,7 @@ import 'package:analyzer/src/generated/parser.dart'; CompilationUnit parseText(Source source, String text, FeatureSet featureSet) { CharSequenceReader reader = CharSequenceReader(text); - Scanner scanner = Scanner(source, reader, DiagnosticListener.NULL_LISTENER) + Scanner scanner = Scanner(source, reader, DiagnosticListener.nullListener) ..configureFeatures( featureSetForOverriding: featureSet, featureSet: featureSet, @@ -28,7 +28,7 @@ CompilationUnit parseText(Source source, String text, FeatureSet featureSet) { // and downgraded the feature set it holds. Parser parser = Parser( source, - DiagnosticListener.NULL_LISTENER, + DiagnosticListener.nullListener, featureSet: scanner.featureSet, languageVersion: LibraryLanguageVersion( package: ExperimentStatus.currentVersion, diff --git a/pkg/analyzer_cli/tool/perf.dart b/pkg/analyzer_cli/tool/perf.dart index e59999d6f01..46e58d6d3c5 100644 --- a/pkg/analyzer_cli/tool/perf.dart +++ b/pkg/analyzer_cli/tool/perf.dart @@ -95,7 +95,7 @@ CompilationUnit parseDirectives(Source source) { var lineInfo = LineInfo(result.lineStarts); var parser = Parser( source, - DiagnosticListener.NULL_LISTENER, + DiagnosticListener.nullListener, featureSet: FeatureSet.latestLanguageVersion(), lineInfo: lineInfo, languageVersion: languageVersion, @@ -136,7 +136,7 @@ CompilationUnit parseFull(Source source) { var lineInfo = LineInfo(result.lineStarts); var parser = Parser( source, - DiagnosticListener.NULL_LISTENER, + DiagnosticListener.nullListener, featureSet: FeatureSet.latestLanguageVersion(), languageVersion: languageVersion, lineInfo: lineInfo, @@ -238,7 +238,7 @@ ScannerResult tokenize(Source source) { Scanner( source, CharSequenceReader(contents), - DiagnosticListener.NULL_LISTENER, + DiagnosticListener.nullListener, ) ..configureFeatures( featureSetForOverriding: featureSet, diff --git a/pkg/front_end/tool/perf.dart b/pkg/front_end/tool/perf.dart index 093a835223d..b549c470541 100644 --- a/pkg/front_end/tool/perf.dart +++ b/pkg/front_end/tool/perf.dart @@ -24,13 +24,13 @@ import 'package:_fe_analyzer_shared/src/scanner/string_canonicalizer.dart'; import 'package:analyzer/dart/analysis/features.dart'; import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/element/element.dart'; -import 'package:analyzer/src/dart/analysis/experiments.dart'; import 'package:analyzer/error/listener.dart'; import 'package:analyzer/file_system/file_system.dart' show Folder; import 'package:analyzer/file_system/physical_file_system.dart'; import 'package:analyzer/source/line_info.dart'; import 'package:analyzer/source/source.dart'; import 'package:analyzer/src/context/packages.dart'; +import 'package:analyzer/src/dart/analysis/experiments.dart'; import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk; import 'package:analyzer/src/file_system/file_system.dart'; import 'package:analyzer/src/generated/parser.dart'; @@ -113,7 +113,7 @@ CompilationUnit parseDirectives(Source source) { var lineInfo = LineInfo(result.lineStarts); var parser = new Parser( source, - DiagnosticListener.NULL_LISTENER, + DiagnosticListener.nullListener, featureSet: FeatureSet.latestLanguageVersion(), languageVersion: LibraryLanguageVersion( package: ExperimentStatus.currentVersion, override: null), @@ -141,7 +141,7 @@ CompilationUnit parseFull(Source source) { parseTimer.start(); var parser = new Parser( source, - DiagnosticListener.NULL_LISTENER, + DiagnosticListener.nullListener, featureSet: FeatureSet.latestLanguageVersion(), languageVersion: LibraryLanguageVersion( package: ExperimentStatus.currentVersion, override: null), diff --git a/pkg/linter/lib/src/test_utilities/test_linter.dart b/pkg/linter/lib/src/test_utilities/test_linter.dart index 061275f4189..a4cb0bc66fb 100644 --- a/pkg/linter/lib/src/test_utilities/test_linter.dart +++ b/pkg/linter/lib/src/test_utilities/test_linter.dart @@ -77,7 +77,7 @@ class TestLinter implements DiagnosticListener { } @override - void onError(Diagnostic error) => errors.add(error); + void onDiagnostic(Diagnostic error) => errors.add(error); /// Returns whether this [entry] is a pubspec file. bool _isPubspecFile(FileSystemEntity entry) => diff --git a/pkg/scrape/lib/src/error_listener.dart b/pkg/scrape/lib/src/error_listener.dart index ec605c78f1c..33bf9667462 100644 --- a/pkg/scrape/lib/src/error_listener.dart +++ b/pkg/scrape/lib/src/error_listener.dart @@ -18,7 +18,7 @@ class SimpleDiagnosticListener implements DiagnosticListener { bool get hadDiagnostic => _hadDiagnostic; @override - void onError(Diagnostic diagnostic) { + void onDiagnostic(Diagnostic diagnostic) { _hadDiagnostic = true; if (_printDiagnostics) {