Skip to content

Commit 49562fd

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Deprecate ErrorCode in favor of replacement: DiagnosticCode
Work towards #60635 Change-Id: I0cfc0bff4e5d10b7cb373f77de55fffc13b8cf76 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426641 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent ad7b242 commit 49562fd

32 files changed

+167
-162
lines changed

pkg/_fe_analyzer_shared/lib/src/base/errors.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import 'customized_codes.dart';
1313
/// Generally, messages should follow the [Guide for Writing
1414
/// Diagnostics](https://github.com/dart-lang/sdk/blob/main/pkg/front_end/lib/src/base/diagnostics.md).
1515
@AnalyzerPublicApi(message: 'exported by package:analyzer/error/error.dart')
16-
typedef DiagnosticCode = ErrorCode;
16+
@Deprecated("Use 'DiagnosticCode' instead.")
17+
typedef ErrorCode = DiagnosticCode;
1718

1819
/// An error code associated with an `AnalysisError`.
1920
///
@@ -23,7 +24,7 @@ typedef DiagnosticCode = ErrorCode;
2324
/// Note that this class name, `ErrorCode`, is soft-deprecated in favor of the
2425
/// type alias, `DiagnosticCode`.
2526
@AnalyzerPublicApi(message: 'exported by package:analyzer/error/error.dart')
26-
abstract class ErrorCode {
27+
abstract class DiagnosticCode {
2728
/// Regular expression for identifying positional arguments in error messages.
2829
static final RegExp _positionalArgumentRegExp = new RegExp(r'{(\d+)\}');
2930

@@ -58,7 +59,7 @@ abstract class ErrorCode {
5859
* template. The correction associated with the error will be created from the
5960
* given [correctionMessage] template.
6061
*/
61-
const ErrorCode({
62+
const DiagnosticCode({
6263
String? correctionMessage,
6364
this.hasPublishedDocs = false,
6465
this.isUnresolvedIdentifier = false,
@@ -133,7 +134,7 @@ abstract class ErrorCode {
133134
typedef ErrorSeverity = DiagnosticSeverity;
134135

135136
/**
136-
* The severity of an [ErrorCode].
137+
* The severity of an [DiagnosticCode].
137138
*
138139
* Note that this class name, `ErrorSeverity`, is soft-deprecated in favor of
139140
* the type alias, [DiagnosticSeverity].

pkg/_fe_analyzer_shared/lib/src/scanner/errors.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ typedef ReportError(
121121
/**
122122
* The error codes used for errors detected by the scanner.
123123
*/
124-
class ScannerErrorCode extends ErrorCode {
124+
class ScannerErrorCode extends DiagnosticCode {
125125
/**
126126
* Parameters:
127127
* 0: the token that was expected but not found

pkg/analyzer/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
* Deprecate `XyzElement2` classes; use `XyzElement` instead.
99
* Deprecate `AnalysisError.correction` field; use
1010
`AnalysisError.correctionMessage` instead.
11-
* Deprecate `ErrorType`; use `DiagnosticType` instead.
11+
* Deprecate `ErrorCode`; use `DiagnosticCode` instead.
1212
* Deprecate `ErrorSeverity`; use `DiagnosticSeverity` instead.
13+
* Deprecate `ErrorType`; use `DiagnosticType` instead.
1314
* Change `ElementDirective` from `sealed` to `abstract`.
1415
This allows the analyzer to have an internal implementation
1516
class corresponding to `ElementDirective`.

pkg/analyzer/api.txt

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4330,13 +4330,13 @@ package:analyzer/dart/sdk/build_sdk_summary.dart:
43304330
buildSdkSummary (function: Future<Uint8List> Function({String? embedderYamlPath, required ResourceProvider resourceProvider, required String sdkPath}))
43314331
package:analyzer/diagnostic/diagnostic.dart:
43324332
Diagnostic (class extends Object):
4333-
forValues (constructor: Diagnostic Function({List<DiagnosticMessage> contextMessages, String? correctionMessage, Object? data, required ErrorCode errorCode, required int length, required String message, required int offset, required Source source}))
4334-
tmp (constructor: Diagnostic Function({List<Object?> arguments, List<DiagnosticMessage> contextMessages, Object? data, required ErrorCode errorCode, required int length, required int offset, required Source source}))
4333+
forValues (constructor: Diagnostic Function({List<DiagnosticMessage> contextMessages, String? correctionMessage, Object? data, required DiagnosticCode errorCode, required int length, required String message, required int offset, required Source source}))
4334+
tmp (constructor: Diagnostic Function({List<Object?> arguments, List<DiagnosticMessage> contextMessages, Object? data, required DiagnosticCode errorCode, required int length, required int offset, required Source source}))
43354335
contextMessages (getter: List<DiagnosticMessage>)
43364336
correction (getter: String?, deprecated)
43374337
correctionMessage (getter: String?)
43384338
data (getter: Object?)
4339-
errorCode (getter: ErrorCode)
4339+
errorCode (getter: DiagnosticCode)
43404340
hashCode (getter: int)
43414341
length (getter: int)
43424342
message (getter: String)
@@ -4359,8 +4359,22 @@ package:analyzer/diagnostic/diagnostic.dart:
43594359
values (static getter: List<Severity>)
43604360
warning (static getter: Severity)
43614361
package:analyzer/error/error.dart:
4362-
errorCodeValues (static getter: List<ErrorCode>)
4363-
errorCodeByUniqueName (function: ErrorCode? Function(String))
4362+
errorCodeValues (static getter: List<DiagnosticCode>)
4363+
errorCodeByUniqueName (function: DiagnosticCode? Function(String))
4364+
DiagnosticCode (class extends Object):
4365+
new (constructor: DiagnosticCode Function({String? correctionMessage, bool hasPublishedDocs, bool isUnresolvedIdentifier, required String name, required String problemMessage, required String uniqueName}))
4366+
correctionMessage (getter: String?)
4367+
errorSeverity (getter: DiagnosticSeverity)
4368+
hasPublishedDocs (getter: bool)
4369+
isIgnorable (getter: bool)
4370+
isUnresolvedIdentifier (getter: bool)
4371+
name (getter: String)
4372+
numParameters (getter: int)
4373+
problemMessage (getter: String)
4374+
type (getter: DiagnosticType)
4375+
uniqueName (getter: String)
4376+
url (getter: String?)
4377+
toString (method: String Function())
43644378
DiagnosticSeverity (class extends Object implements Comparable<DiagnosticSeverity>):
43654379
ERROR (static getter: DiagnosticSeverity)
43664380
INFO (static getter: DiagnosticSeverity)
@@ -4393,29 +4407,15 @@ package:analyzer/error/error.dart:
43934407
severity (getter: DiagnosticSeverity)
43944408
compareTo (method: int Function(DiagnosticType))
43954409
toString (method: String Function())
4396-
ErrorCode (class extends Object):
4397-
new (constructor: ErrorCode Function({String? correctionMessage, bool hasPublishedDocs, bool isUnresolvedIdentifier, required String name, required String problemMessage, required String uniqueName}))
4398-
correctionMessage (getter: String?)
4399-
errorSeverity (getter: DiagnosticSeverity)
4400-
hasPublishedDocs (getter: bool)
4401-
isIgnorable (getter: bool)
4402-
isUnresolvedIdentifier (getter: bool)
4403-
name (getter: String)
4404-
numParameters (getter: int)
4405-
problemMessage (getter: String)
4406-
type (getter: DiagnosticType)
4407-
uniqueName (getter: String)
4408-
url (getter: String?)
4409-
toString (method: String Function())
4410-
LintCode (class extends ErrorCode):
4410+
LintCode (class extends DiagnosticCode):
44114411
new (constructor: LintCode Function(String, String, {String? correctionMessage, bool hasPublishedDocs, String? uniqueName}))
44124412
errorSeverity (getter: DiagnosticSeverity)
44134413
hashCode (getter: int)
44144414
type (getter: DiagnosticType)
44154415
url (getter: String?)
44164416
== (method: bool Function(Object))
44174417
AnalysisError (type alias for Diagnostic)
4418-
DiagnosticCode (type alias for ErrorCode)
4418+
ErrorCode (type alias for DiagnosticCode, deprecated)
44194419
ErrorSeverity (type alias for DiagnosticSeverity, deprecated)
44204420
ErrorType (type alias for DiagnosticType, deprecated)
44214421
package:analyzer/error/listener.dart:
@@ -4432,13 +4432,13 @@ package:analyzer/error/listener.dart:
44324432
lockLevel (getter: int)
44334433
lockLevel= (setter: int)
44344434
source (getter: Source)
4435-
atConstructorDeclaration (method: void Function(ConstructorDeclaration, ErrorCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
4436-
atElement2 (method: void Function(Element, ErrorCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}), experimental)
4437-
atEntity (method: void Function(SyntacticEntity, ErrorCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
4438-
atNode (method: void Function(AstNode, ErrorCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
4439-
atOffset (method: void Function({List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data, required ErrorCode errorCode, required int length, required int offset}))
4440-
atSourceSpan (method: void Function(SourceSpan, ErrorCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
4441-
atToken (method: void Function(Token, ErrorCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
4435+
atConstructorDeclaration (method: void Function(ConstructorDeclaration, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
4436+
atElement2 (method: void Function(Element, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}), experimental)
4437+
atEntity (method: void Function(SyntacticEntity, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
4438+
atNode (method: void Function(AstNode, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
4439+
atOffset (method: void Function({List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data, required DiagnosticCode errorCode, required int length, required int offset}))
4440+
atSourceSpan (method: void Function(SourceSpan, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
4441+
atToken (method: void Function(Token, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
44424442
reportError (method: void Function(Diagnostic))
44434443
RecordingErrorListener (class extends Object implements AnalysisErrorListener):
44444444
new (constructor: RecordingErrorListener Function())

pkg/analyzer/lib/diagnostic/diagnostic.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class Diagnostic {
6565
required Source source,
6666
required int offset,
6767
required int length,
68-
required ErrorCode errorCode,
68+
// TODO(srawlins): Rename to `diagnosticCode`.
69+
required DiagnosticCode errorCode,
6970
List<Object?> arguments = const [],
7071
List<DiagnosticMessage> contextMessages = const [],
7172
Object? data,

pkg/analyzer/lib/error/error.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ export 'package:_fe_analyzer_shared/src/base/errors.dart'
1616
DiagnosticCode,
1717
DiagnosticSeverity,
1818
DiagnosticType,
19+
// Continue exporting the deprecated element until it is removed.
20+
// ignore: deprecated_member_use
1921
ErrorCode,
20-
// Continue exporting the deleted element until it is removed.
22+
// Continue exporting the deprecated element until it is removed.
2123
// ignore: deprecated_member_use
2224
ErrorSeverity,
23-
// Continue exporting the deleted element until it is removed.
25+
// Continue exporting the deprecated element until it is removed.
2426
// ignore: deprecated_member_use
2527
ErrorType;
2628
export 'package:analyzer/src/dart/error/lint_codes.dart' show LintCode;
2729
export 'package:analyzer/src/error/error_code_values.g.dart';
2830

29-
/// The lazy initialized map from [ErrorCode.uniqueName] to the
31+
/// The lazy initialized map from [DiagnosticCode.uniqueName] to the
3032
/// [DiagnosticCode] instance.
3133
final HashMap<String, DiagnosticCode> _uniqueNameToCodeMap =
3234
_computeUniqueNameToCodeMap();
@@ -37,8 +39,8 @@ DiagnosticCode? errorCodeByUniqueName(String uniqueName) {
3739
return _uniqueNameToCodeMap[uniqueName];
3840
}
3941

40-
/// Return the map from [ErrorCode.uniqueName] to the [DiagnosticCode] instance
41-
/// for all [errorCodeValues].
42+
/// Return the map from [DiagnosticCode.uniqueName] to the [DiagnosticCode]
43+
/// instance for all [errorCodeValues].
4244
HashMap<String, DiagnosticCode> _computeUniqueNameToCodeMap() {
4345
var result = HashMap<String, DiagnosticCode>();
4446
for (DiagnosticCode diagnosticCode in errorCodeValues) {

pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ library;
2020

2121
import "package:analyzer/error/error.dart";
2222

23-
class AnalysisOptionsErrorCode extends ErrorCode {
23+
class AnalysisOptionsErrorCode extends DiagnosticCode {
2424
/// An error code indicating that there is a syntactic error in the included
2525
/// file.
2626
///
@@ -65,7 +65,7 @@ class AnalysisOptionsErrorCode extends ErrorCode {
6565
DiagnosticType get type => DiagnosticType.COMPILE_TIME_ERROR;
6666
}
6767

68-
class AnalysisOptionsWarningCode extends ErrorCode {
68+
class AnalysisOptionsWarningCode extends DiagnosticCode {
6969
/// An error code indicating that the given option is deprecated.
7070
///
7171
/// Parameters:

pkg/analyzer/lib/src/dart/error/ffi_code.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ library;
2020

2121
import "package:analyzer/error/error.dart";
2222

23-
class FfiCode extends ErrorCode {
23+
class FfiCode extends DiagnosticCode {
2424
/// No parameters.
2525
static const FfiCode ABI_SPECIFIC_INTEGER_INVALID = FfiCode(
2626
'ABI_SPECIFIC_INTEGER_INVALID',

pkg/analyzer/lib/src/dart/error/hint_codes.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ library;
2020

2121
import "package:analyzer/error/error.dart";
2222

23-
class HintCode extends ErrorCode {
23+
class HintCode extends DiagnosticCode {
2424
/// No parameters.
2525
///
2626
/// Note: Since this diagnostic is only produced in pre-3.0 code, we do not

pkg/analyzer/lib/src/dart/error/lint_codes.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'package:analyzer/error/error.dart';
1515
/// unintended code, maintainability, style and other best practices that might
1616
/// be aggregated to define a project's style guide.
1717
@AnalyzerPublicApi(message: 'exported by lib/error/error.dart')
18-
class LintCode extends ErrorCode {
18+
class LintCode extends DiagnosticCode {
1919
const LintCode(
2020
String name,
2121
String problemMessage, {

0 commit comments

Comments
 (0)