diff --git a/packages/_internal/lib/models.dart b/packages/_internal/lib/models.dart index 7046bdf5..4e2aca86 100644 --- a/packages/_internal/lib/models.dart +++ b/packages/_internal/lib/models.dart @@ -64,24 +64,6 @@ class ConstructorDetails with _$ConstructorDetails { String get callbackName => constructorNameToCallbackName(name); } -@freezed -class MapConfig with _$MapConfig { - factory MapConfig({ - required bool map, - required bool mapOrNull, - required bool maybeMap, - }) = _MapConfig; -} - -@freezed -class WhenConfig with _$WhenConfig { - factory WhenConfig({ - required bool when, - required bool whenOrNull, - required bool maybeWhen, - }) = _WhenConfig; -} - @freezed class Data with _$Data { @Assert('constructors.isNotEmpty') @@ -91,8 +73,6 @@ class Data with _$Data { required bool generateCopyWith, required bool generateEqual, required bool generateToString, - required MapConfig map, - required WhenConfig when, required bool generateFromJson, required bool generateToJson, required bool makeCollectionsImmutable, diff --git a/packages/_internal/lib/models.freezed.dart b/packages/_internal/lib/models.freezed.dart index ac1ce9f4..a15fb2ec 100644 --- a/packages/_internal/lib/models.freezed.dart +++ b/packages/_internal/lib/models.freezed.dart @@ -746,337 +746,6 @@ abstract class _ConstructorDetails extends ConstructorDetails { throw _privateConstructorUsedError; } -/// @nodoc -mixin _$MapConfig { - bool get map => throw _privateConstructorUsedError; - bool get mapOrNull => throw _privateConstructorUsedError; - bool get maybeMap => throw _privateConstructorUsedError; - - /// Create a copy of MapConfig - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - $MapConfigCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $MapConfigCopyWith<$Res> { - factory $MapConfigCopyWith(MapConfig value, $Res Function(MapConfig) then) = - _$MapConfigCopyWithImpl<$Res, MapConfig>; - @useResult - $Res call({bool map, bool mapOrNull, bool maybeMap}); -} - -/// @nodoc -class _$MapConfigCopyWithImpl<$Res, $Val extends MapConfig> - implements $MapConfigCopyWith<$Res> { - _$MapConfigCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of MapConfig - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? map = null, - Object? mapOrNull = null, - Object? maybeMap = null, - }) { - return _then(_value.copyWith( - map: null == map - ? _value.map - : map // ignore: cast_nullable_to_non_nullable - as bool, - mapOrNull: null == mapOrNull - ? _value.mapOrNull - : mapOrNull // ignore: cast_nullable_to_non_nullable - as bool, - maybeMap: null == maybeMap - ? _value.maybeMap - : maybeMap // ignore: cast_nullable_to_non_nullable - as bool, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$MapConfigImplCopyWith<$Res> - implements $MapConfigCopyWith<$Res> { - factory _$$MapConfigImplCopyWith( - _$MapConfigImpl value, $Res Function(_$MapConfigImpl) then) = - __$$MapConfigImplCopyWithImpl<$Res>; - @override - @useResult - $Res call({bool map, bool mapOrNull, bool maybeMap}); -} - -/// @nodoc -class __$$MapConfigImplCopyWithImpl<$Res> - extends _$MapConfigCopyWithImpl<$Res, _$MapConfigImpl> - implements _$$MapConfigImplCopyWith<$Res> { - __$$MapConfigImplCopyWithImpl( - _$MapConfigImpl _value, $Res Function(_$MapConfigImpl) _then) - : super(_value, _then); - - /// Create a copy of MapConfig - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? map = null, - Object? mapOrNull = null, - Object? maybeMap = null, - }) { - return _then(_$MapConfigImpl( - map: null == map - ? _value.map - : map // ignore: cast_nullable_to_non_nullable - as bool, - mapOrNull: null == mapOrNull - ? _value.mapOrNull - : mapOrNull // ignore: cast_nullable_to_non_nullable - as bool, - maybeMap: null == maybeMap - ? _value.maybeMap - : maybeMap // ignore: cast_nullable_to_non_nullable - as bool, - )); - } -} - -/// @nodoc - -class _$MapConfigImpl implements _MapConfig { - _$MapConfigImpl( - {required this.map, required this.mapOrNull, required this.maybeMap}); - - @override - final bool map; - @override - final bool mapOrNull; - @override - final bool maybeMap; - - @override - String toString() { - return 'MapConfig(map: $map, mapOrNull: $mapOrNull, maybeMap: $maybeMap)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$MapConfigImpl && - (identical(other.map, map) || other.map == map) && - (identical(other.mapOrNull, mapOrNull) || - other.mapOrNull == mapOrNull) && - (identical(other.maybeMap, maybeMap) || - other.maybeMap == maybeMap)); - } - - @override - int get hashCode => Object.hash(runtimeType, map, mapOrNull, maybeMap); - - /// Create a copy of MapConfig - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$MapConfigImplCopyWith<_$MapConfigImpl> get copyWith => - __$$MapConfigImplCopyWithImpl<_$MapConfigImpl>(this, _$identity); -} - -abstract class _MapConfig implements MapConfig { - factory _MapConfig( - {required final bool map, - required final bool mapOrNull, - required final bool maybeMap}) = _$MapConfigImpl; - - @override - bool get map; - @override - bool get mapOrNull; - @override - bool get maybeMap; - - /// Create a copy of MapConfig - /// with the given fields replaced by the non-null parameter values. - @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$MapConfigImplCopyWith<_$MapConfigImpl> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -mixin _$WhenConfig { - bool get when => throw _privateConstructorUsedError; - bool get whenOrNull => throw _privateConstructorUsedError; - bool get maybeWhen => throw _privateConstructorUsedError; - - /// Create a copy of WhenConfig - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - $WhenConfigCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $WhenConfigCopyWith<$Res> { - factory $WhenConfigCopyWith( - WhenConfig value, $Res Function(WhenConfig) then) = - _$WhenConfigCopyWithImpl<$Res, WhenConfig>; - @useResult - $Res call({bool when, bool whenOrNull, bool maybeWhen}); -} - -/// @nodoc -class _$WhenConfigCopyWithImpl<$Res, $Val extends WhenConfig> - implements $WhenConfigCopyWith<$Res> { - _$WhenConfigCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of WhenConfig - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? when = null, - Object? whenOrNull = null, - Object? maybeWhen = null, - }) { - return _then(_value.copyWith( - when: null == when - ? _value.when - : when // ignore: cast_nullable_to_non_nullable - as bool, - whenOrNull: null == whenOrNull - ? _value.whenOrNull - : whenOrNull // ignore: cast_nullable_to_non_nullable - as bool, - maybeWhen: null == maybeWhen - ? _value.maybeWhen - : maybeWhen // ignore: cast_nullable_to_non_nullable - as bool, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$WhenConfigImplCopyWith<$Res> - implements $WhenConfigCopyWith<$Res> { - factory _$$WhenConfigImplCopyWith( - _$WhenConfigImpl value, $Res Function(_$WhenConfigImpl) then) = - __$$WhenConfigImplCopyWithImpl<$Res>; - @override - @useResult - $Res call({bool when, bool whenOrNull, bool maybeWhen}); -} - -/// @nodoc -class __$$WhenConfigImplCopyWithImpl<$Res> - extends _$WhenConfigCopyWithImpl<$Res, _$WhenConfigImpl> - implements _$$WhenConfigImplCopyWith<$Res> { - __$$WhenConfigImplCopyWithImpl( - _$WhenConfigImpl _value, $Res Function(_$WhenConfigImpl) _then) - : super(_value, _then); - - /// Create a copy of WhenConfig - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? when = null, - Object? whenOrNull = null, - Object? maybeWhen = null, - }) { - return _then(_$WhenConfigImpl( - when: null == when - ? _value.when - : when // ignore: cast_nullable_to_non_nullable - as bool, - whenOrNull: null == whenOrNull - ? _value.whenOrNull - : whenOrNull // ignore: cast_nullable_to_non_nullable - as bool, - maybeWhen: null == maybeWhen - ? _value.maybeWhen - : maybeWhen // ignore: cast_nullable_to_non_nullable - as bool, - )); - } -} - -/// @nodoc - -class _$WhenConfigImpl implements _WhenConfig { - _$WhenConfigImpl( - {required this.when, required this.whenOrNull, required this.maybeWhen}); - - @override - final bool when; - @override - final bool whenOrNull; - @override - final bool maybeWhen; - - @override - String toString() { - return 'WhenConfig(when: $when, whenOrNull: $whenOrNull, maybeWhen: $maybeWhen)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$WhenConfigImpl && - (identical(other.when, when) || other.when == when) && - (identical(other.whenOrNull, whenOrNull) || - other.whenOrNull == whenOrNull) && - (identical(other.maybeWhen, maybeWhen) || - other.maybeWhen == maybeWhen)); - } - - @override - int get hashCode => Object.hash(runtimeType, when, whenOrNull, maybeWhen); - - /// Create a copy of WhenConfig - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$WhenConfigImplCopyWith<_$WhenConfigImpl> get copyWith => - __$$WhenConfigImplCopyWithImpl<_$WhenConfigImpl>(this, _$identity); -} - -abstract class _WhenConfig implements WhenConfig { - factory _WhenConfig( - {required final bool when, - required final bool whenOrNull, - required final bool maybeWhen}) = _$WhenConfigImpl; - - @override - bool get when; - @override - bool get whenOrNull; - @override - bool get maybeWhen; - - /// Create a copy of WhenConfig - /// with the given fields replaced by the non-null parameter values. - @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$WhenConfigImplCopyWith<_$WhenConfigImpl> get copyWith => - throw _privateConstructorUsedError; -} - /// @nodoc mixin _$Data { String get name => throw _privateConstructorUsedError; @@ -1084,8 +753,6 @@ mixin _$Data { bool get generateCopyWith => throw _privateConstructorUsedError; bool get generateEqual => throw _privateConstructorUsedError; bool get generateToString => throw _privateConstructorUsedError; - MapConfig get map => throw _privateConstructorUsedError; - WhenConfig get when => throw _privateConstructorUsedError; bool get generateFromJson => throw _privateConstructorUsedError; bool get generateToJson => throw _privateConstructorUsedError; bool get makeCollectionsImmutable => throw _privateConstructorUsedError; @@ -1116,8 +783,6 @@ abstract class $DataCopyWith<$Res> { bool generateCopyWith, bool generateEqual, bool generateToString, - MapConfig map, - WhenConfig when, bool generateFromJson, bool generateToJson, bool makeCollectionsImmutable, @@ -1127,9 +792,6 @@ abstract class $DataCopyWith<$Res> { GenericsParameterTemplate genericsParameterTemplate, bool shouldUseExtends, bool genericArgumentFactories}); - - $MapConfigCopyWith<$Res> get map; - $WhenConfigCopyWith<$Res> get when; } /// @nodoc @@ -1152,8 +814,6 @@ class _$DataCopyWithImpl<$Res, $Val extends Data> Object? generateCopyWith = null, Object? generateEqual = null, Object? generateToString = null, - Object? map = null, - Object? when = null, Object? generateFromJson = null, Object? generateToJson = null, Object? makeCollectionsImmutable = null, @@ -1185,14 +845,6 @@ class _$DataCopyWithImpl<$Res, $Val extends Data> ? _value.generateToString : generateToString // ignore: cast_nullable_to_non_nullable as bool, - map: null == map - ? _value.map - : map // ignore: cast_nullable_to_non_nullable - as MapConfig, - when: null == when - ? _value.when - : when // ignore: cast_nullable_to_non_nullable - as WhenConfig, generateFromJson: null == generateFromJson ? _value.generateFromJson : generateFromJson // ignore: cast_nullable_to_non_nullable @@ -1231,26 +883,6 @@ class _$DataCopyWithImpl<$Res, $Val extends Data> as bool, ) as $Val); } - - /// Create a copy of Data - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $MapConfigCopyWith<$Res> get map { - return $MapConfigCopyWith<$Res>(_value.map, (value) { - return _then(_value.copyWith(map: value) as $Val); - }); - } - - /// Create a copy of Data - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $WhenConfigCopyWith<$Res> get when { - return $WhenConfigCopyWith<$Res>(_value.when, (value) { - return _then(_value.copyWith(when: value) as $Val); - }); - } } /// @nodoc @@ -1266,8 +898,6 @@ abstract class _$$DataImplCopyWith<$Res> implements $DataCopyWith<$Res> { bool generateCopyWith, bool generateEqual, bool generateToString, - MapConfig map, - WhenConfig when, bool generateFromJson, bool generateToJson, bool makeCollectionsImmutable, @@ -1277,11 +907,6 @@ abstract class _$$DataImplCopyWith<$Res> implements $DataCopyWith<$Res> { GenericsParameterTemplate genericsParameterTemplate, bool shouldUseExtends, bool genericArgumentFactories}); - - @override - $MapConfigCopyWith<$Res> get map; - @override - $WhenConfigCopyWith<$Res> get when; } /// @nodoc @@ -1301,8 +926,6 @@ class __$$DataImplCopyWithImpl<$Res> Object? generateCopyWith = null, Object? generateEqual = null, Object? generateToString = null, - Object? map = null, - Object? when = null, Object? generateFromJson = null, Object? generateToJson = null, Object? makeCollectionsImmutable = null, @@ -1334,14 +957,6 @@ class __$$DataImplCopyWithImpl<$Res> ? _value.generateToString : generateToString // ignore: cast_nullable_to_non_nullable as bool, - map: null == map - ? _value.map - : map // ignore: cast_nullable_to_non_nullable - as MapConfig, - when: null == when - ? _value.when - : when // ignore: cast_nullable_to_non_nullable - as WhenConfig, generateFromJson: null == generateFromJson ? _value.generateFromJson : generateFromJson // ignore: cast_nullable_to_non_nullable @@ -1391,8 +1006,6 @@ class _$DataImpl implements _Data { required this.generateCopyWith, required this.generateEqual, required this.generateToString, - required this.map, - required this.when, required this.generateFromJson, required this.generateToJson, required this.makeCollectionsImmutable, @@ -1417,10 +1030,6 @@ class _$DataImpl implements _Data { @override final bool generateToString; @override - final MapConfig map; - @override - final WhenConfig when; - @override final bool generateFromJson; @override final bool generateToJson; @@ -1454,7 +1063,7 @@ class _$DataImpl implements _Data { @override String toString() { - return 'Data(name: $name, unionKey: $unionKey, generateCopyWith: $generateCopyWith, generateEqual: $generateEqual, generateToString: $generateToString, map: $map, when: $when, generateFromJson: $generateFromJson, generateToJson: $generateToJson, makeCollectionsImmutable: $makeCollectionsImmutable, concretePropertiesName: $concretePropertiesName, constructors: $constructors, genericsDefinitionTemplate: $genericsDefinitionTemplate, genericsParameterTemplate: $genericsParameterTemplate, shouldUseExtends: $shouldUseExtends, genericArgumentFactories: $genericArgumentFactories)'; + return 'Data(name: $name, unionKey: $unionKey, generateCopyWith: $generateCopyWith, generateEqual: $generateEqual, generateToString: $generateToString, generateFromJson: $generateFromJson, generateToJson: $generateToJson, makeCollectionsImmutable: $makeCollectionsImmutable, concretePropertiesName: $concretePropertiesName, constructors: $constructors, genericsDefinitionTemplate: $genericsDefinitionTemplate, genericsParameterTemplate: $genericsParameterTemplate, shouldUseExtends: $shouldUseExtends, genericArgumentFactories: $genericArgumentFactories)'; } @override @@ -1471,8 +1080,6 @@ class _$DataImpl implements _Data { other.generateEqual == generateEqual) && (identical(other.generateToString, generateToString) || other.generateToString == generateToString) && - (identical(other.map, map) || other.map == map) && - (identical(other.when, when) || other.when == when) && (identical(other.generateFromJson, generateFromJson) || other.generateFromJson == generateFromJson) && (identical(other.generateToJson, generateToJson) || @@ -1506,8 +1113,6 @@ class _$DataImpl implements _Data { generateCopyWith, generateEqual, generateToString, - map, - when, generateFromJson, generateToJson, makeCollectionsImmutable, @@ -1534,8 +1139,6 @@ abstract class _Data implements Data { required final bool generateCopyWith, required final bool generateEqual, required final bool generateToString, - required final MapConfig map, - required final WhenConfig when, required final bool generateFromJson, required final bool generateToJson, required final bool makeCollectionsImmutable, @@ -1557,10 +1160,6 @@ abstract class _Data implements Data { @override bool get generateToString; @override - MapConfig get map; - @override - WhenConfig get when; - @override bool get generateFromJson; @override bool get generateToJson; diff --git a/packages/_internal/pubspec.lock b/packages/_internal/pubspec.lock index 1e02abe3..a6e562c6 100644 --- a/packages/_internal/pubspec.lock +++ b/packages/_internal/pubspec.lock @@ -5,23 +5,18 @@ packages: dependency: transitive description: name: _fe_analyzer_shared - sha256: "45cfa8471b89fb6643fe9bf51bd7931a76b8f5ec2d65de4fb176dba8d4f22c77" + sha256: dc27559385e905ad30838356c5f5d574014ba39872d732111cd07ac0beff4c57 url: "https://pub.dev" source: hosted - version: "73.0.0" - _macros: - dependency: transitive - description: dart - source: sdk - version: "0.3.2" + version: "80.0.0" analyzer: dependency: transitive description: name: analyzer - sha256: "4959fec185fe70cce007c57e9ab6983101dbe593d2bf8bbfb4453aaec0cf470a" + sha256: "192d1c5b944e7e53b24b5586db760db934b177d4147c42fbca8c8c5f1eb8d11e" url: "https://pub.dev" source: hosted - version: "6.8.0" + version: "7.3.0" args: dependency: transitive description: @@ -34,10 +29,10 @@ packages: dependency: transitive description: name: async - sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63 + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" url: "https://pub.dev" source: hosted - version: "2.12.0" + version: "2.13.0" boolean_selector: dependency: transitive description: @@ -50,50 +45,50 @@ packages: dependency: transitive description: name: build - sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" + sha256: cef23f1eda9b57566c81e2133d196f8e3df48f244b317368d65c5943d91148f0 url: "https://pub.dev" source: hosted - version: "2.4.1" + version: "2.4.2" build_config: dependency: transitive description: name: build_config - sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 + sha256: "4ae2de3e1e67ea270081eaee972e1bd8f027d459f249e0f1186730784c2e7e33" url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.1.2" build_daemon: dependency: transitive description: name: build_daemon - sha256: "79b2aef6ac2ed00046867ed354c88778c9c0f029df8a20fe10b5436826721ef9" + sha256: "8e928697a82be082206edb0b9c99c5a4ad6bc31c9e9b8b2f291ae65cd4a25daa" url: "https://pub.dev" source: hosted - version: "4.0.2" + version: "4.0.4" build_resolvers: dependency: transitive description: name: build_resolvers - sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a" + sha256: b9e4fda21d846e192628e7a4f6deda6888c36b5b69ba02ff291a01fd529140f0 url: "https://pub.dev" source: hosted - version: "2.4.2" + version: "2.4.4" build_runner: dependency: "direct dev" description: name: build_runner - sha256: "028819cfb90051c6b5440c7e574d1896f8037e3c96cf17aaeb054c9311cfbf4d" + sha256: "058fe9dce1de7d69c4b84fada934df3e0153dd000758c4d65964d0166779aa99" url: "https://pub.dev" source: hosted - version: "2.4.13" + version: "2.4.15" build_runner_core: dependency: transitive description: name: build_runner_core - sha256: f8126682b87a7282a339b871298cc12009cb67109cfa1614d6436fb0289193e0 + sha256: "22e3aa1c80e0ada3722fe5b63fd43d9c8990759d0a2cf489c8c5d7b2bdebc021" url: "https://pub.dev" source: hosted - version: "7.3.2" + version: "8.0.0" built_collection: dependency: transitive description: @@ -154,10 +149,10 @@ packages: dependency: transitive description: name: dart_style - sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab" + sha256: "27eb0ae77836989a3bc541ce55595e8ceee0992807f14511552a898ddd0d88ac" url: "https://pub.dev" source: hosted - version: "2.3.7" + version: "3.0.1" file: dependency: transitive description: @@ -178,10 +173,10 @@ packages: dependency: "direct dev" description: name: freezed - sha256: "44c19278dd9d89292cf46e97dc0c1e52ce03275f40a97c5a348e802a924bf40e" + sha256: "59a584c24b3acdc5250bb856d0d3e9c0b798ed14a4af1ddb7dc1c7b41df91c9c" url: "https://pub.dev" source: hosted - version: "2.5.7" + version: "2.5.8" freezed_annotation: dependency: "direct main" description: @@ -202,10 +197,10 @@ packages: dependency: transitive description: name: glob - sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + sha256: c3f1ee72c96f8f78935e18aa8cecced9ab132419e8625dc187e1c2408efc20de url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.3" graphs: dependency: transitive description: @@ -214,6 +209,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.2" + http: + dependency: transitive + description: + name: http + sha256: fe7ab022b76f3034adc518fb6ea04a82387620e19977665ea18d30a1cf43442f + url: "https://pub.dev" + source: hosted + version: "1.3.0" http_multi_server: dependency: transitive description: @@ -242,10 +245,10 @@ packages: dependency: transitive description: name: js - sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf + sha256: "53385261521cc4a0c4658fd0ad07a7d14591cf8fc33abbceae306ddb974888dc" url: "https://pub.dev" source: hosted - version: "0.7.1" + version: "0.7.2" json_annotation: dependency: transitive description: @@ -262,14 +265,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.0" - macros: - dependency: transitive - description: - name: macros - sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536" - url: "https://pub.dev" - source: hosted - version: "0.1.2-main.4" matcher: dependency: transitive description: @@ -330,10 +325,10 @@ packages: dependency: transitive description: name: pubspec_parse - sha256: "81876843eb50dc2e1e5b151792c9a985c5ed2536914115ed04e9c8528f6647b0" + sha256: "0560ba233314abbed0a48a2956f7f022cce7c3e1e73df540277da7544cad4082" url: "https://pub.dev" source: hosted - version: "1.4.0" + version: "1.5.0" shelf: dependency: transitive description: @@ -346,18 +341,18 @@ packages: dependency: transitive description: name: shelf_web_socket - sha256: cc36c297b52866d203dbf9332263c94becc2fe0ceaa9681d07b6ef9807023b67 + sha256: "3632775c8e90d6c9712f883e633716432a27758216dfb61bd86a8321c0580925" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.0" source_gen: dependency: transitive description: name: source_gen - sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832" + sha256: "35c8150ece9e8c8d263337a265153c3329667640850b9304861faea59fc98f6b" url: "https://pub.dev" source: hosted - version: "1.5.0" + version: "2.0.0" source_span: dependency: transitive description: @@ -378,10 +373,10 @@ packages: dependency: transitive description: name: stream_channel - sha256: "4ac0537115a24d772c408a2520ecd0abb99bca2ea9c4e634ccbdbfae64fe17ec" + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" url: "https://pub.dev" source: hosted - version: "2.1.3" + version: "2.1.4" stream_transform: dependency: transitive description: @@ -458,10 +453,10 @@ packages: dependency: transitive description: name: web_socket_channel - sha256: "9f187088ed104edd8662ca07af4b124465893caf063ba29758f97af57e61da8f" + sha256: "0b8e2457400d8a859b7b2030786835a28a8e80836ef64402abef392ff4f1d0e5" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.0.2" yaml: dependency: transitive description: @@ -471,4 +466,4 @@ packages: source: hosted version: "3.1.3" sdks: - dart: ">=3.5.0 <4.0.0" + dart: ">=3.7.0-0 <4.0.0" diff --git a/packages/freezed/CHANGELOG.md b/packages/freezed/CHANGELOG.md index 7179d72e..310e5cfe 100644 --- a/packages/freezed/CHANGELOG.md +++ b/packages/freezed/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased 3.0.0 + +- **Breaking**: Removed `map/when` and variants. These have been discouraged since Dart got pattern matching. + ## 2.5.8 - 2025-01-06 Support analyzer 7.0.0 diff --git a/packages/freezed/README.md b/packages/freezed/README.md index 939e30c8..fd5abc4a 100644 --- a/packages/freezed/README.md +++ b/packages/freezed/README.md @@ -6,11 +6,7 @@ [](https://flutter.dev/docs/development/packages-and-plugins/favorites) -Welcome to [Freezed], yet another code generator for data classes, unions, and cloning. - -> [!NOTE] -> An early preview of Freezed using macro is available. -> To learn more, go to . +Welcome to [Freezed], yet another code generator for data classes, tagged unions, nested classes and cloning. # Motivation @@ -55,9 +51,6 @@ to focus on the definition of your model. - [Union types](#union-types) - [Shared properties](#shared-properties) - [Using pattern matching to read non-shared properties](#using-pattern-matching-to-read-non-shared-properties) - - [(Legacy) Pattern matching utilities](#legacy-pattern-matching-utilities) - - [When](#when) - - [Map](#map) - [Configurations](#configurations) - [Changing the behavior for a specific model](#changing-the-behavior-for-a-specific-model) - [Changing the behavior for the entire project](#changing-the-behavior-for-the-entire-project) @@ -423,7 +416,7 @@ class Person with _$Person { then it will fail with the error `The non-abstract class _$_Person is missing implementations for these members:`. -For that to work, we need to define a private empty constructor. That will enable the generated code to *extend/subclass* our class, instead of *implementing* it (which is the default, and only inherits type, and not properties or methods): +For that to work, we need to define a private empty constructor. That will enable the generated code to _extend/subclass_ our class, instead of _implementing_ it (which is the default, and only inherits type, and not properties or methods): ```dart @freezed @@ -1010,124 +1003,6 @@ switch (example) { If using Dart 2, you can use also use the [legacy pattern matching utilities](#legacy-pattern-matching-utilities) generated by Freezed to inspect the content of our object. You could also using `is`/`as` to cast an `Example` variable into either a `Person` or a `City`, but this is heavily discouraged. Use one of the other two options. -#### (Legacy) Pattern matching utilities - -> [!WARNING] -> As of Dart 3, Dart now has built-in pattern-matching using sealed classes. -> As such, you no-longer need to rely on Freezed's generated methods for pattern matching. -> Instead of using `when`/`map`, use the official Dart syntax. -> -> The references to `when`/`map` are kept for users who have yet to -> migrate to Dart 3. -> But in the long term, you should stop relying on them and migrate to `switch` expressions. - -##### When - -The [when] method is the equivalent to pattern matching with destructing. -The prototype of the method depends on the constructors defined. - -For example, with: - -```dart -@freezed -sealed class Union with _$Union { - const factory Union(int value) = Data; - const factory Union.loading() = Loading; - const factory Union.error([String? message]) = ErrorDetails; -} -``` - -Then [when] will be: - -```dart -var union = Union(42); - -print( - union.when( - (int value) => 'Data $value', - loading: () => 'loading', - error: (String? message) => 'Error: $message', - ), -); // Data 42 -``` - -Whereas if we defined: - -```dart -@freezed -sealed class Model with _$Model { - factory Model.first(String a) = First; - factory Model.second(int b, bool c) = Second; -} -``` - -Then [when] will be: - -```dart -var model = Model.first('42'); - -print( - model.when( - first: (String a) => 'first $a', - second: (int b, bool c) => 'second $b $c' - ), -); // first 42 -``` - -Notice how each callback matches with a constructor's name and prototype. - -##### Map - -The [map] methods are equivalent to [when], but **without** destructuring. - -Consider this class: - -```dart -@freezed -sealed class Model with _$Model { - factory Model.first(String a) = First; - factory Model.second(int b, bool c) = Second; -} -``` - -With such class, while [when] will be: - -```dart -var model = Model.first('42'); - -print( - model.when( - first: (String a) => 'first $a', - second: (int b, bool c) => 'second $b $c' - ), -); // first 42 -``` - -[map] will instead be: - -```dart -var model = Model.first('42'); - -print( - model.map( - first: (First value) => 'first ${value.a}', - second: (Second value) => 'second ${value.b} ${value.c}' - ), -); // first 42 -``` - -This can be useful if you want to do complex operations, like [copyWith]/`toString` for example: - -```dart -var model = Model.second(42, false) -print( - model.map( - first: (value) => value, - second: (value) => value.copyWith(c: true), - ) -); // Model.second(b: 42, c: true) -``` - ## Configurations Freezed offers various options to customize the generated code. For example, you diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index b0e044b3..a16c7b25 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -14,13 +14,7 @@ import 'package:freezed/src/templates/properties.dart'; import 'package:freezed/src/templates/prototypes.dart'; import 'package:freezed/src/tools/type.dart'; import 'package:freezed_annotation/freezed_annotation.dart' - show - Assert, - Freezed, - FreezedMapOptions, - FreezedUnionCase, - FreezedUnionValue, - FreezedWhenOptions; + show Assert, Freezed, FreezedUnionCase, FreezedUnionValue; import 'package:json_annotation/json_annotation.dart' show JsonSerializable; import 'package:meta/meta.dart'; import 'package:source_gen/source_gen.dart'; @@ -101,12 +95,6 @@ class FreezedGenerator extends ParserGenerator { configs, ); - final shouldGenerateUnions = constructorsNeedsGeneration - .where( - (element) => element.name.isNotEmpty && !element.name.startsWith('_'), - ) - .isNotEmpty; - late final needsJsonSerializable = _needsJsonSerializable( buildStep, globalData, @@ -124,16 +112,6 @@ class FreezedGenerator extends ParserGenerator { generateFromJson: configs.fromJson ?? await needsJsonSerializable, generateToJson: configs.toJson ?? await needsJsonSerializable, genericArgumentFactories: configs.genericArgumentFactories, - map: MapConfig( - map: configs.map?.map ?? shouldGenerateUnions, - mapOrNull: configs.map?.mapOrNull ?? shouldGenerateUnions, - maybeMap: configs.map?.maybeMap ?? shouldGenerateUnions, - ), - when: WhenConfig( - when: configs.when?.when ?? shouldGenerateUnions, - whenOrNull: configs.when?.whenOrNull ?? shouldGenerateUnions, - maybeWhen: configs.when?.maybeWhen ?? shouldGenerateUnions, - ), makeCollectionsImmutable: configs.makeCollectionsUnmodifiable!, constructors: constructorsNeedsGeneration, concretePropertiesName: [ @@ -598,29 +576,6 @@ class FreezedGenerator extends ParserGenerator { orElse: () => _buildYamlConfigs.fromJson, ), addImplicitFinal: annotation.getField('addImplicitFinal')!.toBoolValue()!, - map: annotation.decodeField( - 'map', - decode: (obj) { - return FreezedMapOptions( - map: obj.decodeField( - 'map', - decode: (obj) => obj.toBoolValue(), - orElse: () => _buildYamlConfigs.map?.map, - ), - maybeMap: obj.decodeField( - 'maybeMap', - decode: (obj) => obj.toBoolValue(), - orElse: () => _buildYamlConfigs.map?.maybeMap, - ), - mapOrNull: obj.decodeField( - 'mapOrNull', - decode: (obj) => obj.toBoolValue(), - orElse: () => _buildYamlConfigs.map?.mapOrNull, - ), - ); - }, - orElse: () => _buildYamlConfigs.map, - ), toJson: annotation.decodeField( 'toJson', decode: (obj) => obj.toBoolValue(), @@ -653,29 +608,6 @@ class FreezedGenerator extends ParserGenerator { }, orElse: () => _buildYamlConfigs.unionValueCase, ), - when: annotation.decodeField( - 'when', - decode: (obj) { - return FreezedWhenOptions( - when: obj.decodeField( - 'when', - decode: (obj) => obj.toBoolValue(), - orElse: () => _buildYamlConfigs.when?.when, - ), - maybeWhen: obj.decodeField( - 'maybeWhen', - decode: (obj) => obj.toBoolValue(), - orElse: () => _buildYamlConfigs.when?.maybeWhen, - ), - whenOrNull: obj.decodeField( - 'whenOrNull', - decode: (obj) => obj.toBoolValue(), - orElse: () => _buildYamlConfigs.when?.whenOrNull, - ), - ); - }, - orElse: () => _buildYamlConfigs.when, - ), ); } diff --git a/packages/freezed/lib/src/models.dart b/packages/freezed/lib/src/models.dart index 26a8ea58..1420fd52 100644 --- a/packages/freezed/lib/src/models.dart +++ b/packages/freezed/lib/src/models.dart @@ -54,24 +54,6 @@ class ConstructorDetails with _$ConstructorDetails { String get callbackName => constructorNameToCallbackName(name); } -@freezed -class MapConfig with _$MapConfig { - factory MapConfig({ - required bool map, - required bool mapOrNull, - required bool maybeMap, - }) = _MapConfig; -} - -@freezed -class WhenConfig with _$WhenConfig { - factory WhenConfig({ - required bool when, - required bool whenOrNull, - required bool maybeWhen, - }) = _WhenConfig; -} - @freezed class Data with _$Data { @Assert('constructors.isNotEmpty') @@ -81,8 +63,6 @@ class Data with _$Data { required bool generateCopyWith, required bool generateEqual, required bool generateToString, - required MapConfig map, - required WhenConfig when, required bool generateFromJson, required bool generateToJson, required bool makeCollectionsImmutable, diff --git a/packages/freezed/lib/src/models.freezed.dart b/packages/freezed/lib/src/models.freezed.dart index b1c315f6..a15fb2ec 100644 --- a/packages/freezed/lib/src/models.freezed.dart +++ b/packages/freezed/lib/src/models.freezed.dart @@ -23,6 +23,8 @@ mixin _$DeepCloneableProperty { GenericsParameterTemplate get genericParameters => throw _privateConstructorUsedError; + /// Create a copy of DeepCloneableProperty + /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) $DeepCloneablePropertyCopyWith get copyWith => throw _privateConstructorUsedError; @@ -53,6 +55,8 @@ class _$DeepCloneablePropertyCopyWithImpl<$Res, // ignore: unused_field final $Res Function($Val) _then; + /// Create a copy of DeepCloneableProperty + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -113,6 +117,8 @@ class __$$DeepCloneablePropertyImplCopyWithImpl<$Res> $Res Function(_$DeepCloneablePropertyImpl) _then) : super(_value, _then); + /// Create a copy of DeepCloneableProperty + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -192,6 +198,8 @@ class _$DeepCloneablePropertyImpl implements _DeepCloneableProperty { int get hashCode => Object.hash( runtimeType, name, typeName, type, nullable, genericParameters); + /// Create a copy of DeepCloneableProperty + /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') @@ -219,6 +227,9 @@ abstract class _DeepCloneableProperty implements DeepCloneableProperty { bool get nullable; @override GenericsParameterTemplate get genericParameters; + + /// Create a copy of DeepCloneableProperty + /// with the given fields replaced by the non-null parameter values. @override @JsonKey(includeFromJson: false, includeToJson: false) _$$DeepCloneablePropertyImplCopyWith<_$DeepCloneablePropertyImpl> @@ -245,6 +256,8 @@ mixin _$ConstructorDetails { throw _privateConstructorUsedError; List get asserts => throw _privateConstructorUsedError; + /// Create a copy of ConstructorDetails + /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) $ConstructorDetailsCopyWith get copyWith => throw _privateConstructorUsedError; @@ -285,6 +298,8 @@ class _$ConstructorDetailsCopyWithImpl<$Res, $Val extends ConstructorDetails> // ignore: unused_field final $Res Function($Val) _then; + /// Create a copy of ConstructorDetails + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -409,6 +424,8 @@ class __$$ConstructorDetailsImplCopyWithImpl<$Res> $Res Function(_$ConstructorDetailsImpl) _then) : super(_value, _then); + /// Create a copy of ConstructorDetails + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -658,6 +675,8 @@ class _$ConstructorDetailsImpl extends _ConstructorDetails { const DeepCollectionEquality().hash(_cloneableProperties), const DeepCollectionEquality().hash(_asserts)); + /// Create a copy of ConstructorDetails + /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') @@ -718,318 +737,12 @@ abstract class _ConstructorDetails extends ConstructorDetails { List get cloneableProperties; @override List get asserts; - @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$ConstructorDetailsImplCopyWith<_$ConstructorDetailsImpl> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -mixin _$MapConfig { - bool get map => throw _privateConstructorUsedError; - bool get mapOrNull => throw _privateConstructorUsedError; - bool get maybeMap => throw _privateConstructorUsedError; - - @JsonKey(includeFromJson: false, includeToJson: false) - $MapConfigCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $MapConfigCopyWith<$Res> { - factory $MapConfigCopyWith(MapConfig value, $Res Function(MapConfig) then) = - _$MapConfigCopyWithImpl<$Res, MapConfig>; - @useResult - $Res call({bool map, bool mapOrNull, bool maybeMap}); -} - -/// @nodoc -class _$MapConfigCopyWithImpl<$Res, $Val extends MapConfig> - implements $MapConfigCopyWith<$Res> { - _$MapConfigCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? map = null, - Object? mapOrNull = null, - Object? maybeMap = null, - }) { - return _then(_value.copyWith( - map: null == map - ? _value.map - : map // ignore: cast_nullable_to_non_nullable - as bool, - mapOrNull: null == mapOrNull - ? _value.mapOrNull - : mapOrNull // ignore: cast_nullable_to_non_nullable - as bool, - maybeMap: null == maybeMap - ? _value.maybeMap - : maybeMap // ignore: cast_nullable_to_non_nullable - as bool, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$MapConfigImplCopyWith<$Res> - implements $MapConfigCopyWith<$Res> { - factory _$$MapConfigImplCopyWith( - _$MapConfigImpl value, $Res Function(_$MapConfigImpl) then) = - __$$MapConfigImplCopyWithImpl<$Res>; - @override - @useResult - $Res call({bool map, bool mapOrNull, bool maybeMap}); -} - -/// @nodoc -class __$$MapConfigImplCopyWithImpl<$Res> - extends _$MapConfigCopyWithImpl<$Res, _$MapConfigImpl> - implements _$$MapConfigImplCopyWith<$Res> { - __$$MapConfigImplCopyWithImpl( - _$MapConfigImpl _value, $Res Function(_$MapConfigImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? map = null, - Object? mapOrNull = null, - Object? maybeMap = null, - }) { - return _then(_$MapConfigImpl( - map: null == map - ? _value.map - : map // ignore: cast_nullable_to_non_nullable - as bool, - mapOrNull: null == mapOrNull - ? _value.mapOrNull - : mapOrNull // ignore: cast_nullable_to_non_nullable - as bool, - maybeMap: null == maybeMap - ? _value.maybeMap - : maybeMap // ignore: cast_nullable_to_non_nullable - as bool, - )); - } -} - -/// @nodoc - -class _$MapConfigImpl implements _MapConfig { - _$MapConfigImpl( - {required this.map, required this.mapOrNull, required this.maybeMap}); - - @override - final bool map; - @override - final bool mapOrNull; - @override - final bool maybeMap; - - @override - String toString() { - return 'MapConfig(map: $map, mapOrNull: $mapOrNull, maybeMap: $maybeMap)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$MapConfigImpl && - (identical(other.map, map) || other.map == map) && - (identical(other.mapOrNull, mapOrNull) || - other.mapOrNull == mapOrNull) && - (identical(other.maybeMap, maybeMap) || - other.maybeMap == maybeMap)); - } - - @override - int get hashCode => Object.hash(runtimeType, map, mapOrNull, maybeMap); - - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$MapConfigImplCopyWith<_$MapConfigImpl> get copyWith => - __$$MapConfigImplCopyWithImpl<_$MapConfigImpl>(this, _$identity); -} - -abstract class _MapConfig implements MapConfig { - factory _MapConfig( - {required final bool map, - required final bool mapOrNull, - required final bool maybeMap}) = _$MapConfigImpl; - - @override - bool get map; - @override - bool get mapOrNull; - @override - bool get maybeMap; - @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$MapConfigImplCopyWith<_$MapConfigImpl> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -mixin _$WhenConfig { - bool get when => throw _privateConstructorUsedError; - bool get whenOrNull => throw _privateConstructorUsedError; - bool get maybeWhen => throw _privateConstructorUsedError; - - @JsonKey(includeFromJson: false, includeToJson: false) - $WhenConfigCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $WhenConfigCopyWith<$Res> { - factory $WhenConfigCopyWith( - WhenConfig value, $Res Function(WhenConfig) then) = - _$WhenConfigCopyWithImpl<$Res, WhenConfig>; - @useResult - $Res call({bool when, bool whenOrNull, bool maybeWhen}); -} - -/// @nodoc -class _$WhenConfigCopyWithImpl<$Res, $Val extends WhenConfig> - implements $WhenConfigCopyWith<$Res> { - _$WhenConfigCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? when = null, - Object? whenOrNull = null, - Object? maybeWhen = null, - }) { - return _then(_value.copyWith( - when: null == when - ? _value.when - : when // ignore: cast_nullable_to_non_nullable - as bool, - whenOrNull: null == whenOrNull - ? _value.whenOrNull - : whenOrNull // ignore: cast_nullable_to_non_nullable - as bool, - maybeWhen: null == maybeWhen - ? _value.maybeWhen - : maybeWhen // ignore: cast_nullable_to_non_nullable - as bool, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$WhenConfigImplCopyWith<$Res> - implements $WhenConfigCopyWith<$Res> { - factory _$$WhenConfigImplCopyWith( - _$WhenConfigImpl value, $Res Function(_$WhenConfigImpl) then) = - __$$WhenConfigImplCopyWithImpl<$Res>; - @override - @useResult - $Res call({bool when, bool whenOrNull, bool maybeWhen}); -} - -/// @nodoc -class __$$WhenConfigImplCopyWithImpl<$Res> - extends _$WhenConfigCopyWithImpl<$Res, _$WhenConfigImpl> - implements _$$WhenConfigImplCopyWith<$Res> { - __$$WhenConfigImplCopyWithImpl( - _$WhenConfigImpl _value, $Res Function(_$WhenConfigImpl) _then) - : super(_value, _then); - @pragma('vm:prefer-inline') + /// Create a copy of ConstructorDetails + /// with the given fields replaced by the non-null parameter values. @override - $Res call({ - Object? when = null, - Object? whenOrNull = null, - Object? maybeWhen = null, - }) { - return _then(_$WhenConfigImpl( - when: null == when - ? _value.when - : when // ignore: cast_nullable_to_non_nullable - as bool, - whenOrNull: null == whenOrNull - ? _value.whenOrNull - : whenOrNull // ignore: cast_nullable_to_non_nullable - as bool, - maybeWhen: null == maybeWhen - ? _value.maybeWhen - : maybeWhen // ignore: cast_nullable_to_non_nullable - as bool, - )); - } -} - -/// @nodoc - -class _$WhenConfigImpl implements _WhenConfig { - _$WhenConfigImpl( - {required this.when, required this.whenOrNull, required this.maybeWhen}); - - @override - final bool when; - @override - final bool whenOrNull; - @override - final bool maybeWhen; - - @override - String toString() { - return 'WhenConfig(when: $when, whenOrNull: $whenOrNull, maybeWhen: $maybeWhen)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$WhenConfigImpl && - (identical(other.when, when) || other.when == when) && - (identical(other.whenOrNull, whenOrNull) || - other.whenOrNull == whenOrNull) && - (identical(other.maybeWhen, maybeWhen) || - other.maybeWhen == maybeWhen)); - } - - @override - int get hashCode => Object.hash(runtimeType, when, whenOrNull, maybeWhen); - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$WhenConfigImplCopyWith<_$WhenConfigImpl> get copyWith => - __$$WhenConfigImplCopyWithImpl<_$WhenConfigImpl>(this, _$identity); -} - -abstract class _WhenConfig implements WhenConfig { - factory _WhenConfig( - {required final bool when, - required final bool whenOrNull, - required final bool maybeWhen}) = _$WhenConfigImpl; - - @override - bool get when; - @override - bool get whenOrNull; - @override - bool get maybeWhen; - @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$WhenConfigImplCopyWith<_$WhenConfigImpl> get copyWith => + _$$ConstructorDetailsImplCopyWith<_$ConstructorDetailsImpl> get copyWith => throw _privateConstructorUsedError; } @@ -1040,8 +753,6 @@ mixin _$Data { bool get generateCopyWith => throw _privateConstructorUsedError; bool get generateEqual => throw _privateConstructorUsedError; bool get generateToString => throw _privateConstructorUsedError; - MapConfig get map => throw _privateConstructorUsedError; - WhenConfig get when => throw _privateConstructorUsedError; bool get generateFromJson => throw _privateConstructorUsedError; bool get generateToJson => throw _privateConstructorUsedError; bool get makeCollectionsImmutable => throw _privateConstructorUsedError; @@ -1055,6 +766,8 @@ mixin _$Data { bool get shouldUseExtends => throw _privateConstructorUsedError; bool get genericArgumentFactories => throw _privateConstructorUsedError; + /// Create a copy of Data + /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) $DataCopyWith get copyWith => throw _privateConstructorUsedError; } @@ -1070,8 +783,6 @@ abstract class $DataCopyWith<$Res> { bool generateCopyWith, bool generateEqual, bool generateToString, - MapConfig map, - WhenConfig when, bool generateFromJson, bool generateToJson, bool makeCollectionsImmutable, @@ -1081,9 +792,6 @@ abstract class $DataCopyWith<$Res> { GenericsParameterTemplate genericsParameterTemplate, bool shouldUseExtends, bool genericArgumentFactories}); - - $MapConfigCopyWith<$Res> get map; - $WhenConfigCopyWith<$Res> get when; } /// @nodoc @@ -1096,6 +804,8 @@ class _$DataCopyWithImpl<$Res, $Val extends Data> // ignore: unused_field final $Res Function($Val) _then; + /// Create a copy of Data + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -1104,8 +814,6 @@ class _$DataCopyWithImpl<$Res, $Val extends Data> Object? generateCopyWith = null, Object? generateEqual = null, Object? generateToString = null, - Object? map = null, - Object? when = null, Object? generateFromJson = null, Object? generateToJson = null, Object? makeCollectionsImmutable = null, @@ -1137,14 +845,6 @@ class _$DataCopyWithImpl<$Res, $Val extends Data> ? _value.generateToString : generateToString // ignore: cast_nullable_to_non_nullable as bool, - map: null == map - ? _value.map - : map // ignore: cast_nullable_to_non_nullable - as MapConfig, - when: null == when - ? _value.when - : when // ignore: cast_nullable_to_non_nullable - as WhenConfig, generateFromJson: null == generateFromJson ? _value.generateFromJson : generateFromJson // ignore: cast_nullable_to_non_nullable @@ -1183,22 +883,6 @@ class _$DataCopyWithImpl<$Res, $Val extends Data> as bool, ) as $Val); } - - @override - @pragma('vm:prefer-inline') - $MapConfigCopyWith<$Res> get map { - return $MapConfigCopyWith<$Res>(_value.map, (value) { - return _then(_value.copyWith(map: value) as $Val); - }); - } - - @override - @pragma('vm:prefer-inline') - $WhenConfigCopyWith<$Res> get when { - return $WhenConfigCopyWith<$Res>(_value.when, (value) { - return _then(_value.copyWith(when: value) as $Val); - }); - } } /// @nodoc @@ -1214,8 +898,6 @@ abstract class _$$DataImplCopyWith<$Res> implements $DataCopyWith<$Res> { bool generateCopyWith, bool generateEqual, bool generateToString, - MapConfig map, - WhenConfig when, bool generateFromJson, bool generateToJson, bool makeCollectionsImmutable, @@ -1225,11 +907,6 @@ abstract class _$$DataImplCopyWith<$Res> implements $DataCopyWith<$Res> { GenericsParameterTemplate genericsParameterTemplate, bool shouldUseExtends, bool genericArgumentFactories}); - - @override - $MapConfigCopyWith<$Res> get map; - @override - $WhenConfigCopyWith<$Res> get when; } /// @nodoc @@ -1239,6 +916,8 @@ class __$$DataImplCopyWithImpl<$Res> __$$DataImplCopyWithImpl(_$DataImpl _value, $Res Function(_$DataImpl) _then) : super(_value, _then); + /// Create a copy of Data + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -1247,8 +926,6 @@ class __$$DataImplCopyWithImpl<$Res> Object? generateCopyWith = null, Object? generateEqual = null, Object? generateToString = null, - Object? map = null, - Object? when = null, Object? generateFromJson = null, Object? generateToJson = null, Object? makeCollectionsImmutable = null, @@ -1280,14 +957,6 @@ class __$$DataImplCopyWithImpl<$Res> ? _value.generateToString : generateToString // ignore: cast_nullable_to_non_nullable as bool, - map: null == map - ? _value.map - : map // ignore: cast_nullable_to_non_nullable - as MapConfig, - when: null == when - ? _value.when - : when // ignore: cast_nullable_to_non_nullable - as WhenConfig, generateFromJson: null == generateFromJson ? _value.generateFromJson : generateFromJson // ignore: cast_nullable_to_non_nullable @@ -1337,8 +1006,6 @@ class _$DataImpl implements _Data { required this.generateCopyWith, required this.generateEqual, required this.generateToString, - required this.map, - required this.when, required this.generateFromJson, required this.generateToJson, required this.makeCollectionsImmutable, @@ -1363,10 +1030,6 @@ class _$DataImpl implements _Data { @override final bool generateToString; @override - final MapConfig map; - @override - final WhenConfig when; - @override final bool generateFromJson; @override final bool generateToJson; @@ -1400,7 +1063,7 @@ class _$DataImpl implements _Data { @override String toString() { - return 'Data(name: $name, unionKey: $unionKey, generateCopyWith: $generateCopyWith, generateEqual: $generateEqual, generateToString: $generateToString, map: $map, when: $when, generateFromJson: $generateFromJson, generateToJson: $generateToJson, makeCollectionsImmutable: $makeCollectionsImmutable, concretePropertiesName: $concretePropertiesName, constructors: $constructors, genericsDefinitionTemplate: $genericsDefinitionTemplate, genericsParameterTemplate: $genericsParameterTemplate, shouldUseExtends: $shouldUseExtends, genericArgumentFactories: $genericArgumentFactories)'; + return 'Data(name: $name, unionKey: $unionKey, generateCopyWith: $generateCopyWith, generateEqual: $generateEqual, generateToString: $generateToString, generateFromJson: $generateFromJson, generateToJson: $generateToJson, makeCollectionsImmutable: $makeCollectionsImmutable, concretePropertiesName: $concretePropertiesName, constructors: $constructors, genericsDefinitionTemplate: $genericsDefinitionTemplate, genericsParameterTemplate: $genericsParameterTemplate, shouldUseExtends: $shouldUseExtends, genericArgumentFactories: $genericArgumentFactories)'; } @override @@ -1417,8 +1080,6 @@ class _$DataImpl implements _Data { other.generateEqual == generateEqual) && (identical(other.generateToString, generateToString) || other.generateToString == generateToString) && - (identical(other.map, map) || other.map == map) && - (identical(other.when, when) || other.when == when) && (identical(other.generateFromJson, generateFromJson) || other.generateFromJson == generateFromJson) && (identical(other.generateToJson, generateToJson) || @@ -1452,8 +1113,6 @@ class _$DataImpl implements _Data { generateCopyWith, generateEqual, generateToString, - map, - when, generateFromJson, generateToJson, makeCollectionsImmutable, @@ -1464,6 +1123,8 @@ class _$DataImpl implements _Data { shouldUseExtends, genericArgumentFactories); + /// Create a copy of Data + /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') @@ -1478,8 +1139,6 @@ abstract class _Data implements Data { required final bool generateCopyWith, required final bool generateEqual, required final bool generateToString, - required final MapConfig map, - required final WhenConfig when, required final bool generateFromJson, required final bool generateToJson, required final bool makeCollectionsImmutable, @@ -1501,10 +1160,6 @@ abstract class _Data implements Data { @override bool get generateToString; @override - MapConfig get map; - @override - WhenConfig get when; - @override bool get generateFromJson; @override bool get generateToJson; @@ -1522,6 +1177,9 @@ abstract class _Data implements Data { bool get shouldUseExtends; @override bool get genericArgumentFactories; + + /// Create a copy of Data + /// with the given fields replaced by the non-null parameter values. @override @JsonKey(includeFromJson: false, includeToJson: false) _$$DataImplCopyWith<_$DataImpl> get copyWith => @@ -1533,6 +1191,8 @@ mixin _$GlobalData { bool get hasJson => throw _privateConstructorUsedError; bool get hasDiagnostics => throw _privateConstructorUsedError; + /// Create a copy of GlobalData + /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) $GlobalDataCopyWith get copyWith => throw _privateConstructorUsedError; @@ -1557,6 +1217,8 @@ class _$GlobalDataCopyWithImpl<$Res, $Val extends GlobalData> // ignore: unused_field final $Res Function($Val) _then; + /// Create a copy of GlobalData + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -1595,6 +1257,8 @@ class __$$GlobalDataImplCopyWithImpl<$Res> _$GlobalDataImpl _value, $Res Function(_$GlobalDataImpl) _then) : super(_value, _then); + /// Create a copy of GlobalData + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ @@ -1642,6 +1306,8 @@ class _$GlobalDataImpl implements _GlobalData { @override int get hashCode => Object.hash(runtimeType, hasJson, hasDiagnostics); + /// Create a copy of GlobalData + /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') @@ -1658,6 +1324,9 @@ abstract class _GlobalData implements GlobalData { bool get hasJson; @override bool get hasDiagnostics; + + /// Create a copy of GlobalData + /// with the given fields replaced by the non-null parameter values. @override @JsonKey(includeFromJson: false, includeToJson: false) _$$GlobalDataImplCopyWith<_$GlobalDataImpl> get copyWith => diff --git a/packages/freezed/lib/src/templates/abstract_template.dart b/packages/freezed/lib/src/templates/abstract_template.dart index 890b9428..662445ba 100644 --- a/packages/freezed/lib/src/templates/abstract_template.dart +++ b/packages/freezed/lib/src/templates/abstract_template.dart @@ -30,12 +30,6 @@ class Abstract { mixin _\$${data.name.public}${data.genericsDefinitionTemplate} { $abstractProperties -$_when -$_whenOrNull -$_maybeWhen -$_map -$_mapOrNull -$_maybeMap $_toJson ${copyWith?.abstractCopyWithGetter ?? ''} } @@ -54,34 +48,4 @@ ${copyWith?.commonConcreteImpl ?? ''} 'Map toJson($_toJsonParams)' ' => throw $privConstUsedErrorVarName;'; } - - String get _when { - if (!data.when.when) return ''; - return '${whenPrototype(data.constructors)} => throw $privConstUsedErrorVarName;'; - } - - String get _whenOrNull { - if (!data.when.whenOrNull) return ''; - return '${whenOrNullPrototype(data.constructors)} => throw $privConstUsedErrorVarName;'; - } - - String get _maybeWhen { - if (!data.when.maybeWhen) return ''; - return '${maybeWhenPrototype(data.constructors)} => throw $privConstUsedErrorVarName;'; - } - - String get _map { - if (!data.map.map) return ''; - return '${mapPrototype(data.constructors, data.genericsParameterTemplate)} => throw $privConstUsedErrorVarName;'; - } - - String get _mapOrNull { - if (!data.map.mapOrNull) return ''; - return '${mapOrNullPrototype(data.constructors, data.genericsParameterTemplate)} => throw $privConstUsedErrorVarName;'; - } - - String get _maybeMap { - if (!data.map.maybeMap) return ''; - return '${maybeMapPrototype(data.constructors, data.genericsParameterTemplate)} => throw $privConstUsedErrorVarName;'; - } } diff --git a/packages/freezed/lib/src/templates/concrete_template.dart b/packages/freezed/lib/src/templates/concrete_template.dart index 97ff6d62..249e75ea 100644 --- a/packages/freezed/lib/src/templates/concrete_template.dart +++ b/packages/freezed/lib/src/templates/concrete_template.dart @@ -76,12 +76,6 @@ $_debugFillProperties $_operatorEqualMethod $_hashCodeMethod ${copyWith?.concreteCopyWithGetter ?? ''} -$_when -$_whenOrNull -$_maybeWhen -$_map -$_mapOrNull -$_maybeMap $_toJson } @@ -333,93 +327,6 @@ void debugFillProperties(DiagnosticPropertiesBuilder properties) { '''; } - String get _maybeMap { - if (!data.map.maybeMap) return ''; - - return ''' -@override -${maybeMapPrototype(data.constructors, data.genericsParameterTemplate)} { - if (${constructor.callbackName} != null) { - return ${constructor.callbackName}(this); - } - return orElse(); -}'''; - } - - String get _map { - if (!data.map.map) return ''; - - return ''' -@override -${mapPrototype(data.constructors, data.genericsParameterTemplate)} { - return ${constructor.callbackName}(this); -}'''; - } - - String get _mapOrNull { - if (!data.map.mapOrNull) return ''; - - return ''' -@override -${mapOrNullPrototype(data.constructors, data.genericsParameterTemplate)} { - return ${constructor.callbackName}?.call(this); -}'''; - } - - String get _maybeWhen { - if (!data.when.maybeWhen) return ''; - - var callbackParameters = constructor.impliedProperties.map((e) { - if (data.constructors.any((c) => c.callbackName == e.name)) { - return 'this.${e.name}'; - } - return e.name; - }).join(','); - - return ''' -@override -${maybeWhenPrototype(data.constructors)} { - if (${constructor.callbackName} != null) { - return ${constructor.callbackName}($callbackParameters); - } - return orElse(); -}'''; - } - - String get _when { - if (!data.when.when) return ''; - - var callbackParameters = constructor.impliedProperties.map((e) { - if (data.constructors.any((c) => c.callbackName == e.name)) { - return 'this.${e.name}'; - } - return e.name; - }).join(','); - - return ''' -@override -${whenPrototype(data.constructors)} { - return ${constructor.callbackName}($callbackParameters); -}'''; - } - - String get _whenOrNull { - if (!data.when.whenOrNull) return ''; - - var callbackParameters = constructor.impliedProperties.map((e) { - if (data.constructors.any((c) => c.callbackName == e.name)) { - return 'this.${e.name}'; - } - return e.name; - }).join(','); - - return ''' -@override -${whenOrNullPrototype(data.constructors)} { - return ${constructor.callbackName}?.call($callbackParameters); -}'''; - } - String get _abstractProperties { return constructor.impliedProperties.expand((p) { return [ diff --git a/packages/freezed/lib/src/templates/prototypes.dart b/packages/freezed/lib/src/templates/prototypes.dart index e2d11a0d..3f6b206b 100644 --- a/packages/freezed/lib/src/templates/prototypes.dart +++ b/packages/freezed/lib/src/templates/prototypes.dart @@ -2,7 +2,6 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:source_gen/source_gen.dart'; -import '../models.dart'; import 'parameter_template.dart'; List parseDecorators(List metadata) { @@ -36,198 +35,6 @@ extension FreezedElementAnnotation on ElementAnnotation { } } -String whenPrototype(List allConstructors) { - return _whenPrototype( - allConstructors, - areCallbacksRequired: true, - isReturnTypeNullable: false, - name: 'when', - ); -} - -String whenOrNullPrototype(List allConstructors) { - return _whenPrototype( - allConstructors, - areCallbacksRequired: false, - isReturnTypeNullable: true, - name: 'whenOrNull', - ); -} - -String maybeWhenPrototype(List allConstructors) { - return _whenPrototype( - allConstructors, - areCallbacksRequired: false, - isReturnTypeNullable: false, - name: 'maybeWhen', - ); -} - -String mapPrototype( - List allConstructors, - GenericsParameterTemplate genericParameters, -) { - return _mapPrototype( - allConstructors, - genericParameters, - areCallbacksRequired: true, - isReturnTypeNullable: false, - name: 'map', - ); -} - -String mapOrNullPrototype( - List allConstructors, - GenericsParameterTemplate genericParameters, -) { - return _mapPrototype( - allConstructors, - genericParameters, - areCallbacksRequired: false, - isReturnTypeNullable: true, - name: 'mapOrNull', - ); -} - -String maybeMapPrototype( - List allConstructors, - GenericsParameterTemplate genericParameters, -) { - return _mapPrototype( - allConstructors, - genericParameters, - areCallbacksRequired: false, - isReturnTypeNullable: false, - name: 'maybeMap', - ); -} - -String _mapPrototype( - List allConstructors, - GenericsParameterTemplate genericParameters, { - required bool areCallbacksRequired, - required bool isReturnTypeNullable, - required String name, -}) { - return _unionPrototype( - allConstructors, - areCallbacksRequired: areCallbacksRequired, - isReturnTypeNullable: isReturnTypeNullable, - name: name, - ctor2parameters: (constructor) { - return ParametersTemplate([ - Parameter( - name: 'value', - type: '${constructor.redirectedName}$genericParameters', - isRequired: false, - isNullable: false, - isFinal: false, - isDartList: false, - isDartSet: false, - isDartMap: false, - decorators: const [], - defaultValueSource: '', - doc: '', - // TODO: do we want to support freezed classes that implements MapView/ListView? - isPossiblyDartCollection: false, - showDefaultValue: false, - parameterElement: null, - ), - ]); - }, - ); -} - -String _whenPrototype( - List allConstructors, { - required bool areCallbacksRequired, - required bool isReturnTypeNullable, - required String name, -}) { - return _unionPrototype( - allConstructors, - areCallbacksRequired: areCallbacksRequired, - isReturnTypeNullable: isReturnTypeNullable, - name: name, - ctor2parameters: (constructor) { - return ParametersTemplate([ - ...constructor.parameters.requiredPositionalParameters - .map((e) => e.copyWith(isFinal: false)), - ...constructor.parameters.optionalPositionalParameters - .map((e) => e.copyWith( - isFinal: false, - showDefaultValue: false, - )), - ...constructor.parameters.namedParameters.map((e) => e.copyWith( - isRequired: false, - isFinal: false, - showDefaultValue: false, - )), - ]); - }, - ); -} - -String _unionPrototype( - List allConstructors, { - required bool areCallbacksRequired, - required bool isReturnTypeNullable, - required String name, - required ParametersTemplate Function(ConstructorDetails) ctor2parameters, -}) { - final returnType = isReturnTypeNullable ? 'TResult?' : 'TResult'; - - final buffer = StringBuffer( - '@optionalTypeArgs $returnType $name('); - - final parameters = []; - for (final constructor in allConstructors) { - var template = CallbackParameter( - name: constructorNameToCallbackName(constructor.name), - type: returnType, - isFinal: false, - isDartList: false, - isDartMap: false, - isDartSet: false, - isRequired: !constructor.isDefault && areCallbacksRequired, - isNullable: !areCallbacksRequired, - parameters: ctor2parameters(constructor), - decorators: const [], - defaultValueSource: '', - doc: '', - isPossiblyDartCollection: false, - parameterElement: null, - ); - - if (constructor.isDefault) { - buffer - ..write(template) - ..write(','); - } else { - parameters.add(template); - } - } - - final hasOrElse = !areCallbacksRequired && !isReturnTypeNullable; - - if (parameters.isNotEmpty || hasOrElse) { - buffer.write('{'); - if (parameters.isNotEmpty) { - buffer - ..writeAll(parameters, ',') - ..write(','); - } - - if (hasOrElse) { - buffer.write('required $returnType orElse(),'); - } - - buffer.write('}'); - } - buffer.write(')'); - return buffer.toString(); -} - bool isDefaultConstructor(ConstructorElement constructor) { return constructor.name.isEmpty; } diff --git a/packages/freezed/test/generic_test.dart b/packages/freezed/test/generic_test.dart index 60301a96..fbdfc4cf 100644 --- a/packages/freezed/test/generic_test.dart +++ b/packages/freezed/test/generic_test.dart @@ -54,27 +54,6 @@ void main() { expect(model.value, 42); }); - test('map is generic too', () { - var result = MultipleConstructors(false) - .map>( - (Default value) => value, - first: (First value) => value, - second: (Second value) => value, - ); - - expect(result, MultipleConstructors(false)); - - MultipleConstructors(false) - .maybeMap>( - (Default value) => value, - first: (First value) => value, - second: (Second value) => value, - orElse: () => throw Error(), - ); - - expect(result, MultipleConstructors(false)); - }); - test('is generic2', () { MultiGeneric> value = MultiGeneric(Model(42)); Model model = value.model; diff --git a/packages/freezed/test/integration/multiple_constructors.dart b/packages/freezed/test/integration/multiple_constructors.dart index 76999376..47e797c2 100644 --- a/packages/freezed/test/integration/multiple_constructors.dart +++ b/packages/freezed/test/integration/multiple_constructors.dart @@ -104,7 +104,7 @@ class NoDefault with _$NoDefault { } @freezed -class NameConflict with _$NameConflict { +sealed class NameConflict with _$NameConflict { factory NameConflict.something(Error error) = Something; factory NameConflict.error(Error error) = SomeError; } diff --git a/packages/freezed/test/integration/optional_maybe.dart b/packages/freezed/test/integration/optional_maybe.dart index 45506269..2cd27fb7 100644 --- a/packages/freezed/test/integration/optional_maybe.dart +++ b/packages/freezed/test/integration/optional_maybe.dart @@ -3,18 +3,6 @@ import 'package:freezed_annotation/freezed_annotation.dart'; part 'optional_maybe.freezed.dart'; part 'optional_maybe.g.dart'; -@Freezed(map: FreezedMapOptions.none) -class OptionalMaybeMap with _$OptionalMaybeMap { - const factory OptionalMaybeMap.first() = OptionalMaybeMap1; - const factory OptionalMaybeMap.second() = OptionalMaybeMap2; -} - -@Freezed(when: FreezedWhenOptions.none) -class OptionalMaybeWhen with _$OptionalMaybeWhen { - const factory OptionalMaybeWhen.first() = OptionalMaybeWhen1; - const factory OptionalMaybeWhen.second() = OptionalMaybeWhen2; -} - @Freezed(copyWith: false) class OptionalCopyWith with _$OptionalCopyWith { const factory OptionalCopyWith([int? a]) = _OptionalCopyWith; @@ -30,16 +18,6 @@ class OptionalEqual with _$OptionalEqual { factory OptionalEqual() = _OptionalEqual; } -@Freezed(map: FreezedMapOptions.all, when: FreezedWhenOptions.all) -class ForceUnionMethod with _$ForceUnionMethod { - factory ForceUnionMethod() = _ForceUnionMethod; -} - -@Freezed(map: FreezedMapOptions.all, when: FreezedWhenOptions.all) -class ForceUnionMethod2 with _$ForceUnionMethod2 { - factory ForceUnionMethod2.two() = _ForceUnionMethod2; -} - @Freezed(toJson: false) class OptionalToJson with _$OptionalToJson { factory OptionalToJson() = _OptionalToJson; diff --git a/packages/freezed/test/map_test.dart b/packages/freezed/test/map_test.dart deleted file mode 100644 index 9f8164b6..00000000 --- a/packages/freezed/test/map_test.dart +++ /dev/null @@ -1,438 +0,0 @@ -// ignore_for_file: prefer_const_constructors, omit_local_variable_types - -import 'package:analyzer/dart/analysis/results.dart'; -import 'package:build_test/build_test.dart'; -import 'package:test/test.dart'; - -import 'common.dart'; -import 'integration/multiple_constructors.dart'; - -void main() { - group('map', () { - test('works with no default ctr', () { - var value = NoDefault.first('a'); - - expect( - value.map( - first: (NoDefault1 value) => '${value.a} first', - second: (NoDefault2 value) => throw Error(), - ), - 'a first', - ); - - value = NoDefault.second('a'); - - expect( - value.map( - first: (NoDefault1 value) => throw Error(), - second: (NoDefault2 value) => '${value.a} second', - ), - 'a second', - ); - }); - - group('default ctor', () { - test("assert callbacks can't be null", () async { - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest('a'); - - value.map( - (SwitchTest0 a) {}, - first: (SwitchTest1 b) {}, - second: (SwitchTest2 c) {}, - ); -} -'''), completes); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest('a'); - - value.map( - (SwitchTest0 a) {}, - first: null, - second: (SwitchTest2 value) {}, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest('a'); - - value.map( - null, - first: (SwitchTest1 value) {}, - second: (SwitchTest2 value) {}, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest('a'); - - value.map( - (SwitchTest0 a) {}, - first: (SwitchTest1 value) {}, - second: null, - ); -} -'''), throwsCompileError); - }); - test('calls default callback', () { - final value = SwitchTest('a'); - - expect( - value.map( - (SwitchTest0 value) => '${value.a} 42', - first: (SwitchTest1 value) => throw Error(), - second: (SwitchTest2 value) => throw Error(), - ), - 'a 42', - ); - }); - }); - - group('first ctor', () { - test("assert callbacks can't be null", () async { - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.first('a'); - - value.map( - (SwitchTest0 a) {}, - first: (SwitchTest1 b) {}, - second: (SwitchTest2 c) {}, - ); -} -'''), completes); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.first('a'); - - value.map( - (SwitchTest0 a) {}, - first: null, - second: (SwitchTest2 value) {}, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.first('a'); - - value.map( - null, - first: (SwitchTest1 value) {}, - second: (SwitchTest2 value) {}, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.first('a'); - - value.map( - (SwitchTest0 a) {}, - first: (SwitchTest1 value) {}, - second: null, - ); -} -'''), throwsCompileError); - }); - - test('calls first callback', () { - final value = SwitchTest.first('a', b: false, d: .42); - - expect( - value.map( - (SwitchTest0 a) => throw Error(), - first: (SwitchTest1 value) => '${value.a} ${value.b} ${value.d}', - second: (SwitchTest2 value) => throw Error(), - ), - 'a false 0.42', - ); - }); - }); - group('second ctor', () { - test("assert callbacks can't be null", () async { - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.second('a'); - - value.map( - (SwitchTest0 a) {}, - first: (SwitchTest1 b) {}, - second: (SwitchTest2 c) {}, - ); -} -'''), completes); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.second('a'); - - value.map( - (SwitchTest0 a) {}, - first: null, - second: (SwitchTest2 value) {}, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.second('a'); - - value.map( - null, - first: (SwitchTest1 value) {}, - second: (SwitchTest2 value) {}, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.second('a'); - - value.map( - (SwitchTest0 a) {}, - first: (SwitchTest1 value) {}, - second: null, - ); -} -'''), throwsCompileError); - }); - test('calls second callback', () { - final value = SwitchTest.second('a', 21, .42); - - expect( - value.map( - (SwitchTest0 a) => throw Error(), - first: (SwitchTest1 value) => throw Error(), - second: (SwitchTest2 value) => '${value.a} ${value.c} ${value.d}', - ), - 'a 21 0.42', - ); - }); - }); - - test('named parameters are marked as required', () async { - final main = await resolveSources( - { - 'freezed|test/integration/main.dart': r''' -library main; -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.first('a', b: false, d: .42); - - value.map( - (a) => 42, - ); -} -''', - }, - (r) => r.findLibraryByName('main'), - ); - - final errorResult = await main!.session - .getErrors('/freezed/test/integration/main.dart') as ErrorsResult; - - expect(errorResult.errors, isNotEmpty); - }); - }); - - group('maybeMap', () { - test('returns callback result if has callback', () { - var value = SwitchTest('a'); - - expect( - value.maybeMap( - (value) => '${value.a} default', - orElse: () => throw Error(), - ), - 'a default', - ); - - value = SwitchTest.first('a', b: false, d: .42); - - expect( - value.maybeMap( - null, - first: (SwitchTest1 value) => '${value.a} ${value.b} ${value.d}', - orElse: () => throw Error(), - ), - 'a false 0.42', - ); - - value = SwitchTest.second('a', 21, 0.42); - - expect( - value.maybeMap( - null, - second: (SwitchTest2 value) => '${value.a} ${value.c} ${value.d}', - orElse: () => throw Error(), - ), - 'a 21 0.42', - ); - }); - - test('assert orElse is passed', () async { - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - var value = SwitchTest('a'); - - value.maybeMap( - (SwitchTest0 a) {}, - orElse: () {}, - ); -} -'''), completes); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - var value = SwitchTest('a'); - - value.maybeMap( - (SwitchTest0 a) => '$a default', - orElse: null, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - var value = SwitchTest('a'); - - value.maybeMap( - (SwitchTest0 a) => '$a default', - orElse: null, - ); -} -'''), throwsCompileError); - }); - - test('orElse is called', () { - var value = SwitchTest('a'); - - expect(value.maybeMap(null, orElse: () => 42), 42); - - value = SwitchTest.first('a', b: false, d: .42); - - expect(value.maybeMap(null, orElse: () => 42), 42); - - value = SwitchTest.second('a', 21, 0.42); - - expect(value.maybeMap(null, orElse: () => 42), 42); - }); - - test('named parameters are not required', () async { - final main = await resolveSources( - { - 'freezed|test/integration/main.dart': r''' -library main; -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest('a'); - - value.maybeMap(null, orElse: () => 42); -} -''', - }, - (r) => r.findLibraryByName('main'), - ); - - final errorResult = await main!.session - .getErrors('/freezed/test/integration/main.dart') as ErrorsResult; - - expect(errorResult.errors, isEmpty); - }); - - test('orElse is required', () async { - final main = await resolveSources( - { - 'freezed|test/integration/main.dart': r''' -library main; -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest('a'); - - value.maybeMap(null); -} -''', - }, - (r) => r.findLibraryByName('main'), - ); - - final errorResult = await main!.session - .getErrors('/freezed/test/integration/main.dart') as ErrorsResult; - - expect(errorResult.errors, isNotEmpty); - }); - }); - - group('mapOrNull', () { - test('has all parameters as optional', () { - expect(NoDefault.first('a').mapOrNull(), null); - expect(NoDefault.second('a').mapOrNull(), null); - }); - - test('can map to nullable return type without type cast', () { - String? res = NoDefault.first('a').mapOrNull( - first: (value) => value.a.isEmpty ? null : value.a, - ); - expect(res, 'a'); - }); - - test('calls callback on matching constructor', () { - expect( - NoDefault.first('a').mapOrNull(first: (v) => v), - NoDefault.first('a'), - ); - - expect( - NoDefault.second('a').mapOrNull(second: (v) => v), - NoDefault.second('a'), - ); - }); - }); -} diff --git a/packages/freezed/test/multiple_constructors_test.dart b/packages/freezed/test/multiple_constructors_test.dart index 12b12ea2..cbb8d769 100644 --- a/packages/freezed/test/multiple_constructors_test.dart +++ b/packages/freezed/test/multiple_constructors_test.dart @@ -202,177 +202,6 @@ void main() { '''), throwsCompileError); }); - test('when works on unnamed constructors', () { - expect(RequiredParams(a: 'a').when((a) => 21, second: (_) => 42), 21); - expect( - RequiredParams.second(a: 'a').when((a) => 21, second: (_) => 42), - 42, - ); - }); - - test('whenOrNull works on unnamed constructors', () { - expect( - RequiredParams(a: 'a').whenOrNull((a) => 21, second: (_) => 42), - 21, - ); - expect( - RequiredParams.second(a: 'a').whenOrNull( - (a) => 21, - second: (_) => 42, - ), - 42, - ); - - expect( - RequiredParams(a: 'a').whenOrNull(null, second: (_) => 42), - null, - ); - expect( - RequiredParams.second(a: 'a').whenOrNull((a) => 21), - null, - ); - }); - - test('map works on unnamed constructors', () { - expect(RequiredParams(a: 'a').map((a) => 21, second: (_) => 42), 21); - expect( - RequiredParams.second(a: 'a').map((a) => 21, second: (_) => 42), - 42, - ); - }); - - test('mapOrNull works on unnamed constructors', () { - expect(RequiredParams(a: 'a').mapOrNull((a) => 21), 21); - expect( - RequiredParams.second(a: 'a').mapOrNull((a) => 21, second: (_) => 42), - 42, - ); - - expect(RequiredParams(a: 'a').mapOrNull(null), null); - expect( - RequiredParams.second(a: 'a').mapOrNull(null), - null, - ); - }); - - test('maybeMap works on unnamed constructors', () { - expect(RequiredParams(a: 'a').maybeMap((a) => 21, orElse: () => 42), 21); - expect( - RequiredParams.second(a: 'a').maybeMap((a) => 21, orElse: () => 42), - 42, - ); - expect(RequiredParams(a: 'a').maybeMap(null, orElse: () => 42), 42); - expect( - RequiredParams.second(a: 'a').maybeMap(null, orElse: () => 42), - 42, - ); - }); - - test('maybeWhen works on unnamed constructors', () { - expect(RequiredParams(a: 'a').maybeWhen((a) => 21, orElse: () => 42), 21); - expect( - RequiredParams.second(a: 'a').maybeWhen((a) => 21, orElse: () => 42), - 42, - ); - expect(RequiredParams(a: 'a').maybeWhen(null, orElse: () => 42), 42); - expect( - RequiredParams.second(a: 'a').maybeWhen(null, orElse: () => 42), - 42, - ); - }); - - test('maybeMap can use FutureOr', () async { - var res = NoDefault.first('a').maybeMap>( - first: (a) => 21, - orElse: () => Future.value(42), - ); - - expect(res, 21); - - res = NoDefault.second('a').maybeMap>( - second: (b) => Future.value(42), - orElse: () => 21, - ); - - await expectLater(res, completion(42)); - }); - - test('mapOrNull can use FutureOr', () async { - var res = NoDefault.first('a').mapOrNull>( - first: (a) => 21, - ); - - expect(res, 21); - - res = NoDefault.second('a').mapOrNull>( - second: (b) => Future.value(42), - ); - - await expectLater(res, completion(42)); - }); - - test('map can use FutureOr', () async { - var res = NoDefault.first('a').map>( - first: (a) => 21, - second: (b) => Future.value(42), - ); - - expect(res, 21); - - res = NoDefault.second('a').map>( - first: (a) => 21, - second: (b) => Future.value(42), - ); - - await expectLater(res, completion(42)); - }); - - test('maybeWhen can use FutureOr', () async { - var res = NoDefault.first('a').maybeWhen>( - first: (a) => 21, - orElse: () => Future.value(42), - ); - - expect(res, 21); - - res = NoDefault.second('a').maybeWhen>( - second: (b) => Future.value(42), - orElse: () => 21, - ); - - await expectLater(res, completion(42)); - }); - - test('whenOrNull can use FutureOr', () async { - var res = NoDefault.first('a').whenOrNull>( - first: (a) => 21, - ); - - expect(res, 21); - - res = NoDefault.second('a').whenOrNull>( - second: (b) => Future.value(42), - ); - - await expectLater(res, completion(42)); - }); - - test('when can use FutureOr', () async { - var res = NoDefault.first('a').when>( - first: (a) => 21, - second: (b) => Future.value(42), - ); - - expect(res, 21); - - res = NoDefault.second('a').when>( - first: (a) => 21, - second: (b) => Future.value(42), - ); - - await expectLater(res, completion(42)); - }); - test('redirected constructors do have public properties', () { final ctor0 = NoCommonParam0('a', b: 42); String a = ctor0.a; @@ -521,10 +350,11 @@ void main() { final value = NameConflict.error(error); expect( - value.when(something: (_) => 42, error: (err) => err), + switch (value) { Something() => 42, SomeError(:final error) => error }, error, ); }); + group('NestedList', () { test('generates List of correct type', () async { final nestedListClass = _getClassElement('ShallowNestedList'); diff --git a/packages/freezed/test/optional_maybe_test.dart b/packages/freezed/test/optional_maybe_test.dart deleted file mode 100644 index b964d910..00000000 --- a/packages/freezed/test/optional_maybe_test.dart +++ /dev/null @@ -1,137 +0,0 @@ -import 'package:analyzer/dart/analysis/results.dart'; -import 'package:build_test/build_test.dart'; -import 'package:test/test.dart'; - -import 'common.dart'; -import 'integration/optional_maybe.dart'; - -void main() { - test('has no issue', () async { - final main = await resolveSources( - { - 'freezed|test/integration/optional_maybe.dart': useAssetReader, - }, - (r) => r.libraries.firstWhere( - (element) => element.source.toString().contains('optional_maybe')), - ); - - final errorResult = await main.session.getErrors( - '/freezed/test/integration/optional_maybe_test.freezed.dart') - as ErrorsResult; - - expect(errorResult.errors, isEmpty); - }); - - test('does not generates maybeMap', () async { - await expectLater(compile(r''' - import 'optional_maybe.dart'; - - void main() { - final value = OptionalMaybeMap.first(); - - value.maybeMap(orElse: () => null); - value.map( - first: (_) {}, - second: (_) {}, - ); - value.mapOrNull(); - } - '''), throwsCompileError); - - const OptionalMaybeMap.first() - ..whenOrNull() - ..maybeWhen(orElse: () {}) - ..when( - first: () {}, - second: () {}, - ); - }); - - test('does not generates maybeWhen', () async { - await expectLater(compile(r''' - import 'optional_maybe.dart'; - - void main() { - final value = OptionalMaybeWhen.first(); - - value.maybeWhen(orElse: () => null); - value.when( - first: () {}, - second: () {}, - ); - value.whenOrNull(); - } - '''), throwsCompileError); - - const OptionalMaybeWhen.first() - ..mapOrNull() - ..maybeMap(orElse: () {}) - ..map( - first: (_) {}, - second: (_) {}, - ); - }); - - test('can disable copyWith', () async { - await expectLater(compile(r''' -import 'optional_maybe.dart'; - -void main() { - OptionalCopyWith().copyWith; -} -'''), throwsCompileError); - }); - - test('can disable toString', () { - expect( - const OptionalToString().toString(), - r"Instance of '_$OptionalToStringImpl'", - ); - }); - - test('can disable ==/hash', () { - expect( - OptionalEqual(), - isNot(OptionalEqual()), - ); - expect( - OptionalEqual().hashCode, - isNot(OptionalEqual().hashCode), - ); - }); - - test('can force the generation of when/map', () { - ForceUnionMethod2.two() - ..map(two: (_) {}) - ..mapOrNull() - ..maybeMap(orElse: () {}) - ..when(two: () {}) - ..whenOrNull() - ..maybeWhen(orElse: () {}); - - ForceUnionMethod() - ..map((value) => null) - ..mapOrNull((value) => null) - ..maybeMap((value) => null, orElse: () {}) - ..when(() => null) - ..whenOrNull(() => null) - ..maybeWhen(() => null, orElse: () {}); - }); - - test('can disable toJson', () async { - OptionalToJson(); - OptionalToJson.fromJson({}); - - await expectLater(compile(r''' -import 'optional_maybe.dart'; - -void main() { - OptionalToJson().toJson; -} -'''), throwsCompileError); - }); - - test('can force toJson', () async { - expect(ForceToJson(42).toJson(), {'a': 42}); - }); -} diff --git a/packages/freezed/test/options_test.dart b/packages/freezed/test/options_test.dart new file mode 100644 index 00000000..f3e9d212 --- /dev/null +++ b/packages/freezed/test/options_test.dart @@ -0,0 +1,69 @@ +import 'package:analyzer/dart/analysis/results.dart'; +import 'package:build_test/build_test.dart'; +import 'package:test/test.dart'; + +import 'common.dart'; +import 'integration/optional_maybe.dart'; + +void main() { + test('has no issue', () async { + final main = await resolveSources( + { + 'freezed|test/integration/optional_maybe.dart': useAssetReader, + }, + (r) => r.libraries.firstWhere( + (element) => element.source.toString().contains('optional_maybe')), + ); + + final errorResult = await main.session.getErrors( + '/freezed/test/integration/optional_maybe_test.freezed.dart') + as ErrorsResult; + + expect(errorResult.errors, isEmpty); + }); + + test('can disable copyWith', () async { + await expectLater(compile(r''' +import 'optional_maybe.dart'; + +void main() { + OptionalCopyWith().copyWith; +} +'''), throwsCompileError); + }); + + test('can disable toString', () { + expect( + const OptionalToString().toString(), + r"Instance of '_$OptionalToStringImpl'", + ); + }); + + test('can disable ==/hash', () { + expect( + OptionalEqual(), + isNot(OptionalEqual()), + ); + expect( + OptionalEqual().hashCode, + isNot(OptionalEqual().hashCode), + ); + }); + + test('can disable toJson', () async { + OptionalToJson(); + OptionalToJson.fromJson({}); + + await expectLater(compile(r''' +import 'optional_maybe.dart'; + +void main() { + OptionalToJson().toJson; +} +'''), throwsCompileError); + }); + + test('can force toJson', () async { + expect(ForceToJson(42).toJson(), {'a': 42}); + }); +} diff --git a/packages/freezed/test/private_constructor_test.dart b/packages/freezed/test/private_constructor_test.dart index fb9b99f1..7f8f682f 100644 --- a/packages/freezed/test/private_constructor_test.dart +++ b/packages/freezed/test/private_constructor_test.dart @@ -6,14 +6,7 @@ void main() { test("mixin's default methods throw", () { final c = PrivateConstructor.illegal(); expect(c, isA()); - expect(() => c.map((value) => null, union1: (_) => null), - throwsUnsupportedError); - expect(() => c.maybeMap((value) => null, orElse: () {}), - throwsUnsupportedError); - expect(() => c.when((value) => null, union1: (_, __) => null), - throwsUnsupportedError); - expect(() => c.maybeWhen((value) => null, orElse: () => null), - throwsUnsupportedError); - expect(() => c..name, throwsUnsupportedError); + + expect(() => c.name, throwsUnsupportedError); }); } diff --git a/packages/freezed/test/single_class_constructor_test.dart b/packages/freezed/test/single_class_constructor_test.dart index 696f12d7..b6ed5bb4 100644 --- a/packages/freezed/test/single_class_constructor_test.dart +++ b/packages/freezed/test/single_class_constructor_test.dart @@ -429,42 +429,6 @@ void main() { expect('${SingleNamedCtor.named(42)}', 'SingleNamedCtor.named(a: 42)'); }); - test('single-case union does have map', () async { - expect( - SingleNamedCtor.named(42).map( - named: (WhateverSingleNamedCtor value) => '${value.a}', - ), - '42', - ); - }); - - test('single-case union does have maybeMap', () async { - expect( - SingleNamedCtor.named(42).maybeMap( - named: (WhateverSingleNamedCtor value) => '${value.a}', - orElse: () => throw Exception('orElse called'), - ), - '42', - ); - }); - - test('single-case union does have when', () async { - expect( - SingleNamedCtor.named(42).when(named: (int value) => '$value'), - '42', - ); - }); - - test('single-case union does have maybeWhen', () async { - expect( - SingleNamedCtor.named(42).maybeWhen( - named: (int value) => '$value', - orElse: () => throw Exception('orElse called'), - ), - '42', - ); - }); - test('can be created as const', () { expect(identical(const MyClass(a: '42'), const MyClass(a: '42')), isTrue); }); diff --git a/packages/freezed/test/when_test.dart b/packages/freezed/test/when_test.dart deleted file mode 100644 index 3ef190ed..00000000 --- a/packages/freezed/test/when_test.dart +++ /dev/null @@ -1,437 +0,0 @@ -// ignore_for_file: prefer_const_constructors, omit_local_variable_types -import 'package:analyzer/dart/analysis/results.dart'; -import 'package:build_test/build_test.dart'; -import 'package:test/test.dart'; - -import 'common.dart'; -import 'integration/multiple_constructors.dart'; - -void main() { - group('when', () { - test('works with no default ctr', () { - var value = NoDefault.first('a'); - - expect( - value.when( - first: (String a) => '$a first', - second: (String a) => throw Error(), - ), - 'a first', - ); - - value = NoDefault.second('a'); - - expect( - value.when( - first: (String a) => throw Error(), - second: (String a) => '$a second', - ), - 'a second', - ); - }); - group('default ctor', () { - test("assert callbacks can't be null", () async { - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest('a'); - - value.when( - (String a) {}, - first: (String a, bool? b, double? d) {}, - second: (String a, int? c, double? d) {}, - ); -} -'''), completes); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest('a'); - - value.when( - (String a) {}, - first: null, - second: (String value) {}, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest('a'); - - value.when( - null, - first: (String value) {}, - second: (String value) {}, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest('a'); - - value.when( - (String a) {}, - first: (String value) {}, - second: null, - ); -} -'''), throwsCompileError); - }); - - test('calls default callback', () { - final value = SwitchTest('a'); - - expect( - value.when( - (String a) => '$a 42', - first: (String a, bool? b, double? d) => throw Error(), - second: (String a, int? c, double? d) => throw Error(), - ), - 'a 42', - ); - }); - }); - - group('first ctor', () { - test("assert callbacks can't be null", () async { - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.first('a'); - value.when( - (String a) {}, - first: (String a, bool? b, double? d) {}, - second: (String a, int? c, double? d) {}, - ); -} -'''), completes); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.first('a'); - - value.when( - (String a) {}, - first: null, - second: (String value) {}, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.first('a'); - - value.when( - null, - first: (String value) {}, - second: (String value) {}, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.first('a'); - - value.when( - (String a) {}, - first: (String value) {}, - second: null, - ); -} -'''), throwsCompileError); - }); - - test('calls first callback', () { - final value = SwitchTest.first('a', b: false, d: .42); - - expect( - value.when( - (String a) => throw Error(), - first: (String a, bool? b, double? d) => '$a $b $d', - second: (String a, int? c, double? d) => throw Error(), - ), - 'a false 0.42', - ); - }); - }); - - group('second ctor', () { - test("assert callbacks can't be null", () async { - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.second('a'); - value.when( - (String a) {}, - first: (String a, bool? b, double? d) {}, - second: (String a, int? c, double? d) {}, - ); -} -'''), completes); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.second('a'); - - value.when( - (String a) {}, - first: null, - second: (String value) {}, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.second('a'); - - value.when( - null, - first: (String value) {}, - second: (String value) {}, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.second('a'); - - value.when( - (String a) {}, - first: (String value) {}, - second: null, - ); -} -'''), throwsCompileError); - }); - - test('calls second callback', () { - final value = SwitchTest.second('a', 21, .42); - - expect( - value.when( - (String a) => throw Error(), - first: (String a, bool? b, double? d) => throw Error(), - second: (String a, int? c, double? d) => '$a $c $d', - ), - 'a 21 0.42', - ); - }); - }); - - test('named parameters are marked as required', () async { - final main = await resolveSources( - { - 'freezed|test/integration/main.dart': r''' -library main; -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest.first('a', b: false, d: .42); - - value.when( - (String a) => 42, - ); -} -''', - }, - (r) => r.findLibraryByName('main'), - ); - - final errorResult = await main!.session - .getErrors('/freezed/test/integration/main.dart') as ErrorsResult; - - expect(errorResult.errors, isNotEmpty); - }); - }); - - group('maybeWhen', () { - test('returns callback result if has callback', () { - var value = SwitchTest('a'); - - expect( - value.maybeWhen( - (String a) => '$a default', - orElse: () => throw Error(), - ), - 'a default', - ); - - value = SwitchTest.first('a', b: false, d: .42); - - expect( - value.maybeWhen( - null, - first: (a, b, d) => '$a $b $d', - orElse: () => throw Error(), - ), - 'a false 0.42', - ); - - value = SwitchTest.second('a', 21, 0.42); - - expect( - value.maybeWhen( - null, - second: (a, c, d) => '$a $c $d', - orElse: () => throw Error(), - ), - 'a 21 0.42', - ); - }); - - test('assert orElse is passed', () async { - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - var value = SwitchTest('a'); - - value.maybeWhen( - (String a) {}, - orElse: () {}, - ); -} -'''), completes); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - var value = SwitchTest('a'); - - value.maybeWhen( - (String a) => '$a default', - orElse: null, - ); -} -'''), throwsCompileError); - - await expectLater(compile(r''' -import 'multiple_constructors.dart'; - -void main() { - var value = SwitchTest('a'); - - value.maybeWhen( - (String a) => '$a default', - orElse: null, - ); -} -'''), throwsCompileError); - }); - - test('orElse is called', () { - var value = SwitchTest('a'); - - expect(value.maybeWhen(null, orElse: () => 42), 42); - - value = SwitchTest.first('a', b: false, d: .42); - - expect(value.maybeWhen(null, orElse: () => 42), 42); - - value = SwitchTest.second('a', 21, 0.42); - - expect(value.maybeWhen(null, orElse: () => 42), 42); - }); - - test('named parameters are not required', () async { - final main = await resolveSources( - { - 'freezed|test/integration/main.dart': r''' -library main; -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest('a'); - - value.maybeWhen(null, orElse: () => 42); -} -''', - }, - (r) => r.findLibraryByName('main'), - ); - - final errorResult = await main!.session - .getErrors('/freezed/test/integration/main.dart') as ErrorsResult; - - expect(errorResult.errors, isEmpty); - }); - - test('orElse is required', () async { - final main = await resolveSources( - { - 'freezed|test/integration/main.dart': r''' -library main; -import 'multiple_constructors.dart'; - -void main() { - final value = SwitchTest('a'); - - value.maybeWhen(null); -} -''', - }, - (r) => r.findLibraryByName('main'), - ); - - final errorResult = await main!.session - .getErrors('/freezed/test/integration/main.dart') as ErrorsResult; - - expect(errorResult.errors, isNotEmpty); - }); - }); - - group('whenOrNull', () { - test('can map to nullable return type without type cast', () { - String? res = NoDefault.first('a').whenOrNull( - first: (a) => a.isEmpty ? null : a, - ); - expect(res, 'a'); - }); - - test('has all parameters as optional', () { - expect(NoDefault.first('a').whenOrNull(), null); - expect(NoDefault.second('a').whenOrNull(), null); - }); - - test('calls callback on matching constructor', () { - expect( - NoDefault.first('a').whenOrNull(first: (v) => v), - 'a', - ); - - expect( - NoDefault.second('a').whenOrNull(second: (v) => v), - 'a', - ); - }); - }); -} diff --git a/packages/freezed_annotation/CHANGELOG.md b/packages/freezed_annotation/CHANGELOG.md index a2d8798f..8df946ed 100644 --- a/packages/freezed_annotation/CHANGELOG.md +++ b/packages/freezed_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased 3.0.0 + +- **Breaking** removed `when`/`map` related options + ## 2.4.4 - 2024-07-15 - Require json_annotation ^4.8.0 diff --git a/packages/freezed_annotation/lib/freezed_annotation.dart b/packages/freezed_annotation/lib/freezed_annotation.dart index 28e25f6e..83536a03 100644 --- a/packages/freezed_annotation/lib/freezed_annotation.dart +++ b/packages/freezed_annotation/lib/freezed_annotation.dart @@ -62,139 +62,6 @@ class EqualUnmodifiableMapView int get hashCode => Object.hash(runtimeType, _source); } -/// Options for enabling/disabling specific `Union.map` features; -@JsonSerializable( - fieldRename: FieldRename.snake, - createToJson: false, - anyMap: true, -) -class FreezedMapOptions { - /// Options for enabling/disabling specific `Union.map` features; - const FreezedMapOptions({this.map, this.mapOrNull, this.maybeMap}); - - /// Decode a [FreezedMapOptions] from a build.yaml - factory FreezedMapOptions.fromJson(Map json) => - _$FreezedMapOptionsFromJson(json); - - /// Enables the generation of all `Union.map` features - static const all = - FreezedMapOptions(map: true, mapOrNull: true, maybeMap: true); - - /// Disables the generation of all `Union.map` features - static const none = - FreezedMapOptions(map: false, mapOrNull: false, maybeMap: false); - - /// Whether to generate `Union.map` - /// - /// If null, will fallback to the build.yaml configs - /// If that value is null too, defaults to true. - final bool? map; - - /// Whether to generate `Union.mapOrNull` - /// - /// If null, will fallback to the build.yaml configs - /// If that value is null too, defaults to true. - final bool? mapOrNull; - - /// Whether to generate `Union.maybeMap` - /// - /// If null, will fallback to the build.yaml configs - /// If that value is null too, defaults to true. - final bool? maybeMap; -} - -/// Options for enabling/disabling specific `Union.when` features; -@JsonSerializable( - fieldRename: FieldRename.snake, - createToJson: false, - anyMap: true, -) -class FreezedWhenOptions { - /// Options for enabling/disabling specific `Union.when` features; - const FreezedWhenOptions({ - this.when, - this.whenOrNull, - this.maybeWhen, - }); - - /// Decode a [FreezedWhenOptions] from a build.yaml - factory FreezedWhenOptions.fromJson(Map json) => - _$FreezedWhenOptionsFromJson(json); - - /// Enables the generation of all `Union.when` features - static const all = - FreezedWhenOptions(when: true, whenOrNull: true, maybeWhen: true); - - /// Disables the generation of all `Union.when` features - static const none = FreezedWhenOptions( - when: false, - whenOrNull: false, - maybeWhen: false, - ); - - /// Whether to generate `Union.when` - /// - /// If null, will fallback to the build.yaml configs - /// If that value is null too, defaults to true. - final bool? when; - - /// Whether to generate `Union.whenOrNull` - /// - /// If null, will fallback to the build.yaml configs - /// If that value is null too, defaults to true. - final bool? whenOrNull; - - /// Whether to generate `Union.maybeWhen` - /// - /// If null, will fallback to the build.yaml configs. - /// If that value is null too, defaults to true. - final bool? maybeWhen; -} - -class _FreezedWhenOptionsConverter - implements JsonConverter { - const _FreezedWhenOptionsConverter(); - - @override - FreezedWhenOptions? fromJson(Object? json) { - if (json == true) return FreezedWhenOptions.all; - if (json == false) return FreezedWhenOptions.none; - if (json == null) return null; - if (json is Map) return FreezedWhenOptions.fromJson(json); - - throw ArgumentError.value( - json, - 'json', - 'Expected a bool a Map, got ${json.runtimeType}', - ); - } - - @override - Object? toJson(FreezedWhenOptions? object) => null; -} - -class _FreezedMapOptionsConverter - implements JsonConverter { - const _FreezedMapOptionsConverter(); - - @override - FreezedMapOptions? fromJson(Object? json) { - if (json == true) return FreezedMapOptions.all; - if (json == false) return FreezedMapOptions.none; - if (json == null) return null; - if (json is Map) return FreezedMapOptions.fromJson(json); - - throw ArgumentError.value( - json, - 'json', - 'Expected a bool or a Map, got ${json.runtimeType}', - ); - } - - @override - Object? toJson(FreezedMapOptions? object) => throw UnimplementedError(); -} - /// {@template freezed_annotation.freezed} /// Flags a class as needing to be processed by Freezed and allows passing options. /// {@endtemplate} @@ -214,8 +81,6 @@ class Freezed { this.toStringOverride, this.fromJson, this.toJson, - this.map, - this.when, this.makeCollectionsUnmodifiable, this.addImplicitFinal = true, this.genericArgumentFactories = false, @@ -475,20 +340,6 @@ class Freezed { /// } /// ``` final bool genericArgumentFactories; - - /// Options for customizing the generation of `map` functions - /// - /// If null, picks up the default values from the project's `build.yaml`. - /// If that value is null too, defaults to [FreezedMapOptions.all]. - @_FreezedMapOptionsConverter() - final FreezedMapOptions? map; - - /// Options for customizing the generation of `when` functions - /// - /// If null, picks up the default values from the project's `build.yaml` - /// If that value is null too, defaults to [FreezedWhenOptions.all]. - @_FreezedWhenOptionsConverter() - final FreezedWhenOptions? when; } /// Defines an immutable data-class. diff --git a/packages/freezed_annotation/lib/freezed_annotation.g.dart b/packages/freezed_annotation/lib/freezed_annotation.g.dart index 5f3a0dd3..ba408394 100644 --- a/packages/freezed_annotation/lib/freezed_annotation.g.dart +++ b/packages/freezed_annotation/lib/freezed_annotation.g.dart @@ -8,18 +8,6 @@ part of 'freezed_annotation.dart'; // JsonSerializableGenerator // ************************************************************************** -FreezedMapOptions _$FreezedMapOptionsFromJson(Map json) => FreezedMapOptions( - map: json['map'] as bool?, - mapOrNull: json['map_or_null'] as bool?, - maybeMap: json['maybe_map'] as bool?, - ); - -FreezedWhenOptions _$FreezedWhenOptionsFromJson(Map json) => FreezedWhenOptions( - when: json['when'] as bool?, - whenOrNull: json['when_or_null'] as bool?, - maybeWhen: json['maybe_when'] as bool?, - ); - Freezed _$FreezedFromJson(Map json) => Freezed( unionKey: json['union_key'] as String? ?? 'runtimeType', unionValueCase: $enumDecodeNullable( @@ -30,8 +18,6 @@ Freezed _$FreezedFromJson(Map json) => Freezed( toStringOverride: json['to_string_override'] as bool?, fromJson: json['from_json'] as bool?, toJson: json['to_json'] as bool?, - map: const _FreezedMapOptionsConverter().fromJson(json['map']), - when: const _FreezedWhenOptionsConverter().fromJson(json['when']), makeCollectionsUnmodifiable: json['make_collections_unmodifiable'] as bool? ?? true, addImplicitFinal: json['add_implicit_final'] as bool? ?? true, diff --git a/packages/freezed_annotation/test/freezed_test.dart b/packages/freezed_annotation/test/freezed_test.dart index 3a8b205c..bd5af86d 100644 --- a/packages/freezed_annotation/test/freezed_test.dart +++ b/packages/freezed_annotation/test/freezed_test.dart @@ -2,140 +2,6 @@ import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:test/test.dart'; void main() { - group('FreezedMapOptions', () { - test('.fromJson', () { - expect( - FreezedMapOptions.fromJson({'map': false}).map, - isFalse, - ); - expect( - FreezedMapOptions.fromJson({'map': false}).mapOrNull, - isNull, - ); - expect( - FreezedMapOptions.fromJson({'map': false}).maybeMap, - isNull, - ); - - expect( - FreezedMapOptions.fromJson({'map_or_null': false}) - .map, - isNull, - ); - expect( - FreezedMapOptions.fromJson({'map_or_null': false}) - .mapOrNull, - isFalse, - ); - expect( - FreezedMapOptions.fromJson({'map_or_null': false}) - .maybeMap, - isNull, - ); - - expect( - FreezedMapOptions.fromJson({'maybe_map': false}).map, - isNull, - ); - expect( - FreezedMapOptions.fromJson({'maybe_map': false}) - .mapOrNull, - isNull, - ); - expect( - FreezedMapOptions.fromJson({'maybe_map': false}) - .maybeMap, - isFalse, - ); - }); - - test('.all', () { - expect(FreezedMapOptions.all.map, isTrue); - expect(FreezedMapOptions.all.maybeMap, isTrue); - expect(FreezedMapOptions.all.mapOrNull, isTrue); - }); - - test('.none', () { - expect(FreezedMapOptions.none.map, isFalse); - expect(FreezedMapOptions.none.maybeMap, isFalse); - expect(FreezedMapOptions.none.mapOrNull, isFalse); - }); - - test('()', () { - expect(FreezedMapOptions().map, isNull); - expect(FreezedMapOptions().maybeMap, isNull); - expect(FreezedMapOptions().mapOrNull, isNull); - }); - }); - - group('FreezedWhenOptions', () { - test('.fromJson', () { - expect( - FreezedWhenOptions.fromJson({'when': false}).when, - isFalse, - ); - expect( - FreezedWhenOptions.fromJson({'when': false}) - .whenOrNull, - isNull, - ); - expect( - FreezedWhenOptions.fromJson({'when': false}) - .maybeWhen, - isNull, - ); - - expect( - FreezedWhenOptions.fromJson({'when_or_null': false}) - .when, - isNull, - ); - expect( - FreezedWhenOptions.fromJson({'when_or_null': false}) - .whenOrNull, - isFalse, - ); - expect( - FreezedWhenOptions.fromJson({'when_or_null': false}) - .maybeWhen, - isNull, - ); - - expect( - FreezedWhenOptions.fromJson({'maybe_when': false}) - .when, - isNull); - expect( - FreezedWhenOptions.fromJson({'maybe_when': false}) - .whenOrNull, - isNull, - ); - expect( - FreezedWhenOptions.fromJson({'maybe_when': false}) - .maybeWhen, - isFalse, - ); - }); - - test('.all', () { - expect(FreezedWhenOptions.all.when, isTrue); - expect(FreezedWhenOptions.all.maybeWhen, isTrue); - expect(FreezedWhenOptions.all.whenOrNull, isTrue); - }); - - test('.none', () { - expect(FreezedWhenOptions.none.when, isFalse); - expect(FreezedWhenOptions.none.maybeWhen, isFalse); - expect(FreezedWhenOptions.none.whenOrNull, isFalse); - }); - - test('()', () { - expect(FreezedWhenOptions().when, isNull); - expect(FreezedWhenOptions().maybeWhen, isNull); - expect(FreezedWhenOptions().whenOrNull, isNull); - }); - }); - group('Freezed', () { test('.fromJson', () { final defaultValue = Freezed.fromJson({}); @@ -144,86 +10,12 @@ void main() { expect(defaultValue.equal, isNull); expect(defaultValue.fallbackUnion, null); expect(defaultValue.fromJson, isNull); - expect(defaultValue.map, isNull); expect(defaultValue.toJson, isNull); expect(defaultValue.toStringOverride, isNull); expect(defaultValue.unionKey, 'runtimeType'); expect(defaultValue.unionValueCase, isNull); - expect(defaultValue.when, isNull); expect(defaultValue.makeCollectionsUnmodifiable, isTrue); }); - - test('.fromJson({map: x})', () { - expect(Freezed.fromJson({'map': false}).map, FreezedMapOptions.none); - expect(Freezed.fromJson({'map': true}).map, FreezedMapOptions.all); - - expect( - Freezed.fromJson({ - 'map': { - 'map': true, - 'maybe_map': false, - 'map_or_null': true, - } - }).map, - isA() - .having( - (e) => e.map, - 'map', - isTrue, - ) - .having( - (e) => e.maybeMap, - 'maybeMap', - isFalse, - ) - .having( - (e) => e.mapOrNull, - 'mapOrNull', - isTrue, - ), - ); - - expect( - () => Freezed.fromJson({'map': 42}), - throwsA(isA()), - ); - }); - - test('.fromJson({when: x})', () { - expect(Freezed.fromJson({'when': false}).when, FreezedWhenOptions.none); - expect(Freezed.fromJson({'when': true}).when, FreezedWhenOptions.all); - - expect( - Freezed.fromJson({ - 'when': { - 'when': true, - 'maybe_when': false, - 'when_or_null': true, - } - }).when, - isA() - .having( - (e) => e.when, - 'when', - isTrue, - ) - .having( - (e) => e.maybeWhen, - 'maybeWhen', - isFalse, - ) - .having( - (e) => e.whenOrNull, - 'whenOrNull', - isTrue, - ), - ); - - expect( - () => Freezed.fromJson({'when': 42}), - throwsA(isA()), - ); - }); }); test('unfreezed', () {