Skip to content

Commit e3bdaae

Browse files
stereotype441Commit Queue
authored andcommitted
[messages] Clean up references to DiagnosticCode-derived classes.
Replaces "is" tests that refer to classes derived from `DiagnosticCode` with tests on `DiagnosticCode.type`: - `x is ScannerErrorCode || x is ParserErrorCode` is replaced with `x.type == DiagnosticType.SYNTACTIC_ERROR`. This is exactly equivalent, because `ScannerErrorCode` and `ParserErrorCode` are the only two `DiagnosticCode`-derived classes whose `type` method returns `SYNTACTIC_ERROR`. - `x is TodoCode` is replaced with `x.type == DiagnosticType.TODO`. This is exactly equivalent, because `TodoCode` is the only `DiagnosticCode`-derived class whose `type` method returns `TODO`. - In `statement_completion.dart`, `x is! HintCode && x is! WarningCode` is replaced with `x.type == DiagnosticType.SYNTACTIC_ERROR`. The new test is less accepting: for example, it previously accepted diagnostics of type `StaticWarningCode`. This test is used to short-cut the generation of statement completions such as completing an incomplete `do` statement. These completions are only necessary to generate if there is a syntax error, so there should be no user-visible behavior change. - In `fix_processor.dart`, `x is LintCode || x is HintCode || x is WarningCode` is replaced with `x.type == DiagnosticType.LINT || x.type == DiagnosticType.STATIC_WARNING`. The new test is more accepting: it now accepts any diagnostic code whose type is `STATIC_WARNING`, when previously it only accepted warnings of type `WarningCode` (and rejected warnings of types like `StaticWarningCode`). This test determines when quick fixes like "ignore diagnostic on this line" are offered, so the behavior change is appropriate. - Also replaces a documentation reference to `TodoCode` (in `todo_codes.dart`) with a reference to `DiagnosticType.TODO`. These changes pave the way for a follow-up CL in which I plan to eliminate these derived classes entirely. Change-Id: I6a6a69647ff62dfe06b0219d8b292da53427cf0d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461140 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 368277d commit e3bdaae

File tree

9 files changed

+18
-27
lines changed

9 files changed

