Skip to content

Commit 57bfb6a

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
analyzer: Use new DiagnosticCode name in some directories
Work towards #60635 Change-Id: I942e690ab2946c564c10df228d17bd44de4ed375 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425406 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent c56a8be commit 57bfb6a

File tree

13 files changed

+278
-232
lines changed

13 files changed

+278
-232
lines changed

pkg/analyzer/lib/diagnostic/diagnostic.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import 'package:analyzer/src/generated/java_core.dart';
1616
///
1717
/// [guidelines]: https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/doc/implementation/diagnostics.md
1818
class Diagnostic {
19-
/// The error code associated with the diagnostic.
20-
final ErrorCode errorCode;
19+
/// The diagnostic code associated with the diagnostic.
20+
// TODO(srawlins): Rename this to `diagnosticCode`.
21+
final DiagnosticCode errorCode;
2122

2223
/// A list of messages that provide context for understanding the problem
2324
/// being reported. The list will be empty if there are no such messages.

pkg/analyzer/lib/error/error.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
/// @docImport 'package:analyzer/error/listener.dart';
6+
library;
7+
58
import 'dart:collection';
69

710
import 'package:_fe_analyzer_shared/src/base/errors.dart';
@@ -21,30 +24,30 @@ export 'package:_fe_analyzer_shared/src/base/errors.dart'
2124
export 'package:analyzer/src/dart/error/lint_codes.dart' show LintCode;
2225
export 'package:analyzer/src/error/error_code_values.g.dart';
2326

24-
/// The lazy initialized map from [ErrorCode.uniqueName] to the [ErrorCode]
25-
/// instance.
26-
final HashMap<String, ErrorCode> _uniqueNameToCodeMap =
27+
/// The lazy initialized map from [ErrorCode.uniqueName] to the
28+
/// [DiagnosticCode] instance.
29+
final HashMap<String, DiagnosticCode> _uniqueNameToCodeMap =
2730
_computeUniqueNameToCodeMap();
2831

29-
/// Return the [ErrorCode] with the given [uniqueName], or `null` if not
32+
/// Return the [DiagnosticCode] with the given [uniqueName], or `null` if not
3033
/// found.
31-
ErrorCode? errorCodeByUniqueName(String uniqueName) {
34+
DiagnosticCode? errorCodeByUniqueName(String uniqueName) {
3235
return _uniqueNameToCodeMap[uniqueName];
3336
}
3437

35-
/// Return the map from [ErrorCode.uniqueName] to the [ErrorCode] instance
38+
/// Return the map from [ErrorCode.uniqueName] to the [DiagnosticCode] instance
3639
/// for all [errorCodeValues].
37-
HashMap<String, ErrorCode> _computeUniqueNameToCodeMap() {
38-
var result = HashMap<String, ErrorCode>();
39-
for (ErrorCode errorCode in errorCodeValues) {
40-
var uniqueName = errorCode.uniqueName;
40+
HashMap<String, DiagnosticCode> _computeUniqueNameToCodeMap() {
41+
var result = HashMap<String, DiagnosticCode>();
42+
for (DiagnosticCode diagnosticCode in errorCodeValues) {
43+
var uniqueName = diagnosticCode.uniqueName;
4144
assert(() {
4245
if (result.containsKey(uniqueName)) {
4346
throw StateError('Not unique: $uniqueName');
4447
}
4548
return true;
4649
}());
47-
result[uniqueName] = errorCode;
50+
result[uniqueName] = diagnosticCode;
4851
}
4952
return result;
5053
}

pkg/analyzer/lib/error/listener.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ErrorReporter {
6969
/// The location of the diagnostic will be the name of the [node].
7070
void atConstructorDeclaration(
7171
ConstructorDeclaration node,
72-
ErrorCode errorCode, {
72+
DiagnosticCode errorCode, {
7373
List<Object>? arguments,
7474
List<DiagnosticMessage>? contextMessages,
7575
Object? data,
@@ -95,7 +95,7 @@ class ErrorReporter {
9595
@experimental
9696
void atElement2(
9797
Element element2,
98-
ErrorCode diagnosticCode, {
98+
DiagnosticCode diagnosticCode, {
9999
List<Object>? arguments,
100100
List<DiagnosticMessage>? contextMessages,
101101
Object? data,
@@ -115,7 +115,7 @@ class ErrorReporter {
115115
/// The [entity] is used to compute the location of the error.
116116
void atEntity(
117117
SyntacticEntity entity,
118-
ErrorCode errorCode, {
118+
DiagnosticCode errorCode, {
119119
List<Object>? arguments,
120120
List<DiagnosticMessage>? contextMessages,
121121
Object? data,
@@ -134,7 +134,7 @@ class ErrorReporter {
134134
/// The [node] is used to compute the location of the error.
135135
void atNode(
136136
AstNode node,
137-
ErrorCode diagnosticCode, {
137+
DiagnosticCode diagnosticCode, {
138138
List<Object>? arguments,
139139
List<DiagnosticMessage>? contextMessages,
140140
Object? data,
@@ -154,7 +154,7 @@ class ErrorReporter {
154154
void atOffset({
155155
required int offset,
156156
required int length,
157-
required ErrorCode errorCode,
157+
required DiagnosticCode errorCode,
158158
List<Object>? arguments,
159159
List<DiagnosticMessage>? contextMessages,
160160
Object? data,
@@ -198,7 +198,7 @@ class ErrorReporter {
198198
/// The [span] is used to compute the location of the error.
199199
void atSourceSpan(
200200
SourceSpan span,
201-
ErrorCode errorCode, {
201+
DiagnosticCode errorCode, {
202202
List<Object>? arguments,
203203
List<DiagnosticMessage>? contextMessages,
204204
Object? data,
@@ -217,7 +217,7 @@ class ErrorReporter {
217217
/// used to compute the location of the error.
218218
void atToken(
219219
Token token,
220-
ErrorCode diagnosticCode, {
220+
DiagnosticCode diagnosticCode, {
221221
List<Object>? arguments,
222222
List<DiagnosticMessage>? contextMessages,
223223
Object? data,

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,9 +2665,9 @@ abstract class DriverWatcher {
26652665
class ErrorEncoding {
26662666
static AnalysisError? decode(Source source, AnalysisDriverUnitError error) {
26672667
String errorName = error.uniqueName;
2668-
ErrorCode? errorCode =
2668+
DiagnosticCode? diagnosticCode =
26692669
errorCodeByUniqueName(errorName) ?? _lintCodeByUniqueName(errorName);
2670-
if (errorCode == null) {
2670+
if (diagnosticCode == null) {
26712671
// This could fail because the error code is no longer defined, or, in
26722672
// the case of a lint rule, if the lint rule has been disabled since the
26732673
// errors were written.
@@ -2695,7 +2695,7 @@ class ErrorEncoding {
26952695
source: source,
26962696
offset: error.offset,
26972697
length: error.length,
2698-
errorCode: errorCode,
2698+
errorCode: diagnosticCode,
26992699
message: error.message,
27002700
correctionMessage: error.correction.isEmpty ? null : error.correction,
27012701
contextMessages: contextMessages,
@@ -2726,10 +2726,10 @@ class ErrorEncoding {
27262726
);
27272727
}
27282728

2729-
/// Return the lint code with the given [errorName], or `null` if there is no
2730-
/// lint registered with that name.
2731-
static ErrorCode? _lintCodeByUniqueName(String errorName) {
2732-
return linter.Registry.ruleRegistry.codeForUniqueName(errorName);
2729+
/// Returns the lint code with the given [diagnosticName], or `null` if there
2730+
/// is no lint registered with that name.
2731+
static DiagnosticCode? _lintCodeByUniqueName(String diagnosticName) {
2732+
return linter.Registry.ruleRegistry.codeForUniqueName(diagnosticName);
27332733
}
27342734
}
27352735

pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,11 +1003,15 @@ class LibraryAnalyzer {
10031003
directive?.element = partElement;
10041004

10051005
void reportOnDirectiveUri(
1006-
ErrorCode errorCode, {
1006+
DiagnosticCode diagnosticCode, {
10071007
List<Object>? arguments = const [],
10081008
}) {
10091009
if (directive != null) {
1010-
errorReporter.atNode(directive.uri, errorCode, arguments: arguments);
1010+
errorReporter.atNode(
1011+
directive.uri,
1012+
diagnosticCode,
1013+
arguments: arguments,
1014+
);
10111015
}
10121016
}
10131017

@@ -1036,15 +1040,15 @@ class LibraryAnalyzer {
10361040
var includedKind = includedFile.kind;
10371041

10381042
if (includedKind is! PartFileKind) {
1039-
ErrorCode errorCode;
1043+
DiagnosticCode diagnosticCode;
10401044
if (includedFile.exists) {
1041-
errorCode = CompileTimeErrorCode.PART_OF_NON_PART;
1045+
diagnosticCode = CompileTimeErrorCode.PART_OF_NON_PART;
10421046
} else if (isGeneratedSource(includedFile.source)) {
1043-
errorCode = CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED;
1047+
diagnosticCode = CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED;
10441048
} else {
1045-
errorCode = CompileTimeErrorCode.URI_DOES_NOT_EXIST;
1049+
diagnosticCode = CompileTimeErrorCode.URI_DOES_NOT_EXIST;
10461050
}
1047-
reportOnDirectiveUri(errorCode, arguments: [includedFile.uriStr]);
1051+
reportOnDirectiveUri(diagnosticCode, arguments: [includedFile.uriStr]);
10481052
return;
10491053
}
10501054

0 commit comments

Comments
 (0)