Skip to content

Commit 0b07bee

Browse files
stereotype441Commit Queue
authored andcommitted
[messages] Make AnalyzerCode.className non-optional.
All the `analyzerCode` values that remain in `messages.yaml` files are fully qualified (they take the form `className.error_name` or `className.ERROR_NAME`), so there is no need for `AnalyzerCode` to be able to represent an unqualified analyzer code anymore. In a follow-up CL I intend to generalize the analyzer codes in `_fe_analyzer_shared/messages.yaml` so that their class name doesn't have to be `ParserErrorCode`. Making the class name non-optional will make that work easier. Change-Id: I6a6a696419c3b1208bb512e70d40cab32f647627 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453103 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent b3a185e commit 0b07bee

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

pkg/analyzer_utilities/lib/messages.dart

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,8 @@ List<String> _splitText(
182182
/// This class implements [Comparable], so lists of it can be safely
183183
/// [List.sort]ed.
184184
class AnalyzerCode implements Comparable<AnalyzerCode> {
185-
/// The class name, or `null` if no class name was specified.
186-
///
187-
// TODO(paulberry): change `messages.yaml` so that a class name is always
188-
// specified.
189-
final String? className;
185+
/// The class name.
186+
final String className;
190187

191188
/// The error name.
192189
///
@@ -215,19 +212,14 @@ class AnalyzerCode implements Comparable<AnalyzerCode> {
215212
int compareTo(AnalyzerCode other) {
216213
var className = this.className;
217214
var otherClassName = other.className;
218-
if (className == null) {
219-
if (otherClassName != null) return -1;
220-
} else if (otherClassName == null) {
221-
return 1;
222-
} else if (className.compareTo(otherClassName) case var result
223-
when result != 0) {
215+
if (className.compareTo(otherClassName) case var result when result != 0) {
224216
return result;
225217
}
226218
return snakeCaseErrorName.compareTo(other.snakeCaseErrorName);
227219
}
228220

229221
@override
230-
String toString() => [?className, snakeCaseErrorName].join('.');
222+
String toString() => [className, snakeCaseErrorName].join('.');
231223
}
232224

233225
/// In-memory representation of error code information obtained from a
@@ -1026,8 +1018,6 @@ class SharedErrorCodeInfo extends CfeStyleErrorCodeInfo {
10261018

10271019
static AnalyzerCode _decodeAnalyzerCode(String s) {
10281020
switch (s.split('.')) {
1029-
case [var errorName] when errorName == errorName.toUpperCase():
1030-
return AnalyzerCode(className: null, snakeCaseErrorName: errorName);
10311021
case [var className, var errorName]
10321022
when errorName == errorName.toUpperCase():
10331023
return AnalyzerCode(
@@ -1036,8 +1026,8 @@ class SharedErrorCodeInfo extends CfeStyleErrorCodeInfo {
10361026
);
10371027
default:
10381028
throw StateError(
1039-
'Analyzer codes must take the form DIAGNOSTIC_NAME or '
1040-
'ClassName.DIAGNOSTIC_NAME. Found ${json.encode(s)} instead.',
1029+
'Analyzer codes must take the form ClassName.DIAGNOSTIC_NAME. Found '
1030+
'${json.encode(s)} instead.',
10411031
);
10421032
}
10431033
}

pkg/front_end/test/messages_suite.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ class MessageTestSuite extends ChainContext {
331331
'analyzerCode should be a string: $value',
332332
);
333333
}
334+
if (value.split('.') case [
335+
_,
336+
var diagnosticName,
337+
] when diagnosticName == diagnosticName.toUpperCase()) {
338+
// ok
339+
} else {
340+
throw new ArgumentError(
341+
'analyzerCode should take the form ClassName.DIAGNOSTIC_NAME',
342+
);
343+
}
334344
analyzerCode = value;
335345
if (!analyzerCodeRequired) {
336346
throw new ArgumentError(

0 commit comments

Comments
 (0)