Skip to content

Commit c219974

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Deprecate Diagnostic.errorCode in favor of diagnosticCode
Work towards #60635 Change-Id: I2c7d64a81bc214e64fbc3ac95cf1fe2363a6ebd0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433242 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent 0242cc0 commit c219974

File tree

124 files changed

+682
-593
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+682
-593
lines changed

pkg/analysis_server/lib/src/g3/fixes.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class LintFixTester {
7575
Diagnostic diagnostic;
7676
var errors = unitResult.errors;
7777
if (inFile) {
78-
var groups = errors.groupListsBy((error) => error.errorCode);
78+
var groups = errors.groupListsBy((error) => error.diagnosticCode);
7979
if (groups.length != 1) {
8080
throw StateError(
8181
'Exactly one error code expected:'
@@ -90,7 +90,7 @@ class LintFixTester {
9090
diagnostic = errors.single;
9191
}
9292

93-
if (diagnostic.errorCode is! LintCode) {
93+
if (diagnostic.diagnosticCode is! LintCode) {
9494
throw StateError('A lint expected: $errors');
9595
}
9696

pkg/analysis_server/lib/src/g3/utilities.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ String format(String content, {Version? languageVersion}) {
3535
/// code. On failure, the result contains the unsorted original code, and the
3636
/// cause of the failure, a list of [Diagnostic]s.
3737
ParseStringResult sortDirectives(String contents, {String? fileName}) {
38-
var (unit, errors) = _parse(contents, fullName: fileName);
38+
var (unit, diagnostics) = _parse(contents, fullName: fileName);
3939
var parseErrors =
40-
errors
40+
diagnostics
4141
.where(
42-
(error) =>
43-
error.errorCode is ScannerErrorCode ||
44-
error.errorCode is ParserErrorCode,
42+
(d) =>
43+
d.diagnosticCode is ScannerErrorCode ||
44+
d.diagnosticCode is ParserErrorCode,
4545
)
4646
.toList();
4747
if (parseErrors.isNotEmpty) {

pkg/analysis_server/lib/src/handler/legacy/edit_get_fixes.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class EditGetFixesHandler extends LegacyHandler
224224
var parametersFile = '''
225225
offset: $offset
226226
error: $error
227-
error.errorCode: ${error.errorCode}
227+
error.errorCode: ${error.diagnosticCode}
228228
''';
229229
throw CaughtExceptionWithFiles(exception, stackTrace, {
230230
file: unitResult.content,

pkg/analysis_server/lib/src/handler/legacy/legacy_handler.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ abstract class LegacyHandler {
8282
/// Return the number of syntactic errors in the list of [diagnostics].
8383
int numberOfSyntacticErrors(List<Diagnostic> diagnostics) {
8484
var numScanParseErrors = 0;
85-
for (var error in diagnostics) {
86-
if (error.errorCode is ScannerErrorCode ||
87-
error.errorCode is ParserErrorCode) {
85+
for (var diagnostic in diagnostics) {
86+
if (diagnostic.diagnosticCode is ScannerErrorCode ||
87+
diagnostic.diagnosticCode is ParserErrorCode) {
8888
numScanParseErrors++;
8989
}
9090
}

pkg/analysis_server/lib/src/lsp/handlers/commands/simple_edit_handler.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ abstract class SimpleEditCommandHandler<S extends AnalysisServer>
2323

2424
bool hasScanParseErrors(List<engine.Diagnostic> diagnostics) {
2525
return diagnostics.any(
26-
(error) =>
27-
error.errorCode is engine.ScannerErrorCode ||
28-
error.errorCode is engine.ParserErrorCode,
26+
(d) =>
27+
d.diagnosticCode is engine.ScannerErrorCode ||
28+
d.diagnosticCode is engine.ParserErrorCode,
2929
);
3030
}
3131

pkg/analysis_server/lib/src/protocol_server.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ AnalysisError newAnalysisError_fromEngine(
144144
engine.Diagnostic diagnostic, [
145145
engine.DiagnosticSeverity? diagnosticSeverity,
146146
]) {
147-
var errorCode = diagnostic.errorCode;
148-
// prepare location
147+
var diagnosticCode = diagnostic.diagnosticCode;
148+
// Prepare location.
149149
Location location;
150150
{
151151
var file = diagnostic.source.fullName;
@@ -172,14 +172,14 @@ AnalysisError newAnalysisError_fromEngine(
172172
);
173173
}
174174

175-
// Default to the error's severity if none is specified.
176-
diagnosticSeverity ??= errorCode.severity;
175+
// Default to the diagnostic's severity if none is specified.
176+
diagnosticSeverity ??= diagnosticCode.severity;
177177

178178
// done
179179
var severity = AnalysisErrorSeverity.values.byName(diagnosticSeverity.name);
180-
var type = AnalysisErrorType.values.byName(errorCode.type.name);
180+
var type = AnalysisErrorType.values.byName(diagnosticCode.type.name);
181181
var message = diagnostic.message;
182-
var code = errorCode.name.toLowerCase();
182+
var code = diagnosticCode.name.toLowerCase();
183183
List<DiagnosticMessage>? contextMessages;
184184
if (diagnostic.contextMessages.isNotEmpty) {
185185
contextMessages =
@@ -188,7 +188,7 @@ AnalysisError newAnalysisError_fromEngine(
188188
.toList();
189189
}
190190
var correction = diagnostic.correctionMessage;
191-
var url = errorCode.url;
191+
var url = diagnosticCode.url;
192192
return AnalysisError(
193193
severity,
194194
type,

pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ class StatementCompletionProcessor {
188188
}
189189
for (var error in statementContext.resolveResult.errors) {
190190
if (error.offset >= node.offset && error.offset <= node.end) {
191-
if (error.errorCode is! HintCode && error.errorCode is! WarningCode) {
191+
if (error.diagnosticCode is! HintCode &&
192+
error.diagnosticCode is! WarningCode) {
192193
diagnostics.add(error);
193194
}
194195
}
@@ -302,7 +303,7 @@ class StatementCompletionProcessor {
302303
DiagnosticCode diagnosticCode, {
303304
Pattern? partialMatch,
304305
}) {
305-
var error = _findError(diagnosticCode, partialMatch: partialMatch);
306+
var error = _findDiagnostic(diagnosticCode, partialMatch: partialMatch);
306307
if (error == null) {
307308
return null;
308309
}
@@ -434,7 +435,7 @@ class StatementCompletionProcessor {
434435
var previousInsertions = _lengthOfInsertions();
435436
var delta = 0;
436437
if (diagnostics.isNotEmpty) {
437-
var error = _findError(
438+
var error = _findDiagnostic(
438439
ParserErrorCode.EXPECTED_TOKEN,
439440
partialMatch: "';'",
440441
);
@@ -751,7 +752,9 @@ class StatementCompletionProcessor {
751752
var needsParen = false;
752753
int computeExitPos(FormalParameterList parameters) {
753754
if (needsParen = parameters.rightParenthesis.isSynthetic) {
754-
var error = _findError(ParserErrorCode.MISSING_CLOSING_PARENTHESIS);
755+
var error = _findDiagnostic(
756+
ParserErrorCode.MISSING_CLOSING_PARENTHESIS,
757+
);
755758
if (error != null) {
756759
return error.offset - 1;
757760
}
@@ -790,7 +793,10 @@ class StatementCompletionProcessor {
790793
if (node is! FunctionDeclarationStatement) {
791794
return false;
792795
}
793-
var error = _findError(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "';'");
796+
var error = _findDiagnostic(
797+
ParserErrorCode.EXPECTED_TOKEN,
798+
partialMatch: "';'",
799+
);
794800
if (error != null) {
795801
var src = utils.getNodeText(node);
796802
var insertOffset = node.functionDeclaration.end - 1;
@@ -922,8 +928,8 @@ class StatementCompletionProcessor {
922928

923929
bool _complete_methodCall(AstNode node) {
924930
var parenError =
925-
_findError(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "')'") ??
926-
_findError(ScannerErrorCode.EXPECTED_TOKEN, partialMatch: "')'");
931+
_findDiagnostic(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "')'") ??
932+
_findDiagnostic(ScannerErrorCode.EXPECTED_TOKEN, partialMatch: "')'");
927933
if (parenError == null) {
928934
return false;
929935
}
@@ -941,7 +947,7 @@ class StatementCompletionProcessor {
941947
var previousInsertions = _lengthOfInsertions();
942948
var loc = min(selectionOffset, argList.end - 1);
943949
var delta = 1;
944-
var semicolonError = _findError(
950+
var semicolonError = _findDiagnostic(
945951
ParserErrorCode.EXPECTED_TOKEN,
946952
partialMatch: "';'",
947953
);
@@ -980,7 +986,10 @@ class StatementCompletionProcessor {
980986
if (diagnostics.length != 1) {
981987
return false;
982988
}
983-
var error = _findError(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "';'");
989+
var error = _findDiagnostic(
990+
ParserErrorCode.EXPECTED_TOKEN,
991+
partialMatch: "';'",
992+
);
984993
if (error != null) {
985994
var previousInsertions = _lengthOfInsertions();
986995
// TODO(messick): Fix this to find the correct place in all cases.
@@ -1070,7 +1079,7 @@ class StatementCompletionProcessor {
10701079
var exceptionType = catchNode.exceptionType;
10711080
if (onKeyword != null && exceptionType != null) {
10721081
if (exceptionType.length == 0 ||
1073-
_findError(
1082+
_findDiagnostic(
10741083
CompileTimeErrorCode.NON_TYPE_IN_CATCH_CLAUSE,
10751084
partialMatch: "name 'catch",
10761085
) !=
@@ -1169,11 +1178,14 @@ class StatementCompletionProcessor {
11691178
);
11701179
}
11711180

1172-
engine.Diagnostic? _findError(DiagnosticCode code, {Pattern? partialMatch}) {
1181+
engine.Diagnostic? _findDiagnostic(
1182+
DiagnosticCode code, {
1183+
Pattern? partialMatch,
1184+
}) {
11731185
return diagnostics.firstWhereOrNull(
1174-
(err) =>
1175-
err.errorCode == code &&
1176-
(partialMatch == null ? true : err.message.contains(partialMatch)),
1186+
(d) =>
1187+
d.diagnosticCode == code &&
1188+
(partialMatch == null ? true : d.message.contains(partialMatch)),
11771189
);
11781190
}
11791191

@@ -1273,7 +1285,7 @@ class StatementCompletionProcessor {
12731285
}
12741286

12751287
void _removeError(DiagnosticCode diagnosticCode, {Pattern? partialMatch}) {
1276-
var error = _findError(diagnosticCode, partialMatch: partialMatch);
1288+
var error = _findDiagnostic(diagnosticCode, partialMatch: partialMatch);
12771289
if (error != null) {
12781290
diagnostics.remove(error);
12791291
}

0 commit comments

Comments
 (0)