From 35e8b9ba0bf6af905759f757c0b6060b98775fca Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Wed, 30 Apr 2025 19:07:42 -0700 Subject: [PATCH] analyzer: Deprecate ErrorType in favor of new name, DiagnosticType Change-Id: I552e816de6d526e3476cac9dd3ee2919fc7ec499 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425720 Commit-Queue: Samuel Rawlins Reviewed-by: Paul Berry Reviewed-by: Kevin Moore --- .../lib/src/base/errors.dart | 45 ++++++++++--------- .../lib/src/scanner/errors.dart | 2 +- .../lib/src/lsp/lsp_analysis_server.dart | 2 +- .../add_diagnostic_property_reference.dart | 2 +- .../dart/replace_with_decorated_box.dart | 2 +- .../data_driven/transform_set_error_code.dart | 2 +- .../test/protocol_server_test.dart | 8 ++-- .../convert_for_each_to_for_loop_test.dart | 8 ++-- .../tool/bulk_fix/supported_diagnostics.dart | 3 +- pkg/analyzer/CHANGELOG.md | 7 +-- pkg/analyzer/api.txt | 40 ++++++++--------- pkg/analyzer/example/analyze.dart | 2 +- pkg/analyzer/lib/error/error.dart | 2 + .../error/option_codes.g.dart | 4 +- .../lib/src/dart/error/ffi_code.g.dart | 4 +- .../lib/src/dart/error/hint_codes.g.dart | 4 +- .../lib/src/dart/error/lint_codes.dart | 2 +- .../src/dart/error/syntactic_errors.g.dart | 2 +- .../lib/src/dart/error/todo_codes.dart | 2 +- pkg/analyzer/lib/src/error/codes.g.dart | 8 ++-- .../lib/src/ignore_comments/ignore_info.dart | 6 +-- .../src/manifest/manifest_warning_code.g.dart | 2 +- .../src/pubspec/pubspec_warning_code.g.dart | 2 +- .../test/src/diagnostics/mock_sdk_test.dart | 4 +- .../tool/benchmark/heap/flutter_elements.dart | 3 +- .../tool/messages/error_code_info.dart | 2 +- pkg/analyzer/tool/messages/generate.dart | 2 +- pkg/analyzer_cli/lib/src/error_formatter.dart | 8 ++-- pkg/analyzer_cli/lib/src/error_severity.dart | 2 +- pkg/analyzer_cli/test/mocks.dart | 2 +- pkg/analyzer_cli/test/reporter_test.dart | 16 ++++--- .../lib/utilities/analyzer_converter.dart | 2 +- .../utilities/analyzer_converter_test.dart | 2 +- pkg/linter/test/formatter_test.dart | 2 +- pkg/linter/test/mocks.dart | 6 +-- tools/verify_docs/bin/verify_docs.dart | 2 +- 36 files changed, 113 insertions(+), 101 deletions(-) diff --git a/pkg/_fe_analyzer_shared/lib/src/base/errors.dart b/pkg/_fe_analyzer_shared/lib/src/base/errors.dart index 7eb8a190008..6a93229a9c4 100644 --- a/pkg/_fe_analyzer_shared/lib/src/base/errors.dart +++ b/pkg/_fe_analyzer_shared/lib/src/base/errors.dart @@ -110,7 +110,7 @@ abstract class ErrorCode { /** * The type of the error. */ - ErrorType get type; + DiagnosticType get type; /** * Return a URL that can be used to access documentation for diagnostics with @@ -207,66 +207,67 @@ class ErrorSeverity implements Comparable { String toString() => name; } -/// The type of a [DiagnosticCode]. @AnalyzerPublicApi(message: 'exported by package:analyzer/error/error.dart') -typedef DiagnosticType = ErrorType; +@Deprecated("Use 'DiagnosticType' instead.") +typedef ErrorType = DiagnosticType; /** - * The type of an [ErrorCode]. - * - * Note that this class name, `ErrorType`, is soft-deprecated in favor of - * the type alias, [DiagnosticType]. + * The type of a [DiagnosticCode]. */ @AnalyzerPublicApi(message: 'exported by package:analyzer/error/error.dart') -class ErrorType implements Comparable { +class DiagnosticType implements Comparable { /** * Task (todo) comments in user code. */ - static const ErrorType TODO = const ErrorType('TODO', 0, ErrorSeverity.INFO); + static const DiagnosticType TODO = + const DiagnosticType('TODO', 0, ErrorSeverity.INFO); /** * Extra analysis run over the code to follow best practices, which are not in * the Dart Language Specification. */ - static const ErrorType HINT = const ErrorType('HINT', 1, ErrorSeverity.INFO); + static const DiagnosticType HINT = + const DiagnosticType('HINT', 1, ErrorSeverity.INFO); /** * Compile-time errors are errors that preclude execution. A compile time * error must be reported by a Dart compiler before the erroneous code is * executed. */ - static const ErrorType COMPILE_TIME_ERROR = - const ErrorType('COMPILE_TIME_ERROR', 2, ErrorSeverity.ERROR); + static const DiagnosticType COMPILE_TIME_ERROR = + const DiagnosticType('COMPILE_TIME_ERROR', 2, ErrorSeverity.ERROR); /** * Checked mode compile-time errors are errors that preclude execution in * checked mode. */ - static const ErrorType CHECKED_MODE_COMPILE_TIME_ERROR = const ErrorType( - 'CHECKED_MODE_COMPILE_TIME_ERROR', 3, ErrorSeverity.ERROR); + static const DiagnosticType CHECKED_MODE_COMPILE_TIME_ERROR = + const DiagnosticType( + 'CHECKED_MODE_COMPILE_TIME_ERROR', 3, ErrorSeverity.ERROR); /** * Static warnings are those warnings reported by the static checker. They * have no effect on execution. Static warnings must be provided by Dart * compilers used during development. */ - static const ErrorType STATIC_WARNING = - const ErrorType('STATIC_WARNING', 4, ErrorSeverity.WARNING); + static const DiagnosticType STATIC_WARNING = + const DiagnosticType('STATIC_WARNING', 4, ErrorSeverity.WARNING); /** * Syntactic errors are errors produced as a result of input that does not * conform to the grammar. */ - static const ErrorType SYNTACTIC_ERROR = - const ErrorType('SYNTACTIC_ERROR', 6, ErrorSeverity.ERROR); + static const DiagnosticType SYNTACTIC_ERROR = + const DiagnosticType('SYNTACTIC_ERROR', 6, ErrorSeverity.ERROR); /** * Lint warnings describe style and best practice recommendations that can be * used to formalize a project's style guidelines. */ - static const ErrorType LINT = const ErrorType('LINT', 7, ErrorSeverity.INFO); + static const DiagnosticType LINT = + const DiagnosticType('LINT', 7, ErrorSeverity.INFO); - static const List values = const [ + static const List values = const [ TODO, HINT, COMPILE_TIME_ERROR, @@ -295,7 +296,7 @@ class ErrorType implements Comparable { * Initialize a newly created error type to have the given [name] and * [severity]. */ - const ErrorType(this.name, this.ordinal, this.severity); + const DiagnosticType(this.name, this.ordinal, this.severity); String get displayName => name.toLowerCase().replaceAll('_', ' '); @@ -303,7 +304,7 @@ class ErrorType implements Comparable { int get hashCode => ordinal; @override - int compareTo(ErrorType other) => ordinal - other.ordinal; + int compareTo(DiagnosticType other) => ordinal - other.ordinal; @override String toString() => name; diff --git a/pkg/_fe_analyzer_shared/lib/src/scanner/errors.dart b/pkg/_fe_analyzer_shared/lib/src/scanner/errors.dart index 4087411c257..d19f4bf8e65 100644 --- a/pkg/_fe_analyzer_shared/lib/src/scanner/errors.dart +++ b/pkg/_fe_analyzer_shared/lib/src/scanner/errors.dart @@ -205,5 +205,5 @@ class ScannerErrorCode extends ErrorCode { ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; @override - ErrorType get type => ErrorType.SYNTACTIC_ERROR; + DiagnosticType get type => DiagnosticType.SYNTACTIC_ERROR; } diff --git a/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart b/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart index 8d52d5b3591..88cc50b1a9e 100644 --- a/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart +++ b/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart @@ -1394,7 +1394,7 @@ class LspServerContextManagerCallbacks bool _shouldSendError(protocol.AnalysisError error) { // Non-TODOs are always shown. - if (error.type.name != ErrorType.TODO.name) { + if (error.type.name != DiagnosticType.TODO.name) { return true; } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart index a4bf2de9d7a..b1863b977cc 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart @@ -331,7 +331,7 @@ class AddDiagnosticPropertyReference extends ResolvedCorrectionProducer { var endOffset = startOffset + declaration.length; for (var error in unitResult.errors) { var errorCode = error.errorCode; - if (errorCode.type == ErrorType.LINT && + if (errorCode.type == DiagnosticType.LINT && errorCode == LinterLintCode.diagnostic_describe_all_properties && error.offset > startOffset && error.offset < endOffset) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/replace_with_decorated_box.dart b/pkg/analysis_server/lib/src/services/correction/dart/replace_with_decorated_box.dart index 9b1db1aeb16..311f8542759 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/replace_with_decorated_box.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/replace_with_decorated_box.dart @@ -120,7 +120,7 @@ class ReplaceWithDecoratedBox extends ResolvedCorrectionProducer { var constructorName = expression.constructorName; return unitResult.errors.any((error) { var errorCode = error.errorCode; - return errorCode.type == ErrorType.LINT && + return errorCode.type == DiagnosticType.LINT && errorCode == LinterLintCode.use_decorated_box && error.offset == constructorName.offset && error.length == constructorName.length; diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.dart index d86d31e2d63..042382574a7 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.dart @@ -191,5 +191,5 @@ class TransformSetErrorCode extends DiagnosticCode { ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; @override - ErrorType get type => ErrorType.COMPILE_TIME_ERROR; + DiagnosticType get type => DiagnosticType.COMPILE_TIME_ERROR; } diff --git a/pkg/analysis_server/test/protocol_server_test.dart b/pkg/analysis_server/test/protocol_server_test.dart index 0b223f2af37..e62586b1131 100644 --- a/pkg/analysis_server/test/protocol_server_test.dart +++ b/pkg/analysis_server/test/protocol_server_test.dart @@ -236,8 +236,8 @@ class EnumTest { } void test_AnalysisErrorType() { - EnumTester().run( - (engine.ErrorType engineErrorType) => + EnumTester().run( + (engine.DiagnosticType engineErrorType) => AnalysisErrorType.values.byName(engineErrorType.name), ); } @@ -387,7 +387,7 @@ class MockAnalysisError implements engine.AnalysisError { class MockDiagnosticCode implements engine.DiagnosticCode { @override - engine.ErrorType type; + engine.DiagnosticType type; @override engine.ErrorSeverity errorSeverity; @@ -399,7 +399,7 @@ class MockDiagnosticCode implements engine.DiagnosticCode { String? url; MockDiagnosticCode({ - this.type = engine.ErrorType.COMPILE_TIME_ERROR, + this.type = engine.DiagnosticType.COMPILE_TIME_ERROR, this.errorSeverity = engine.ErrorSeverity.ERROR, this.name = 'TEST_ERROR', this.url, diff --git a/pkg/analysis_server/test/src/services/correction/fix/convert_for_each_to_for_loop_test.dart b/pkg/analysis_server/test/src/services/correction/fix/convert_for_each_to_for_loop_test.dart index b2b4bc8e8f6..3a965e75030 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/convert_for_each_to_for_loop_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/convert_for_each_to_for_loop_test.dart @@ -487,7 +487,7 @@ void f(List list) { } '''); await assertNoFix( - errorFilter: (error) => error.errorCode.type == ErrorType.LINT, + errorFilter: (error) => error.errorCode.type == DiagnosticType.LINT, ); } @@ -498,7 +498,7 @@ void f(List list) { } '''); await assertNoFix( - errorFilter: (error) => error.errorCode.type == ErrorType.LINT, + errorFilter: (error) => error.errorCode.type == DiagnosticType.LINT, ); } @@ -509,7 +509,7 @@ void f(List list, bool b) { } '''); await assertNoFix( - errorFilter: (error) => error.errorCode.type == ErrorType.LINT, + errorFilter: (error) => error.errorCode.type == DiagnosticType.LINT, ); } @@ -525,6 +525,6 @@ void f(List list) { {x}; } } -''', errorFilter: (error) => error.errorCode.type == ErrorType.LINT); +''', errorFilter: (error) => error.errorCode.type == DiagnosticType.LINT); } } diff --git a/pkg/analysis_server/tool/bulk_fix/supported_diagnostics.dart b/pkg/analysis_server/tool/bulk_fix/supported_diagnostics.dart index adefb620d21..4ac6b9c4bbe 100644 --- a/pkg/analysis_server/tool/bulk_fix/supported_diagnostics.dart +++ b/pkg/analysis_server/tool/bulk_fix/supported_diagnostics.dart @@ -16,7 +16,8 @@ Future main() async { var hintEntries = registeredFixGenerators.nonLintProducers.entries.where( (e) => - e.key.type == ErrorType.HINT || e.key.type == ErrorType.STATIC_WARNING, + e.key.type == DiagnosticType.HINT || + e.key.type == DiagnosticType.STATIC_WARNING, ); var diagnostics = [ diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md index 06cb19a601d..e3461edeb7b 100644 --- a/pkg/analyzer/CHANGELOG.md +++ b/pkg/analyzer/CHANGELOG.md @@ -3,11 +3,12 @@ * Remove deprecated `DartType.isStructurallyEqualTo`. * Remove deprecated `RecordType.positionalTypes`. * Remove deprecated `RecordType.sortedNamedTypes`. -* Remove `ElementLocation` class, its values are not returned anymore. -* Deprecated `element2.dart` library, import `element.dart`. -* Deprecated `XyzElement2` classes, use `XyzElement` instead. +* Remove `ElementLocation` class; its values are not returned anymore. +* Deprecate `element2.dart` library; import `element.dart`. +* Deprecate `XyzElement2` classes; use `XyzElement` instead. * Deprecate `AnalysisError.correction` field; use `AnalysisError.correctionMessage` instead. +* Deprecate `ErrorType`; use `DiagnosticType` instead. ## 7.4.1 * Restore `InstanceElement.augmented` getter. diff --git a/pkg/analyzer/api.txt b/pkg/analyzer/api.txt index 496e998c9bb..57b3ba48d67 100644 --- a/pkg/analyzer/api.txt +++ b/pkg/analyzer/api.txt @@ -4364,6 +4364,23 @@ package:analyzer/error/error.dart: source (getter: Source) == (method: bool Function(Object)) toString (method: String Function()) + DiagnosticType (class extends Object implements Comparable): + CHECKED_MODE_COMPILE_TIME_ERROR (static getter: DiagnosticType) + COMPILE_TIME_ERROR (static getter: DiagnosticType) + HINT (static getter: DiagnosticType) + LINT (static getter: DiagnosticType) + STATIC_WARNING (static getter: DiagnosticType) + SYNTACTIC_ERROR (static getter: DiagnosticType) + TODO (static getter: DiagnosticType) + values (static getter: List) + new (constructor: DiagnosticType Function(String, int, ErrorSeverity)) + displayName (getter: String) + hashCode (getter: int) + name (getter: String) + ordinal (getter: int) + severity (getter: ErrorSeverity) + compareTo (method: int Function(DiagnosticType)) + toString (method: String Function()) ErrorCode (class extends Object): new (constructor: ErrorCode Function({String? correctionMessage, bool hasPublishedDocs, bool isUnresolvedIdentifier, required String name, required String problemMessage, required String uniqueName})) correctionMessage (getter: String?) @@ -4374,7 +4391,7 @@ package:analyzer/error/error.dart: name (getter: String) numParameters (getter: int) problemMessage (getter: String) - type (getter: ErrorType) + type (getter: DiagnosticType) uniqueName (getter: String) url (getter: String?) toString (method: String Function()) @@ -4393,33 +4410,16 @@ package:analyzer/error/error.dart: compareTo (method: int Function(ErrorSeverity)) max (method: ErrorSeverity Function(ErrorSeverity)) toString (method: String Function()) - ErrorType (class extends Object implements Comparable): - CHECKED_MODE_COMPILE_TIME_ERROR (static getter: ErrorType) - COMPILE_TIME_ERROR (static getter: ErrorType) - HINT (static getter: ErrorType) - LINT (static getter: ErrorType) - STATIC_WARNING (static getter: ErrorType) - SYNTACTIC_ERROR (static getter: ErrorType) - TODO (static getter: ErrorType) - values (static getter: List) - new (constructor: ErrorType Function(String, int, ErrorSeverity)) - displayName (getter: String) - hashCode (getter: int) - name (getter: String) - ordinal (getter: int) - severity (getter: ErrorSeverity) - compareTo (method: int Function(ErrorType)) - toString (method: String Function()) LintCode (class extends ErrorCode): new (constructor: LintCode Function(String, String, {String? correctionMessage, bool hasPublishedDocs, String? uniqueName})) errorSeverity (getter: ErrorSeverity) hashCode (getter: int) - type (getter: ErrorType) + type (getter: DiagnosticType) url (getter: String?) == (method: bool Function(Object)) DiagnosticCode (type alias for ErrorCode) DiagnosticSeverity (type alias for ErrorSeverity) - DiagnosticType (type alias for ErrorType) + ErrorType (type alias for DiagnosticType, deprecated) package:analyzer/error/listener.dart: AnalysisErrorListener (class extends Object): NULL_LISTENER (static getter: AnalysisErrorListener) diff --git a/pkg/analyzer/example/analyze.dart b/pkg/analyzer/example/analyze.dart index 57652eeb36f..76d3128377b 100644 --- a/pkg/analyzer/example/analyze.dart +++ b/pkg/analyzer/example/analyze.dart @@ -36,7 +36,7 @@ void main(List args) async { var errorsResult = await context.currentSession.getErrors(filePath); if (errorsResult is ErrorsResult) { for (var error in errorsResult.errors) { - if (error.errorCode.type != ErrorType.TODO) { + if (error.errorCode.type != DiagnosticType.TODO) { print( ' \u001b[1m${error.source.shortName}\u001b[0m ${error.message}', ); diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart index 31cdadccb80..00fd0656fd3 100644 --- a/pkg/analyzer/lib/error/error.dart +++ b/pkg/analyzer/lib/error/error.dart @@ -18,6 +18,8 @@ export 'package:_fe_analyzer_shared/src/base/errors.dart' DiagnosticType, ErrorCode, ErrorSeverity, + // Continue exporting the deleted element until it is removed. + // ignore: deprecated_member_use ErrorType; export 'package:analyzer/src/dart/error/lint_codes.dart' show LintCode; export 'package:analyzer/src/error/error_code_values.g.dart'; diff --git a/pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart b/pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart index ca31e064f28..d1c716c51d2 100644 --- a/pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart +++ b/pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart @@ -62,7 +62,7 @@ class AnalysisOptionsErrorCode extends ErrorCode { ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; @override - ErrorType get type => ErrorType.COMPILE_TIME_ERROR; + DiagnosticType get type => DiagnosticType.COMPILE_TIME_ERROR; } class AnalysisOptionsWarningCode extends ErrorCode { @@ -326,5 +326,5 @@ class AnalysisOptionsWarningCode extends ErrorCode { ErrorSeverity get errorSeverity => ErrorSeverity.WARNING; @override - ErrorType get type => ErrorType.STATIC_WARNING; + DiagnosticType get type => DiagnosticType.STATIC_WARNING; } diff --git a/pkg/analyzer/lib/src/dart/error/ffi_code.g.dart b/pkg/analyzer/lib/src/dart/error/ffi_code.g.dart index caf1648e986..d3b4506bc15 100644 --- a/pkg/analyzer/lib/src/dart/error/ffi_code.g.dart +++ b/pkg/analyzer/lib/src/dart/error/ffi_code.g.dart @@ -536,8 +536,8 @@ class FfiCode extends ErrorCode { ); @override - ErrorSeverity get errorSeverity => ErrorType.COMPILE_TIME_ERROR.severity; + ErrorSeverity get errorSeverity => DiagnosticType.COMPILE_TIME_ERROR.severity; @override - ErrorType get type => ErrorType.COMPILE_TIME_ERROR; + DiagnosticType get type => DiagnosticType.COMPILE_TIME_ERROR; } diff --git a/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart b/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart index 49521faaf62..bf11de2bb1e 100644 --- a/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart +++ b/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart @@ -121,8 +121,8 @@ class HintCode extends ErrorCode { ); @override - ErrorSeverity get errorSeverity => ErrorType.HINT.severity; + ErrorSeverity get errorSeverity => DiagnosticType.HINT.severity; @override - ErrorType get type => ErrorType.HINT; + DiagnosticType get type => DiagnosticType.HINT; } diff --git a/pkg/analyzer/lib/src/dart/error/lint_codes.dart b/pkg/analyzer/lib/src/dart/error/lint_codes.dart index 9e8a6d91c46..5151444cc44 100644 --- a/pkg/analyzer/lib/src/dart/error/lint_codes.dart +++ b/pkg/analyzer/lib/src/dart/error/lint_codes.dart @@ -35,7 +35,7 @@ class LintCode extends ErrorCode { int get hashCode => uniqueName.hashCode; @override - ErrorType get type => ErrorType.LINT; + DiagnosticType get type => DiagnosticType.LINT; @override String? get url => null; diff --git a/pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart b/pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart index ace48c2b63f..0c12a098ca6 100644 --- a/pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart +++ b/pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart @@ -2075,5 +2075,5 @@ class ParserErrorCode extends ErrorCode { ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; @override - ErrorType get type => ErrorType.SYNTACTIC_ERROR; + DiagnosticType get type => DiagnosticType.SYNTACTIC_ERROR; } diff --git a/pkg/analyzer/lib/src/dart/error/todo_codes.dart b/pkg/analyzer/lib/src/dart/error/todo_codes.dart index 37b235a451b..96cecc6ef50 100644 --- a/pkg/analyzer/lib/src/dart/error/todo_codes.dart +++ b/pkg/analyzer/lib/src/dart/error/todo_codes.dart @@ -89,5 +89,5 @@ class TodoCode extends ErrorCode { ErrorSeverity get errorSeverity => ErrorSeverity.INFO; @override - ErrorType get type => ErrorType.TODO; + DiagnosticType get type => DiagnosticType.TODO; } diff --git a/pkg/analyzer/lib/src/error/codes.g.dart b/pkg/analyzer/lib/src/error/codes.g.dart index 785fe3753df..4cafe5b9edb 100644 --- a/pkg/analyzer/lib/src/error/codes.g.dart +++ b/pkg/analyzer/lib/src/error/codes.g.dart @@ -6060,10 +6060,10 @@ class CompileTimeErrorCode extends ErrorCode { ); @override - ErrorSeverity get errorSeverity => ErrorType.COMPILE_TIME_ERROR.severity; + ErrorSeverity get errorSeverity => DiagnosticType.COMPILE_TIME_ERROR.severity; @override - ErrorType get type => ErrorType.COMPILE_TIME_ERROR; + DiagnosticType get type => DiagnosticType.COMPILE_TIME_ERROR; } class StaticWarningCode extends ErrorCode { @@ -6192,7 +6192,7 @@ class StaticWarningCode extends ErrorCode { ErrorSeverity get errorSeverity => ErrorSeverity.WARNING; @override - ErrorType get type => ErrorType.STATIC_WARNING; + DiagnosticType get type => DiagnosticType.STATIC_WARNING; } class WarningCode extends ErrorCode { @@ -7782,5 +7782,5 @@ class WarningCode extends ErrorCode { ErrorSeverity get errorSeverity => ErrorSeverity.WARNING; @override - ErrorType get type => ErrorType.STATIC_WARNING; + DiagnosticType get type => DiagnosticType.STATIC_WARNING; } diff --git a/pkg/analyzer/lib/src/ignore_comments/ignore_info.dart b/pkg/analyzer/lib/src/ignore_comments/ignore_info.dart index 4a696499d60..9f37cda36c1 100644 --- a/pkg/analyzer/lib/src/ignore_comments/ignore_info.dart +++ b/pkg/analyzer/lib/src/ignore_comments/ignore_info.dart @@ -65,9 +65,9 @@ class IgnoredDiagnosticType implements IgnoredElement { bool _matches(ErrorCode errorCode, {String? pluginName}) { // Ignore 'pluginName'; it is irrelevant in an IgnoredDiagnosticType. return switch (errorCode.type) { - ErrorType.HINT => type == 'hint', - ErrorType.LINT => type == 'lint', - ErrorType.STATIC_WARNING => type == 'warning', + DiagnosticType.HINT => type == 'hint', + DiagnosticType.LINT => type == 'lint', + DiagnosticType.STATIC_WARNING => type == 'warning', // Only errors with one of the above types can be ignored via the type. _ => false, }; diff --git a/pkg/analyzer/lib/src/manifest/manifest_warning_code.g.dart b/pkg/analyzer/lib/src/manifest/manifest_warning_code.g.dart index 400c5d1ded5..69347d00c7c 100644 --- a/pkg/analyzer/lib/src/manifest/manifest_warning_code.g.dart +++ b/pkg/analyzer/lib/src/manifest/manifest_warning_code.g.dart @@ -130,5 +130,5 @@ class ManifestWarningCode extends ErrorCode { ErrorSeverity get errorSeverity => ErrorSeverity.WARNING; @override - ErrorType get type => ErrorType.STATIC_WARNING; + DiagnosticType get type => DiagnosticType.STATIC_WARNING; } diff --git a/pkg/analyzer/lib/src/pubspec/pubspec_warning_code.g.dart b/pkg/analyzer/lib/src/pubspec/pubspec_warning_code.g.dart index 9aa813cc629..9b00738eb22 100644 --- a/pkg/analyzer/lib/src/pubspec/pubspec_warning_code.g.dart +++ b/pkg/analyzer/lib/src/pubspec/pubspec_warning_code.g.dart @@ -265,5 +265,5 @@ class PubspecWarningCode extends ErrorCode { ErrorSeverity get errorSeverity => ErrorSeverity.WARNING; @override - ErrorType get type => ErrorType.STATIC_WARNING; + DiagnosticType get type => DiagnosticType.STATIC_WARNING; } diff --git a/pkg/analyzer/test/src/diagnostics/mock_sdk_test.dart b/pkg/analyzer/test/src/diagnostics/mock_sdk_test.dart index e02643b2a3b..111605756cd 100644 --- a/pkg/analyzer/test/src/diagnostics/mock_sdk_test.dart +++ b/pkg/analyzer/test/src/diagnostics/mock_sdk_test.dart @@ -48,8 +48,8 @@ class MockSdkTest extends PubPackageResolutionTest { resolvedUnit.errors .where( (element) => - element.errorCode.type != ErrorType.HINT && - element.errorCode.type != ErrorType.STATIC_WARNING, + element.errorCode.type != DiagnosticType.HINT && + element.errorCode.type != DiagnosticType.STATIC_WARNING, ) .toList(); assertErrorsInList(notHints, []); diff --git a/pkg/analyzer/tool/benchmark/heap/flutter_elements.dart b/pkg/analyzer/tool/benchmark/heap/flutter_elements.dart index 2cd8f7fda4d..ef4b057719c 100644 --- a/pkg/analyzer/tool/benchmark/heap/flutter_elements.dart +++ b/pkg/analyzer/tool/benchmark/heap/flutter_elements.dart @@ -104,7 +104,8 @@ Future _analyzeFiles(AnalysisContextCollectionImpl collection) async { errorsResult.errors .where( (element) => - element.errorCode.type == ErrorType.COMPILE_TIME_ERROR, + element.errorCode.type == + DiagnosticType.COMPILE_TIME_ERROR, ) .toList(); if (errors.isNotEmpty) { diff --git a/pkg/analyzer/tool/messages/error_code_info.dart b/pkg/analyzer/tool/messages/error_code_info.dart index b2f42b8add1..2b177f85f80 100644 --- a/pkg/analyzer/tool/messages/error_code_info.dart +++ b/pkg/analyzer/tool/messages/error_code_info.dart @@ -447,7 +447,7 @@ class ErrorClassInfo { } /// Generates the code to compute the type of errors of this class. - String get typeCode => 'ErrorType.$type'; + String get typeCode => 'DiagnosticType.$type'; } /// In-memory representation of error code information obtained from either the diff --git a/pkg/analyzer/tool/messages/generate.dart b/pkg/analyzer/tool/messages/generate.dart index d755bb7a4cc..499f846b5a3 100644 --- a/pkg/analyzer/tool/messages/generate.dart +++ b/pkg/analyzer/tool/messages/generate.dart @@ -173,7 +173,7 @@ library; ); out.writeln(); out.writeln('@override'); - out.writeln('ErrorType get type => ${errorClass.typeCode};'); + out.writeln('DiagnosticType get type => ${errorClass.typeCode};'); out.writeln('}'); } } diff --git a/pkg/analyzer_cli/lib/src/error_formatter.dart b/pkg/analyzer_cli/lib/src/error_formatter.dart index 83b70def7fb..9d59c06721b 100644 --- a/pkg/analyzer_cli/lib/src/error_formatter.dart +++ b/pkg/analyzer_cli/lib/src/error_formatter.dart @@ -300,8 +300,8 @@ class HumanErrorFormatter extends ErrorFormatter { // Get display name; translate INFOs into LINTS and HINTS. var errorType = severity.displayName; if (severity == ErrorSeverity.INFO) { - if (error.errorCode.type == ErrorType.HINT || - error.errorCode.type == ErrorType.LINT) { + if (error.errorCode.type == DiagnosticType.HINT || + error.errorCode.type == DiagnosticType.LINT) { errorType = error.errorCode.type.displayName; } } @@ -492,9 +492,9 @@ class MachineErrorFormatter extends ErrorFormatter { stats.errorCount++; } else if (severity == ErrorSeverity.WARNING) { stats.warnCount++; - } else if (error.errorCode.type == ErrorType.HINT) { + } else if (error.errorCode.type == DiagnosticType.HINT) { stats.hintCount++; - } else if (error.errorCode.type == ErrorType.LINT) { + } else if (error.errorCode.type == DiagnosticType.LINT) { stats.lintCount++; } diff --git a/pkg/analyzer_cli/lib/src/error_severity.dart b/pkg/analyzer_cli/lib/src/error_severity.dart index eb210828440..ddea50bf06c 100644 --- a/pkg/analyzer_cli/lib/src/error_severity.dart +++ b/pkg/analyzer_cli/lib/src/error_severity.dart @@ -34,7 +34,7 @@ ErrorSeverity? determineProcessedSeverity( ) { var severity = computeSeverity(error, commandLineOptions, analysisOptions); // Skip TODOs categorically unless escalated to ERROR or HINT (#26215). - if (error.errorCode.type == ErrorType.TODO && + if (error.errorCode.type == DiagnosticType.TODO && severity == ErrorSeverity.INFO) { return null; } diff --git a/pkg/analyzer_cli/test/mocks.dart b/pkg/analyzer_cli/test/mocks.dart index ff7853bf00d..de9e3be5891 100644 --- a/pkg/analyzer_cli/test/mocks.dart +++ b/pkg/analyzer_cli/test/mocks.dart @@ -69,7 +69,7 @@ class MockCommandLineOptions implements CommandLineOptions { class MockErrorCode implements ErrorCode { @override - ErrorType type; + DiagnosticType type; @override ErrorSeverity errorSeverity; diff --git a/pkg/analyzer_cli/test/reporter_test.dart b/pkg/analyzer_cli/test/reporter_test.dart index 6768075f6ac..be075df2987 100644 --- a/pkg/analyzer_cli/test/reporter_test.dart +++ b/pkg/analyzer_cli/test/reporter_test.dart @@ -45,7 +45,10 @@ void main() { }); test('error', () async { - var error = mockResult(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR); + var error = mockResult( + DiagnosticType.SYNTACTIC_ERROR, + ErrorSeverity.ERROR, + ); await reporter.formatErrors([error]); reporter.flush(); @@ -56,7 +59,7 @@ void main() { }); test('hint', () async { - var error = mockResult(ErrorType.HINT, ErrorSeverity.INFO); + var error = mockResult(DiagnosticType.HINT, ErrorSeverity.INFO); await reporter.formatErrors([error]); reporter.flush(); @@ -67,7 +70,7 @@ void main() { }); test('stats', () async { - var error = mockResult(ErrorType.HINT, ErrorSeverity.INFO); + var error = mockResult(DiagnosticType.HINT, ErrorSeverity.INFO); await reporter.formatErrors([error]); reporter.flush(); stats.print(out); @@ -85,7 +88,10 @@ void main() { }); test('error', () async { - var error = mockResult(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR); + var error = mockResult( + DiagnosticType.SYNTACTIC_ERROR, + ErrorSeverity.ERROR, + ); await reporter.formatErrors([error]); reporter.flush(); @@ -103,7 +109,7 @@ void main() { }); } -ErrorsResultImpl mockResult(ErrorType type, ErrorSeverity severity) { +ErrorsResultImpl mockResult(DiagnosticType type, ErrorSeverity severity) { // ErrorInfo var location = CharacterLocation(3, 3); var lineInfo = MockLineInfo(defaultLocation: location); diff --git a/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart b/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart index feba7dc5e98..858d0e42f7c 100644 --- a/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart +++ b/pkg/analyzer_plugin/lib/utilities/analyzer_converter.dart @@ -181,7 +181,7 @@ class AnalyzerConverter { /// Convert the error [type] from the 'analyzer' package to an analysis error /// type defined by the plugin API. - plugin.AnalysisErrorType convertErrorType(analyzer.ErrorType type) => + plugin.AnalysisErrorType convertErrorType(analyzer.DiagnosticType type) => plugin.AnalysisErrorType.values.byName(type.name); String getElementDisplayName(analyzer.Element element) { diff --git a/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart b/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart index eda8aec32f0..13113972f33 100644 --- a/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart +++ b/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart @@ -629,7 +629,7 @@ typedef A = Map; } void test_convertErrorType() { - for (var type in analyzer.ErrorType.values) { + for (var type in analyzer.DiagnosticType.values) { expect(converter.convertErrorType(type), isNotNull, reason: type.name); } } diff --git a/pkg/linter/test/formatter_test.dart b/pkg/linter/test/formatter_test.dart index 0569f3aa31d..c7b1b28111c 100644 --- a/pkg/linter/test/formatter_test.dart +++ b/pkg/linter/test/formatter_test.dart @@ -32,7 +32,7 @@ void defineTests() { setUp(() async { var lineInfo = LineInfo([3, 6, 9]); - var type = MockErrorType()..displayName = 'test'; + var type = MockDiagnosticType()..displayName = 'test'; var code = TestErrorCode('mock_code', 'MSG')..type = type; diff --git a/pkg/linter/test/mocks.dart b/pkg/linter/test/mocks.dart index 66e8048b9c2..0fcbc34ab5d 100644 --- a/pkg/linter/test/mocks.dart +++ b/pkg/linter/test/mocks.dart @@ -9,7 +9,7 @@ import 'package:analyzer/error/error.dart'; import 'package:analyzer/src/generated/engine.dart'; import 'package:analyzer/src/generated/source.dart'; -class MockErrorType implements ErrorType { +class MockDiagnosticType implements DiagnosticType { @override late String displayName; @@ -23,7 +23,7 @@ class MockErrorType implements ErrorType { late ErrorSeverity severity; @override - int compareTo(ErrorType other) => 0; + int compareTo(DiagnosticType other) => 0; @override String toString() => 'MockErrorType'; @@ -85,7 +85,7 @@ class TestErrorCode extends ErrorCode { late ErrorSeverity errorSeverity; @override - late ErrorType type; + late DiagnosticType type; TestErrorCode(String name, String message) : super( diff --git a/tools/verify_docs/bin/verify_docs.dart b/tools/verify_docs/bin/verify_docs.dart index 28d57c7ce0e..34bed81e6dd 100755 --- a/tools/verify_docs/bin/verify_docs.dart +++ b/tools/verify_docs/bin/verify_docs.dart @@ -115,7 +115,7 @@ Future verifyFile( // Throw if there are syntactic errors. var syntacticErrors = parseResult.errors.where((error) { - return error.errorCode.type == ErrorType.SYNTACTIC_ERROR; + return error.errorCode.type == DiagnosticType.SYNTACTIC_ERROR; }).toList(); if (syntacticErrors.isNotEmpty) { throw Exception(syntacticErrors);