Skip to content

Commit 3a9f433

Browse files
srawlinsCommit Queue
authored andcommitted
analysis_server: Use new DiagnosticCode name
Work towards #60635 Change-Id: I76c3f7b3ed890b808f3831f2b7776bd1988a223d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425407 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 3fd1ad3 commit 3a9f433

File tree

19 files changed

+141
-123
lines changed

19 files changed

+141
-123
lines changed

pkg/analysis_server/lib/src/lsp/mapping.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,21 @@ final completionFilterTextSplitPattern = RegExp(r'=>|[\(]');
5353
final completionSetterTypePattern = RegExp(r'^\((\S+)\s+\S+\)$');
5454

5555
final diagnosticTagsForErrorCode = <String, List<lsp.DiagnosticTag>>{
56-
_errorCode(WarningCode.DEAD_CODE): [lsp.DiagnosticTag.Unnecessary],
57-
_errorCode(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE): [
56+
_diagnosticCode(WarningCode.DEAD_CODE): [lsp.DiagnosticTag.Unnecessary],
57+
_diagnosticCode(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE): [
5858
lsp.DiagnosticTag.Deprecated,
5959
],
60-
_errorCode(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE): [
60+
_diagnosticCode(
61+
HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE,
62+
): [lsp.DiagnosticTag.Deprecated],
63+
_diagnosticCode(HintCode.DEPRECATED_MEMBER_USE): [
6164
lsp.DiagnosticTag.Deprecated,
6265
],
63-
_errorCode(HintCode.DEPRECATED_MEMBER_USE): [lsp.DiagnosticTag.Deprecated],
6466
'deprecated_member_use_from_same_package': [lsp.DiagnosticTag.Deprecated],
6567
'deprecated_member_use_from_same_package_with_message': [
6668
lsp.DiagnosticTag.Deprecated,
6769
],
68-
_errorCode(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE): [
70+
_diagnosticCode(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE): [
6971
lsp.DiagnosticTag.Deprecated,
7072
],
7173
};
@@ -1846,7 +1848,7 @@ lsp.MarkupContent _asMarkup(
18461848
return lsp.MarkupContent(kind: format, value: content);
18471849
}
18481850

1849-
String _errorCode(server.ErrorCode code) => code.name.toLowerCase();
1851+
String _diagnosticCode(server.DiagnosticCode code) => code.name.toLowerCase();
18501852

18511853
/// Additional details about a completion that may be formatted differently
18521854
/// depending on the client capabilities.

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,11 @@ class StatementCompletionProcessor {
299299
void _checkExpressions(AstNode node) {
300300
// Note: This may queue edits that have to be accounted for later.
301301
// See _lengthOfInsertions().
302-
AstNode? errorMatching(ErrorCode errorCode, {Pattern? partialMatch}) {
303-
var error = _findError(errorCode, partialMatch: partialMatch);
302+
AstNode? diagnosticMatching(
303+
DiagnosticCode diagnosticCode, {
304+
Pattern? partialMatch,
305+
}) {
306+
var error = _findError(diagnosticCode, partialMatch: partialMatch);
304307
if (error == null) {
305308
return null;
306309
}
@@ -310,7 +313,7 @@ class StatementCompletionProcessor {
310313
: null;
311314
}
312315

313-
var expr = errorMatching(ScannerErrorCode.UNTERMINATED_STRING_LITERAL);
316+
var expr = diagnosticMatching(ScannerErrorCode.UNTERMINATED_STRING_LITERAL);
314317
if (expr != null) {
315318
var source = utils.getNodeText(expr);
316319
var content = source;
@@ -340,8 +343,14 @@ class StatementCompletionProcessor {
340343
_addInsertEdit(loc, delimiter);
341344
}
342345
expr =
343-
errorMatching(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "']'") ??
344-
errorMatching(ScannerErrorCode.EXPECTED_TOKEN, partialMatch: "']'");
346+
diagnosticMatching(
347+
ParserErrorCode.EXPECTED_TOKEN,
348+
partialMatch: "']'",
349+
) ??
350+
diagnosticMatching(
351+
ScannerErrorCode.EXPECTED_TOKEN,
352+
partialMatch: "']'",
353+
);
345354
if (expr != null) {
346355
expr = expr.thisOrAncestorOfType<ListLiteral>();
347356
if (expr is ListLiteral) {
@@ -1161,7 +1170,10 @@ class StatementCompletionProcessor {
11611170
);
11621171
}
11631172

1164-
engine.AnalysisError? _findError(ErrorCode code, {Pattern? partialMatch}) {
1173+
engine.AnalysisError? _findError(
1174+
DiagnosticCode code, {
1175+
Pattern? partialMatch,
1176+
}) {
11651177
return errors.firstWhereOrNull(
11661178
(err) =>
11671179
err.errorCode == code &&
@@ -1264,8 +1276,8 @@ class StatementCompletionProcessor {
12641276
return Position(file, offset);
12651277
}
12661278

1267-
void _removeError(ErrorCode errorCode, {Pattern? partialMatch}) {
1268-
var error = _findError(errorCode, partialMatch: partialMatch);
1279+
void _removeError(DiagnosticCode diagnosticCode, {Pattern? partialMatch}) {
1280+
var error = _findError(diagnosticCode, partialMatch: partialMatch);
12691281
if (error != null) {
12701282
errors.remove(error);
12711283
}

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class BulkFixProcessor {
8787
/// The expectation is that only one of the correction producers will produce
8888
/// a change for a given fix. If more than one change is produced the result
8989
/// will almost certainly be invalid code.
90-
static const Map<ErrorCode, List<MultiProducerGenerator>>
90+
static const Map<DiagnosticCode, List<MultiProducerGenerator>>
9191
nonLintMultiProducerMap = {
9292
CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE: [DataDriven.new],
9393
CompileTimeErrorCode.CAST_TO_NON_TYPE: [DataDriven.new],
@@ -152,10 +152,12 @@ class BulkFixProcessor {
152152
};
153153

154154
/// Cached results of [_canBulkFix].
155-
static final Map<ErrorCode, bool> _bulkFixableErrorCodes = {};
155+
static final Map<DiagnosticCode, bool> _bulkFixableCodes = {};
156156

157-
static final Set<String> _errorCodes =
158-
errorCodeValues.map((ErrorCode code) => code.name.toLowerCase()).toSet();
157+
static final Set<String> _diagnosticCodes =
158+
errorCodeValues
159+
.map((DiagnosticCode code) => code.name.toLowerCase())
160+
.toSet();
159161

160162
static final Set<String> _lintCodes =
161163
Registry.ruleRegistry.rules.map((rule) => rule.name).toSet();
@@ -487,7 +489,7 @@ class BulkFixProcessor {
487489
if (_codes != null) {
488490
var undefinedCodes = <String>[];
489491
for (var code in _codes) {
490-
if (!_errorCodes.contains(code) && !_lintCodes.contains(code)) {
492+
if (!_diagnosticCodes.contains(code) && !_lintCodes.contains(code)) {
491493
undefinedCodes.add(code);
492494
}
493495
}
@@ -960,8 +962,8 @@ class BulkFixProcessor {
960962
return [];
961963
}
962964

963-
/// Returns whether [errorCode] is an error that can be fixed in bulk.
964-
static bool _canBulkFix(ErrorCode errorCode) {
965+
/// Returns whether [diagnosticCode] is an error that can be fixed in bulk.
966+
static bool _canBulkFix(DiagnosticCode diagnosticCode) {
965967
bool hasBulkFixProducers(List<ProducerGenerator>? generators) {
966968
return generators != null &&
967969
generators.any(
@@ -972,19 +974,19 @@ class BulkFixProcessor {
972974
);
973975
}
974976

975-
return _bulkFixableErrorCodes.putIfAbsent(errorCode, () {
976-
if (errorCode is LintCode) {
977-
var producers = registeredFixGenerators.lintProducers[errorCode];
977+
return _bulkFixableCodes.putIfAbsent(diagnosticCode, () {
978+
if (diagnosticCode is LintCode) {
979+
var producers = registeredFixGenerators.lintProducers[diagnosticCode];
978980
if (hasBulkFixProducers(producers)) {
979981
return true;
980982
}
981983

982984
return registeredFixGenerators.lintMultiProducers.containsKey(
983-
errorCode,
985+
diagnosticCode,
984986
);
985987
}
986988

987-
var producers = registeredFixGenerators.nonLintProducers[errorCode];
989+
var producers = registeredFixGenerators.nonLintProducers[diagnosticCode];
988990
if (hasBulkFixProducers(producers)) {
989991
return true;
990992
}
@@ -993,9 +995,9 @@ class BulkFixProcessor {
993995
// producers may vary depending on the resolved unit (we must configure
994996
// them before we can determine the producers).
995997
return registeredFixGenerators.nonLintMultiProducers.containsKey(
996-
errorCode,
998+
diagnosticCode,
997999
) ||
998-
BulkFixProcessor.nonLintMultiProducerMap.containsKey(errorCode);
1000+
BulkFixProcessor.nonLintMultiProducerMap.containsKey(diagnosticCode);
9991001
});
10001002
}
10011003

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class AddMissingRequiredArgument extends ResolvedCorrectionProducer {
3232
@override
3333
FixKind get fixKind => DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT;
3434

35-
/// All the error codes that this fix can be applied to.
36-
List<ErrorCode> get _errorCodesWhereThisIsValid {
35+
/// All the diagnostic codes that this fix can be applied to.
36+
List<DiagnosticCode> get _codesWhereThisIsValid {
3737
var producerGenerators = [AddMissingRequiredArgument.new];
3838
var nonLintProducers = registeredFixGenerators.nonLintProducers;
3939
return [
@@ -71,7 +71,7 @@ class AddMissingRequiredArgument extends ResolvedCorrectionProducer {
7171
return;
7272
}
7373

74-
var validErrors = _errorCodesWhereThisIsValid;
74+
var validErrors = _codesWhereThisIsValid;
7575
var errors = unitResult.errors.where(
7676
(e) => diagnostic.sameRangeAs(e) && validErrors.contains(e.errorCode),
7777
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ class ImportLibrary extends MultiCorrectionProducer {
8080
];
8181
}
8282

83-
/// A map of all the error codes that this fix can be applied to and the
83+
/// A map of all the diagnostic codes that this fix can be applied to and the
8484
/// generators that can be used to apply the fix.
85-
Map<ErrorCode, List<MultiProducerGenerator>> get _errorCodesWhereThisIsValid {
85+
Map<DiagnosticCode, List<MultiProducerGenerator>> get _codesWhereThisIsValid {
8686
var producerGenerators = _ImportKind.values.map((key) => key.fn).toList();
8787
var nonLintMultiProducers = registeredFixGenerators.nonLintMultiProducers;
8888
return {
@@ -720,7 +720,7 @@ class ImportLibrary extends MultiCorrectionProducer {
720720
/// Searches all diagnostics reported for this compilation unit for unresolved
721721
/// names where this fix can be applied besides the current diagnostic.
722722
Future<Set<String>> _otherUnresolvedNames(String? prefix, String name) async {
723-
var errorsForThisFix = _errorCodesWhereThisIsValid;
723+
var errorsForThisFix = _codesWhereThisIsValid;
724724
var errors =
725725
<AnalysisError, List<MultiProducerGenerator>>{}..addEntries(
726726
unitResult.errors.map((error) {

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ abstract class _RemoveConst extends ParsedCorrectionProducer {
134134

135135
/// A map of all the error codes that this fix can be applied to and the
136136
/// generators that can be used to apply the fix.
137-
Map<ErrorCode, List<ProducerGenerator>> get _errorCodesWhereThisIsValid {
137+
Map<DiagnosticCode, List<ProducerGenerator>> get _codesWhereThisIsValid {
138138
var constructors = [RemoveUnnecessaryConst.new, RemoveConst.new];
139139
var nonLintMultiProducers = registeredFixGenerators.nonLintProducers;
140140
return {
@@ -171,10 +171,8 @@ abstract class _RemoveConst extends ParsedCorrectionProducer {
171171
if (constantContext != null) {
172172
var constKeyword = constantContext.$2;
173173
if (constKeyword != null) {
174-
var validErrors = _errorCodesWhereThisIsValid.keys.toList();
175-
var validDiagnostics = unitResult.errors.whereErrorCodeIn(
176-
validErrors,
177-
);
174+
var validErrors = _codesWhereThisIsValid.keys.toList();
175+
var validDiagnostics = unitResult.errors.whereCodeIn(validErrors);
178176
switch (constantContext.$1) {
179177
case InstanceCreationExpression contextNode:
180178
var (:constNodes, :nodesWithDiagnostic) = contextNode
@@ -282,10 +280,8 @@ extension on List<AstNode> {
282280
}
283281

284282
extension on List<AnalysisError> {
285-
List<AnalysisError> whereErrorCodeIn(List<ErrorCode> errors) =>
286-
where((error) {
287-
return errors.contains(error.errorCode);
288-
}).toList();
283+
List<AnalysisError> whereCodeIn(List<DiagnosticCode> codes) =>
284+
where((c) => codes.contains(c.errorCode)).toList();
289285
}
290286

291287
extension<T> on Iterable<T> {

pkg/analysis_server/lib/src/services/correction/fix/analysis_options/fix_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import 'package:yaml_edit/yaml_edit.dart';
2929

3030
/// The generator used to generate fixes in analysis options files.
3131
class AnalysisOptionsFixGenerator {
32-
static const List<ErrorCode> codesWithFixes = [
32+
static const List<DiagnosticCode> codesWithFixes = [
3333
AnalysisOptionsWarningCode.DEPRECATED_LINT,
3434
AnalysisOptionsWarningCode.ANALYSIS_OPTION_DEPRECATED_WITH_REPLACEMENT,
3535
AnalysisOptionsWarningCode.DUPLICATE_RULE,

pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:analyzer/error/error.dart';
66

77
/// An error code representing a problem in a file containing an encoding of a
88
/// transform set.
9-
class TransformSetErrorCode extends ErrorCode {
9+
class TransformSetErrorCode extends DiagnosticCode {
1010
/// Parameters:
1111
/// 0: the conflicting key
1212
/// 1: the key that it conflicts with

pkg/analysis_server/lib/src/services/correction/fix/pubspec/fix_generator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import 'package:yaml/yaml.dart';
2222

2323
/// The generator used to generate fixes in pubspec.yaml files.
2424
class PubspecFixGenerator {
25-
static const List<ErrorCode> codesWithFixes = [
25+
static const List<DiagnosticCode> codesWithFixes = [
2626
PubspecWarningCode.MISSING_DEPENDENCY,
2727
PubspecWarningCode.MISSING_NAME,
2828
];
@@ -154,7 +154,7 @@ class PubspecFixGenerator {
154154
fixes.add(Fix(kind: kind, change: change));
155155
}
156156

157-
Future<void> _addMissingDependency(ErrorCode errorCode) async {
157+
Future<void> _addMissingDependency(DiagnosticCode diagnosticCode) async {
158158
var node = this.node;
159159
if (node is! YamlMap) {
160160
return;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ final _builtInLintMultiGenerators = {
563563
],
564564
};
565565

566-
final _builtInNonLintGenerators = <ErrorCode, List<ProducerGenerator>>{
566+
final _builtInNonLintGenerators = <DiagnosticCode, List<ProducerGenerator>>{
567567
CompileTimeErrorCode.ABSTRACT_FIELD_INITIALIZER: [
568568
RemoveAbstract.new,
569569
RemoveInitializer.new,

0 commit comments

Comments
 (0)