+18
-27
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:analyzer/dart/analysis/results.dart';
88
import 'package:analyzer/dart/ast/ast.dart';
99
import 'package:analyzer/dart/element/element.dart';
1010
import 'package:analyzer/diagnostic/diagnostic.dart';
11+
import 'package:analyzer/error/error.dart';
1112
import 'package:analyzer/error/listener.dart';
1213
import 'package:analyzer/source/line_info.dart';
1314
import 'package:analyzer/src/dart/analysis/experiments.dart';
@@ -37,11 +38,7 @@ String format(String content, {Version? languageVersion}) {
3738
ParseStringResult sortDirectives(String contents, {String? fileName}) {
3839
var (unit, diagnostics) = _parse(contents, fullName: fileName);
3940
var parseErrors = diagnostics
40-
.where(
41-
(d) =>
42-
d.diagnosticCode is ScannerErrorCode ||
43-
d.diagnosticCode is ParserErrorCode,
44-
)
41+
.where((d) => d.diagnosticCode.type == DiagnosticType.SYNTACTIC_ERROR)
4542
.toList();
4643
if (parseErrors.isNotEmpty) {
4744
return ParseStringResultImpl(contents, unit, parseErrors);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:analysis_server/src/legacy_analysis_server.dart';
1010
import 'package:analysis_server/src/protocol/protocol_internal.dart';
1111
import 'package:analyzer/dart/analysis/results.dart';
1212
import 'package:analyzer/diagnostic/diagnostic.dart';
13-
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
13+
import 'package:analyzer/error/error.dart';
1414
import 'package:analyzer/src/util/performance/operation_performance.dart';
1515
import 'package:analyzer/src/utilities/cancellation.dart';
1616
import 'package:dart_style/dart_style.dart';
@@ -82,8 +82,7 @@ abstract class LegacyHandler {
8282
int numberOfSyntacticErrors(List<Diagnostic> diagnostics) {
8383
var numScanParseErrors = 0;
8484
for (var diagnostic in diagnostics) {
85-
if (diagnostic.diagnosticCode is ScannerErrorCode ||
86-
diagnostic.diagnosticCode is ParserErrorCode) {
85+
if (diagnostic.diagnosticCode.type == DiagnosticType.SYNTACTIC_ERROR) {
8786
numScanParseErrors++;
8887
}
8988
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import 'package:analysis_server/src/lsp/mapping.dart';
1111
import 'package:analysis_server/src/lsp/source_edits.dart';
1212
import 'package:analyzer/dart/ast/ast.dart';
1313
import 'package:analyzer/diagnostic/diagnostic.dart' as engine;
14-
import 'package:analyzer/src/dart/scanner/scanner.dart' as engine;
15-
import 'package:analyzer/src/generated/parser.dart' as engine;
14+
import 'package:analyzer/error/error.dart';
1615
import 'package:analyzer_plugin/protocol/protocol_common.dart';
1716

1817
abstract class SimpleEditCommandHandler<S extends AnalysisServer>
@@ -23,9 +22,7 @@ abstract class SimpleEditCommandHandler<S extends AnalysisServer>
2322

2423
bool hasScanParseErrors(List<engine.Diagnostic> diagnostics) {
2524
return diagnostics.any(
26-
(d) =>
27-
d.diagnosticCode is engine.ScannerErrorCode ||
28-
d.diagnosticCode is engine.ParserErrorCode,
25+
(d) => d.diagnosticCode.type == DiagnosticType.SYNTACTIC_ERROR,
2926
);
3027
}
3128

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ class StatementCompletionProcessor {
188188
}
189189
for (var diagnostic in statementContext.resolveResult.diagnostics) {
190190
if (diagnostic.offset >= node.offset && diagnostic.offset <= node.end) {
191-
if (diagnostic.diagnosticCode is! HintCode &&
192-
diagnostic.diagnosticCode is! WarningCode) {
191+
if (diagnostic.diagnosticCode.type == DiagnosticType.SYNTACTIC_ERROR) {
193192
diagnostics.add(diagnostic);
194193
}
195194
}

pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import 'package:analyzer/source/file_source.dart';
3232
import 'package:analyzer/source/source.dart';
3333
import 'package:analyzer/source/source_range.dart';
3434
import 'package:analyzer/src/analysis_rule/rule_context.dart';
35-
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
3635
import 'package:analyzer/src/error/codes.dart';
3736
import 'package:analyzer/src/lint/linter_visitor.dart';
3837
import 'package:analyzer/src/lint/registry.dart';
@@ -918,9 +917,7 @@ class BulkFixProcessor {
918917
var diagnostics = unitResult.diagnostics;
919918
// Check if there are scan/parse errors in the file.
920919
var hasParseErrors = diagnostics.any(
921-
(d) =>
922-
d.diagnosticCode is ScannerErrorCode ||
923-
d.diagnosticCode is ParserErrorCode,
920+
(d) => d.diagnosticCode.type == DiagnosticType.SYNTACTIC_ERROR,
924921
);
925922
if (hasParseErrors) {
926923
// Cannot process files with parse errors.

pkg/analysis_server_plugin/lib/src/correction/fix_processor.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:analysis_server_plugin/src/correction/fix_generators.dart';
99
import 'package:analysis_server_plugin/src/correction/fix_in_file_processor.dart';
1010
import 'package:analysis_server_plugin/src/correction/ignore_diagnostic.dart';
1111
import 'package:analysis_server_plugin/src/correction/performance.dart';
12-
import 'package:analyzer/src/error/codes.dart';
12+
import 'package:analyzer/error/error.dart';
1313
import 'package:analyzer/src/generated/java_core.dart';
1414
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
1515
import 'package:analyzer_plugin/utilities/change_builder/conflicting_edit_exception.dart';
@@ -152,9 +152,9 @@ class FixProcessor {
152152
}
153153
}
154154

155-
if (diagnosticCode is LintCode ||
156-
diagnosticCode is HintCode ||
157-
diagnosticCode is WarningCode) {
155+
if (diagnosticCode.type == DiagnosticType.LINT ||
156+
diagnosticCode.type == DiagnosticType.HINT ||
157+
diagnosticCode.type == DiagnosticType.STATIC_WARNING) {
158158
for (var generator in registeredFixGenerators.ignoreProducerGenerators) {
159159
var producer = generator(context: context);
160160
if (producer.fixKind == ignoreErrorAnalysisFileKind) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import 'package:_fe_analyzer_shared/src/base/errors.dart';
66

77
part 'package:analyzer/src/dart/error/todo_codes.g.dart';
88

9-
/// Static helper methods and properties for working with [TodoCode]s.
9+
/// Static helper methods and properties for working with [DiagnosticType.TODO]
10+
/// codes.
1011
class Todo {
1112
static const _codes = {
1213
'TODO': TodoCode.todo,

pkg/analyzer/test/src/task/strong/inferred_type_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:analyzer/dart/element/element.dart';
66
import 'package:analyzer/dart/element/type.dart';
7+
import 'package:analyzer/error/error.dart';
78
import 'package:analyzer/file_system/file_system.dart';
89
import 'package:analyzer/src/error/codes.dart';
910
import 'package:analyzer/src/utilities/extensions/file_system.dart';
@@ -5906,7 +5907,7 @@ main() {
59065907
assertErrorsInList(
59075908
result.diagnostics.where((e) {
59085909
return e.diagnosticCode != WarningCode.unusedLocalVariable &&
5909-
e.diagnosticCode is! TodoCode;
5910+
e.diagnosticCode.type != DiagnosticType.TODO;
59105911
}).toList(),
59115912
expectedDiagnostics,
59125913
);

pkg/analyzer/tool/fine/ab_mutate/engine.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
99
import 'package:analyzer/dart/analysis/results.dart';
1010
import 'package:analyzer/dart/ast/ast.dart';
1111
import 'package:analyzer/diagnostic/diagnostic.dart';
12+
import 'package:analyzer/error/error.dart';
1213
import 'package:analyzer/file_system/overlay_file_system.dart';
1314
import 'package:analyzer/source/error_processor.dart';
1415
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
15-
import 'package:analyzer/src/error/codes.dart';
1616
import 'package:analyzer/src/util/performance/operation_performance.dart';
1717
import 'package:analyzer/src/utilities/extensions/object.dart';
1818

@@ -77,7 +77,7 @@ class ABEngine {
7777
if (errorsResult is ErrorsResult) {
7878
for (var diagnostic in errorsResult.diagnostics) {
7979
// Filter TODOs, not interesting for comparison.
80-
if (diagnostic.diagnosticCode is TodoCode) {
80+
if (diagnostic.diagnosticCode.type == DiagnosticType.TODO) {
8181
continue;
8282
}
8383
var severityName = _getProcessedSeverity(errorsResult, diagnostic);

0 commit comments

Comments
 (0)