33// BSD-style license that can be found in the LICENSE file.
44
55import 'package:analyzer/dart/element/type.dart' ;
6- import 'package:collection/collection.dart' ;
76import 'package:source_helper/source_helper.dart' ;
87
98import '../constants.dart' ;
@@ -18,11 +17,7 @@ class MapHelper extends TypeHelper<TypeHelperContextWithConfig> {
1817 const MapHelper ();
1918
2019 @override
21- String ? serialize (
22- DartType targetType,
23- String expression,
24- TypeHelperContextWithConfig context,
25- ) {
20+ String ? serialize (DartType targetType, String expression, TypeHelperContextWithConfig context) {
2621 if (! coreMapTypeChecker.isAssignableFromType (targetType)) {
2722 return null ;
2823 }
@@ -92,7 +87,7 @@ class MapHelper extends TypeHelper<TypeHelperContextWithConfig> {
9287 // `toDouble` on input values
9388 valueArg.isSimpleJsonTypeNotDouble)) {
9489 // No mapping of the values or null check required!
95- final valueString = valueArg.getDisplayString (withNullability : true );
90+ final valueString = valueArg.getDisplayString ();
9691 return 'Map<String, $valueString >.from($expression as Map)' ;
9792 }
9893 }
@@ -133,14 +128,9 @@ final _intString = ToFromStringHelper('int.parse', 'toString()', 'int');
133128
134129/// [ToFromStringHelper] instances representing non-String types that can
135130/// be used as [Map] keys.
136- final _instances = [
137- bigIntString,
138- dateTimeString,
139- _intString,
140- uriString,
141- ];
131+ final _instances = [bigIntString, dateTimeString, _intString, uriString];
142132
143- ToFromStringHelper ? _forType (DartType type) => _instances.singleWhereOrNull ((i) => i.matches (type));
133+ ToFromStringHelper ? _forType (DartType type) => _instances.where ((i) => i.matches (type)).singleOrNull ;
144134
145135/// Returns `true` if [keyType] can be automatically converted to/from String –
146136/// and is therefor usable as a key in a [Map] .
@@ -155,19 +145,20 @@ void _checkSafeKeyType(String expression, DartType keyArg) {
155145 return ;
156146 }
157147
158- throw UnsupportedTypeError (
159- keyArg,
160- expression,
161- 'Map keys must be one of: ${allowedMapKeyTypes .join (', ' )}.' ,
162- );
148+ throw UnsupportedTypeError (keyArg, expression, 'Map keys must be one of: ${allowedMapKeyTypes .join (', ' )}.' );
163149}
164150
165151/// The names of types that can be used as [Map] keys.
166152///
167153/// Used in [_checkSafeKeyType] to provide a helpful error with unsupported
168154/// types.
169- List <String > get allowedMapKeyTypes =>
170- ['Object' , 'dynamic' , 'enum' , 'String' , ..._instances.map ((i) => i.coreTypeName)];
155+ List <String > get allowedMapKeyTypes => [
156+ 'Object' ,
157+ 'dynamic' ,
158+ 'enum' ,
159+ 'String' ,
160+ ..._instances.map ((i) => i.coreTypeName),
161+ ];
171162
172163extension on DartType {
173164 bool get isSimpleJsonTypeNotDouble => ! isDartCoreDouble && simpleJsonTypeChecker.isAssignableFromType (this );
0 commit comments