@@ -299,10 +299,7 @@ abstract class ErrorCodeInfo {
299299
300300 /// A list of [ErrorCodeParameter] objects describing the parameters for this
301301 /// error code, obtained from the `parameters` entry in the yaml file.
302- ///
303- /// If `null` , then there is no `parameters` entry, meaning the error code
304- /// hasn't been translated from the old placeholder format yet.
305- final List <ErrorCodeParameter >? parameters;
302+ final List <ErrorCodeParameter > parameters;
306303
307304 /// The raw YAML node that this `ErrorCodeInfo` was parsed from, or `null` if
308305 /// this `ErrorCodeInfo` was created without reference to a raw YAML node.
@@ -322,7 +319,7 @@ abstract class ErrorCodeInfo {
322319 this .deprecatedMessage,
323320 this .previousName,
324321 this .removedIn,
325- this .parameters,
322+ required this .parameters,
326323 this .yamlNode,
327324 }) {
328325 for (var MapEntry (: key, : value) in {
@@ -364,33 +361,12 @@ abstract class ErrorCodeInfo {
364361 /// Given a messages.yaml entry, come up with a mapping from placeholder
365362 /// patterns in its message strings to their corresponding indices.
366363 Map <String , int > computePlaceholderToIndexMap () {
367- if (parameters case var parameters? ) {
368- // Parameters were explicitly specified, so the mapping is determined by
369- // the order in which they were specified.
370- return {
371- for (var (index, parameter) in parameters.indexed)
372- '#${parameter .name }' : index,
373- };
374- } else {
375- // Parameters are not explicitly specified, so it's necessary to invent a
376- // mapping by searching the problemMessage and correctionMessage for
377- // placeholders.
378- var mapping = < String , int > {};
379- for (var value in [problemMessage, correctionMessage]) {
380- if (value is ! String ) continue ;
381- for (Match match in placeholderPattern.allMatches (value)) {
382- // CFE supports a bunch of formatting options that analyzer doesn't;
383- // make sure none of those are used.
384- if (match.group (0 ) != '#${match .group (1 )}' ) {
385- throw 'Template string ${json .encode (value )} contains unsupported '
386- 'placeholder pattern ${json .encode (match .group (0 ))}' ;
387- }
388-
389- mapping[match.group (0 )! ] ?? = mapping.length;
390- }
391- }
392- return mapping;
393- }
364+ // Parameters are always explicitly specified, so the mapping is determined
365+ // by the order in which they were specified.
366+ return {
367+ for (var (index, parameter) in parameters.indexed)
368+ '#${parameter .name }' : index,
369+ };
394370 }
395371
396372 void outputConstantHeader (StringSink out) {
@@ -420,13 +396,12 @@ abstract class ErrorCodeInfo {
420396 String className;
421397 String templateParameters = '' ;
422398 String ? withArgumentsName;
423- if (parameters != null && parameters .isNotEmpty && ! usesParameters) {
399+ if (parameters.isNotEmpty && ! usesParameters) {
424400 throw StateError (
425401 'Error code declares parameters using a `parameters` entry, but '
426402 "doesn't use them" ,
427403 );
428- } else if (parameters == null ||
429- parameters.any ((p) => ! p.type.isSupportedByAnalyzer)) {
404+ } else if (parameters.any ((p) => ! p.type.isSupportedByAnalyzer)) {
430405 // Do not generate literate API yet.
431406 className = errorClassInfo.name;
432407 } else if (parameters.isNotEmpty) {
@@ -520,7 +495,7 @@ static LocatableDiagnostic $withArgumentsName({$withArgumentsParams}) {
520495 case []:
521496 if (commentLines.isNotEmpty) commentLines.add ('' );
522497 commentLines.add ('No parameters.' );
523- case var parameters ? :
498+ default :
524499 if (commentLines.isNotEmpty) commentLines.add ('' );
525500 commentLines.add ('Parameters:' );
526501 for (var p in parameters) {
@@ -559,14 +534,10 @@ static LocatableDiagnostic $withArgumentsName({$withArgumentsParams}) {
559534 };
560535
561536 String _computeExpectedTypes () {
562- if (parameters case var parameters? ) {
563- var expectedTypes = [
564- for (var parameter in parameters) 'ExpectedType.${parameter .type .name }' ,
565- ];
566- return '[${expectedTypes .join (', ' )}]' ;
567- } else {
568- return 'null' ;
569- }
537+ var expectedTypes = [
538+ for (var parameter in parameters) 'ExpectedType.${parameter .type .name }' ,
539+ ];
540+ return '[${expectedTypes .join (', ' )}]' ;
570541 }
571542
572543 String _encodeString (String s) {
@@ -590,8 +561,10 @@ static LocatableDiagnostic $withArgumentsName({$withArgumentsParams}) {
590561 }
591562 }
592563
593- static List <ErrorCodeParameter >? _decodeParameters (Object ? yaml) {
594- if (yaml == null ) return null ;
564+ static List <ErrorCodeParameter > _decodeParameters (Object ? yaml) {
565+ if (yaml == null ) {
566+ throw StateError ('Missing parameters section' );
567+ }
595568 if (yaml == 'none' ) return const [];
596569 yaml as Map <Object ?, Object ?>;
597570 var result = < ErrorCodeParameter > [];
0 commit comments