diff --git a/json_annotation/CHANGELOG.md b/json_annotation/CHANGELOG.md index 99086f891..14c1969d9 100644 --- a/json_annotation/CHANGELOG.md +++ b/json_annotation/CHANGELOG.md @@ -1,7 +1,8 @@ -## 4.0.1-dev +## 4.0.1 - Fix a potential error with `checked: true` when `ArgumentError.message` is `null`. +- Updated `JsonSerializable.fromJson` to handle `null` values. ## 4.0.0 diff --git a/json_annotation/lib/src/json_serializable.g.dart b/json_annotation/lib/src/json_serializable.g.dart index 4aa268cb6..7606a71ff 100644 --- a/json_annotation/lib/src/json_serializable.g.dart +++ b/json_annotation/lib/src/json_serializable.g.dart @@ -18,24 +18,25 @@ JsonSerializable _$JsonSerializableFromJson(Map json) { 'field_rename', 'generic_argument_factories', 'ignore_unannotated', - 'include_if_null', + 'include_if_null' ]); final val = JsonSerializable( - anyMap: $checkedConvert(json, 'any_map', (v) => v as bool), - checked: $checkedConvert(json, 'checked', (v) => v as bool), - createFactory: $checkedConvert(json, 'create_factory', (v) => v as bool), - createToJson: $checkedConvert(json, 'create_to_json', (v) => v as bool), - disallowUnrecognizedKeys: - $checkedConvert(json, 'disallow_unrecognized_keys', (v) => v as bool), + anyMap: $checkedConvert(json, 'any_map', (v) => v as bool?), + checked: $checkedConvert(json, 'checked', (v) => v as bool?), + createFactory: $checkedConvert(json, 'create_factory', (v) => v as bool?), + createToJson: $checkedConvert(json, 'create_to_json', (v) => v as bool?), + disallowUnrecognizedKeys: $checkedConvert( + json, 'disallow_unrecognized_keys', (v) => v as bool?), explicitToJson: - $checkedConvert(json, 'explicit_to_json', (v) => v as bool), + $checkedConvert(json, 'explicit_to_json', (v) => v as bool?), fieldRename: $checkedConvert(json, 'field_rename', (v) => _$enumDecodeNullable(_$FieldRenameEnumMap, v)), ignoreUnannotated: - $checkedConvert(json, 'ignore_unannotated', (v) => v as bool), - includeIfNull: $checkedConvert(json, 'include_if_null', (v) => v as bool), - genericArgumentFactories: - $checkedConvert(json, 'generic_argument_factories', (v) => v as bool), + $checkedConvert(json, 'ignore_unannotated', (v) => v as bool?), + includeIfNull: + $checkedConvert(json, 'include_if_null', (v) => v as bool?), + genericArgumentFactories: $checkedConvert( + json, 'generic_argument_factories', (v) => v as bool?), ); return val; }, fieldKeyMap: const { @@ -65,37 +66,41 @@ Map _$JsonSerializableToJson(JsonSerializable instance) => 'include_if_null': instance.includeIfNull, }; -T _$enumDecode( - Map enumValues, - dynamic source, { - T? unknownValue, +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, }) { if (source == null) { - throw ArgumentError('A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}'); + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); } - final value = enumValues.entries - .cast?>() - .singleWhere((e) => e!.value == source, orElse: () => null) - ?.key; - - if (value == null && unknownValue == null) { - throw ArgumentError('`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}'); - } - return value ?? unknownValue!; + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; } -T? _$enumDecodeNullable( - Map enumValues, +K? _$enumDecodeNullable( + Map enumValues, dynamic source, { - T? unknownValue, + K? unknownValue, }) { if (source == null) { return null; } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); + return _$enumDecode(enumValues, source, unknownValue: unknownValue); } const _$FieldRenameEnumMap = { diff --git a/json_annotation/pubspec.yaml b/json_annotation/pubspec.yaml index 7879496a9..62e04e7ba 100644 --- a/json_annotation/pubspec.yaml +++ b/json_annotation/pubspec.yaml @@ -1,5 +1,5 @@ name: json_annotation -version: 4.0.1-dev +version: 4.0.1 description: >- Classes and helper functions that support JSON code generation via the `json_serializable` package. @@ -10,4 +10,4 @@ environment: # When changing JsonSerializable class. # dev_dependencies: # build_runner: ^1.0.0 -# json_serializable: ^3.1.0 +# json_serializable: ^4.0.0 diff --git a/json_serializable/CHANGELOG.md b/json_serializable/CHANGELOG.md index 0a4595685..bcc29a002 100644 --- a/json_serializable/CHANGELOG.md +++ b/json_serializable/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.0-dev + +- Implementation is now null-safe. + ## 4.0.3 - Correctly handle nullable values with `genericArgumentFactories`. diff --git a/json_serializable/example/example.dart b/json_serializable/example/example.dart index 025ae5459..28d252925 100644 --- a/json_serializable/example/example.dart +++ b/json_serializable/example/example.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'example.g.dart'; diff --git a/json_serializable/example/example.g.dart b/json_serializable/example/example.g.dart index b5d4ad39e..a01e08473 100644 --- a/json_serializable/example/example.g.dart +++ b/json_serializable/example/example.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'example.dart'; diff --git a/json_serializable/lib/builder.dart b/json_serializable/lib/builder.dart index cd9014e26..c66e3df21 100644 --- a/json_serializable/lib/builder.dart +++ b/json_serializable/lib/builder.dart @@ -34,7 +34,7 @@ Builder jsonSerializable(BuilderOptions options) { lines.add('There is a problem with "${e.key}".'); } if (e.message != null) { - lines.add(e.message); + lines.add(e.message!); } else if (e.innerError != null) { lines.add(e.innerError.toString()); } diff --git a/json_serializable/lib/src/decode_helper.dart b/json_serializable/lib/src/decode_helper.dart index 12002a865..f6bed5954 100644 --- a/json_serializable/lib/src/decode_helper.dart +++ b/json_serializable/lib/src/decode_helper.dart @@ -25,15 +25,15 @@ abstract class DecodeHelper implements HelperCore { Map accessibleFields, Map unavailableReasons, ) { - assert(config.createFactory); + assert(config.createFactory!); final buffer = StringBuffer(); - final mapType = config.anyMap ? 'Map' : 'Map'; + final mapType = config.anyMap! ? 'Map' : 'Map'; buffer.write('$targetClassReference ' '${prefix}FromJson${genericClassArgumentsImpl(true)}' '($mapType json'); - if (config.genericArgumentFactories) { + if (config.genericArgumentFactories!) { for (var arg in element.typeParameters) { final helperName = fromJsonForType( arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), @@ -49,8 +49,8 @@ abstract class DecodeHelper implements HelperCore { buffer.write(') {\n'); String deserializeFun(String paramOrFieldName, - {ParameterElement ctorParam}) => - _deserializeForField(accessibleFields[paramOrFieldName], + {ParameterElement? ctorParam}) => + _deserializeForField(accessibleFields[paramOrFieldName]!, ctorParam: ctorParam); final data = _writeConstructorInvocation( @@ -72,7 +72,7 @@ abstract class DecodeHelper implements HelperCore { final checks = _checkKeys(accessibleFields.values .where((fe) => data.usedCtorParamsAndFields.contains(fe.name))); - if (config.checked) { + if (config.checked!) { final classLiteral = escapeDartString(element.name); buffer..write(''' @@ -84,12 +84,12 @@ abstract class DecodeHelper implements HelperCore { for (final field in data.fieldsToSet) { buffer.writeln(); - final safeName = safeNameAccess(accessibleFields[field]); + final safeName = safeNameAccess(accessibleFields[field]!); buffer ..write(''' \$checkedConvert(json, $safeName, (v) => ''') ..write('val.$field = ') - ..write(_deserializeForField(accessibleFields[field], + ..write(_deserializeForField(accessibleFields[field]!, checkedProperty: true)) ..write(');'); } @@ -98,7 +98,7 @@ abstract class DecodeHelper implements HelperCore { }'''); final fieldKeyMap = Map.fromEntries(data.usedCtorParamsAndFields - .map((k) => MapEntry(k, nameAccess(accessibleFields[k]))) + .map((k) => MapEntry(k, nameAccess(accessibleFields[k]!))) .where((me) => me.key != me.value)); String fieldKeyMapArg; @@ -131,14 +131,14 @@ abstract class DecodeHelper implements HelperCore { String constantList(Iterable things) => 'const ${jsonLiteralAsDart(things.map(nameAccess).toList())}'; - if (config.disallowUnrecognizedKeys) { + if (config.disallowUnrecognizedKeys!) { final allowKeysLiteral = constantList(accessibleFields); args.add('allowedKeys: $allowKeysLiteral'); } final requiredKeys = - accessibleFields.where((fe) => jsonKeyFor(fe).required).toList(); + accessibleFields.where((fe) => jsonKeyFor(fe).required!).toList(); if (requiredKeys.isNotEmpty) { final requiredKeyLiteral = constantList(requiredKeys); @@ -146,7 +146,7 @@ abstract class DecodeHelper implements HelperCore { } final disallowNullKeys = accessibleFields - .where((fe) => jsonKeyFor(fe).disallowNullValue) + .where((fe) => jsonKeyFor(fe).disallowNullValue!) .toList(); if (disallowNullKeys.isNotEmpty) { final disallowNullKeyLiteral = constantList(disallowNullKeys); @@ -163,10 +163,9 @@ abstract class DecodeHelper implements HelperCore { String _deserializeForField( FieldElement field, { - ParameterElement ctorParam, - bool checkedProperty, + ParameterElement? ctorParam, + bool checkedProperty = false, }) { - checkedProperty ??= false; final jsonKeyName = safeNameAccess(field); final targetType = ctorParam?.type ?? field.type; final contextHelper = getHelperContext(field); @@ -174,7 +173,7 @@ abstract class DecodeHelper implements HelperCore { String value; try { - if (config.checked) { + if (config.checked!) { value = contextHelper .deserialize( targetType, @@ -205,7 +204,7 @@ abstract class DecodeHelper implements HelperCore { final jsonKey = jsonKeyFor(field); final defaultValue = jsonKey.defaultValue; if (defaultValue != null) { - if (jsonKey.disallowNullValue && jsonKey.required) { + if (jsonKey.disallowNullValue! && jsonKey.required!) { log.warning('The `defaultValue` on field `${field.name}` will have no ' 'effect because both `disallowNullValue` and `required` are set to ' '`true`.'); diff --git a/json_serializable/lib/src/encoder_helper.dart b/json_serializable/lib/src/encoder_helper.dart index 6ea548781..c11773a3f 100644 --- a/json_serializable/lib/src/encoder_helper.dart +++ b/json_serializable/lib/src/encoder_helper.dart @@ -17,7 +17,7 @@ abstract class EncodeHelper implements HelperCore { String _fieldAccess(FieldElement field) => '$_toJsonParamName.${field.name}'; Iterable createToJson(Set accessibleFields) sync* { - assert(config.createToJson); + assert(config.createToJson!); final buffer = StringBuffer(); @@ -25,7 +25,7 @@ abstract class EncodeHelper implements HelperCore { buffer.write('Map ' '$functionName($targetClassReference $_toJsonParamName'); - if (config.genericArgumentFactories) { + if (config.genericArgumentFactories!) { for (var arg in element.typeParameters) { final helperName = toJsonForType( arg.instantiate(nullabilitySuffix: NullabilitySuffix.none), @@ -140,7 +140,7 @@ abstract class EncodeHelper implements HelperCore { bool _writeJsonValueNaive(FieldElement field) { final jsonKey = jsonKeyFor(field); - return jsonKey.includeIfNull || + return jsonKey.includeIfNull! || (!field.type.isNullableType && !_fieldHasCustomEncoder(field)); } diff --git a/json_serializable/lib/src/field_helpers.dart b/json_serializable/lib/src/field_helpers.dart index 932c43df5..83b293c90 100644 --- a/json_serializable/lib/src/field_helpers.dart +++ b/json_serializable/lib/src/field_helpers.dart @@ -17,9 +17,9 @@ class _FieldSet implements Comparable<_FieldSet> { _FieldSet._(this.field, this.sortField) : assert(field.name == sortField.name); - factory _FieldSet(FieldElement classField, FieldElement superField) { + factory _FieldSet(FieldElement? classField, FieldElement? superField) { // At least one of these will != null, perhaps both. - final fields = [classField, superField].where((fe) => fe != null).toList(); + final fields = [classField, superField].whereType().toList(); // Prefer the class field over the inherited field when sorting. final sortField = fields.first; @@ -58,9 +58,9 @@ class _FieldSet implements Comparable<_FieldSet> { /// Returns the offset of given field/property in its source file – with a /// preference for the getter if it's defined. int _offsetFor(FieldElement e) { - if (e.getter != null && e.getter.nameOffset != e.nameOffset) { + if (e.getter != null && e.getter!.nameOffset != e.nameOffset) { assert(e.nameOffset == -1); - return e.getter.nameOffset; + return e.getter!.nameOffset; } return e.nameOffset; } diff --git a/json_serializable/lib/src/generator_helper.dart b/json_serializable/lib/src/generator_helper.dart index 011fd46d3..95c7d1e36 100644 --- a/json_serializable/lib/src/generator_helper.dart +++ b/json_serializable/lib/src/generator_helper.dart @@ -41,7 +41,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { Iterable generate() sync* { assert(_addedMembers.isEmpty); - if (config.genericArgumentFactories && element.typeParameters.isEmpty) { + if (config.genericArgumentFactories! && element.typeParameters.isEmpty) { log.warning( 'The class `${element.displayName}` is annotated ' 'with `JsonSerializable` field `genericArgumentFactories: true`. ' @@ -68,7 +68,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { unavailableReasons[field.name] = 'Setter-only properties are not supported.'; log.warning('Setters are ignored: ${element.name}.${field.name}'); - } else if (jsonKeyFor(field).ignore) { + } else if (jsonKeyFor(field).ignore!) { unavailableReasons[field.name] = 'It is assigned to an ignored field.'; } else { @@ -81,7 +81,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { ); var accessibleFieldSet = accessibleFields.values.toSet(); - if (config.createFactory) { + if (config.createFactory!) { final createResult = createFactory(accessibleFields, unavailableReasons); yield createResult.output; @@ -108,7 +108,7 @@ class GeneratorHelper extends HelperCore with EncodeHelper, DecodeHelper { }, ); - if (config.createToJson) { + if (config.createToJson!) { yield* createToJson(accessibleFieldSet); } diff --git a/json_serializable/lib/src/helper_core.dart b/json_serializable/lib/src/helper_core.dart index 4e389f58e..20eb2fb7b 100644 --- a/json_serializable/lib/src/helper_core.dart +++ b/json_serializable/lib/src/helper_core.dart @@ -30,7 +30,7 @@ abstract class HelperCore { '${element.name}${genericClassArgumentsImpl(false)}'; @protected - String nameAccess(FieldElement field) => jsonKeyFor(field).name; + String nameAccess(FieldElement field) => jsonKeyFor(field).name!; @protected String safeNameAccess(FieldElement field) => @@ -62,7 +62,7 @@ InvalidGenerationSourceError createInvalidGenerationError( ) { var message = 'Could not generate `$targetMember` code for `${field.name}`'; - String todo; + String? todo; if (error.type is TypeParameterType) { message = '$message because of type ' '`${error.type.getDisplayString(withNullability: false)}` (type parameter)'; @@ -76,7 +76,7 @@ $converterOrKeyInstructions message = '$message because of type `${typeToCode(error.type)}`'; } else { todo = ''' -To support the type `${error.type.element.name}` you can: +To support the type `${error.type.element!.name}` you can: $converterOrKeyInstructions'''; } @@ -112,13 +112,13 @@ $converterOrKeyInstructions'''; /// ``` /// "" /// ``` -String genericClassArguments(ClassElement element, bool withConstraints) { +String genericClassArguments(ClassElement element, bool? withConstraints) { if (withConstraints == null || element.typeParameters.isEmpty) { return ''; } final values = element.typeParameters.map((t) { if (withConstraints && t.bound != null) { - final boundCode = typeToCode(t.bound); + final boundCode = typeToCode(t.bound!); return '${t.name} extends $boundCode'; } else { return t.name; diff --git a/json_serializable/lib/src/json_key_utils.dart b/json_serializable/lib/src/json_key_utils.dart index 0a51473c4..cde0bf487 100644 --- a/json_serializable/lib/src/json_key_utils.dart +++ b/json_serializable/lib/src/json_key_utils.dart @@ -34,7 +34,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { /// Returns a literal value for [dartObject] if possible, otherwise throws /// an [InvalidGenerationSourceError] using [typeInformation] to describe /// the unsupported type. - Object literalForObject( + Object? literalForObject( DartObject dartObject, Iterable typeInformation, ) { @@ -44,7 +44,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { final reader = ConstantReader(dartObject); - String badType; + String? badType; if (reader.isSymbol) { badType = 'Symbol'; } else if (reader.isType) { @@ -53,7 +53,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { // TODO: Support calling function for the default value? badType = 'Function'; } else if (!reader.isLiteral) { - badType = dartObject.type.element.name; + badType = dartObject.type!.element!.name; } if (badType != null) { @@ -93,8 +93,8 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { ]; return reader.mapValue.map( (k, v) => MapEntry( - literalForObject(k, mapTypeInformation), - literalForObject(v, mapTypeInformation), + literalForObject(k!, mapTypeInformation), + literalForObject(v!, mapTypeInformation), ), ); } @@ -114,15 +114,15 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { /// If [mustBeEnum] is `true`, throws an [InvalidGenerationSourceError] if /// either the annotated field is not an `enum` or `List` or if the value in /// [fieldName] is not an `enum` value. - Object _annotationValue(String fieldName, {bool mustBeEnum = false}) { + Object? _annotationValue(String fieldName, {bool mustBeEnum = false}) { final annotationValue = obj.read(fieldName); final enumFields = annotationValue.isNull ? null - : iterateEnumFields(annotationValue.objectValue.type); + : iterateEnumFields(annotationValue.objectValue.type!); if (enumFields != null) { if (mustBeEnum) { - DartType targetEnumType; + late DartType targetEnumType; if (isEnum(element.type)) { targetEnumType = element.type; } else if (coreIterableTypeChecker.isAssignableFromType(element.type)) { @@ -134,8 +134,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { 'Iterable, List, or Set instances of an enum type.', ); } - assert(targetEnumType != null); - final annotatedEnumType = annotationValue.objectValue.type; + final annotatedEnumType = annotationValue.objectValue.type!; if (!_interfaceTypesEqual(annotatedEnumType, targetEnumType)) { throwUnsupported( element, @@ -153,7 +152,7 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { final enumValueName = enumValueForDartObject( annotationValue.objectValue, enumValueNames, (n) => n); - return '${annotationValue.objectValue.type.element.name}.$enumValueName'; + return '${annotationValue.objectValue.type!.element!.name}.$enumValueName'; } else { final defaultValueLiteral = annotationValue.isNull ? null @@ -175,11 +174,11 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { classAnnotation, element, defaultValue: _annotationValue('defaultValue'), - disallowNullValue: obj.read('disallowNullValue').literalValue as bool, - ignore: obj.read('ignore').literalValue as bool, - includeIfNull: obj.read('includeIfNull').literalValue as bool, - name: obj.read('name').literalValue as String, - required: obj.read('required').literalValue as bool, + disallowNullValue: obj.read('disallowNullValue').literalValue as bool?, + ignore: obj.read('ignore').literalValue as bool?, + includeIfNull: obj.read('includeIfNull').literalValue as bool?, + name: obj.read('name').literalValue as String?, + required: obj.read('required').literalValue as bool?, unknownEnumValue: _annotationValue('unknownEnumValue', mustBeEnum: true), ); } @@ -187,13 +186,13 @@ JsonKey _from(FieldElement element, JsonSerializable classAnnotation) { JsonKey _populateJsonKey( JsonSerializable classAnnotation, FieldElement element, { - Object defaultValue, - bool disallowNullValue, - bool ignore, - bool includeIfNull, - String name, - bool required, - Object unknownEnumValue, + Object? defaultValue, + bool? disallowNullValue, + bool? ignore, + bool? includeIfNull, + String? name, + bool? required, + Object? unknownEnumValue, }) { if (disallowNullValue == true) { if (includeIfNull == true) { @@ -218,8 +217,11 @@ JsonKey _populateJsonKey( return jsonKey; } -String _encodedFieldName(JsonSerializable classAnnotation, - String jsonKeyNameValue, FieldElement fieldElement) { +String _encodedFieldName( + JsonSerializable classAnnotation, + String? jsonKeyNameValue, + FieldElement fieldElement, +) { if (jsonKeyNameValue != null) { return jsonKeyNameValue; } @@ -233,20 +235,20 @@ String _encodedFieldName(JsonSerializable classAnnotation, return kebabCase(fieldElement.name); case FieldRename.pascal: return pascalCase(fieldElement.name); + default: + throw ArgumentError.value( + classAnnotation, + 'classAnnotation', + 'The provided `fieldRename` (${classAnnotation.fieldRename}) is not ' + 'supported.', + ); } - - throw ArgumentError.value( - classAnnotation, - 'classAnnotation', - 'The provided `fieldRename` (${classAnnotation.fieldRename}) is not ' - 'supported.', - ); } -bool _includeIfNull( - bool keyIncludeIfNull, - bool keyDisallowNullValue, - bool classIncludeIfNull, +bool? _includeIfNull( + bool? keyIncludeIfNull, + bool? keyDisallowNullValue, + bool? classIncludeIfNull, ) { if (keyDisallowNullValue == true) { assert(keyIncludeIfNull != true); diff --git a/json_serializable/lib/src/json_part_builder.dart b/json_serializable/lib/src/json_part_builder.dart index 1bf2d38f3..8cc040444 100644 --- a/json_serializable/lib/src/json_part_builder.dart +++ b/json_serializable/lib/src/json_part_builder.dart @@ -16,8 +16,8 @@ import 'settings.dart'; /// [formatOutput] is called to format the generated code. If not provided, /// the default Dart code formatter is used. Builder jsonPartBuilder({ - String Function(String code) formatOutput, - JsonSerializable config, + String Function(String code)? formatOutput, + JsonSerializable? config, }) { final settings = Settings(config: config); diff --git a/json_serializable/lib/src/json_serializable_generator.dart b/json_serializable/lib/src/json_serializable_generator.dart index e0894c58a..0513a7716 100644 --- a/json_serializable/lib/src/json_serializable_generator.dart +++ b/json_serializable/lib/src/json_serializable_generator.dart @@ -30,8 +30,8 @@ class JsonSerializableGenerator /// [BigIntHelper], [DateTimeHelper], [DurationHelper], [JsonHelper], and /// [UriHelper]. factory JsonSerializableGenerator({ - JsonSerializable config, - List typeHelpers, + JsonSerializable? config, + List? typeHelpers, }) => JsonSerializableGenerator.fromSettings(Settings( config: config, @@ -46,7 +46,7 @@ class JsonSerializableGenerator /// [UriHelper]. factory JsonSerializableGenerator.withDefaultHelpers( Iterable typeHelpers, { - JsonSerializable config, + JsonSerializable? config, }) => JsonSerializableGenerator( config: config, @@ -61,7 +61,7 @@ class JsonSerializableGenerator ConstantReader annotation, BuildStep buildStep, ) { - if (!element.library.isNonNullableByDefault) { + if (!element.library!.isNonNullableByDefault) { throw InvalidGenerationSourceError( 'Generator cannot target libraries that have not been migrated to ' 'null-safety.', @@ -76,8 +76,7 @@ class JsonSerializableGenerator ); } - final classElement = element as ClassElement; - final helper = GeneratorHelper(_settings, classElement, annotation); + final helper = GeneratorHelper(_settings, element, annotation); return helper.generate(); } } diff --git a/json_serializable/lib/src/settings.dart b/json_serializable/lib/src/settings.dart index 50b6639de..5d9e3ea40 100644 --- a/json_serializable/lib/src/settings.dart +++ b/json_serializable/lib/src/settings.dart @@ -52,8 +52,8 @@ class Settings { /// [BigIntHelper], [DateTimeHelper], [DurationHelper], [JsonHelper], and /// [UriHelper]. const Settings({ - JsonSerializable config, - List typeHelpers, + JsonSerializable? config, + List? typeHelpers, }) : _config = config ?? JsonSerializable.defaults, _typeHelpers = typeHelpers ?? defaultHelpers; @@ -65,7 +65,7 @@ class Settings { /// [UriHelper]. factory Settings.withDefaultHelpers( Iterable typeHelpers, { - JsonSerializable config, + JsonSerializable? config, }) => Settings( config: config, diff --git a/json_serializable/lib/src/shared_checkers.dart b/json_serializable/lib/src/shared_checkers.dart index 0f4a6dca3..40a78cc1e 100644 --- a/json_serializable/lib/src/shared_checkers.dart +++ b/json_serializable/lib/src/shared_checkers.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; +import 'package:collection/collection.dart'; import 'package:source_gen/source_gen.dart' show TypeChecker; import 'helper_core.dart'; @@ -28,7 +29,7 @@ DartType coreIterableGenericType(DartType type) => List typeArgumentsOf(DartType type, TypeChecker checker) { final implementation = _getImplementationType(type, checker) as InterfaceType; - return implementation?.typeArguments; + return implementation.typeArguments; } /// A [TypeChecker] for [String], [bool] and [num]. @@ -79,11 +80,10 @@ Iterable typeImplementations(DartType type) sync* { yield* type.mixins.expand(typeImplementations); if (type.superclass != null) { - yield* typeImplementations(type.superclass); + yield* typeImplementations(type.superclass!); } } } -DartType _getImplementationType(DartType type, TypeChecker checker) => - typeImplementations(type) - .firstWhere(checker.isExactlyType, orElse: () => null); +DartType? _getImplementationType(DartType type, TypeChecker checker) => + typeImplementations(type).firstWhereOrNull(checker.isExactlyType); diff --git a/json_serializable/lib/src/type_helper.dart b/json_serializable/lib/src/type_helper.dart index af0c1167c..3d7e10f5a 100644 --- a/json_serializable/lib/src/type_helper.dart +++ b/json_serializable/lib/src/type_helper.dart @@ -17,11 +17,11 @@ abstract class TypeHelperContext { /// [expression] may be just the name of the field or it may an expression /// representing the serialization of a value. - Object serialize(DartType fieldType, String expression); + Object? serialize(DartType fieldType, String expression); /// [expression] may be just the name of the field or it may an expression /// representing the serialization of a value. - Object deserialize(DartType fieldType, String expression); + Object? deserialize(DartType fieldType, String expression); /// Adds [memberContent] to the set of generated, top-level members. void addMember(String memberContent); @@ -51,7 +51,7 @@ abstract class TypeHelper { /// String serialize(DartType targetType, String expression) => /// "$expression.id"; /// ```. - Object serialize(DartType targetType, String expression, T context); + Object? serialize(DartType targetType, String expression, T context); /// Returns Dart code that deserializes an [expression] representing a JSON /// literal to into [targetType]. @@ -76,7 +76,7 @@ abstract class TypeHelper { /// String deserialize(DartType targetType, String expression) => /// "new ${targetType.name}.fromInt($expression)"; /// ```. - Object deserialize( + Object? deserialize( DartType targetType, String expression, T context, diff --git a/json_serializable/lib/src/type_helper_ctx.dart b/json_serializable/lib/src/type_helper_ctx.dart index cd1efaff5..ab1fff795 100644 --- a/json_serializable/lib/src/type_helper_ctx.dart +++ b/json_serializable/lib/src/type_helper_ctx.dart @@ -6,7 +6,6 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; -import 'package:meta/meta.dart'; import 'helper_core.dart'; import 'type_helper.dart'; @@ -34,10 +33,10 @@ class TypeHelperCtx TypeHelperCtx._(this._helperCore, this.fieldElement); @override - ConvertData get serializeConvertData => _pairFromContext?.toJson; + ConvertData? get serializeConvertData => _pairFromContext.toJson; @override - ConvertData get deserializeConvertData => _pairFromContext?.fromJson; + ConvertData? get deserializeConvertData => _pairFromContext.fromJson; _ConvertPair get _pairFromContext => _ConvertPair(fieldElement); @@ -47,17 +46,17 @@ class TypeHelperCtx } @override - Object serialize(DartType targetType, String expression) => _run( + Object? serialize(DartType targetType, String expression) => _run( targetType, expression, (TypeHelper th) => th.serialize(targetType, expression, this), ); @override - Object deserialize( + Object? deserialize( DartType targetType, String expression, { - @required bool defaultProvided, + bool defaultProvided = false, }) => _run( targetType, @@ -66,25 +65,25 @@ class TypeHelperCtx targetType, expression, this, - defaultProvided ?? false, + defaultProvided, ), ); Object _run( DartType targetType, String expression, - Object Function(TypeHelper) invoke, + Object? Function(TypeHelper) invoke, ) => _helperCore.allTypeHelpers.map(invoke).firstWhere( (r) => r != null, orElse: () => throw UnsupportedTypeError(targetType, expression), - ); + ) as Object; } class _ConvertPair { static final _expando = Expando<_ConvertPair>(); - final ConvertData fromJson, toJson; + final ConvertData? fromJson, toJson; _ConvertPair._(this.fromJson, this.toJson); @@ -106,7 +105,7 @@ class _ConvertPair { } } -ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { +ConvertData? _convertData(DartObject obj, FieldElement element, bool isFrom) { final paramName = isFrom ? 'fromJson' : 'toJson'; final objectValue = obj.getField(paramName); @@ -114,7 +113,7 @@ ConvertData _convertData(DartObject obj, FieldElement element, bool isFrom) { return null; } - final executableElement = objectValue.toFunctionValue(); + final executableElement = objectValue.toFunctionValue()!; if (executableElement.parameters.isEmpty || executableElement.parameters.first.isNamed || diff --git a/json_serializable/lib/src/type_helpers/big_int_helper.dart b/json_serializable/lib/src/type_helpers/big_int_helper.dart index 4a4166d91..b2da21a27 100644 --- a/json_serializable/lib/src/type_helpers/big_int_helper.dart +++ b/json_serializable/lib/src/type_helpers/big_int_helper.dart @@ -12,7 +12,7 @@ class BigIntHelper extends TypeHelper { const BigIntHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContext context, @@ -24,7 +24,7 @@ class BigIntHelper extends TypeHelper { ); @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/lib/src/type_helpers/convert_helper.dart b/json_serializable/lib/src/type_helpers/convert_helper.dart index b605c5c4d..8d31f9863 100644 --- a/json_serializable/lib/src/type_helpers/convert_helper.dart +++ b/json_serializable/lib/src/type_helpers/convert_helper.dart @@ -18,16 +18,16 @@ class ConvertData { } abstract class TypeHelperContextWithConvert extends TypeHelperContext { - ConvertData get serializeConvertData; + ConvertData? get serializeConvertData; - ConvertData get deserializeConvertData; + ConvertData? get deserializeConvertData; } class ConvertHelper extends TypeHelper { const ConvertHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContextWithConvert context, @@ -43,7 +43,7 @@ class ConvertHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContextWithConvert context, diff --git a/json_serializable/lib/src/type_helpers/date_time_helper.dart b/json_serializable/lib/src/type_helpers/date_time_helper.dart index beefd0065..d97bc17ac 100644 --- a/json_serializable/lib/src/type_helpers/date_time_helper.dart +++ b/json_serializable/lib/src/type_helpers/date_time_helper.dart @@ -12,7 +12,7 @@ class DateTimeHelper extends TypeHelper { const DateTimeHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContext context, @@ -24,7 +24,7 @@ class DateTimeHelper extends TypeHelper { ); @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/lib/src/type_helpers/duration_helper.dart b/json_serializable/lib/src/type_helpers/duration_helper.dart index 95acda21a..cf597a6be 100644 --- a/json_serializable/lib/src/type_helpers/duration_helper.dart +++ b/json_serializable/lib/src/type_helpers/duration_helper.dart @@ -12,7 +12,7 @@ class DurationHelper extends TypeHelper { const DurationHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContext context, @@ -33,7 +33,7 @@ class DurationHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/lib/src/type_helpers/enum_helper.dart b/json_serializable/lib/src/type_helpers/enum_helper.dart index f12c54740..c3aa4ba31 100644 --- a/json_serializable/lib/src/type_helpers/enum_helper.dart +++ b/json_serializable/lib/src/type_helpers/enum_helper.dart @@ -15,7 +15,7 @@ class EnumHelper extends TypeHelper { const EnumHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -32,7 +32,7 @@ class EnumHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -69,9 +69,9 @@ class EnumHelper extends TypeHelper { } String _constMapName(DartType targetType) => - '_\$${targetType.element.name}EnumMap'; + '_\$${targetType.element!.name}EnumMap'; -String _enumValueMapFromType(DartType targetType) { +String? _enumValueMapFromType(DartType targetType) { final enumMap = enumFieldsMap(targetType); if (enumMap == null) { @@ -79,7 +79,7 @@ String _enumValueMapFromType(DartType targetType) { } final items = enumMap.entries - .map((e) => ' ${targetType.element.name}.${e.key.name}: ' + .map((e) => ' ${targetType.element!.name}.${e.key.name}: ' '${jsonLiteralAsDart(e.value)},') .join(); diff --git a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart index a8f8dc88c..8227065f4 100644 --- a/json_serializable/lib/src/type_helpers/generic_factory_helper.dart +++ b/json_serializable/lib/src/type_helpers/generic_factory_helper.dart @@ -11,12 +11,12 @@ class GenericFactoryHelper extends TypeHelper { const GenericFactoryHelper(); @override - Object serialize( + Object? serialize( DartType targetType, String expression, TypeHelperContextWithConfig context, ) { - if (context.config.genericArgumentFactories && + if (context.config.genericArgumentFactories! && targetType is TypeParameterType) { return LambdaResult(expression, toJsonForType(targetType)); } @@ -25,13 +25,13 @@ class GenericFactoryHelper extends TypeHelper { } @override - Object deserialize( + Object? deserialize( DartType targetType, String expression, TypeHelperContextWithConfig context, bool defaultProvided, ) { - if (context.config.genericArgumentFactories && + if (context.config.genericArgumentFactories! && targetType is TypeParameterType) { return LambdaResult(expression, fromJsonForType(targetType)); } diff --git a/json_serializable/lib/src/type_helpers/iterable_helper.dart b/json_serializable/lib/src/type_helpers/iterable_helper.dart index 53f2fcf69..4c26fb42e 100644 --- a/json_serializable/lib/src/type_helpers/iterable_helper.dart +++ b/json_serializable/lib/src/type_helpers/iterable_helper.dart @@ -15,7 +15,7 @@ class IterableHelper extends TypeHelper { const IterableHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -30,7 +30,7 @@ class IterableHelper extends TypeHelper { // Although it's possible that child elements may be marked unsafe var isList = _coreListChecker.isAssignableFromType(targetType); - final subField = context.serialize(itemType, closureArg); + final subField = context.serialize(itemType, closureArg)!; var optionalQuestion = targetType.isNullableType ? '?' : ''; @@ -59,7 +59,7 @@ class IterableHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContext context, @@ -73,7 +73,7 @@ class IterableHelper extends TypeHelper { final iterableGenericType = coreIterableGenericType(targetType); - final itemSubVal = context.deserialize(iterableGenericType, closureArg); + final itemSubVal = context.deserialize(iterableGenericType, closureArg)!; var output = '$expression as List'; diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index f1f2bdfd1..9c9044f40 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -20,7 +21,7 @@ class JsonConverterHelper extends TypeHelper { const JsonConverterHelper(); @override - Object serialize( + Object? serialize( DartType targetType, String expression, TypeHelperContext context, @@ -35,7 +36,7 @@ class JsonConverterHelper extends TypeHelper { } @override - Object deserialize( + Object? deserialize( DartType targetType, String expression, TypeHelperContext context, @@ -76,10 +77,10 @@ class _JsonConvertData { accessor.isEmpty ? '' : '.$accessor'; } -_JsonConvertData _typeConverter(DartType targetType, TypeHelperContext ctx) { +_JsonConvertData? _typeConverter(DartType targetType, TypeHelperContext ctx) { List<_ConverterMatch> converterMatches(List items) => items .map((annotation) => _compatibleMatch(targetType, annotation)) - .where((dt) => dt != null) + .whereType<_ConverterMatch>() .toList(); var matchingAnnotations = converterMatches(ctx.fieldElement.metadata); @@ -96,7 +97,7 @@ _JsonConvertData _typeConverter(DartType targetType, TypeHelperContext ctx) { return _typeConverterFrom(matchingAnnotations, targetType); } -_JsonConvertData _typeConverterFrom( +_JsonConvertData? _typeConverterFrom( List<_ConverterMatch> matchingAnnotations, DartType targetType, ) { @@ -137,15 +138,15 @@ _JsonConvertData _typeConverterFrom( if (match.genericTypeArg != null) { return _JsonConvertData.genericClass( - match.annotation.type.element.name, - match.genericTypeArg, + match.annotation.type!.element!.name!, + match.genericTypeArg!, reviver.accessor, match.jsonType, ); } return _JsonConvertData.className( - match.annotation.type.element.name, + match.annotation.type!.element!.name!, reviver.accessor, match.jsonType, ); @@ -155,7 +156,7 @@ class _ConverterMatch { final DartObject annotation; final DartType jsonType; final ElementAnnotation elementAnnotation; - final String genericTypeArg; + final String? genericTypeArg; _ConverterMatch( this.elementAnnotation, @@ -165,17 +166,18 @@ class _ConverterMatch { ); } -_ConverterMatch _compatibleMatch( +_ConverterMatch? _compatibleMatch( DartType targetType, ElementAnnotation annotation, ) { - final constantValue = annotation.computeConstantValue(); + final constantValue = annotation.computeConstantValue()!; - final converterClassElement = constantValue.type.element as ClassElement; + final converterClassElement = constantValue.type!.element as ClassElement; - final jsonConverterSuper = converterClassElement.allSupertypes.singleWhere( - (e) => e is InterfaceType && _jsonConverterChecker.isExactly(e.element), - orElse: () => null); + final jsonConverterSuper = + converterClassElement.allSupertypes.singleWhereOrNull( + (e) => e is InterfaceType && _jsonConverterChecker.isExactly(e.element), + ); if (jsonConverterSuper == null) { return null; diff --git a/json_serializable/lib/src/type_helpers/json_helper.dart b/json_serializable/lib/src/type_helpers/json_helper.dart index a678a309e..86de56fc9 100644 --- a/json_serializable/lib/src/type_helpers/json_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_helper.dart @@ -5,6 +5,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:collection/collection.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:source_gen/source_gen.dart'; @@ -23,7 +24,7 @@ class JsonHelper extends TypeHelper { /// By default, JSON encoding in from `dart:convert` calls `toJson()` on /// provided objects. @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -54,7 +55,7 @@ class JsonHelper extends TypeHelper { ); } - if (context.config.explicitToJson || toJsonArgs.isNotEmpty) { + if (context.config.explicitToJson! || toJsonArgs.isNotEmpty) { return '$expression${interfaceType.isNullableType ? '?' : ''}' '.toJson(${toJsonArgs.map((a) => '$a, ').join()} )'; } @@ -62,7 +63,7 @@ class JsonHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -72,11 +73,10 @@ class JsonHelper extends TypeHelper { return null; } - final type = targetType as InterfaceType; - final classElement = type.element; + final classElement = targetType.element; final fromJsonCtor = classElement.constructors - .singleWhere((ce) => ce.name == 'fromJson', orElse: () => null); + .singleWhereOrNull((ce) => ce.name == 'fromJson'); var output = expression; if (fromJsonCtor != null) { @@ -95,7 +95,7 @@ class JsonHelper extends TypeHelper { var asCastType = positionalParams.first.type; if (asCastType is InterfaceType) { - final instantiated = _instantiate(asCastType as InterfaceType, type); + final instantiated = _instantiate(asCastType, targetType); if (instantiated != null) { asCastType = instantiated; } @@ -108,15 +108,15 @@ class JsonHelper extends TypeHelper { ..._helperParams( context.deserialize, _decodeHelper, - targetType as InterfaceType, + targetType, positionalParams.skip(1), fromJsonCtor, ), ]; output = args.join(', '); - } else if (_annotation(context.config, type)?.createFactory == true) { - if (context.config.anyMap) { + } else if (_annotation(context.config, targetType)?.createFactory == true) { + if (context.config.anyMap!) { output += ' as Map'; } else { output += ' as Map'; @@ -135,7 +135,7 @@ class JsonHelper extends TypeHelper { } List _helperParams( - Object Function(DartType, String) execute, + Object? Function(DartType, String) execute, TypeParameterType Function(ParameterElement, Element) paramMapper, InterfaceType type, Iterable positionalParams, @@ -172,7 +172,7 @@ TypeParameterType _decodeHelper( type.normalParameterTypes.length == 1) { final funcReturnType = type.returnType; - if (param.name == fromJsonForName(funcReturnType.element.name)) { + if (param.name == fromJsonForName(funcReturnType.element!.name!)) { final funcParamType = type.normalParameterTypes.single; if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) || @@ -203,7 +203,7 @@ TypeParameterType _encodeHelper( type.normalParameterTypes.length == 1) { final funcParamType = type.normalParameterTypes.single; - if (param.name == toJsonForName(funcParamType.element.name)) { + if (param.name == toJsonForName(funcParamType.element!.name!)) { if (funcParamType is TypeParameterType) { return funcParamType; } @@ -238,7 +238,7 @@ bool _canSerialize(JsonSerializable config, DartType type) { /// Returns an instantiation of [ctorParamType] by providing argument types /// derived by matching corresponding type parameters from [classType]. -InterfaceType _instantiate( +InterfaceType? _instantiate( InterfaceType ctorParamType, InterfaceType classType, ) { @@ -260,13 +260,13 @@ InterfaceType _instantiate( } return ctorParamType.element.instantiate( - typeArguments: argTypes, + typeArguments: argTypes.cast(), // TODO: not 100% sure nullabilitySuffix is right... Works for now nullabilitySuffix: NullabilitySuffix.none, ); } -JsonSerializable _annotation(JsonSerializable config, InterfaceType source) { +JsonSerializable? _annotation(JsonSerializable config, InterfaceType source) { final annotations = const TypeChecker.fromRuntime(JsonSerializable) .annotationsOfExact(source.element, throwOnUnresolved: false) .toList(); @@ -282,6 +282,6 @@ JsonSerializable _annotation(JsonSerializable config, InterfaceType source) { ); } -MethodElement _toJsonMethod(DartType type) => typeImplementations(type) +MethodElement? _toJsonMethod(DartType type) => typeImplementations(type) .map((dt) => dt is InterfaceType ? dt.getMethod('toJson') : null) - .firstWhere((me) => me != null, orElse: () => null); + .firstWhereOrNull((me) => me != null); diff --git a/json_serializable/lib/src/type_helpers/map_helper.dart b/json_serializable/lib/src/type_helpers/map_helper.dart index 5eb83300b..764cd89e9 100644 --- a/json_serializable/lib/src/type_helpers/map_helper.dart +++ b/json_serializable/lib/src/type_helpers/map_helper.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/dart/element/type.dart'; +import 'package:collection/collection.dart'; import '../constants.dart'; import '../shared_checkers.dart'; @@ -17,7 +18,7 @@ class MapHelper extends TypeHelper { const MapHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -50,7 +51,7 @@ class MapHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -76,7 +77,7 @@ class MapHelper extends TypeHelper { if (!isKeyStringable) { if (valueArgIsAny) { - if (context.config.anyMap) { + if (context.config.anyMap!) { if (isLikeDynamic(keyArg)) { return '$expression as Map$optionalQuestion'; } @@ -101,7 +102,7 @@ class MapHelper extends TypeHelper { final itemSubVal = context.deserialize(valueArg, closureArg); - var mapCast = context.config.anyMap ? 'as Map' : 'as Map'; + var mapCast = context.config.anyMap! ? 'as Map' : 'as Map'; if (targetTypeIsNullable) { mapCast += '?'; @@ -110,10 +111,10 @@ class MapHelper extends TypeHelper { String keyUsage; if (isEnum(keyArg)) { keyUsage = context.deserialize(keyArg, _keyParam).toString(); - } else if (context.config.anyMap && + } else if (context.config.anyMap! && !(keyArg.isDartCoreObject || keyArg.isDynamic)) { keyUsage = '$_keyParam as String'; - } else if (context.config.anyMap && + } else if (context.config.anyMap! && keyArg.isDartCoreObject && !keyArg.isNullableType) { keyUsage = '$_keyParam as Object'; @@ -123,7 +124,7 @@ class MapHelper extends TypeHelper { final toFromString = _forType(keyArg); if (toFromString != null) { - keyUsage = toFromString.deserialize(keyArg, keyUsage, false, true); + keyUsage = toFromString.deserialize(keyArg, keyUsage, false, true)!; } return '($expression $mapCast)$optionalQuestion.map( ' @@ -142,8 +143,8 @@ final _instances = [ uriString, ]; -ToFromStringHelper _forType(DartType type) => - _instances.singleWhere((i) => i.matches(type), orElse: () => null); +ToFromStringHelper? _forType(DartType type) => + _instances.singleWhereOrNull((i) => i.matches(type)); /// Returns `true` if [keyType] can be automatically converted to/from String – /// and is therefor usable as a key in a [Map]. diff --git a/json_serializable/lib/src/type_helpers/to_from_string.dart b/json_serializable/lib/src/type_helpers/to_from_string.dart index 7a5d94715..55f8aae7e 100644 --- a/json_serializable/lib/src/type_helpers/to_from_string.dart +++ b/json_serializable/lib/src/type_helpers/to_from_string.dart @@ -48,7 +48,7 @@ class ToFromStringHelper { bool matches(DartType type) => _checker.isExactlyType(type); - String serialize( + String? serialize( DartType type, String expression, bool nullable, @@ -64,7 +64,7 @@ class ToFromStringHelper { return '$expression.$_toString'; } - String deserialize( + String? deserialize( DartType type, String expression, bool nullable, diff --git a/json_serializable/lib/src/type_helpers/uri_helper.dart b/json_serializable/lib/src/type_helpers/uri_helper.dart index 2100812a5..28e40621e 100644 --- a/json_serializable/lib/src/type_helpers/uri_helper.dart +++ b/json_serializable/lib/src/type_helpers/uri_helper.dart @@ -12,7 +12,7 @@ class UriHelper extends TypeHelper { const UriHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContext context, @@ -24,7 +24,7 @@ class UriHelper extends TypeHelper { ); @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/lib/src/type_helpers/value_helper.dart b/json_serializable/lib/src/type_helpers/value_helper.dart index 0f9c0b43f..16719c656 100644 --- a/json_serializable/lib/src/type_helpers/value_helper.dart +++ b/json_serializable/lib/src/type_helpers/value_helper.dart @@ -13,7 +13,7 @@ class ValueHelper extends TypeHelper { const ValueHelper(); @override - String serialize( + String? serialize( DartType targetType, String expression, TypeHelperContext context, @@ -28,7 +28,7 @@ class ValueHelper extends TypeHelper { } @override - String deserialize( + String? deserialize( DartType targetType, String expression, TypeHelperContext context, diff --git a/json_serializable/lib/src/unsupported_type_error.dart b/json_serializable/lib/src/unsupported_type_error.dart index 3642cc2c4..4d9a00fb3 100644 --- a/json_serializable/lib/src/unsupported_type_error.dart +++ b/json_serializable/lib/src/unsupported_type_error.dart @@ -8,7 +8,7 @@ import 'package:analyzer/dart/element/type.dart'; /// [reason]. class UnsupportedTypeError extends Error { final DartType type; - final String reason; + final String? reason; /// Not currently accesses. Will likely be removed in a future release. final String expression; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index 3b94f13bd..f397cdbb7 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -7,18 +7,17 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:json_annotation/json_annotation.dart'; -import 'package:meta/meta.dart' show alwaysThrows, required; import 'package:source_gen/source_gen.dart'; import 'helper_core.dart'; const _jsonKeyChecker = TypeChecker.fromRuntime(JsonKey); -DartObject _jsonKeyAnnotation(FieldElement element) => +DartObject? _jsonKeyAnnotation(FieldElement element) => _jsonKeyChecker.firstAnnotationOf(element) ?? (element.getter == null ? null - : _jsonKeyChecker.firstAnnotationOf(element.getter)); + : _jsonKeyChecker.firstAnnotationOf(element.getter!)); ConstantReader jsonKeyAnnotation(FieldElement element) => ConstantReader(_jsonKeyAnnotation(element)); @@ -43,7 +42,7 @@ String pascalCase(String input) { String _fixCase(String input, String separator) => input.replaceAllMapped(_upperCase, (match) { - var lower = match.group(0).toLowerCase(); + var lower = match.group(0)!.toLowerCase(); if (match.start > 0) { lower = '$separator$lower'; @@ -52,13 +51,12 @@ String _fixCase(String input, String separator) => return lower; }); -@alwaysThrows -void throwUnsupported(FieldElement element, String message) => +Never throwUnsupported(FieldElement element, String message) => throw InvalidGenerationSourceError( 'Error with `@JsonKey` on `${element.name}`. $message', element: element); -FieldRename _fromDartObject(ConstantReader reader) => reader.isNull +FieldRename? _fromDartObject(ConstantReader reader) => reader.isNull ? null : enumValueForDartObject( reader.objectValue, @@ -76,18 +74,18 @@ T enumValueForDartObject( /// Return an instance of [JsonSerializable] corresponding to a the provided /// [reader]. JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( - anyMap: reader.read('anyMap').literalValue as bool, - checked: reader.read('checked').literalValue as bool, - createFactory: reader.read('createFactory').literalValue as bool, - createToJson: reader.read('createToJson').literalValue as bool, + anyMap: reader.read('anyMap').literalValue as bool?, + checked: reader.read('checked').literalValue as bool?, + createFactory: reader.read('createFactory').literalValue as bool?, + createToJson: reader.read('createToJson').literalValue as bool?, disallowUnrecognizedKeys: - reader.read('disallowUnrecognizedKeys').literalValue as bool, - explicitToJson: reader.read('explicitToJson').literalValue as bool, + reader.read('disallowUnrecognizedKeys').literalValue as bool?, + explicitToJson: reader.read('explicitToJson').literalValue as bool?, fieldRename: _fromDartObject(reader.read('fieldRename')), genericArgumentFactories: - reader.read('genericArgumentFactories').literalValue as bool, - ignoreUnannotated: reader.read('ignoreUnannotated').literalValue as bool, - includeIfNull: reader.read('includeIfNull').literalValue as bool, + reader.read('genericArgumentFactories').literalValue as bool?, + ignoreUnannotated: reader.read('ignoreUnannotated').literalValue as bool?, + includeIfNull: reader.read('includeIfNull').literalValue as bool?, ); /// Returns a [JsonSerializable] with values from the [JsonSerializable] @@ -102,7 +100,7 @@ JsonSerializable _valueForAnnotation(ConstantReader reader) => JsonSerializable( JsonSerializable mergeConfig( JsonSerializable config, ConstantReader reader, { - @required ClassElement classElement, + required ClassElement classElement, }) { final annotation = _valueForAnnotation(reader); @@ -117,7 +115,7 @@ JsonSerializable mergeConfig( fieldRename: annotation.fieldRename ?? config.fieldRename, genericArgumentFactories: annotation.genericArgumentFactories ?? (classElement.typeParameters.isNotEmpty && - config.genericArgumentFactories), + config.genericArgumentFactories!), ignoreUnannotated: annotation.ignoreUnannotated ?? config.ignoreUnannotated, includeIfNull: annotation.includeIfNull ?? config.includeIfNull, ); @@ -137,7 +135,7 @@ final _enumMapExpando = Expando>(); /// used if it's set and not `null`. /// /// If [targetType] is not an enum, `null` is returned. -Map enumFieldsMap(DartType targetType) { +Map? enumFieldsMap(DartType targetType) { MapEntry _generateEntry(FieldElement fe) { final annotation = const TypeChecker.fromRuntime(JsonValue).firstAnnotationOfExact(fe); @@ -179,7 +177,7 @@ Map enumFieldsMap(DartType targetType) { /// with its values. /// /// Otherwise, `null`. -Iterable iterateEnumFields(DartType targetType) => +Iterable? iterateEnumFields(DartType targetType) => enumFieldsMap(targetType)?.keys; /// Returns a quoted String literal for [value] that can be used in generated @@ -191,7 +189,7 @@ String escapeDartString(String value) { var canBeRaw = true; value = value.replaceAllMapped(_escapeRegExp, (match) { - final value = match[0]; + final value = match[0]!; if (value == "'") { hasSingleQuote = true; return value; @@ -267,8 +265,8 @@ String _getHexLiteral(String input) { extension DartTypeExtension on DartType { bool isAssignableTo(DartType other) => // If the library is `null`, treat it like dynamic => `true` - element.library == null || - element.library.typeSystem.isAssignableTo(this, other); + element!.library == null || + element!.library!.typeSystem.isAssignableTo(this, other); } extension TypeExtension on DartType { diff --git a/json_serializable/pubspec.yaml b/json_serializable/pubspec.yaml index c00ac598b..d823cca4b 100644 --- a/json_serializable/pubspec.yaml +++ b/json_serializable/pubspec.yaml @@ -1,5 +1,5 @@ name: json_serializable -version: 4.0.3 +version: 5.0.0-dev description: >- Automatically generate code for converting to and from JSON by annotating Dart classes. @@ -7,30 +7,34 @@ repository: https://github.com/google/json_serializable.dart/tree/master/json_se environment: # Keeping this <2.12.0 because the code is not null safe – yet! # https://github.com/google/json_serializable.dart/issues/821 - sdk: '>=2.11.99 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: analyzer: '>=0.41.2 <2.0.0' build: ^2.0.0 build_config: ^0.4.4 + collection: ^1.14.0 # Use a tight version constraint to ensure that a constraint on # `json_annotation` properly constrains all features it provides. # For v3 only – allow a wide range since the only change was to REMOVE things # from json_annotation - json_annotation: '>=4.0.0 <4.1.0' + json_annotation: '>=4.0.1 <4.1.0' meta: ^1.3.0 path: ^1.8.0 - source_gen: ^0.9.9 + source_gen: ^1.0.0 dev_dependencies: build_runner: ^1.0.0 build_verify: ^2.0.0 - collection: ^1.14.0 - dart_style: ^1.2.0 + dart_style: ^2.0.0 logging: ^1.0.0 pub_semver: ^2.0.0 - source_gen_test: ^0.1.0 + source_gen_test: ^1.0.0 stack_trace: ^1.10.0 test: ^1.16.0 yaml: ^3.0.0 + +dependency_overrides: + json_annotation: + path: ../json_annotation diff --git a/json_serializable/test/config_test.dart b/json_serializable/test/config_test.dart index 7356a47f6..065aead27 100644 --- a/json_serializable/test/config_test.dart +++ b/json_serializable/test/config_test.dart @@ -114,7 +114,7 @@ void main() { final lastLine = entry.key == 'field_rename' ? '`42` is not one of the supported values: none, kebab, snake, ' 'pascal' - : "type 'int' is not a subtype of type 'bool' in type cast"; + : "type 'int' is not a subtype of type 'bool?' in type cast"; final matcher = isA().having( (v) => v.message, diff --git a/json_serializable/test/custom_configuration_test.dart b/json_serializable/test/custom_configuration_test.dart index 02a04cf1b..e9d9ab19d 100644 --- a/json_serializable/test/custom_configuration_test.dart +++ b/json_serializable/test/custom_configuration_test.dart @@ -18,7 +18,7 @@ import 'package:test/test.dart'; import 'shared_config.dart'; -LibraryReader _libraryReader; +late LibraryReader _libraryReader; Future main() async { initializeBuildLogTracking(); @@ -36,7 +36,7 @@ Future main() async { group('configuration', () { Future runWithConfigAndLogger( - JsonSerializable config, String className) async { + JsonSerializable? config, String className) async { await generateForElement( JsonSerializableGenerator( config: config, typeHelpers: const [_ConfigLogger()]), @@ -214,7 +214,7 @@ class _ConfigLogger implements TypeHelper { const _ConfigLogger(); @override - Object deserialize( + Object? deserialize( DartType targetType, String expression, TypeHelperContextWithConfig context, @@ -225,7 +225,7 @@ class _ConfigLogger implements TypeHelper { } @override - Object serialize(DartType targetType, String expression, + Object? serialize(DartType targetType, String expression, TypeHelperContextWithConfig context) { configurations.add(context.config); return null; diff --git a/json_serializable/test/default_value/default_value.dart b/json_serializable/test/default_value/default_value.dart index 84f1b972e..27eda4ea6 100644 --- a/json_serializable/test/default_value/default_value.dart +++ b/json_serializable/test/default_value/default_value.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: annotate_overrides import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/default_value/default_value.g.dart b/json_serializable/test/default_value/default_value.g.dart index 0c29c64b8..fbf121f1d 100644 --- a/json_serializable/test/default_value/default_value.g.dart +++ b/json_serializable/test/default_value/default_value.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'default_value.dart'; diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.dart index 615505145..9c345aef1 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: annotate_overrides import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart index 5aa38d430..678bab817 100644 --- a/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart +++ b/json_serializable/test/default_value/default_value.g_any_map__checked.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'default_value.g_any_map__checked.dart'; diff --git a/json_serializable/test/default_value/default_value_interface.dart b/json_serializable/test/default_value/default_value_interface.dart index 65076e6eb..06bc33408 100644 --- a/json_serializable/test/default_value/default_value_interface.dart +++ b/json_serializable/test/default_value/default_value_interface.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - abstract class DefaultValue { bool fieldBool; String fieldString; diff --git a/json_serializable/test/default_value/default_value_test.dart b/json_serializable/test/default_value/default_value_test.dart index 8a0a83ff1..00ef236ad 100644 --- a/json_serializable/test/default_value/default_value_test.dart +++ b/json_serializable/test/default_value/default_value_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/generic_files/generic_argument_factories.dart b/json_serializable/test/generic_files/generic_argument_factories.dart index c45ebf081..0ebb09d69 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'generic_argument_factories.g.dart'; diff --git a/json_serializable/test/generic_files/generic_argument_factories.g.dart b/json_serializable/test/generic_files/generic_argument_factories.g.dart index 49ba5d532..da41c86ff 100644 --- a/json_serializable/test/generic_files/generic_argument_factories.g.dart +++ b/json_serializable/test/generic_files/generic_argument_factories.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'generic_argument_factories.dart'; diff --git a/json_serializable/test/generic_files/generic_class.dart b/json_serializable/test/generic_files/generic_class.dart index 4b55add02..bf47a098d 100644 --- a/json_serializable/test/generic_files/generic_class.dart +++ b/json_serializable/test/generic_files/generic_class.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'generic_class.g.dart'; diff --git a/json_serializable/test/generic_files/generic_class.g.dart b/json_serializable/test/generic_files/generic_class.g.dart index 2ef18b32d..d1fb01b0f 100644 --- a/json_serializable/test/generic_files/generic_class.g.dart +++ b/json_serializable/test/generic_files/generic_class.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'generic_class.dart'; diff --git a/json_serializable/test/generic_files/generic_test.dart b/json_serializable/test/generic_files/generic_test.dart index b9e62c090..98b7e770b 100644 --- a/json_serializable/test/generic_files/generic_test.dart +++ b/json_serializable/test/generic_files/generic_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'dart:convert'; import 'package:test/test.dart'; diff --git a/json_serializable/test/integration/integration_test.dart b/json_serializable/test/integration/integration_test.dart index 58379af97..c86f4ffbf 100644 --- a/json_serializable/test/integration/integration_test.dart +++ b/json_serializable/test/integration/integration_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/json_serializable/test/integration/json_test_common.dart b/json_serializable/test/integration/json_test_common.dart index 931d0ca14..6cd110a4d 100644 --- a/json_serializable/test/integration/json_test_common.dart +++ b/json_serializable/test/integration/json_test_common.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'dart:collection'; import 'package:collection/collection.dart'; diff --git a/json_serializable/test/integration/json_test_example.dart b/json_serializable/test/integration/json_test_example.dart index 4a1fcec0f..6a30846fe 100644 --- a/json_serializable/test/integration/json_test_example.dart +++ b/json_serializable/test/integration/json_test_example.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: hash_and_equals import 'dart:collection'; diff --git a/json_serializable/test/integration/json_test_example.g.dart b/json_serializable/test/integration/json_test_example.g.dart index a9f5d28e2..da899ac94 100644 --- a/json_serializable/test/integration/json_test_example.g.dart +++ b/json_serializable/test/integration/json_test_example.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'json_test_example.dart'; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.dart b/json_serializable/test/integration/json_test_example.g_any_map.dart index 1796bd37f..c61b891bc 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: hash_and_equals import 'dart:collection'; diff --git a/json_serializable/test/integration/json_test_example.g_any_map.g.dart b/json_serializable/test/integration/json_test_example.g_any_map.g.dart index ef4a6566d..bfa0c1378 100644 --- a/json_serializable/test/integration/json_test_example.g_any_map.g.dart +++ b/json_serializable/test/integration/json_test_example.g_any_map.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'json_test_example.g_any_map.dart'; diff --git a/json_serializable/test/kitchen_sink/json_converters.dart b/json_serializable/test/kitchen_sink/json_converters.dart index c5074416f..aefb246d2 100644 --- a/json_serializable/test/kitchen_sink/json_converters.dart +++ b/json_serializable/test/kitchen_sink/json_converters.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; class GenericConverter implements JsonConverter> { diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.dart b/json_serializable/test/kitchen_sink/kitchen_sink.dart index 113fe5e84..d846eee3d 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart index 3c26454da..863afa9bb 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.factories.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 import 'kitchen_sink.dart' as normal; import 'kitchen_sink.g_any_map.dart' as any_map; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart index 027129a3a..03a894f51 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'kitchen_sink.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart index 5d0ce3fbe..5db543802 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart index 0c88a1cbd..01b13ef4b 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'kitchen_sink.g_any_map.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart index 0c751950d..4782d07a7 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart index 3ff15a43b..42562e25a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_any_map__checked.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'kitchen_sink.g_any_map__checked.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart index 70c60859b..7456d12cd 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart index fdc362702..095cd3892 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_exclude_null.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'kitchen_sink.g_exclude_null.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart index 6bc665612..8f2875f59 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: annotate_overrides, hash_and_equals import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart index 9dda090c9..24e14ac64 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink.g_explicit_to_json.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'kitchen_sink.g_explicit_to_json.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart index 2473ca1df..357085e5c 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_interface.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:collection/collection.dart'; import 'simple_object.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart index 3950b66fa..b8566a9e5 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart index 4b1b60bc0..f69535d6a 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_test_shared.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; diff --git a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart index 55846778d..f9a09b521 100644 --- a/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart +++ b/json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'package:test/test.dart'; import 'package:yaml/yaml.dart'; diff --git a/json_serializable/test/kitchen_sink/simple_object.dart b/json_serializable/test/kitchen_sink/simple_object.dart index b5816fc29..c02cefc31 100644 --- a/json_serializable/test/kitchen_sink/simple_object.dart +++ b/json_serializable/test/kitchen_sink/simple_object.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'simple_object.g.dart'; diff --git a/json_serializable/test/kitchen_sink/simple_object.g.dart b/json_serializable/test/kitchen_sink/simple_object.g.dart index ad76883f5..42d584b69 100644 --- a/json_serializable/test/kitchen_sink/simple_object.g.dart +++ b/json_serializable/test/kitchen_sink/simple_object.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'simple_object.dart'; diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.dart b/json_serializable/test/kitchen_sink/strict_keys_object.dart index bc54f9ba8..757f3eb5c 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'strict_keys_object.g.dart'; diff --git a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart index 50dd9e5d6..dfdda8eaa 100644 --- a/json_serializable/test/kitchen_sink/strict_keys_object.g.dart +++ b/json_serializable/test/kitchen_sink/strict_keys_object.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'strict_keys_object.dart'; diff --git a/json_serializable/test/readme_test.dart b/json_serializable/test/readme_test.dart index c11c50a98..24c1be8b9 100644 --- a/json_serializable/test/readme_test.dart +++ b/json_serializable/test/readme_test.dart @@ -9,7 +9,7 @@ import 'package:path/path.dart' as p; import 'package:test/test.dart'; void main() { - String readmeContent; + late String readmeContent; setUpAll(() { readmeContent = File('README.md').readAsStringSync(); diff --git a/json_serializable/test/src/_json_serializable_test_input.dart b/json_serializable/test/src/_json_serializable_test_input.dart index 7ba5c0f3f..81e6b03b7 100644 --- a/json_serializable/test/src/_json_serializable_test_input.dart +++ b/json_serializable/test/src/_json_serializable_test_input.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'dart:collection'; import 'package:json_annotation/json_annotation.dart'; diff --git a/json_serializable/test/src/checked_test_input.dart b/json_serializable/test/src/checked_test_input.dart index 7d3d17238..9a87630c5 100644 --- a/json_serializable/test/src/checked_test_input.dart +++ b/json_serializable/test/src/checked_test_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/constants_copy.dart b/json_serializable/test/src/constants_copy.dart index 27b33fb51..a4b0f1086 100644 --- a/json_serializable/test/src/constants_copy.dart +++ b/json_serializable/test/src/constants_copy.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - part of '_json_serializable_test_input.dart'; // TODO: remove this and return link to lib/src/constants.dart once this diff --git a/json_serializable/test/src/core_subclass_type_input.dart b/json_serializable/test/src/core_subclass_type_input.dart index 8f58465cc..02b889a2c 100644 --- a/json_serializable/test/src/core_subclass_type_input.dart +++ b/json_serializable/test/src/core_subclass_type_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldThrow( diff --git a/json_serializable/test/src/default_value_input.dart b/json_serializable/test/src/default_value_input.dart index aca8e90dd..f15739b2f 100644 --- a/json_serializable/test/src/default_value_input.dart +++ b/json_serializable/test/src/default_value_input.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldThrow( diff --git a/json_serializable/test/src/field_namer_input.dart b/json_serializable/test/src/field_namer_input.dart index 1a0cb07ca..5f8bc6011 100644 --- a/json_serializable/test/src/field_namer_input.dart +++ b/json_serializable/test/src/field_namer_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/generic_test_input.dart b/json_serializable/test/src/generic_test_input.dart index e60c395e9..1a3b98466 100644 --- a/json_serializable/test/src/generic_test_input.dart +++ b/json_serializable/test/src/generic_test_input.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldThrow( diff --git a/json_serializable/test/src/inheritance_test_input.dart b/json_serializable/test/src/inheritance_test_input.dart index 5d0294408..c853be117 100644 --- a/json_serializable/test/src/inheritance_test_input.dart +++ b/json_serializable/test/src/inheritance_test_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/json_converter_test_input.dart b/json_serializable/test/src/json_converter_test_input.dart index df58ecd00..9086bccff 100644 --- a/json_serializable/test/src/json_converter_test_input.dart +++ b/json_serializable/test/src/json_converter_test_input.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/map_key_variety_test_input.dart b/json_serializable/test/src/map_key_variety_test_input.dart index 4f022d58a..68504cd76 100644 --- a/json_serializable/test/src/map_key_variety_test_input.dart +++ b/json_serializable/test/src/map_key_variety_test_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate(r''' diff --git a/json_serializable/test/src/setter_test_input.dart b/json_serializable/test/src/setter_test_input.dart index 9fe2d890e..b951dfeb5 100644 --- a/json_serializable/test/src/setter_test_input.dart +++ b/json_serializable/test/src/setter_test_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate( diff --git a/json_serializable/test/src/to_from_json_test_input.dart b/json_serializable/test/src/to_from_json_test_input.dart index 321146901..40c997e3a 100644 --- a/json_serializable/test/src/to_from_json_test_input.dart +++ b/json_serializable/test/src/to_from_json_test_input.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - part of '_json_serializable_test_input.dart'; int _toInt(bool input) => 42; diff --git a/json_serializable/test/src/unknown_enum_value_test_input.dart b/json_serializable/test/src/unknown_enum_value_test_input.dart index 0f6907087..ea238231d 100644 --- a/json_serializable/test/src/unknown_enum_value_test_input.dart +++ b/json_serializable/test/src/unknown_enum_value_test_input.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - part of '_json_serializable_test_input.dart'; @ShouldGenerate( diff --git a/json_serializable/test/supported_types/enum_type.dart b/json_serializable/test/supported_types/enum_type.dart index a0f9c2191..360a6bf8e 100644 --- a/json_serializable/test/supported_types/enum_type.dart +++ b/json_serializable/test/supported_types/enum_type.dart @@ -2,6 +2,4 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - enum EnumType { alpha, beta, gamma, delta } diff --git a/json_serializable/test/supported_types/input.dart b/json_serializable/test/supported_types/input.dart index 2319b01c0..8a43e9fcc 100644 --- a/json_serializable/test/supported_types/input.dart +++ b/json_serializable/test/supported_types/input.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.g.dart'; diff --git a/json_serializable/test/supported_types/input.g.dart b/json_serializable/test/supported_types/input.g.dart index 65367bf60..3effa4548 100644 --- a/json_serializable/test/supported_types/input.g.dart +++ b/json_serializable/test/supported_types/input.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.dart'; diff --git a/json_serializable/test/supported_types/input.type_bigint.dart b/json_serializable/test/supported_types/input.type_bigint.dart index 25005752e..07ab37ba4 100644 --- a/json_serializable/test/supported_types/input.type_bigint.dart +++ b/json_serializable/test/supported_types/input.type_bigint.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_bigint.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_bigint.g.dart b/json_serializable/test/supported_types/input.type_bigint.g.dart index c03d1ed5f..c22bc2d85 100644 --- a/json_serializable/test/supported_types/input.type_bigint.g.dart +++ b/json_serializable/test/supported_types/input.type_bigint.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_bigint.dart'; diff --git a/json_serializable/test/supported_types/input.type_bool.dart b/json_serializable/test/supported_types/input.type_bool.dart index 9d898ba07..e3fd6078c 100644 --- a/json_serializable/test/supported_types/input.type_bool.dart +++ b/json_serializable/test/supported_types/input.type_bool.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_bool.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_bool.g.dart b/json_serializable/test/supported_types/input.type_bool.g.dart index 04a942e20..3a793eccc 100644 --- a/json_serializable/test/supported_types/input.type_bool.g.dart +++ b/json_serializable/test/supported_types/input.type_bool.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_bool.dart'; diff --git a/json_serializable/test/supported_types/input.type_datetime.dart b/json_serializable/test/supported_types/input.type_datetime.dart index cc992713e..880c7ce89 100644 --- a/json_serializable/test/supported_types/input.type_datetime.dart +++ b/json_serializable/test/supported_types/input.type_datetime.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_datetime.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_datetime.g.dart b/json_serializable/test/supported_types/input.type_datetime.g.dart index b98a2c17d..2f3d8bd9a 100644 --- a/json_serializable/test/supported_types/input.type_datetime.g.dart +++ b/json_serializable/test/supported_types/input.type_datetime.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_datetime.dart'; diff --git a/json_serializable/test/supported_types/input.type_double.dart b/json_serializable/test/supported_types/input.type_double.dart index e2074ddcd..c51a0e35b 100644 --- a/json_serializable/test/supported_types/input.type_double.dart +++ b/json_serializable/test/supported_types/input.type_double.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_double.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_double.g.dart b/json_serializable/test/supported_types/input.type_double.g.dart index 00d0e424b..1ff5d3cb2 100644 --- a/json_serializable/test/supported_types/input.type_double.g.dart +++ b/json_serializable/test/supported_types/input.type_double.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_double.dart'; diff --git a/json_serializable/test/supported_types/input.type_duration.dart b/json_serializable/test/supported_types/input.type_duration.dart index aa4c716e4..7ecdef825 100644 --- a/json_serializable/test/supported_types/input.type_duration.dart +++ b/json_serializable/test/supported_types/input.type_duration.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_duration.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_duration.g.dart b/json_serializable/test/supported_types/input.type_duration.g.dart index 5d7f2f45f..d2a77f769 100644 --- a/json_serializable/test/supported_types/input.type_duration.g.dart +++ b/json_serializable/test/supported_types/input.type_duration.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_duration.dart'; diff --git a/json_serializable/test/supported_types/input.type_enumtype.dart b/json_serializable/test/supported_types/input.type_enumtype.dart index 14c28a906..9225db715 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; diff --git a/json_serializable/test/supported_types/input.type_enumtype.g.dart b/json_serializable/test/supported_types/input.type_enumtype.g.dart index 547664f35..7233add35 100644 --- a/json_serializable/test/supported_types/input.type_enumtype.g.dart +++ b/json_serializable/test/supported_types/input.type_enumtype.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_enumtype.dart'; diff --git a/json_serializable/test/supported_types/input.type_int.dart b/json_serializable/test/supported_types/input.type_int.dart index 0a2614f22..6d80dc79c 100644 --- a/json_serializable/test/supported_types/input.type_int.dart +++ b/json_serializable/test/supported_types/input.type_int.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_int.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_int.g.dart b/json_serializable/test/supported_types/input.type_int.g.dart index 48295e2b7..c4695d106 100644 --- a/json_serializable/test/supported_types/input.type_int.g.dart +++ b/json_serializable/test/supported_types/input.type_int.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_int.dart'; diff --git a/json_serializable/test/supported_types/input.type_iterable.dart b/json_serializable/test/supported_types/input.type_iterable.dart index a90c4d99c..1471dc935 100644 --- a/json_serializable/test/supported_types/input.type_iterable.dart +++ b/json_serializable/test/supported_types/input.type_iterable.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; diff --git a/json_serializable/test/supported_types/input.type_iterable.g.dart b/json_serializable/test/supported_types/input.type_iterable.g.dart index e0b5389ad..97766b6b8 100644 --- a/json_serializable/test/supported_types/input.type_iterable.g.dart +++ b/json_serializable/test/supported_types/input.type_iterable.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_iterable.dart'; diff --git a/json_serializable/test/supported_types/input.type_list.dart b/json_serializable/test/supported_types/input.type_list.dart index 657d45296..41f35fe72 100644 --- a/json_serializable/test/supported_types/input.type_list.dart +++ b/json_serializable/test/supported_types/input.type_list.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; diff --git a/json_serializable/test/supported_types/input.type_list.g.dart b/json_serializable/test/supported_types/input.type_list.g.dart index 9c1b1a63c..bd7eeb756 100644 --- a/json_serializable/test/supported_types/input.type_list.g.dart +++ b/json_serializable/test/supported_types/input.type_list.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_list.dart'; diff --git a/json_serializable/test/supported_types/input.type_map.dart b/json_serializable/test/supported_types/input.type_map.dart index 74243a4b1..bdf45e336 100644 --- a/json_serializable/test/supported_types/input.type_map.dart +++ b/json_serializable/test/supported_types/input.type_map.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; diff --git a/json_serializable/test/supported_types/input.type_map.g.dart b/json_serializable/test/supported_types/input.type_map.g.dart index dfa1c2f7b..55608e727 100644 --- a/json_serializable/test/supported_types/input.type_map.g.dart +++ b/json_serializable/test/supported_types/input.type_map.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_map.dart'; diff --git a/json_serializable/test/supported_types/input.type_num.dart b/json_serializable/test/supported_types/input.type_num.dart index 5e9657066..57631ce62 100644 --- a/json_serializable/test/supported_types/input.type_num.dart +++ b/json_serializable/test/supported_types/input.type_num.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_num.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_num.g.dart b/json_serializable/test/supported_types/input.type_num.g.dart index d91fb9d68..0456261f1 100644 --- a/json_serializable/test/supported_types/input.type_num.g.dart +++ b/json_serializable/test/supported_types/input.type_num.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_num.dart'; diff --git a/json_serializable/test/supported_types/input.type_object.dart b/json_serializable/test/supported_types/input.type_object.dart index fb0c2e860..193bd440a 100644 --- a/json_serializable/test/supported_types/input.type_object.dart +++ b/json_serializable/test/supported_types/input.type_object.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_object.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_object.g.dart b/json_serializable/test/supported_types/input.type_object.g.dart index 973229f41..691a85539 100644 --- a/json_serializable/test/supported_types/input.type_object.g.dart +++ b/json_serializable/test/supported_types/input.type_object.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_object.dart'; diff --git a/json_serializable/test/supported_types/input.type_set.dart b/json_serializable/test/supported_types/input.type_set.dart index ea7eacd67..8e74fb7c2 100644 --- a/json_serializable/test/supported_types/input.type_set.dart +++ b/json_serializable/test/supported_types/input.type_set.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; import 'enum_type.dart'; diff --git a/json_serializable/test/supported_types/input.type_set.g.dart b/json_serializable/test/supported_types/input.type_set.g.dart index 43bf51e4a..32e27b0e6 100644 --- a/json_serializable/test/supported_types/input.type_set.g.dart +++ b/json_serializable/test/supported_types/input.type_set.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_set.dart'; diff --git a/json_serializable/test/supported_types/input.type_string.dart b/json_serializable/test/supported_types/input.type_string.dart index 1131e9556..d199b13c0 100644 --- a/json_serializable/test/supported_types/input.type_string.dart +++ b/json_serializable/test/supported_types/input.type_string.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_string.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_string.g.dart b/json_serializable/test/supported_types/input.type_string.g.dart index 55ff7b924..54ef11b44 100644 --- a/json_serializable/test/supported_types/input.type_string.g.dart +++ b/json_serializable/test/supported_types/input.type_string.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_string.dart'; diff --git a/json_serializable/test/supported_types/input.type_uri.dart b/json_serializable/test/supported_types/input.type_uri.dart index 15b2c39f0..fe625bbff 100644 --- a/json_serializable/test/supported_types/input.type_uri.dart +++ b/json_serializable/test/supported_types/input.type_uri.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; part 'input.type_uri.g.dart'; diff --git a/json_serializable/test/supported_types/input.type_uri.g.dart b/json_serializable/test/supported_types/input.type_uri.g.dart index d0d8e1daf..8392c64b3 100644 --- a/json_serializable/test/supported_types/input.type_uri.g.dart +++ b/json_serializable/test/supported_types/input.type_uri.g.dart @@ -1,5 +1,4 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 part of 'input.type_uri.dart'; diff --git a/json_serializable/test/supported_types/type_test.bigint_test.dart b/json_serializable/test/supported_types/type_test.bigint_test.dart index 969cadb27..c012ea507 100644 --- a/json_serializable/test/supported_types/type_test.bigint_test.dart +++ b/json_serializable/test/supported_types/type_test.bigint_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.bool_test.dart b/json_serializable/test/supported_types/type_test.bool_test.dart index 31e4f7971..14e24853b 100644 --- a/json_serializable/test/supported_types/type_test.bool_test.dart +++ b/json_serializable/test/supported_types/type_test.bool_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.dart b/json_serializable/test/supported_types/type_test.dart index 4cafc262b..625b8e3c4 100644 --- a/json_serializable/test/supported_types/type_test.dart +++ b/json_serializable/test/supported_types/type_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.datetime_test.dart b/json_serializable/test/supported_types/type_test.datetime_test.dart index 742529c2a..597bbf680 100644 --- a/json_serializable/test/supported_types/type_test.datetime_test.dart +++ b/json_serializable/test/supported_types/type_test.datetime_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.double_test.dart b/json_serializable/test/supported_types/type_test.double_test.dart index c718f6c11..3e4c05acf 100644 --- a/json_serializable/test/supported_types/type_test.double_test.dart +++ b/json_serializable/test/supported_types/type_test.double_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.duration_test.dart b/json_serializable/test/supported_types/type_test.duration_test.dart index ee91fd475..76816e9fc 100644 --- a/json_serializable/test/supported_types/type_test.duration_test.dart +++ b/json_serializable/test/supported_types/type_test.duration_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.enumtype_test.dart b/json_serializable/test/supported_types/type_test.enumtype_test.dart index 5ead9e9f2..1652b359b 100644 --- a/json_serializable/test/supported_types/type_test.enumtype_test.dart +++ b/json_serializable/test/supported_types/type_test.enumtype_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.int_test.dart b/json_serializable/test/supported_types/type_test.int_test.dart index 8ec0cd571..b4252fa5f 100644 --- a/json_serializable/test/supported_types/type_test.int_test.dart +++ b/json_serializable/test/supported_types/type_test.int_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.iterable_test.dart b/json_serializable/test/supported_types/type_test.iterable_test.dart index cad1cbb99..57b9358b0 100644 --- a/json_serializable/test/supported_types/type_test.iterable_test.dart +++ b/json_serializable/test/supported_types/type_test.iterable_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.list_test.dart b/json_serializable/test/supported_types/type_test.list_test.dart index ebfe17126..342a89079 100644 --- a/json_serializable/test/supported_types/type_test.list_test.dart +++ b/json_serializable/test/supported_types/type_test.list_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.map_test.dart b/json_serializable/test/supported_types/type_test.map_test.dart index 2691408d1..c8cf4ccb9 100644 --- a/json_serializable/test/supported_types/type_test.map_test.dart +++ b/json_serializable/test/supported_types/type_test.map_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.num_test.dart b/json_serializable/test/supported_types/type_test.num_test.dart index a72a873a3..52241e719 100644 --- a/json_serializable/test/supported_types/type_test.num_test.dart +++ b/json_serializable/test/supported_types/type_test.num_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.object_test.dart b/json_serializable/test/supported_types/type_test.object_test.dart index ef38a0446..a4f9601f6 100644 --- a/json_serializable/test/supported_types/type_test.object_test.dart +++ b/json_serializable/test/supported_types/type_test.object_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.set_test.dart b/json_serializable/test/supported_types/type_test.set_test.dart index 99fff3b6b..a3b1ed57b 100644 --- a/json_serializable/test/supported_types/type_test.set_test.dart +++ b/json_serializable/test/supported_types/type_test.set_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.string_test.dart b/json_serializable/test/supported_types/type_test.string_test.dart index 41af3050c..845762b19 100644 --- a/json_serializable/test/supported_types/type_test.string_test.dart +++ b/json_serializable/test/supported_types/type_test.string_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/supported_types/type_test.uri_test.dart b/json_serializable/test/supported_types/type_test.uri_test.dart index b32b892cc..ff0710b38 100644 --- a/json_serializable/test/supported_types/type_test.uri_test.dart +++ b/json_serializable/test/supported_types/type_test.uri_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - // ignore_for_file: prefer_const_declarations import 'dart:convert'; diff --git a/json_serializable/test/test_sources/test_sources.dart b/json_serializable/test/test_sources/test_sources.dart index e14ad6205..b1182cb06 100644 --- a/json_serializable/test/test_sources/test_sources.dart +++ b/json_serializable/test/test_sources/test_sources.dart @@ -1,5 +1,3 @@ -// @dart=2.12 - import 'package:json_annotation/json_annotation.dart'; @JsonSerializable() diff --git a/json_serializable/test/test_utils.dart b/json_serializable/test/test_utils.dart index 324cdb27a..6bb67f98a 100644 --- a/json_serializable/test/test_utils.dart +++ b/json_serializable/test/test_utils.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.12 - import 'dart:convert'; import 'package:stack_trace/stack_trace.dart'; diff --git a/json_serializable/tool/doc_builder.dart b/json_serializable/tool/doc_builder.dart index 0dd737305..267690f7a 100644 --- a/json_serializable/tool/doc_builder.dart +++ b/json_serializable/tool/doc_builder.dart @@ -45,7 +45,7 @@ class _DocBuilder extends Builder { for (var className in _annotationClasses) { for (var fe in lib - .findType(className) + .findType(className)! .fields .where((fe) => !fe.isStatic && !fe.hasDeprecated)) { descriptionMap[fe.name] = @@ -121,9 +121,9 @@ String _link(String version, String owner, String name) => 'json_annotation/$owner/$name.html'; class _FieldInfo implements Comparable<_FieldInfo> { - final FieldElement _keyField, _classField; + final FieldElement? _keyField, _classField; - String get name => _keyField?.name ?? _classField.name; + String get name => _keyField?.name ?? _classField!.name; String get classAnnotationName { if (_classField == null) { @@ -144,15 +144,15 @@ class _FieldInfo implements Comparable<_FieldInfo> { return ''; } - return snakeCase(_classField.name); + return snakeCase(_classField!.name); } _FieldInfo(this._keyField, this._classField); - static _FieldInfo update(FieldElement field, _FieldInfo existing) { + static _FieldInfo update(FieldElement field, _FieldInfo? existing) { final parent = field.enclosingElement.name; - FieldElement keyField, classField; + FieldElement? keyField, classField; switch (parent) { case _jsonSerializable: classField = field; diff --git a/json_serializable/tool/shared.dart b/json_serializable/tool/shared.dart index 3e12e469e..f1e0b9914 100644 --- a/json_serializable/tool/shared.dart +++ b/json_serializable/tool/shared.dart @@ -21,7 +21,7 @@ Builder validate(String builderName, Builder builder) { final extensions = Set.from(buildYaml['.dart'] as YamlList); - final codedExtensions = builder.buildExtensions['.dart'].toSet(); + final codedExtensions = builder.buildExtensions['.dart']!.toSet(); final tooMany = extensions.difference(codedExtensions); if (tooMany.isNotEmpty) { diff --git a/json_serializable/tool/test_builder.dart b/json_serializable/tool/test_builder.dart index 52c4a3b70..4282e43e1 100644 --- a/json_serializable/tool/test_builder.dart +++ b/json_serializable/tool/test_builder.dart @@ -27,7 +27,7 @@ class _TestBuilder implements Builder { final factories = SplayTreeMap.from({'$_kitchenSinkBaseName.dart': 'normal'}); - for (var config in _fileConfigurationMap[baseName]) { + for (var config in _fileConfigurationMap[baseName]!) { final extension = _configToExtension(config); final newId = buildStep.inputId.changeExtension(extension); @@ -65,7 +65,7 @@ class _TestBuilder implements Builder { final lines = [ r''' // GENERATED CODE - DO NOT MODIFY BY HAND -// @dart=2.12 + ''', ...factories.entries.map((e) => "import '${e.key}' as ${e.value};"), 'const factories = [', @@ -146,7 +146,7 @@ Iterable _optionReplacement( if (baseName == _kitchenSinkBaseName && _kitchenSinkReplacements.containsKey(optionKey)) { - yield* _kitchenSinkReplacements[optionKey]; + yield* _kitchenSinkReplacements[optionKey]!; } } diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart index fbe201ced..bd310a751 100644 --- a/json_serializable/tool/test_type_data.dart +++ b/json_serializable/tool/test_type_data.dart @@ -1,5 +1,3 @@ -import 'package:meta/meta.dart'; - import 'shared.dart'; const customEnumType = 'EnumType'; @@ -8,15 +6,15 @@ const _annotationImport = "import 'package:json_annotation/json_annotation.dart';"; class TestTypeData { - final String defaultExpression; - final String jsonExpression; - final String altJsonExpression; + final String? defaultExpression; + final String? jsonExpression; + final String? altJsonExpression; final Set genericArgs; const TestTypeData({ this.defaultExpression, - String jsonExpression, - @required String altJsonExpression, + String? jsonExpression, + required String? altJsonExpression, this.genericArgs = const {}, }) : jsonExpression = jsonExpression ?? defaultExpression, altJsonExpression = @@ -110,7 +108,7 @@ class TestTypeData { final defaultReplacement = defaultNotSupported ? '' : _defaultSource - .replaceFirst('42', defaultExpression) + .replaceFirst('42', defaultExpression!) .replaceFirst('dynamic', type); yield Replacement(