diff --git a/pkgs/_augmentation_examples/analysis_options.yaml b/pkgs/_augmentation_examples/analysis_options.yaml new file mode 100644 index 0000000..49ce827 --- /dev/null +++ b/pkgs/_augmentation_examples/analysis_options.yaml @@ -0,0 +1,6 @@ +include: package:dart_flutter_team_lints/analysis_options.yaml + +analyzer: + enable-experiment: + - enhanced-parts + - macros diff --git a/pkgs/_augmentation_examples/lib/built_value.dart b/pkgs/_augmentation_examples/lib/built_value.dart new file mode 100644 index 0000000..38bba24 --- /dev/null +++ b/pkgs/_augmentation_examples/lib/built_value.dart @@ -0,0 +1,141 @@ +// Copyright (c) 2024, Google Inc. Please see the AUTHORS file for details. +// All rights reserved. Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/built_value.dart'; +import 'package:built_value/json_object.dart'; +import 'package:built_value/serializer.dart'; + +part 'built_value.g.dart'; + +abstract class SimpleValue implements Built { + static Serializer get serializer => _$simpleValueSerializer; + + int get anInt; + + String? get aString; + + factory SimpleValue([void Function(SimpleValueBuilder) updates]) = + _$SimpleValue; + SimpleValue._(); +} + +abstract class VerySimpleValue + implements Built { + static Serializer get serializer => + _$verySimpleValueSerializer; + + int get value; + + factory VerySimpleValue(int value) => _$VerySimpleValue._(value: value); + VerySimpleValue._(); +} + +abstract class CompoundValue + implements Built { + static Serializer get serializer => _$compoundValueSerializer; + + SimpleValue get simpleValue; + ValidatedValue? get validatedValue; + + factory CompoundValue([void Function(CompoundValueBuilder) updates]) = + _$CompoundValue; + CompoundValue._(); +} + +abstract class ValidatedValue + implements Built { + static Serializer get serializer => + _$validatedValueSerializer; + + int get anInt; + String? get aString; + + factory ValidatedValue([void Function(ValidatedValueBuilder) updates]) = + _$ValidatedValue; + + ValidatedValue._() { + if (anInt == 7) throw StateError('anInt may not be 7'); + } +} + +abstract class ValueWithCode + implements Built { + static final int youCanHaveStaticFields = 3; + + int get anInt; + String? get aString; + + String get youCanWriteDerivedGetters => anInt.toString() + aString!; + + factory ValueWithCode([void Function(ValueWithCodeBuilder) updates]) = + _$ValueWithCode; + ValueWithCode._(); + + factory ValueWithCode.fromCustomFactory(int anInt) => ValueWithCode( + (b) => + b + ..anInt = anInt + ..aString = 'two', + ); +} + +abstract class ValueWithDefaults + implements Built { + int get anInt; + String? get aString; + + factory ValueWithDefaults([void Function(ValueWithDefaultsBuilder) updates]) = + _$ValueWithDefaults; + ValueWithDefaults._(); +} + +abstract class ValueWithDefaultsBuilder + implements Builder { + int anInt = 7; + + String? aString; + + factory ValueWithDefaultsBuilder() = _$ValueWithDefaultsBuilder; + ValueWithDefaultsBuilder._(); +} + +abstract class DerivedValue + implements Built { + int get anInt; + + @memoized + int get derivedValue => anInt + 10; + + @memoized + Iterable get derivedString => [toString()]; + + factory DerivedValue([void Function(DerivedValueBuilder) updates]) = + _$DerivedValue; + DerivedValue._(); +} + +abstract class Account implements Built { + static Serializer get serializer => _$accountSerializer; + int get id; + String get name; + BuiltMap get keyValues; + + factory Account([void Function(AccountBuilder) updates]) = _$Account; + Account._(); +} + +@BuiltValue(wireName: 'V') +abstract class WireNameValue + implements Built { + static Serializer get serializer => _$wireNameValueSerializer; + + @BuiltValueField(wireName: 'v') + int get value; + + factory WireNameValue([void Function(WireNameValueBuilder) updates]) = + _$WireNameValue; + + WireNameValue._(); +} diff --git a/pkgs/_augmentation_examples/lib/built_value.g.dart b/pkgs/_augmentation_examples/lib/built_value.g.dart new file mode 100644 index 0000000..84a368f --- /dev/null +++ b/pkgs/_augmentation_examples/lib/built_value.g.dart @@ -0,0 +1,1204 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'built_value.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializer _$simpleValueSerializer = new _$SimpleValueSerializer(); +Serializer _$verySimpleValueSerializer = + new _$VerySimpleValueSerializer(); +Serializer _$compoundValueSerializer = + new _$CompoundValueSerializer(); +Serializer _$validatedValueSerializer = + new _$ValidatedValueSerializer(); +Serializer _$accountSerializer = new _$AccountSerializer(); +Serializer _$wireNameValueSerializer = + new _$WireNameValueSerializer(); + +class _$SimpleValueSerializer implements StructuredSerializer { + @override + final Iterable types = const [SimpleValue, _$SimpleValue]; + @override + final String wireName = 'SimpleValue'; + + @override + Iterable serialize(Serializers serializers, SimpleValue object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'anInt', + serializers.serialize(object.anInt, specifiedType: const FullType(int)), + ]; + Object? value; + value = object.aString; + if (value != null) { + result + ..add('aString') + ..add(serializers.serialize(value, + specifiedType: const FullType(String))); + } + return result; + } + + @override + SimpleValue deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new SimpleValueBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'anInt': + result.anInt = serializers.deserialize(value, + specifiedType: const FullType(int))! as int; + break; + case 'aString': + result.aString = serializers.deserialize(value, + specifiedType: const FullType(String)) as String?; + break; + } + } + + return result.build(); + } +} + +class _$VerySimpleValueSerializer + implements StructuredSerializer { + @override + final Iterable types = const [VerySimpleValue, _$VerySimpleValue]; + @override + final String wireName = 'VerySimpleValue'; + + @override + Iterable serialize(Serializers serializers, VerySimpleValue object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'value', + serializers.serialize(object.value, specifiedType: const FullType(int)), + ]; + + return result; + } + + @override + VerySimpleValue deserialize( + Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new VerySimpleValueBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'value': + result.value = serializers.deserialize(value, + specifiedType: const FullType(int))! as int; + break; + } + } + + return result.build(); + } +} + +class _$CompoundValueSerializer implements StructuredSerializer { + @override + final Iterable types = const [CompoundValue, _$CompoundValue]; + @override + final String wireName = 'CompoundValue'; + + @override + Iterable serialize(Serializers serializers, CompoundValue object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'simpleValue', + serializers.serialize(object.simpleValue, + specifiedType: const FullType(SimpleValue)), + ]; + Object? value; + value = object.validatedValue; + if (value != null) { + result + ..add('validatedValue') + ..add(serializers.serialize(value, + specifiedType: const FullType(ValidatedValue))); + } + return result; + } + + @override + CompoundValue deserialize( + Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new CompoundValueBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'simpleValue': + result.simpleValue.replace(serializers.deserialize(value, + specifiedType: const FullType(SimpleValue))! as SimpleValue); + break; + case 'validatedValue': + result.validatedValue.replace(serializers.deserialize(value, + specifiedType: const FullType(ValidatedValue))! + as ValidatedValue); + break; + } + } + + return result.build(); + } +} + +class _$ValidatedValueSerializer + implements StructuredSerializer { + @override + final Iterable types = const [ValidatedValue, _$ValidatedValue]; + @override + final String wireName = 'ValidatedValue'; + + @override + Iterable serialize(Serializers serializers, ValidatedValue object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'anInt', + serializers.serialize(object.anInt, specifiedType: const FullType(int)), + ]; + Object? value; + value = object.aString; + if (value != null) { + result + ..add('aString') + ..add(serializers.serialize(value, + specifiedType: const FullType(String))); + } + return result; + } + + @override + ValidatedValue deserialize( + Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new ValidatedValueBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'anInt': + result.anInt = serializers.deserialize(value, + specifiedType: const FullType(int))! as int; + break; + case 'aString': + result.aString = serializers.deserialize(value, + specifiedType: const FullType(String)) as String?; + break; + } + } + + return result.build(); + } +} + +class _$AccountSerializer implements StructuredSerializer { + @override + final Iterable types = const [Account, _$Account]; + @override + final String wireName = 'Account'; + + @override + Iterable serialize(Serializers serializers, Account object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'id', + serializers.serialize(object.id, specifiedType: const FullType(int)), + 'name', + serializers.serialize(object.name, specifiedType: const FullType(String)), + 'keyValues', + serializers.serialize(object.keyValues, + specifiedType: const FullType(BuiltMap, + const [const FullType(String), const FullType(JsonObject)])), + ]; + + return result; + } + + @override + Account deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new AccountBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'id': + result.id = serializers.deserialize(value, + specifiedType: const FullType(int))! as int; + break; + case 'name': + result.name = serializers.deserialize(value, + specifiedType: const FullType(String))! as String; + break; + case 'keyValues': + result.keyValues.replace(serializers.deserialize(value, + specifiedType: const FullType(BuiltMap, const [ + const FullType(String), + const FullType(JsonObject) + ]))!); + break; + } + } + + return result.build(); + } +} + +class _$WireNameValueSerializer implements StructuredSerializer { + @override + final Iterable types = const [WireNameValue, _$WireNameValue]; + @override + final String wireName = 'V'; + + @override + Iterable serialize(Serializers serializers, WireNameValue object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'v', + serializers.serialize(object.value, specifiedType: const FullType(int)), + ]; + + return result; + } + + @override + WireNameValue deserialize( + Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new WireNameValueBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'v': + result.value = serializers.deserialize(value, + specifiedType: const FullType(int))! as int; + break; + } + } + + return result.build(); + } +} + +class _$SimpleValue extends SimpleValue { + @override + final int anInt; + @override + final String? aString; + + factory _$SimpleValue([void Function(SimpleValueBuilder)? updates]) => + (new SimpleValueBuilder()..update(updates))._build(); + + _$SimpleValue._({required this.anInt, this.aString}) : super._() { + BuiltValueNullFieldError.checkNotNull(anInt, r'SimpleValue', 'anInt'); + } + + @override + SimpleValue rebuild(void Function(SimpleValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + SimpleValueBuilder toBuilder() => new SimpleValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is SimpleValue && + anInt == other.anInt && + aString == other.aString; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, anInt.hashCode); + _$hash = $jc(_$hash, aString.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'SimpleValue') + ..add('anInt', anInt) + ..add('aString', aString)) + .toString(); + } +} + +class SimpleValueBuilder implements Builder { + _$SimpleValue? _$v; + + int? _anInt; + int? get anInt => _$this._anInt; + set anInt(int? anInt) => _$this._anInt = anInt; + + String? _aString; + String? get aString => _$this._aString; + set aString(String? aString) => _$this._aString = aString; + + SimpleValueBuilder(); + + SimpleValueBuilder get _$this { + final $v = _$v; + if ($v != null) { + _anInt = $v.anInt; + _aString = $v.aString; + _$v = null; + } + return this; + } + + @override + void replace(SimpleValue other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$SimpleValue; + } + + @override + void update(void Function(SimpleValueBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + SimpleValue build() => _build(); + + _$SimpleValue _build() { + final _$result = _$v ?? + new _$SimpleValue._( + anInt: BuiltValueNullFieldError.checkNotNull( + anInt, r'SimpleValue', 'anInt'), + aString: aString); + replace(_$result); + return _$result; + } +} + +class _$VerySimpleValue extends VerySimpleValue { + @override + final int value; + + factory _$VerySimpleValue([void Function(VerySimpleValueBuilder)? updates]) => + (new VerySimpleValueBuilder()..update(updates))._build(); + + _$VerySimpleValue._({required this.value}) : super._() { + BuiltValueNullFieldError.checkNotNull(value, r'VerySimpleValue', 'value'); + } + + @override + VerySimpleValue rebuild(void Function(VerySimpleValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + VerySimpleValueBuilder toBuilder() => + new VerySimpleValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is VerySimpleValue && value == other.value; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, value.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'VerySimpleValue') + ..add('value', value)) + .toString(); + } +} + +class VerySimpleValueBuilder + implements Builder { + _$VerySimpleValue? _$v; + + int? _value; + int? get value => _$this._value; + set value(int? value) => _$this._value = value; + + VerySimpleValueBuilder(); + + VerySimpleValueBuilder get _$this { + final $v = _$v; + if ($v != null) { + _value = $v.value; + _$v = null; + } + return this; + } + + @override + void replace(VerySimpleValue other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$VerySimpleValue; + } + + @override + void update(void Function(VerySimpleValueBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + VerySimpleValue build() => _build(); + + _$VerySimpleValue _build() { + final _$result = _$v ?? + new _$VerySimpleValue._( + value: BuiltValueNullFieldError.checkNotNull( + value, r'VerySimpleValue', 'value')); + replace(_$result); + return _$result; + } +} + +class _$CompoundValue extends CompoundValue { + @override + final SimpleValue simpleValue; + @override + final ValidatedValue? validatedValue; + + factory _$CompoundValue([void Function(CompoundValueBuilder)? updates]) => + (new CompoundValueBuilder()..update(updates))._build(); + + _$CompoundValue._({required this.simpleValue, this.validatedValue}) + : super._() { + BuiltValueNullFieldError.checkNotNull( + simpleValue, r'CompoundValue', 'simpleValue'); + } + + @override + CompoundValue rebuild(void Function(CompoundValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + CompoundValueBuilder toBuilder() => new CompoundValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is CompoundValue && + simpleValue == other.simpleValue && + validatedValue == other.validatedValue; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, simpleValue.hashCode); + _$hash = $jc(_$hash, validatedValue.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'CompoundValue') + ..add('simpleValue', simpleValue) + ..add('validatedValue', validatedValue)) + .toString(); + } +} + +class CompoundValueBuilder + implements Builder { + _$CompoundValue? _$v; + + SimpleValueBuilder? _simpleValue; + SimpleValueBuilder get simpleValue => + _$this._simpleValue ??= new SimpleValueBuilder(); + set simpleValue(SimpleValueBuilder? simpleValue) => + _$this._simpleValue = simpleValue; + + ValidatedValueBuilder? _validatedValue; + ValidatedValueBuilder get validatedValue => + _$this._validatedValue ??= new ValidatedValueBuilder(); + set validatedValue(ValidatedValueBuilder? validatedValue) => + _$this._validatedValue = validatedValue; + + CompoundValueBuilder(); + + CompoundValueBuilder get _$this { + final $v = _$v; + if ($v != null) { + _simpleValue = $v.simpleValue.toBuilder(); + _validatedValue = $v.validatedValue?.toBuilder(); + _$v = null; + } + return this; + } + + @override + void replace(CompoundValue other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$CompoundValue; + } + + @override + void update(void Function(CompoundValueBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + CompoundValue build() => _build(); + + _$CompoundValue _build() { + _$CompoundValue _$result; + try { + _$result = _$v ?? + new _$CompoundValue._( + simpleValue: simpleValue.build(), + validatedValue: _validatedValue?.build()); + } catch (_) { + late String _$failedField; + try { + _$failedField = 'simpleValue'; + simpleValue.build(); + _$failedField = 'validatedValue'; + _validatedValue?.build(); + } catch (e) { + throw new BuiltValueNestedFieldError( + r'CompoundValue', _$failedField, e.toString()); + } + rethrow; + } + replace(_$result); + return _$result; + } +} + +class _$ValidatedValue extends ValidatedValue { + @override + final int anInt; + @override + final String? aString; + + factory _$ValidatedValue([void Function(ValidatedValueBuilder)? updates]) => + (new ValidatedValueBuilder()..update(updates))._build(); + + _$ValidatedValue._({required this.anInt, this.aString}) : super._() { + BuiltValueNullFieldError.checkNotNull(anInt, r'ValidatedValue', 'anInt'); + } + + @override + ValidatedValue rebuild(void Function(ValidatedValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + ValidatedValueBuilder toBuilder() => + new ValidatedValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is ValidatedValue && + anInt == other.anInt && + aString == other.aString; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, anInt.hashCode); + _$hash = $jc(_$hash, aString.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'ValidatedValue') + ..add('anInt', anInt) + ..add('aString', aString)) + .toString(); + } +} + +class ValidatedValueBuilder + implements Builder { + _$ValidatedValue? _$v; + + int? _anInt; + int? get anInt => _$this._anInt; + set anInt(int? anInt) => _$this._anInt = anInt; + + String? _aString; + String? get aString => _$this._aString; + set aString(String? aString) => _$this._aString = aString; + + ValidatedValueBuilder(); + + ValidatedValueBuilder get _$this { + final $v = _$v; + if ($v != null) { + _anInt = $v.anInt; + _aString = $v.aString; + _$v = null; + } + return this; + } + + @override + void replace(ValidatedValue other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$ValidatedValue; + } + + @override + void update(void Function(ValidatedValueBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + ValidatedValue build() => _build(); + + _$ValidatedValue _build() { + final _$result = _$v ?? + new _$ValidatedValue._( + anInt: BuiltValueNullFieldError.checkNotNull( + anInt, r'ValidatedValue', 'anInt'), + aString: aString); + replace(_$result); + return _$result; + } +} + +class _$ValueWithCode extends ValueWithCode { + @override + final int anInt; + @override + final String? aString; + + factory _$ValueWithCode([void Function(ValueWithCodeBuilder)? updates]) => + (new ValueWithCodeBuilder()..update(updates))._build(); + + _$ValueWithCode._({required this.anInt, this.aString}) : super._() { + BuiltValueNullFieldError.checkNotNull(anInt, r'ValueWithCode', 'anInt'); + } + + @override + ValueWithCode rebuild(void Function(ValueWithCodeBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + ValueWithCodeBuilder toBuilder() => new ValueWithCodeBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is ValueWithCode && + anInt == other.anInt && + aString == other.aString; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, anInt.hashCode); + _$hash = $jc(_$hash, aString.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'ValueWithCode') + ..add('anInt', anInt) + ..add('aString', aString)) + .toString(); + } +} + +class ValueWithCodeBuilder + implements Builder { + _$ValueWithCode? _$v; + + int? _anInt; + int? get anInt => _$this._anInt; + set anInt(int? anInt) => _$this._anInt = anInt; + + String? _aString; + String? get aString => _$this._aString; + set aString(String? aString) => _$this._aString = aString; + + ValueWithCodeBuilder(); + + ValueWithCodeBuilder get _$this { + final $v = _$v; + if ($v != null) { + _anInt = $v.anInt; + _aString = $v.aString; + _$v = null; + } + return this; + } + + @override + void replace(ValueWithCode other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$ValueWithCode; + } + + @override + void update(void Function(ValueWithCodeBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + ValueWithCode build() => _build(); + + _$ValueWithCode _build() { + final _$result = _$v ?? + new _$ValueWithCode._( + anInt: BuiltValueNullFieldError.checkNotNull( + anInt, r'ValueWithCode', 'anInt'), + aString: aString); + replace(_$result); + return _$result; + } +} + +class _$ValueWithDefaults extends ValueWithDefaults { + @override + final int anInt; + @override + final String? aString; + + factory _$ValueWithDefaults( + [void Function(ValueWithDefaultsBuilder)? updates]) => + (new ValueWithDefaultsBuilder()..update(updates)).build() + as _$ValueWithDefaults; + + _$ValueWithDefaults._({required this.anInt, this.aString}) : super._() { + BuiltValueNullFieldError.checkNotNull(anInt, r'ValueWithDefaults', 'anInt'); + } + + @override + ValueWithDefaults rebuild(void Function(ValueWithDefaultsBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + _$ValueWithDefaultsBuilder toBuilder() => + new _$ValueWithDefaultsBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is ValueWithDefaults && + anInt == other.anInt && + aString == other.aString; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, anInt.hashCode); + _$hash = $jc(_$hash, aString.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'ValueWithDefaults') + ..add('anInt', anInt) + ..add('aString', aString)) + .toString(); + } +} + +class _$ValueWithDefaultsBuilder extends ValueWithDefaultsBuilder { + _$ValueWithDefaults? _$v; + + @override + int get anInt { + _$this; + return super.anInt; + } + + @override + set anInt(int anInt) { + _$this; + super.anInt = anInt; + } + + @override + String? get aString { + _$this; + return super.aString; + } + + @override + set aString(String? aString) { + _$this; + super.aString = aString; + } + + _$ValueWithDefaultsBuilder() : super._(); + + ValueWithDefaultsBuilder get _$this { + final $v = _$v; + if ($v != null) { + super.anInt = $v.anInt; + super.aString = $v.aString; + _$v = null; + } + return this; + } + + @override + void replace(ValueWithDefaults other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$ValueWithDefaults; + } + + @override + void update(void Function(ValueWithDefaultsBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + ValueWithDefaults build() => _build(); + + _$ValueWithDefaults _build() { + final _$result = _$v ?? + new _$ValueWithDefaults._( + anInt: BuiltValueNullFieldError.checkNotNull( + anInt, r'ValueWithDefaults', 'anInt'), + aString: aString); + replace(_$result); + return _$result; + } +} + +class _$DerivedValue extends DerivedValue { + @override + final int anInt; + int? __derivedValue; + Iterable? __derivedString; + + factory _$DerivedValue([void Function(DerivedValueBuilder)? updates]) => + (new DerivedValueBuilder()..update(updates))._build(); + + _$DerivedValue._({required this.anInt}) : super._() { + BuiltValueNullFieldError.checkNotNull(anInt, r'DerivedValue', 'anInt'); + } + + @override + int get derivedValue => __derivedValue ??= super.derivedValue; + + @override + Iterable get derivedString => __derivedString ??= super.derivedString; + + @override + DerivedValue rebuild(void Function(DerivedValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + DerivedValueBuilder toBuilder() => new DerivedValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is DerivedValue && anInt == other.anInt; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, anInt.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'DerivedValue')..add('anInt', anInt)) + .toString(); + } +} + +class DerivedValueBuilder + implements Builder { + _$DerivedValue? _$v; + + int? _anInt; + int? get anInt => _$this._anInt; + set anInt(int? anInt) => _$this._anInt = anInt; + + DerivedValueBuilder(); + + DerivedValueBuilder get _$this { + final $v = _$v; + if ($v != null) { + _anInt = $v.anInt; + _$v = null; + } + return this; + } + + @override + void replace(DerivedValue other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$DerivedValue; + } + + @override + void update(void Function(DerivedValueBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + DerivedValue build() => _build(); + + _$DerivedValue _build() { + final _$result = _$v ?? + new _$DerivedValue._( + anInt: BuiltValueNullFieldError.checkNotNull( + anInt, r'DerivedValue', 'anInt')); + replace(_$result); + return _$result; + } +} + +class _$Account extends Account { + @override + final int id; + @override + final String name; + @override + final BuiltMap keyValues; + + factory _$Account([void Function(AccountBuilder)? updates]) => + (new AccountBuilder()..update(updates))._build(); + + _$Account._({required this.id, required this.name, required this.keyValues}) + : super._() { + BuiltValueNullFieldError.checkNotNull(id, r'Account', 'id'); + BuiltValueNullFieldError.checkNotNull(name, r'Account', 'name'); + BuiltValueNullFieldError.checkNotNull(keyValues, r'Account', 'keyValues'); + } + + @override + Account rebuild(void Function(AccountBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + AccountBuilder toBuilder() => new AccountBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Account && + id == other.id && + name == other.name && + keyValues == other.keyValues; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, id.hashCode); + _$hash = $jc(_$hash, name.hashCode); + _$hash = $jc(_$hash, keyValues.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'Account') + ..add('id', id) + ..add('name', name) + ..add('keyValues', keyValues)) + .toString(); + } +} + +class AccountBuilder implements Builder { + _$Account? _$v; + + int? _id; + int? get id => _$this._id; + set id(int? id) => _$this._id = id; + + String? _name; + String? get name => _$this._name; + set name(String? name) => _$this._name = name; + + MapBuilder? _keyValues; + MapBuilder get keyValues => + _$this._keyValues ??= new MapBuilder(); + set keyValues(MapBuilder? keyValues) => + _$this._keyValues = keyValues; + + AccountBuilder(); + + AccountBuilder get _$this { + final $v = _$v; + if ($v != null) { + _id = $v.id; + _name = $v.name; + _keyValues = $v.keyValues.toBuilder(); + _$v = null; + } + return this; + } + + @override + void replace(Account other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$Account; + } + + @override + void update(void Function(AccountBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + Account build() => _build(); + + _$Account _build() { + _$Account _$result; + try { + _$result = _$v ?? + new _$Account._( + id: BuiltValueNullFieldError.checkNotNull(id, r'Account', 'id'), + name: BuiltValueNullFieldError.checkNotNull( + name, r'Account', 'name'), + keyValues: keyValues.build()); + } catch (_) { + late String _$failedField; + try { + _$failedField = 'keyValues'; + keyValues.build(); + } catch (e) { + throw new BuiltValueNestedFieldError( + r'Account', _$failedField, e.toString()); + } + rethrow; + } + replace(_$result); + return _$result; + } +} + +class _$WireNameValue extends WireNameValue { + @override + final int value; + + factory _$WireNameValue([void Function(WireNameValueBuilder)? updates]) => + (new WireNameValueBuilder()..update(updates))._build(); + + _$WireNameValue._({required this.value}) : super._() { + BuiltValueNullFieldError.checkNotNull(value, r'WireNameValue', 'value'); + } + + @override + WireNameValue rebuild(void Function(WireNameValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + WireNameValueBuilder toBuilder() => new WireNameValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is WireNameValue && value == other.value; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, value.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'WireNameValue')..add('value', value)) + .toString(); + } +} + +class WireNameValueBuilder + implements Builder { + _$WireNameValue? _$v; + + int? _value; + int? get value => _$this._value; + set value(int? value) => _$this._value = value; + + WireNameValueBuilder(); + + WireNameValueBuilder get _$this { + final $v = _$v; + if ($v != null) { + _value = $v.value; + _$v = null; + } + return this; + } + + @override + void replace(WireNameValue other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$WireNameValue; + } + + @override + void update(void Function(WireNameValueBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + WireNameValue build() => _build(); + + _$WireNameValue _build() { + final _$result = _$v ?? + new _$WireNameValue._( + value: BuiltValueNullFieldError.checkNotNull( + value, r'WireNameValue', 'value')); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: deprecated_member_use_from_same_package,type=lint diff --git a/pkgs/_augmentation_examples/lib/built_value_with_augs.a.dart b/pkgs/_augmentation_examples/lib/built_value_with_augs.a.dart new file mode 100644 index 0000000..6716f09 --- /dev/null +++ b/pkgs/_augmentation_examples/lib/built_value_with_augs.a.dart @@ -0,0 +1,1111 @@ +// Generated code modified by hand to use augmenations. + +part of 'built_value_with_augs.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializer _$simpleValueSerializer = new _$SimpleValueSerializer(); +Serializer _$verySimpleValueSerializer = + new _$VerySimpleValueSerializer(); +Serializer _$compoundValueSerializer = + new _$CompoundValueSerializer(); +Serializer _$validatedValueSerializer = + new _$ValidatedValueSerializer(); +Serializer _$accountSerializer = new _$AccountSerializer(); +Serializer _$wireNameValueSerializer = + new _$WireNameValueSerializer(); + +class _$SimpleValueSerializer implements StructuredSerializer { + @override + final Iterable types = const [SimpleValue]; + @override + final String wireName = 'SimpleValue'; + + @override + Iterable serialize(Serializers serializers, SimpleValue object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'anInt', + serializers.serialize(object.anInt, specifiedType: const FullType(int)), + ]; + Object? value; + value = object.aString; + if (value != null) { + result + ..add('aString') + ..add(serializers.serialize(value, + specifiedType: const FullType(String))); + } + return result; + } + + @override + SimpleValue deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new SimpleValueBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'anInt': + result.anInt = serializers.deserialize(value, + specifiedType: const FullType(int))! as int; + break; + case 'aString': + result.aString = serializers.deserialize(value, + specifiedType: const FullType(String)) as String?; + break; + } + } + + return result.build(); + } +} + +class _$VerySimpleValueSerializer + implements StructuredSerializer { + @override + final Iterable types = const [VerySimpleValue]; + @override + final String wireName = 'VerySimpleValue'; + + @override + Iterable serialize(Serializers serializers, VerySimpleValue object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'value', + serializers.serialize(object.value, specifiedType: const FullType(int)), + ]; + + return result; + } + + @override + VerySimpleValue deserialize( + Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new VerySimpleValueBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'value': + result.value = serializers.deserialize(value, + specifiedType: const FullType(int))! as int; + break; + } + } + + return result.build(); + } +} + +class _$CompoundValueSerializer implements StructuredSerializer { + @override + final Iterable types = const [CompoundValue]; + @override + final String wireName = 'CompoundValue'; + + @override + Iterable serialize(Serializers serializers, CompoundValue object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'simpleValue', + serializers.serialize(object.simpleValue, + specifiedType: const FullType(SimpleValue)), + ]; + Object? value; + value = object.validatedValue; + if (value != null) { + result + ..add('validatedValue') + ..add(serializers.serialize(value, + specifiedType: const FullType(ValidatedValue))); + } + return result; + } + + @override + CompoundValue deserialize( + Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new CompoundValueBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'simpleValue': + result.simpleValue.replace(serializers.deserialize(value, + specifiedType: const FullType(SimpleValue))! as SimpleValue); + break; + case 'validatedValue': + result.validatedValue.replace(serializers.deserialize(value, + specifiedType: const FullType(ValidatedValue))! + as ValidatedValue); + break; + } + } + + return result.build(); + } +} + +class _$ValidatedValueSerializer + implements StructuredSerializer { + @override + final Iterable types = const [ValidatedValue]; + @override + final String wireName = 'ValidatedValue'; + + @override + Iterable serialize(Serializers serializers, ValidatedValue object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'anInt', + serializers.serialize(object.anInt, specifiedType: const FullType(int)), + ]; + Object? value; + value = object.aString; + if (value != null) { + result + ..add('aString') + ..add(serializers.serialize(value, + specifiedType: const FullType(String))); + } + return result; + } + + @override + ValidatedValue deserialize( + Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new ValidatedValueBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'anInt': + result.anInt = serializers.deserialize(value, + specifiedType: const FullType(int))! as int; + break; + case 'aString': + result.aString = serializers.deserialize(value, + specifiedType: const FullType(String)) as String?; + break; + } + } + + return result.build(); + } +} + +class _$AccountSerializer implements StructuredSerializer { + @override + final Iterable types = const [Account]; + @override + final String wireName = 'Account'; + + @override + Iterable serialize(Serializers serializers, Account object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'id', + serializers.serialize(object.id, specifiedType: const FullType(int)), + 'name', + serializers.serialize(object.name, specifiedType: const FullType(String)), + 'keyValues', + serializers.serialize(object.keyValues, + specifiedType: const FullType(BuiltMap, + const [const FullType(String), const FullType(JsonObject)])), + ]; + + return result; + } + + @override + Account deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new AccountBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'id': + result.id = serializers.deserialize(value, + specifiedType: const FullType(int))! as int; + break; + case 'name': + result.name = serializers.deserialize(value, + specifiedType: const FullType(String))! as String; + break; + case 'keyValues': + result.keyValues.replace(serializers.deserialize(value, + specifiedType: const FullType(BuiltMap, const [ + const FullType(String), + const FullType(JsonObject) + ]))!); + break; + } + } + + return result.build(); + } +} + +class _$WireNameValueSerializer implements StructuredSerializer { + @override + final Iterable types = const [WireNameValue]; + @override + final String wireName = 'V'; + + @override + Iterable serialize(Serializers serializers, WireNameValue object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'v', + serializers.serialize(object.value, specifiedType: const FullType(int)), + ]; + + return result; + } + + @override + WireNameValue deserialize( + Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new WireNameValueBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'v': + result.value = serializers.deserialize(value, + specifiedType: const FullType(int))! as int; + break; + } + } + + return result.build(); + } +} + +augment class SimpleValue { + static Serializer get serializer => _$simpleValueSerializer; + + factory SimpleValue([void Function(SimpleValueBuilder)? updates]) => + (new SimpleValueBuilder()..update(updates)).build(); + + SimpleValue._({required int anInt, String? aString}) : anInt = anInt, aString = aString { + BuiltValueNullFieldError.checkNotNull(anInt, r'SimpleValue', 'anInt'); + } + + SimpleValue rebuild(void Function(SimpleValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + SimpleValueBuilder toBuilder() => new SimpleValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is SimpleValue && + anInt == other.anInt && + aString == other.aString; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, anInt.hashCode); + _$hash = $jc(_$hash, aString.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'SimpleValue') + ..add('anInt', anInt) + ..add('aString', aString)) + .toString(); + } +} + +class SimpleValueBuilder { + SimpleValue? _$v; + + int? _anInt; + int? get anInt => _$this._anInt; + set anInt(int? anInt) => _$this._anInt = anInt; + + String? _aString; + String? get aString => _$this._aString; + set aString(String? aString) => _$this._aString = aString; + + SimpleValueBuilder(); + + SimpleValueBuilder get _$this { + final $v = _$v; + if ($v != null) { + _anInt = $v.anInt; + _aString = $v.aString; + _$v = null; + } + return this; + } + + void replace(SimpleValue other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other; + } + + void update(void Function(SimpleValueBuilder)? updates) { + if (updates != null) updates(this); + } + + SimpleValue build() { + final _$result = _$v ?? + new SimpleValue._( + anInt: BuiltValueNullFieldError.checkNotNull( + anInt, r'SimpleValue', 'anInt'), + aString: aString); + replace(_$result); + return _$result; + } +} + +augment class VerySimpleValue { + static Serializer get serializer => _$verySimpleValueSerializer; + + factory VerySimpleValue([void Function(VerySimpleValueBuilder)? updates]) => + (new VerySimpleValueBuilder()..update(updates)).build(); + + VerySimpleValue._({required this.value}) : super._() { + BuiltValueNullFieldError.checkNotNull(value, r'VerySimpleValue', 'value'); + } + + VerySimpleValue rebuild(void Function(VerySimpleValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + VerySimpleValueBuilder toBuilder() => + new VerySimpleValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is VerySimpleValue && value == other.value; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, value.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'VerySimpleValue') + ..add('value', value)) + .toString(); + } +} + +class VerySimpleValueBuilder { + VerySimpleValue? _$v; + + int? _value; + int? get value => _$this._value; + set value(int? value) => _$this._value = value; + + VerySimpleValueBuilder(); + + VerySimpleValueBuilder get _$this { + final $v = _$v; + if ($v != null) { + _value = $v.value; + _$v = null; + } + return this; + } + + void replace(VerySimpleValue other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other; + } + + void update(void Function(VerySimpleValueBuilder)? updates) { + if (updates != null) updates(this); + } + + VerySimpleValue build() { + final _$result = _$v ?? + new VerySimpleValue._( + value: BuiltValueNullFieldError.checkNotNull( + value, r'VerySimpleValue', 'value')); + replace(_$result); + return _$result; + } +} + +augment class CompoundValue { + static Serializer get serializer => _$compoundValueSerializer; + + factory CompoundValue([void Function(CompoundValueBuilder)? updates]) => + (new CompoundValueBuilder()..update(updates)).build(); + + CompoundValue._({required SimpleValue simpleValue, ValidatedValue? validatedValue}) + : simpleValue = simpleValue, validatedValue = validatedValue { + BuiltValueNullFieldError.checkNotNull( + simpleValue, r'CompoundValue', 'simpleValue'); + } + + CompoundValue rebuild(void Function(CompoundValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + CompoundValueBuilder toBuilder() => new CompoundValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is CompoundValue && + simpleValue == other.simpleValue && + validatedValue == other.validatedValue; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, simpleValue.hashCode); + _$hash = $jc(_$hash, validatedValue.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'CompoundValue') + ..add('simpleValue', simpleValue) + ..add('validatedValue', validatedValue)) + .toString(); + } +} + +class CompoundValueBuilder { + CompoundValue? _$v; + + SimpleValueBuilder? _simpleValue; + SimpleValueBuilder get simpleValue => + _$this._simpleValue ??= new SimpleValueBuilder(); + set simpleValue(SimpleValueBuilder? simpleValue) => + _$this._simpleValue = simpleValue; + + ValidatedValueBuilder? _validatedValue; + ValidatedValueBuilder get validatedValue => + _$this._validatedValue ??= new ValidatedValueBuilder(); + set validatedValue(ValidatedValueBuilder? validatedValue) => + _$this._validatedValue = validatedValue; + + CompoundValueBuilder(); + + CompoundValueBuilder get _$this { + final $v = _$v; + if ($v != null) { + _simpleValue = $v.simpleValue.toBuilder(); + _validatedValue = $v.validatedValue?.toBuilder(); + _$v = null; + } + return this; + } + + void replace(CompoundValue other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other; + } + + void update(void Function(CompoundValueBuilder)? updates) { + if (updates != null) updates(this); + } + + CompoundValue build() { + CompoundValue _$result; + try { + _$result = _$v ?? + new CompoundValue._( + simpleValue: simpleValue.build(), + validatedValue: _validatedValue?.build()); + } catch (_) { + late String _$failedField; + try { + _$failedField = 'simpleValue'; + simpleValue.build(); + _$failedField = 'validatedValue'; + _validatedValue?.build(); + } catch (e) { + throw new BuiltValueNestedFieldError( + r'CompoundValue', _$failedField, e.toString()); + } + rethrow; + } + replace(_$result); + return _$result; + } +} + +augment class ValidatedValue { + static Serializer get serializer => + _$validatedValueSerializer; + + factory ValidatedValue([void Function(ValidatedValueBuilder)? updates]) => + (new ValidatedValueBuilder()..update(updates)).build(); + + augment ValidatedValue._({required int anInt, String? aString}) + : anInt = anInt, aString = aString{ + BuiltValueNullFieldError.checkNotNull(anInt, r'ValidatedValue', 'anInt'); + augmented(); + } + + ValidatedValue rebuild(void Function(ValidatedValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + ValidatedValueBuilder toBuilder() => + new ValidatedValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is ValidatedValue && + anInt == other.anInt && + aString == other.aString; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, anInt.hashCode); + _$hash = $jc(_$hash, aString.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'ValidatedValue') + ..add('anInt', anInt) + ..add('aString', aString)) + .toString(); + } +} + +class ValidatedValueBuilder { + ValidatedValue? _$v; + + int? _anInt; + int? get anInt => _$this._anInt; + set anInt(int? anInt) => _$this._anInt = anInt; + + String? _aString; + String? get aString => _$this._aString; + set aString(String? aString) => _$this._aString = aString; + + ValidatedValueBuilder(); + + ValidatedValueBuilder get _$this { + final $v = _$v; + if ($v != null) { + _anInt = $v.anInt; + _aString = $v.aString; + _$v = null; + } + return this; + } + + void replace(ValidatedValue other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other; + } + + void update(void Function(ValidatedValueBuilder)? updates) { + if (updates != null) updates(this); + } + + ValidatedValue build() { + final _$result = _$v ?? + new ValidatedValue._( + anInt: BuiltValueNullFieldError.checkNotNull( + anInt, r'ValidatedValue', 'anInt'), + aString: aString); + replace(_$result); + return _$result; + } +} + +augment class ValueWithCode{ + factory ValueWithCode([void Function(ValueWithCodeBuilder)? updates]) => + (new ValueWithCodeBuilder()..update(updates))._build(); + + ValueWithCode._({required int anInt, String? aString}) : this.anInt = anInt, this.aString = aString { + BuiltValueNullFieldError.checkNotNull(anInt, r'ValueWithCode', 'anInt'); + } + + ValueWithCode rebuild(void Function(ValueWithCodeBuilder) updates) => + (toBuilder()..update(updates)).build(); + + ValueWithCodeBuilder toBuilder() => new ValueWithCodeBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is ValueWithCode && + anInt == other.anInt && + aString == other.aString; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, anInt.hashCode); + _$hash = $jc(_$hash, aString.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'ValueWithCode') + ..add('anInt', anInt) + ..add('aString', aString)) + .toString(); + } +} + +class ValueWithCodeBuilder { + ValueWithCode? _$v; + + int? _anInt; + int? get anInt => _$this._anInt; + set anInt(int? anInt) => _$this._anInt = anInt; + + String? _aString; + String? get aString => _$this._aString; + set aString(String? aString) => _$this._aString = aString; + + ValueWithCodeBuilder(); + + ValueWithCodeBuilder get _$this { + final $v = _$v; + if ($v != null) { + _anInt = $v.anInt; + _aString = $v.aString; + _$v = null; + } + return this; + } + + void replace(ValueWithCode other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other; + } + + void update(void Function(ValueWithCodeBuilder)? updates) { + if (updates != null) updates(this); + } + + ValueWithCode build() => _build(); + + ValueWithCode _build() { + final _$result = _$v ?? + new ValueWithCode._( + anInt: BuiltValueNullFieldError.checkNotNull( + anInt, r'ValueWithCode', 'anInt'), + aString: aString); + replace(_$result); + return _$result; + } +} + +augment class ValueWithDefaults { + factory ValueWithDefaults( + [void Function(ValueWithDefaultsBuilder)? updates]) => + (new ValueWithDefaultsBuilder()..update(updates)).build(); + + ValueWithDefaults._({required int anInt, String? aString}) : anInt = anInt, aString = aString { + BuiltValueNullFieldError.checkNotNull(anInt, r'ValueWithDefaults', 'anInt'); + } + + ValueWithDefaults rebuild(void Function(ValueWithDefaultsBuilder) updates) => + (toBuilder()..update(updates)).build(); + + ValueWithDefaultsBuilder toBuilder() => + new ValueWithDefaultsBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is ValueWithDefaults && + anInt == other.anInt && + aString == other.aString; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, anInt.hashCode); + _$hash = $jc(_$hash, aString.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'ValueWithDefaults') + ..add('anInt', anInt) + ..add('aString', aString)) + .toString(); + } +} + +augment class ValueWithDefaultsBuilder { + ValueWithDefaults? _$v; + + augment int get anInt { + _$this; + return augmented; + } + + augment set anInt(int anInt) { + _$this; + augmented = anInt; + } + + augment String? get aString { + _$this; + return augmented; + } + + augment set aString(String? aString) { + _$this; + augmented = aString; + } + + ValueWithDefaultsBuilder(); + + ValueWithDefaultsBuilder get _$this { + final $v = _$v; + if ($v != null) { + anInt = $v.anInt; + aString = $v.aString; + _$v = null; + } + return this; + } + + void replace(ValueWithDefaults other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other; + } + + void update(void Function(ValueWithDefaultsBuilder)? updates) { + if (updates != null) updates(this); + } + + ValueWithDefaults build() => _build(); + + ValueWithDefaults _build() { + final _$result = _$v ?? + new ValueWithDefaults._( + anInt: BuiltValueNullFieldError.checkNotNull( + anInt, r'ValueWithDefaults', 'anInt'), + aString: aString); + replace(_$result); + return _$result; + } +} + +augment class DerivedValue { + int? __derivedValue; + Iterable? __derivedString; + + factory DerivedValue([void Function(DerivedValueBuilder)? updates]) => + (new DerivedValueBuilder()..update(updates))._build(); + + DerivedValue._({required int anInt}) : anInt = anInt { + BuiltValueNullFieldError.checkNotNull(anInt, r'DerivedValue', 'anInt'); + } + + augment int get derivedValue => __derivedValue ??= augmented; + + augment Iterable get derivedString => __derivedString ??= augmented; + + DerivedValue rebuild(void Function(DerivedValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + DerivedValueBuilder toBuilder() => new DerivedValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is DerivedValue && anInt == other.anInt; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, anInt.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'DerivedValue')..add('anInt', anInt)) + .toString(); + } +} + +class DerivedValueBuilder { + DerivedValue? _$v; + + int? _anInt; + int? get anInt => _$this._anInt; + set anInt(int? anInt) => _$this._anInt = anInt; + + DerivedValueBuilder(); + + DerivedValueBuilder get _$this { + final $v = _$v; + if ($v != null) { + _anInt = $v.anInt; + _$v = null; + } + return this; + } + + void replace(DerivedValue other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other; + } + + void update(void Function(DerivedValueBuilder)? updates) { + if (updates != null) updates(this); + } + + DerivedValue build() => _build(); + + DerivedValue _build() { + final _$result = _$v ?? + new DerivedValue._( + anInt: BuiltValueNullFieldError.checkNotNull( + anInt, r'DerivedValue', 'anInt')); + replace(_$result); + return _$result; + } +} + +augment class Account { + static Serializer get serializer => _$accountSerializer; + + factory Account([void Function(AccountBuilder)? updates]) => + (new AccountBuilder()..update(updates))._build(); + + Account._({required int id, required String name, required BuiltMap keyValues}) + : id = id, name = name, keyValues = keyValues { + BuiltValueNullFieldError.checkNotNull(id, r'Account', 'id'); + BuiltValueNullFieldError.checkNotNull(name, r'Account', 'name'); + BuiltValueNullFieldError.checkNotNull(keyValues, r'Account', 'keyValues'); + } + + Account rebuild(void Function(AccountBuilder) updates) => + (toBuilder()..update(updates)).build(); + + AccountBuilder toBuilder() => new AccountBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Account && + id == other.id && + name == other.name && + keyValues == other.keyValues; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, id.hashCode); + _$hash = $jc(_$hash, name.hashCode); + _$hash = $jc(_$hash, keyValues.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'Account') + ..add('id', id) + ..add('name', name) + ..add('keyValues', keyValues)) + .toString(); + } +} + +class AccountBuilder { + Account? _$v; + + int? _id; + int? get id => _$this._id; + set id(int? id) => _$this._id = id; + + String? _name; + String? get name => _$this._name; + set name(String? name) => _$this._name = name; + + MapBuilder? _keyValues; + MapBuilder get keyValues => + _$this._keyValues ??= new MapBuilder(); + set keyValues(MapBuilder? keyValues) => + _$this._keyValues = keyValues; + + AccountBuilder(); + + AccountBuilder get _$this { + final $v = _$v; + if ($v != null) { + _id = $v.id; + _name = $v.name; + _keyValues = $v.keyValues.toBuilder(); + _$v = null; + } + return this; + } + + void replace(Account other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other; + } + + void update(void Function(AccountBuilder)? updates) { + if (updates != null) updates(this); + } + + Account build() => _build(); + + Account _build() { + Account _$result; + try { + _$result = _$v ?? + new Account._( + id: BuiltValueNullFieldError.checkNotNull(id, r'Account', 'id'), + name: BuiltValueNullFieldError.checkNotNull( + name, r'Account', 'name'), + keyValues: keyValues.build()); + } catch (_) { + late String _$failedField; + try { + _$failedField = 'keyValues'; + keyValues.build(); + } catch (e) { + throw new BuiltValueNestedFieldError( + r'Account', _$failedField, e.toString()); + } + rethrow; + } + replace(_$result); + return _$result; + } +} + +augment class WireNameValue { + static Serializer get serializer => _$wireNameValueSerializer; + + factory WireNameValue([void Function(WireNameValueBuilder)? updates]) => + (new WireNameValueBuilder()..update(updates)).build(); + + WireNameValue._({required int value}) : value = value { + BuiltValueNullFieldError.checkNotNull(value, r'WireNameValue', 'value'); + } + + WireNameValue rebuild(void Function(WireNameValueBuilder) updates) => + (toBuilder()..update(updates)).build(); + + WireNameValueBuilder toBuilder() => new WireNameValueBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is WireNameValue && value == other.value; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, value.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'WireNameValue')..add('value', value)) + .toString(); + } +} + +class WireNameValueBuilder { + WireNameValue? _$v; + + int? _value; + int? get value => _$this._value; + set value(int? value) => _$this._value = value; + + WireNameValueBuilder(); + + WireNameValueBuilder get _$this { + final $v = _$v; + if ($v != null) { + _value = $v.value; + _$v = null; + } + return this; + } + + void replace(WireNameValue other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other; + } + + void update(void Function(WireNameValueBuilder)? updates) { + if (updates != null) updates(this); + } + + WireNameValue build() { + final _$result = _$v ?? + new WireNameValue._( + value: BuiltValueNullFieldError.checkNotNull( + value, r'WireNameValue', 'value')); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: deprecated_member_use_from_same_package,type=lint diff --git a/pkgs/_augmentation_examples/lib/built_value_with_augs.dart b/pkgs/_augmentation_examples/lib/built_value_with_augs.dart new file mode 100644 index 0000000..1881412 --- /dev/null +++ b/pkgs/_augmentation_examples/lib/built_value_with_augs.dart @@ -0,0 +1,90 @@ +// Copyright (c) 2024, Google Inc. Please see the AUTHORS file for details. +// All rights reserved. Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/built_value.dart'; +import 'package:built_value/json_object.dart'; +import 'package:built_value/serializer.dart'; + +part 'built_value_with_augs.g.dart'; + +// @BuiltValue(serializable: true) +class SimpleValue { + final int anInt; + final String? aString; +} + +// @BuiltValue(serializable: true) +class VerySimpleValue { + final int value; +} + +// @BuiltValue(serializable: true) +class CompoundValue { + final SimpleValue simpleValue; + final ValidatedValue? validatedValue; +} + +// @BuiltValue(serializable: true) +class ValidatedValue { + final int anInt; + final String? aString; + + ValidatedValue._() { + if (anInt == 7) throw StateError('anInt may not be 7'); + } +} + +// @BuiltValue() +class ValueWithCode { + static final int youCanHaveStaticFields = 3; + + final int anInt; + final String? aString; + + String get youCanWriteDerivedGetters => anInt.toString() + aString!; + + factory ValueWithCode.fromCustomFactory(int anInt) => ValueWithCode( + (b) => + b + ..anInt = anInt + ..aString = 'two', + ); +} + +// @BuiltValue() +class ValueWithDefaults { + final int anInt; + final String? aString; +} + +// @BuiltValueBuilder() +class ValueWithDefaultsBuilder { + int anInt = 7; + String? aString; +} + +// @BuiltValue() +class DerivedValue { + final int anInt; + + @memoized + int get derivedValue => anInt + 10; + + @memoized + Iterable get derivedString => [toString()]; +} + +// @BuiltValue(serializable: true) +class Account { + final int id; + final String name; + final BuiltMap keyValues; +} + +// @BuiltValue(wireName: 'V') +class WireNameValue { + // @BuiltValueField(wireName: 'v') + final int value; +} diff --git a/pkgs/_augmentation_examples/lib/data.json b/pkgs/_augmentation_examples/lib/data.json new file mode 100644 index 0000000..93d0c2c --- /dev/null +++ b/pkgs/_augmentation_examples/lib/data.json @@ -0,0 +1,25 @@ +{ + "glossary": { + "title": "example glossary", + "GlossDiv": { + "title": "S", + "GlossList": { + "GlossEntry": { + "ID": "SGML", + "SortAs": "SGML", + "GlossTerm": "Standard Generalized Markup Language", + "Acronym": "SGML", + "Abbrev": "ISO 8879:1986", + "GlossDef": { + "para": "A meta-markup language, used to create markup languages.", + "GlossSeeAlso": [ + "GML", + "XML" + ] + }, + "GlossSee": "markup" + } + } + } + } + } \ No newline at end of file diff --git a/pkgs/_augmentation_examples/lib/freezed.dart b/pkgs/_augmentation_examples/lib/freezed.dart new file mode 100644 index 0000000..32191f2 --- /dev/null +++ b/pkgs/_augmentation_examples/lib/freezed.dart @@ -0,0 +1,31 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'freezed.freezed.dart'; +part 'freezed.g.dart'; + +@freezed +class MyClass with _$MyClass { + factory MyClass({String? a, int? b}) = _MyClass; +} + +@freezed +class Union with _$Union { + const factory Union(int value) = Data; + const factory Union.loading() = Loading; + const factory Union.error([String? message]) = ErrorDetails; + const factory Union.complex(int a, String b) = Complex; + + factory Union.fromJson(Map json) => _$UnionFromJson(json); +} + +@freezed +class SharedProperty with _$SharedProperty { + factory SharedProperty.person({String? name, int? age}) = SharedProperty0; + + factory SharedProperty.city({String? name, int? population}) = + SharedProperty1; +} diff --git a/pkgs/_augmentation_examples/lib/freezed.freezed.dart b/pkgs/_augmentation_examples/lib/freezed.freezed.dart new file mode 100644 index 0000000..a47c2ab --- /dev/null +++ b/pkgs/_augmentation_examples/lib/freezed.freezed.dart @@ -0,0 +1,1294 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'freezed.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +/// @nodoc +mixin _$MyClass { + String? get a => throw _privateConstructorUsedError; + int? get b => throw _privateConstructorUsedError; + + /// Create a copy of MyClass + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MyClassCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MyClassCopyWith<$Res> { + factory $MyClassCopyWith(MyClass value, $Res Function(MyClass) then) = + _$MyClassCopyWithImpl<$Res, MyClass>; + @useResult + $Res call({String? a, int? b}); +} + +/// @nodoc +class _$MyClassCopyWithImpl<$Res, $Val extends MyClass> + implements $MyClassCopyWith<$Res> { + _$MyClassCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MyClass + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? a = freezed, + Object? b = freezed, + }) { + return _then(_value.copyWith( + a: freezed == a + ? _value.a + : a // ignore: cast_nullable_to_non_nullable + as String?, + b: freezed == b + ? _value.b + : b // ignore: cast_nullable_to_non_nullable + as int?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MyClassImplCopyWith<$Res> implements $MyClassCopyWith<$Res> { + factory _$$MyClassImplCopyWith( + _$MyClassImpl value, $Res Function(_$MyClassImpl) then) = + __$$MyClassImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String? a, int? b}); +} + +/// @nodoc +class __$$MyClassImplCopyWithImpl<$Res> + extends _$MyClassCopyWithImpl<$Res, _$MyClassImpl> + implements _$$MyClassImplCopyWith<$Res> { + __$$MyClassImplCopyWithImpl( + _$MyClassImpl _value, $Res Function(_$MyClassImpl) _then) + : super(_value, _then); + + /// Create a copy of MyClass + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? a = freezed, + Object? b = freezed, + }) { + return _then(_$MyClassImpl( + a: freezed == a + ? _value.a + : a // ignore: cast_nullable_to_non_nullable + as String?, + b: freezed == b + ? _value.b + : b // ignore: cast_nullable_to_non_nullable + as int?, + )); + } +} + +/// @nodoc + +class _$MyClassImpl implements _MyClass { + _$MyClassImpl({this.a, this.b}); + + @override + final String? a; + @override + final int? b; + + @override + String toString() { + return 'MyClass(a: $a, b: $b)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MyClassImpl && + (identical(other.a, a) || other.a == a) && + (identical(other.b, b) || other.b == b)); + } + + @override + int get hashCode => Object.hash(runtimeType, a, b); + + /// Create a copy of MyClass + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MyClassImplCopyWith<_$MyClassImpl> get copyWith => + __$$MyClassImplCopyWithImpl<_$MyClassImpl>(this, _$identity); +} + +abstract class _MyClass implements MyClass { + factory _MyClass({final String? a, final int? b}) = _$MyClassImpl; + + @override + String? get a; + @override + int? get b; + + /// Create a copy of MyClass + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MyClassImplCopyWith<_$MyClassImpl> get copyWith => + throw _privateConstructorUsedError; +} + +Union _$UnionFromJson(Map json) { + switch (json['runtimeType']) { + case 'default': + return Data.fromJson(json); + case 'loading': + return Loading.fromJson(json); + case 'error': + return ErrorDetails.fromJson(json); + case 'complex': + return Complex.fromJson(json); + + default: + throw CheckedFromJsonException(json, 'runtimeType', 'Union', + 'Invalid union type "${json['runtimeType']}"!'); + } +} + +/// @nodoc +mixin _$Union { + @optionalTypeArgs + TResult when( + TResult Function(int value) $default, { + required TResult Function() loading, + required TResult Function(String? message) error, + required TResult Function(int a, String b) complex, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(int value)? $default, { + TResult? Function()? loading, + TResult? Function(String? message)? error, + TResult? Function(int a, String b)? complex, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen( + TResult Function(int value)? $default, { + TResult Function()? loading, + TResult Function(String? message)? error, + TResult Function(int a, String b)? complex, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map( + TResult Function(Data value) $default, { + required TResult Function(Loading value) loading, + required TResult Function(ErrorDetails value) error, + required TResult Function(Complex value) complex, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(Data value)? $default, { + TResult? Function(Loading value)? loading, + TResult? Function(ErrorDetails value)? error, + TResult? Function(Complex value)? complex, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap( + TResult Function(Data value)? $default, { + TResult Function(Loading value)? loading, + TResult Function(ErrorDetails value)? error, + TResult Function(Complex value)? complex, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + /// Serializes this Union to a JSON map. + Map toJson() => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $UnionCopyWith<$Res> { + factory $UnionCopyWith(Union value, $Res Function(Union) then) = + _$UnionCopyWithImpl<$Res, Union>; +} + +/// @nodoc +class _$UnionCopyWithImpl<$Res, $Val extends Union> + implements $UnionCopyWith<$Res> { + _$UnionCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc +abstract class _$$DataImplCopyWith<$Res> { + factory _$$DataImplCopyWith( + _$DataImpl value, $Res Function(_$DataImpl) then) = + __$$DataImplCopyWithImpl<$Res>; + @useResult + $Res call({int value}); +} + +/// @nodoc +class __$$DataImplCopyWithImpl<$Res> + extends _$UnionCopyWithImpl<$Res, _$DataImpl> + implements _$$DataImplCopyWith<$Res> { + __$$DataImplCopyWithImpl(_$DataImpl _value, $Res Function(_$DataImpl) _then) + : super(_value, _then); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? value = null, + }) { + return _then(_$DataImpl( + null == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$DataImpl implements Data { + const _$DataImpl(this.value, {final String? $type}) + : $type = $type ?? 'default'; + + factory _$DataImpl.fromJson(Map json) => + _$$DataImplFromJson(json); + + @override + final int value; + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'Union(value: $value)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$DataImpl && + (identical(other.value, value) || other.value == value)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, value); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$DataImplCopyWith<_$DataImpl> get copyWith => + __$$DataImplCopyWithImpl<_$DataImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when( + TResult Function(int value) $default, { + required TResult Function() loading, + required TResult Function(String? message) error, + required TResult Function(int a, String b) complex, + }) { + return $default(value); + } + + @override + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(int value)? $default, { + TResult? Function()? loading, + TResult? Function(String? message)? error, + TResult? Function(int a, String b)? complex, + }) { + return $default?.call(value); + } + + @override + @optionalTypeArgs + TResult maybeWhen( + TResult Function(int value)? $default, { + TResult Function()? loading, + TResult Function(String? message)? error, + TResult Function(int a, String b)? complex, + required TResult orElse(), + }) { + if ($default != null) { + return $default(value); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map( + TResult Function(Data value) $default, { + required TResult Function(Loading value) loading, + required TResult Function(ErrorDetails value) error, + required TResult Function(Complex value) complex, + }) { + return $default(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(Data value)? $default, { + TResult? Function(Loading value)? loading, + TResult? Function(ErrorDetails value)? error, + TResult? Function(Complex value)? complex, + }) { + return $default?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap( + TResult Function(Data value)? $default, { + TResult Function(Loading value)? loading, + TResult Function(ErrorDetails value)? error, + TResult Function(Complex value)? complex, + required TResult orElse(), + }) { + if ($default != null) { + return $default(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$DataImplToJson( + this, + ); + } +} + +abstract class Data implements Union { + const factory Data(final int value) = _$DataImpl; + + factory Data.fromJson(Map json) = _$DataImpl.fromJson; + + int get value; + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$DataImplCopyWith<_$DataImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$LoadingImplCopyWith<$Res> { + factory _$$LoadingImplCopyWith( + _$LoadingImpl value, $Res Function(_$LoadingImpl) then) = + __$$LoadingImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$LoadingImplCopyWithImpl<$Res> + extends _$UnionCopyWithImpl<$Res, _$LoadingImpl> + implements _$$LoadingImplCopyWith<$Res> { + __$$LoadingImplCopyWithImpl( + _$LoadingImpl _value, $Res Function(_$LoadingImpl) _then) + : super(_value, _then); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc +@JsonSerializable() +class _$LoadingImpl implements Loading { + const _$LoadingImpl({final String? $type}) : $type = $type ?? 'loading'; + + factory _$LoadingImpl.fromJson(Map json) => + _$$LoadingImplFromJson(json); + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'Union.loading()'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is _$LoadingImpl); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when( + TResult Function(int value) $default, { + required TResult Function() loading, + required TResult Function(String? message) error, + required TResult Function(int a, String b) complex, + }) { + return loading(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(int value)? $default, { + TResult? Function()? loading, + TResult? Function(String? message)? error, + TResult? Function(int a, String b)? complex, + }) { + return loading?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen( + TResult Function(int value)? $default, { + TResult Function()? loading, + TResult Function(String? message)? error, + TResult Function(int a, String b)? complex, + required TResult orElse(), + }) { + if (loading != null) { + return loading(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map( + TResult Function(Data value) $default, { + required TResult Function(Loading value) loading, + required TResult Function(ErrorDetails value) error, + required TResult Function(Complex value) complex, + }) { + return loading(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(Data value)? $default, { + TResult? Function(Loading value)? loading, + TResult? Function(ErrorDetails value)? error, + TResult? Function(Complex value)? complex, + }) { + return loading?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap( + TResult Function(Data value)? $default, { + TResult Function(Loading value)? loading, + TResult Function(ErrorDetails value)? error, + TResult Function(Complex value)? complex, + required TResult orElse(), + }) { + if (loading != null) { + return loading(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$LoadingImplToJson( + this, + ); + } +} + +abstract class Loading implements Union { + const factory Loading() = _$LoadingImpl; + + factory Loading.fromJson(Map json) = _$LoadingImpl.fromJson; +} + +/// @nodoc +abstract class _$$ErrorDetailsImplCopyWith<$Res> { + factory _$$ErrorDetailsImplCopyWith( + _$ErrorDetailsImpl value, $Res Function(_$ErrorDetailsImpl) then) = + __$$ErrorDetailsImplCopyWithImpl<$Res>; + @useResult + $Res call({String? message}); +} + +/// @nodoc +class __$$ErrorDetailsImplCopyWithImpl<$Res> + extends _$UnionCopyWithImpl<$Res, _$ErrorDetailsImpl> + implements _$$ErrorDetailsImplCopyWith<$Res> { + __$$ErrorDetailsImplCopyWithImpl( + _$ErrorDetailsImpl _value, $Res Function(_$ErrorDetailsImpl) _then) + : super(_value, _then); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? message = freezed, + }) { + return _then(_$ErrorDetailsImpl( + freezed == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$ErrorDetailsImpl implements ErrorDetails { + const _$ErrorDetailsImpl([this.message, final String? $type]) + : $type = $type ?? 'error'; + + factory _$ErrorDetailsImpl.fromJson(Map json) => + _$$ErrorDetailsImplFromJson(json); + + @override + final String? message; + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'Union.error(message: $message)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ErrorDetailsImpl && + (identical(other.message, message) || other.message == message)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, message); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ErrorDetailsImplCopyWith<_$ErrorDetailsImpl> get copyWith => + __$$ErrorDetailsImplCopyWithImpl<_$ErrorDetailsImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when( + TResult Function(int value) $default, { + required TResult Function() loading, + required TResult Function(String? message) error, + required TResult Function(int a, String b) complex, + }) { + return error(message); + } + + @override + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(int value)? $default, { + TResult? Function()? loading, + TResult? Function(String? message)? error, + TResult? Function(int a, String b)? complex, + }) { + return error?.call(message); + } + + @override + @optionalTypeArgs + TResult maybeWhen( + TResult Function(int value)? $default, { + TResult Function()? loading, + TResult Function(String? message)? error, + TResult Function(int a, String b)? complex, + required TResult orElse(), + }) { + if (error != null) { + return error(message); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map( + TResult Function(Data value) $default, { + required TResult Function(Loading value) loading, + required TResult Function(ErrorDetails value) error, + required TResult Function(Complex value) complex, + }) { + return error(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(Data value)? $default, { + TResult? Function(Loading value)? loading, + TResult? Function(ErrorDetails value)? error, + TResult? Function(Complex value)? complex, + }) { + return error?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap( + TResult Function(Data value)? $default, { + TResult Function(Loading value)? loading, + TResult Function(ErrorDetails value)? error, + TResult Function(Complex value)? complex, + required TResult orElse(), + }) { + if (error != null) { + return error(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$ErrorDetailsImplToJson( + this, + ); + } +} + +abstract class ErrorDetails implements Union { + const factory ErrorDetails([final String? message]) = _$ErrorDetailsImpl; + + factory ErrorDetails.fromJson(Map json) = + _$ErrorDetailsImpl.fromJson; + + String? get message; + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ErrorDetailsImplCopyWith<_$ErrorDetailsImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$ComplexImplCopyWith<$Res> { + factory _$$ComplexImplCopyWith( + _$ComplexImpl value, $Res Function(_$ComplexImpl) then) = + __$$ComplexImplCopyWithImpl<$Res>; + @useResult + $Res call({int a, String b}); +} + +/// @nodoc +class __$$ComplexImplCopyWithImpl<$Res> + extends _$UnionCopyWithImpl<$Res, _$ComplexImpl> + implements _$$ComplexImplCopyWith<$Res> { + __$$ComplexImplCopyWithImpl( + _$ComplexImpl _value, $Res Function(_$ComplexImpl) _then) + : super(_value, _then); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? a = null, + Object? b = null, + }) { + return _then(_$ComplexImpl( + null == a + ? _value.a + : a // ignore: cast_nullable_to_non_nullable + as int, + null == b + ? _value.b + : b // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$ComplexImpl implements Complex { + const _$ComplexImpl(this.a, this.b, {final String? $type}) + : $type = $type ?? 'complex'; + + factory _$ComplexImpl.fromJson(Map json) => + _$$ComplexImplFromJson(json); + + @override + final int a; + @override + final String b; + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'Union.complex(a: $a, b: $b)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ComplexImpl && + (identical(other.a, a) || other.a == a) && + (identical(other.b, b) || other.b == b)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, a, b); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ComplexImplCopyWith<_$ComplexImpl> get copyWith => + __$$ComplexImplCopyWithImpl<_$ComplexImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when( + TResult Function(int value) $default, { + required TResult Function() loading, + required TResult Function(String? message) error, + required TResult Function(int a, String b) complex, + }) { + return complex(a, b); + } + + @override + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(int value)? $default, { + TResult? Function()? loading, + TResult? Function(String? message)? error, + TResult? Function(int a, String b)? complex, + }) { + return complex?.call(a, b); + } + + @override + @optionalTypeArgs + TResult maybeWhen( + TResult Function(int value)? $default, { + TResult Function()? loading, + TResult Function(String? message)? error, + TResult Function(int a, String b)? complex, + required TResult orElse(), + }) { + if (complex != null) { + return complex(a, b); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map( + TResult Function(Data value) $default, { + required TResult Function(Loading value) loading, + required TResult Function(ErrorDetails value) error, + required TResult Function(Complex value) complex, + }) { + return complex(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(Data value)? $default, { + TResult? Function(Loading value)? loading, + TResult? Function(ErrorDetails value)? error, + TResult? Function(Complex value)? complex, + }) { + return complex?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap( + TResult Function(Data value)? $default, { + TResult Function(Loading value)? loading, + TResult Function(ErrorDetails value)? error, + TResult Function(Complex value)? complex, + required TResult orElse(), + }) { + if (complex != null) { + return complex(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$ComplexImplToJson( + this, + ); + } +} + +abstract class Complex implements Union { + const factory Complex(final int a, final String b) = _$ComplexImpl; + + factory Complex.fromJson(Map json) = _$ComplexImpl.fromJson; + + int get a; + String get b; + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ComplexImplCopyWith<_$ComplexImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +mixin _$SharedProperty { + String? get name => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult when({ + required TResult Function(String? name, int? age) person, + required TResult Function(String? name, int? population) city, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String? name, int? age)? person, + TResult? Function(String? name, int? population)? city, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String? name, int? age)? person, + TResult Function(String? name, int? population)? city, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(SharedProperty0 value) person, + required TResult Function(SharedProperty1 value) city, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(SharedProperty0 value)? person, + TResult? Function(SharedProperty1 value)? city, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(SharedProperty0 value)? person, + TResult Function(SharedProperty1 value)? city, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $SharedPropertyCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SharedPropertyCopyWith<$Res> { + factory $SharedPropertyCopyWith( + SharedProperty value, $Res Function(SharedProperty) then) = + _$SharedPropertyCopyWithImpl<$Res, SharedProperty>; + @useResult + $Res call({String? name}); +} + +/// @nodoc +class _$SharedPropertyCopyWithImpl<$Res, $Val extends SharedProperty> + implements $SharedPropertyCopyWith<$Res> { + _$SharedPropertyCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = freezed, + }) { + return _then(_value.copyWith( + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$SharedProperty0ImplCopyWith<$Res> + implements $SharedPropertyCopyWith<$Res> { + factory _$$SharedProperty0ImplCopyWith(_$SharedProperty0Impl value, + $Res Function(_$SharedProperty0Impl) then) = + __$$SharedProperty0ImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String? name, int? age}); +} + +/// @nodoc +class __$$SharedProperty0ImplCopyWithImpl<$Res> + extends _$SharedPropertyCopyWithImpl<$Res, _$SharedProperty0Impl> + implements _$$SharedProperty0ImplCopyWith<$Res> { + __$$SharedProperty0ImplCopyWithImpl( + _$SharedProperty0Impl _value, $Res Function(_$SharedProperty0Impl) _then) + : super(_value, _then); + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = freezed, + Object? age = freezed, + }) { + return _then(_$SharedProperty0Impl( + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + age: freezed == age + ? _value.age + : age // ignore: cast_nullable_to_non_nullable + as int?, + )); + } +} + +/// @nodoc + +class _$SharedProperty0Impl implements SharedProperty0 { + _$SharedProperty0Impl({this.name, this.age}); + + @override + final String? name; + @override + final int? age; + + @override + String toString() { + return 'SharedProperty.person(name: $name, age: $age)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SharedProperty0Impl && + (identical(other.name, name) || other.name == name) && + (identical(other.age, age) || other.age == age)); + } + + @override + int get hashCode => Object.hash(runtimeType, name, age); + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$SharedProperty0ImplCopyWith<_$SharedProperty0Impl> get copyWith => + __$$SharedProperty0ImplCopyWithImpl<_$SharedProperty0Impl>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String? name, int? age) person, + required TResult Function(String? name, int? population) city, + }) { + return person(name, age); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String? name, int? age)? person, + TResult? Function(String? name, int? population)? city, + }) { + return person?.call(name, age); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String? name, int? age)? person, + TResult Function(String? name, int? population)? city, + required TResult orElse(), + }) { + if (person != null) { + return person(name, age); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(SharedProperty0 value) person, + required TResult Function(SharedProperty1 value) city, + }) { + return person(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(SharedProperty0 value)? person, + TResult? Function(SharedProperty1 value)? city, + }) { + return person?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(SharedProperty0 value)? person, + TResult Function(SharedProperty1 value)? city, + required TResult orElse(), + }) { + if (person != null) { + return person(this); + } + return orElse(); + } +} + +abstract class SharedProperty0 implements SharedProperty { + factory SharedProperty0({final String? name, final int? age}) = + _$SharedProperty0Impl; + + @override + String? get name; + int? get age; + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$SharedProperty0ImplCopyWith<_$SharedProperty0Impl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$SharedProperty1ImplCopyWith<$Res> + implements $SharedPropertyCopyWith<$Res> { + factory _$$SharedProperty1ImplCopyWith(_$SharedProperty1Impl value, + $Res Function(_$SharedProperty1Impl) then) = + __$$SharedProperty1ImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String? name, int? population}); +} + +/// @nodoc +class __$$SharedProperty1ImplCopyWithImpl<$Res> + extends _$SharedPropertyCopyWithImpl<$Res, _$SharedProperty1Impl> + implements _$$SharedProperty1ImplCopyWith<$Res> { + __$$SharedProperty1ImplCopyWithImpl( + _$SharedProperty1Impl _value, $Res Function(_$SharedProperty1Impl) _then) + : super(_value, _then); + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = freezed, + Object? population = freezed, + }) { + return _then(_$SharedProperty1Impl( + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + population: freezed == population + ? _value.population + : population // ignore: cast_nullable_to_non_nullable + as int?, + )); + } +} + +/// @nodoc + +class _$SharedProperty1Impl implements SharedProperty1 { + _$SharedProperty1Impl({this.name, this.population}); + + @override + final String? name; + @override + final int? population; + + @override + String toString() { + return 'SharedProperty.city(name: $name, population: $population)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SharedProperty1Impl && + (identical(other.name, name) || other.name == name) && + (identical(other.population, population) || + other.population == population)); + } + + @override + int get hashCode => Object.hash(runtimeType, name, population); + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$SharedProperty1ImplCopyWith<_$SharedProperty1Impl> get copyWith => + __$$SharedProperty1ImplCopyWithImpl<_$SharedProperty1Impl>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String? name, int? age) person, + required TResult Function(String? name, int? population) city, + }) { + return city(name, population); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String? name, int? age)? person, + TResult? Function(String? name, int? population)? city, + }) { + return city?.call(name, population); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String? name, int? age)? person, + TResult Function(String? name, int? population)? city, + required TResult orElse(), + }) { + if (city != null) { + return city(name, population); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(SharedProperty0 value) person, + required TResult Function(SharedProperty1 value) city, + }) { + return city(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(SharedProperty0 value)? person, + TResult? Function(SharedProperty1 value)? city, + }) { + return city?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(SharedProperty0 value)? person, + TResult Function(SharedProperty1 value)? city, + required TResult orElse(), + }) { + if (city != null) { + return city(this); + } + return orElse(); + } +} + +abstract class SharedProperty1 implements SharedProperty { + factory SharedProperty1({final String? name, final int? population}) = + _$SharedProperty1Impl; + + @override + String? get name; + int? get population; + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$SharedProperty1ImplCopyWith<_$SharedProperty1Impl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/pkgs/_augmentation_examples/lib/freezed.g.dart b/pkgs/_augmentation_examples/lib/freezed.g.dart new file mode 100644 index 0000000..ad83303 --- /dev/null +++ b/pkgs/_augmentation_examples/lib/freezed.g.dart @@ -0,0 +1,54 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'freezed.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$DataImpl _$$DataImplFromJson(Map json) => _$DataImpl( + (json['value'] as num).toInt(), + $type: json['runtimeType'] as String?, + ); + +Map _$$DataImplToJson(_$DataImpl instance) => + { + 'value': instance.value, + 'runtimeType': instance.$type, + }; + +_$LoadingImpl _$$LoadingImplFromJson(Map json) => + _$LoadingImpl( + $type: json['runtimeType'] as String?, + ); + +Map _$$LoadingImplToJson(_$LoadingImpl instance) => + { + 'runtimeType': instance.$type, + }; + +_$ErrorDetailsImpl _$$ErrorDetailsImplFromJson(Map json) => + _$ErrorDetailsImpl( + json['message'] as String?, + json['runtimeType'] as String?, + ); + +Map _$$ErrorDetailsImplToJson(_$ErrorDetailsImpl instance) => + { + 'message': instance.message, + 'runtimeType': instance.$type, + }; + +_$ComplexImpl _$$ComplexImplFromJson(Map json) => + _$ComplexImpl( + (json['a'] as num).toInt(), + json['b'] as String, + $type: json['runtimeType'] as String?, + ); + +Map _$$ComplexImplToJson(_$ComplexImpl instance) => + { + 'a': instance.a, + 'b': instance.b, + 'runtimeType': instance.$type, + }; diff --git a/pkgs/_augmentation_examples/lib/freezed_with_augs.a.dart b/pkgs/_augmentation_examples/lib/freezed_with_augs.a.dart new file mode 100644 index 0000000..44829d2 --- /dev/null +++ b/pkgs/_augmentation_examples/lib/freezed_with_augs.a.dart @@ -0,0 +1,1182 @@ +// Generated code modified by hand to use augmenations. + +part of 'freezed_with_augs.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +/// @nodoc +augment class MyClass { + final String? a; + final int? b; + + augment MyClass({String? a, int? b}) : a = a, b = b; + + @override + String toString() { + return 'MyClass(a: $a, b: $b)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is MyClass && + (identical(other.a, a) || other.a == a) && + (identical(other.b, b) || other.b == b)); + } + + @override + int get hashCode => Object.hash(runtimeType, a, b); + + /// Create a copy of MyClass + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + _$$MyClassImplCopyWith get copyWith => + __$$MyClassImplCopyWithImpl(this, _$identity); +} + +/// @nodoc +abstract class $MyClassCopyWith<$Res> { + factory $MyClassCopyWith(MyClass value, $Res Function(MyClass) then) = + _$MyClassCopyWithImpl<$Res, MyClass>; + @useResult + $Res call({String? a, int? b}); +} + +/// @nodoc +class _$MyClassCopyWithImpl<$Res, $Val extends MyClass> + implements $MyClassCopyWith<$Res> { + _$MyClassCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MyClass + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? a = freezed, Object? b = freezed}) { + return _then( + _value.copyWith( + a: + freezed == a + ? _value.a + : a // ignore: cast_nullable_to_non_nullable + as String?, + b: + freezed == b + ? _value.b + : b // ignore: cast_nullable_to_non_nullable + as int?, + ) + as $Val, + ); + } +} + +/// @nodoc +abstract class _$$MyClassImplCopyWith<$Res> implements $MyClassCopyWith<$Res> { + factory _$$MyClassImplCopyWith( + MyClass value, + $Res Function(MyClass) then, + ) = __$$MyClassImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String? a, int? b}); +} + +/// @nodoc +class __$$MyClassImplCopyWithImpl<$Res> + extends _$MyClassCopyWithImpl<$Res, MyClass> + implements _$$MyClassImplCopyWith<$Res> { + __$$MyClassImplCopyWithImpl( + MyClass _value, + $Res Function(MyClass) _then, + ) : super(_value, _then); + + /// Create a copy of MyClass + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? a = freezed, Object? b = freezed}) { + return _then( + MyClass( + a: + freezed == a + ? _value.a + : a // ignore: cast_nullable_to_non_nullable + as String?, + b: + freezed == b + ? _value.b + : b // ignore: cast_nullable_to_non_nullable + as int?, + ), + ); + } +} + +Union _$UnionFromJson(Map json) { + switch (json['runtimeType']) { + case 'default': + return Data.fromJson(json); + case 'loading': + return Loading.fromJson(json); + case 'error': + return ErrorDetails.fromJson(json); + case 'complex': + return Complex.fromJson(json); + + default: + throw CheckedFromJsonException( + json, + 'runtimeType', + 'Union', + 'Invalid union type "${json['runtimeType']}"!', + ); + } +} + +/// @nodoc +augment class Union { + @optionalTypeArgs + TResult when( + TResult Function(int value) $default, { + required TResult Function() loading, + required TResult Function(String? message) error, + required TResult Function(int a, String b) complex, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(int value)? $default, { + TResult? Function()? loading, + TResult? Function(String? message)? error, + TResult? Function(int a, String b)? complex, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen( + TResult Function(int value)? $default, { + TResult Function()? loading, + TResult Function(String? message)? error, + TResult Function(int a, String b)? complex, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map( + TResult Function(Data value) $default, { + required TResult Function(Loading value) loading, + required TResult Function(ErrorDetails value) error, + required TResult Function(Complex value) complex, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(Data value)? $default, { + TResult? Function(Loading value)? loading, + TResult? Function(ErrorDetails value)? error, + TResult? Function(Complex value)? complex, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap( + TResult Function(Data value)? $default, { + TResult Function(Loading value)? loading, + TResult Function(ErrorDetails value)? error, + TResult Function(Complex value)? complex, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + /// Serializes this Union to a JSON map. + Map toJson() => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $UnionCopyWith<$Res> { + factory $UnionCopyWith(Union value, $Res Function(Union) then) = + _$UnionCopyWithImpl<$Res, Union>; +} + +/// @nodoc +class _$UnionCopyWithImpl<$Res, $Val extends Union> + implements $UnionCopyWith<$Res> { + _$UnionCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc +abstract class _$$DataImplCopyWith<$Res> { + factory _$$DataImplCopyWith( + Data value, + $Res Function(Data) then, + ) = __$$DataImplCopyWithImpl<$Res>; + @useResult + $Res call({int value}); +} + +/// @nodoc +class __$$DataImplCopyWithImpl<$Res> + extends _$UnionCopyWithImpl<$Res, Data> + implements _$$DataImplCopyWith<$Res> { + __$$DataImplCopyWithImpl(Data _value, $Res Function(Data) _then) + : super(_value, _then); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? value = null}) { + return _then( + Data( + null == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as int, + ), + ); + } +} + +/// @nodoc +@JsonSerializable() +class Data implements Union { + const Data(this.value, {final String? $type}) + : $type = $type ?? 'default'; + + factory Data.fromJson(Map json) => + _$$DataImplFromJson(json); + + final int value; + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'Union(value: $value)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is Data && + (identical(other.value, value) || other.value == value)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, value); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + _$$DataImplCopyWith get copyWith => + __$$DataImplCopyWithImpl(this, _$identity); + + @optionalTypeArgs + TResult when( + TResult Function(int value) $default, { + required TResult Function() loading, + required TResult Function(String? message) error, + required TResult Function(int a, String b) complex, + }) { + return $default(value); + } + + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(int value)? $default, { + TResult? Function()? loading, + TResult? Function(String? message)? error, + TResult? Function(int a, String b)? complex, + }) { + return $default?.call(value); + } + + @optionalTypeArgs + TResult maybeWhen( + TResult Function(int value)? $default, { + TResult Function()? loading, + TResult Function(String? message)? error, + TResult Function(int a, String b)? complex, + required TResult orElse(), + }) { + if ($default != null) { + return $default(value); + } + return orElse(); + } + + @optionalTypeArgs + TResult map( + TResult Function(Data value) $default, { + required TResult Function(Loading value) loading, + required TResult Function(ErrorDetails value) error, + required TResult Function(Complex value) complex, + }) { + return $default(this); + } + + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(Data value)? $default, { + TResult? Function(Loading value)? loading, + TResult? Function(ErrorDetails value)? error, + TResult? Function(Complex value)? complex, + }) { + return $default?.call(this); + } + + @optionalTypeArgs + TResult maybeMap( + TResult Function(Data value)? $default, { + TResult Function(Loading value)? loading, + TResult Function(ErrorDetails value)? error, + TResult Function(Complex value)? complex, + required TResult orElse(), + }) { + if ($default != null) { + return $default(this); + } + return orElse(); + } + + Map toJson() { + return _$$DataImplToJson(this); + } +} + +/// @nodoc +abstract class _$$LoadingImplCopyWith<$Res> { + factory _$$LoadingImplCopyWith( + Loading value, + $Res Function(Loading) then, + ) = __$$LoadingImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$LoadingImplCopyWithImpl<$Res> + extends _$UnionCopyWithImpl<$Res, Loading> + implements _$$LoadingImplCopyWith<$Res> { + __$$LoadingImplCopyWithImpl( + Loading _value, + $Res Function(Loading) _then, + ) : super(_value, _then); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc +@JsonSerializable() +class Loading implements Union { + const Loading({final String? $type}) : $type = $type ?? 'loading'; + + factory Loading.fromJson(Map json) => + _$$LoadingImplFromJson(json); + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'Union.loading()'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is Loading); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when( + TResult Function(int value) $default, { + required TResult Function() loading, + required TResult Function(String? message) error, + required TResult Function(int a, String b) complex, + }) { + return loading(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(int value)? $default, { + TResult? Function()? loading, + TResult? Function(String? message)? error, + TResult? Function(int a, String b)? complex, + }) { + return loading?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen( + TResult Function(int value)? $default, { + TResult Function()? loading, + TResult Function(String? message)? error, + TResult Function(int a, String b)? complex, + required TResult orElse(), + }) { + if (loading != null) { + return loading(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map( + TResult Function(Data value) $default, { + required TResult Function(Loading value) loading, + required TResult Function(ErrorDetails value) error, + required TResult Function(Complex value) complex, + }) { + return loading(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(Data value)? $default, { + TResult? Function(Loading value)? loading, + TResult? Function(ErrorDetails value)? error, + TResult? Function(Complex value)? complex, + }) { + return loading?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap( + TResult Function(Data value)? $default, { + TResult Function(Loading value)? loading, + TResult Function(ErrorDetails value)? error, + TResult Function(Complex value)? complex, + required TResult orElse(), + }) { + if (loading != null) { + return loading(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$LoadingImplToJson(this); + } +} + +/// @nodoc +abstract class _$$ErrorDetailsImplCopyWith<$Res> { + factory _$$ErrorDetailsImplCopyWith( + ErrorDetails value, + $Res Function(ErrorDetails) then, + ) = __$$ErrorDetailsImplCopyWithImpl<$Res>; + @useResult + $Res call({String? message}); +} + +/// @nodoc +class __$$ErrorDetailsImplCopyWithImpl<$Res> + extends _$UnionCopyWithImpl<$Res, ErrorDetails> + implements _$$ErrorDetailsImplCopyWith<$Res> { + __$$ErrorDetailsImplCopyWithImpl( + ErrorDetails _value, + $Res Function(ErrorDetails) _then, + ) : super(_value, _then); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? message = freezed}) { + return _then( + ErrorDetails( + freezed == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable + as String?, + ), + ); + } +} + +/// @nodoc +@JsonSerializable() +class ErrorDetails implements Union { + const ErrorDetails([this.message, final String? $type]) + : $type = $type ?? 'error'; + + factory ErrorDetails.fromJson(Map json) => + _$$ErrorDetailsImplFromJson(json); + + final String? message; + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'Union.error(message: $message)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is ErrorDetails && + (identical(other.message, message) || other.message == message)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, message); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + _$$ErrorDetailsImplCopyWith get copyWith => + __$$ErrorDetailsImplCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when( + TResult Function(int value) $default, { + required TResult Function() loading, + required TResult Function(String? message) error, + required TResult Function(int a, String b) complex, + }) { + return error(message); + } + + @override + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(int value)? $default, { + TResult? Function()? loading, + TResult? Function(String? message)? error, + TResult? Function(int a, String b)? complex, + }) { + return error?.call(message); + } + + @override + @optionalTypeArgs + TResult maybeWhen( + TResult Function(int value)? $default, { + TResult Function()? loading, + TResult Function(String? message)? error, + TResult Function(int a, String b)? complex, + required TResult orElse(), + }) { + if (error != null) { + return error(message); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map( + TResult Function(Data value) $default, { + required TResult Function(Loading value) loading, + required TResult Function(ErrorDetails value) error, + required TResult Function(Complex value) complex, + }) { + return error(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(Data value)? $default, { + TResult? Function(Loading value)? loading, + TResult? Function(ErrorDetails value)? error, + TResult? Function(Complex value)? complex, + }) { + return error?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap( + TResult Function(Data value)? $default, { + TResult Function(Loading value)? loading, + TResult Function(ErrorDetails value)? error, + TResult Function(Complex value)? complex, + required TResult orElse(), + }) { + if (error != null) { + return error(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$ErrorDetailsImplToJson(this); + } +} + +/// @nodoc +abstract class _$$ComplexImplCopyWith<$Res> { + factory _$$ComplexImplCopyWith( + Complex value, + $Res Function(Complex) then, + ) = __$$ComplexImplCopyWithImpl<$Res>; + @useResult + $Res call({int a, String b}); +} + +/// @nodoc +class __$$ComplexImplCopyWithImpl<$Res> + extends _$UnionCopyWithImpl<$Res, Complex> + implements _$$ComplexImplCopyWith<$Res> { + __$$ComplexImplCopyWithImpl( + Complex _value, + $Res Function(Complex) _then, + ) : super(_value, _then); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? a = null, Object? b = null}) { + return _then( + Complex( + null == a + ? _value.a + : a // ignore: cast_nullable_to_non_nullable + as int, + null == b + ? _value.b + : b // ignore: cast_nullable_to_non_nullable + as String, + ), + ); + } +} + +/// @nodoc +@JsonSerializable() +class Complex implements Union { + const Complex(this.a, this.b, {final String? $type}) + : $type = $type ?? 'complex'; + + factory Complex.fromJson(Map json) => + _$$ComplexImplFromJson(json); + + final int a; + final String b; + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'Union.complex(a: $a, b: $b)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is Complex && + (identical(other.a, a) || other.a == a) && + (identical(other.b, b) || other.b == b)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, a, b); + + /// Create a copy of Union + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + _$$ComplexImplCopyWith get copyWith => + __$$ComplexImplCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when( + TResult Function(int value) $default, { + required TResult Function() loading, + required TResult Function(String? message) error, + required TResult Function(int a, String b) complex, + }) { + return complex(a, b); + } + + @override + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(int value)? $default, { + TResult? Function()? loading, + TResult? Function(String? message)? error, + TResult? Function(int a, String b)? complex, + }) { + return complex?.call(a, b); + } + + @override + @optionalTypeArgs + TResult maybeWhen( + TResult Function(int value)? $default, { + TResult Function()? loading, + TResult Function(String? message)? error, + TResult Function(int a, String b)? complex, + required TResult orElse(), + }) { + if (complex != null) { + return complex(a, b); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map( + TResult Function(Data value) $default, { + required TResult Function(Loading value) loading, + required TResult Function(ErrorDetails value) error, + required TResult Function(Complex value) complex, + }) { + return complex(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(Data value)? $default, { + TResult? Function(Loading value)? loading, + TResult? Function(ErrorDetails value)? error, + TResult? Function(Complex value)? complex, + }) { + return complex?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap( + TResult Function(Data value)? $default, { + TResult Function(Loading value)? loading, + TResult Function(ErrorDetails value)? error, + TResult Function(Complex value)? complex, + required TResult orElse(), + }) { + if (complex != null) { + return complex(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$ComplexImplToJson(this); + } +} + +/// @nodoc +augment class SharedProperty { + String? get name => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult when({ + required TResult Function(String? name, int? age) person, + required TResult Function(String? name, int? population) city, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String? name, int? age)? person, + TResult? Function(String? name, int? population)? city, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String? name, int? age)? person, + TResult Function(String? name, int? population)? city, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(SharedProperty0 value) person, + required TResult Function(SharedProperty1 value) city, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(SharedProperty0 value)? person, + TResult? Function(SharedProperty1 value)? city, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(SharedProperty0 value)? person, + TResult Function(SharedProperty1 value)? city, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $SharedPropertyCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SharedPropertyCopyWith<$Res> { + factory $SharedPropertyCopyWith( + SharedProperty value, + $Res Function(SharedProperty) then, + ) = _$SharedPropertyCopyWithImpl<$Res, SharedProperty>; + @useResult + $Res call({String? name}); +} + +/// @nodoc +class _$SharedPropertyCopyWithImpl<$Res, $Val extends SharedProperty> + implements $SharedPropertyCopyWith<$Res> { + _$SharedPropertyCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? name = freezed}) { + return _then( + _value.copyWith( + name: + freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + ) + as $Val, + ); + } +} + +/// @nodoc +abstract class _$$SharedProperty0ImplCopyWith<$Res> + implements $SharedPropertyCopyWith<$Res> { + factory _$$SharedProperty0ImplCopyWith( + SharedProperty0 value, + $Res Function(SharedProperty0) then, + ) = __$$SharedProperty0ImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String? name, int? age}); +} + +/// @nodoc +class __$$SharedProperty0ImplCopyWithImpl<$Res> + extends _$SharedPropertyCopyWithImpl<$Res, SharedProperty0> + implements _$$SharedProperty0ImplCopyWith<$Res> { + __$$SharedProperty0ImplCopyWithImpl( + SharedProperty0 _value, + $Res Function(SharedProperty0) _then, + ) : super(_value, _then); + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? name = freezed, Object? age = freezed}) { + return _then( + SharedProperty0( + name: + freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + age: + freezed == age + ? _value.age + : age // ignore: cast_nullable_to_non_nullable + as int?, + ), + ); + } +} + +/// @nodoc + +class SharedProperty0 implements SharedProperty { + SharedProperty0({this.name, this.age}); + + @override + final String? name; + final int? age; + + @override + String toString() { + return 'SharedProperty.person(name: $name, age: $age)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is SharedProperty0 && + (identical(other.name, name) || other.name == name) && + (identical(other.age, age) || other.age == age)); + } + + @override + int get hashCode => Object.hash(runtimeType, name, age); + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$SharedProperty0ImplCopyWith get copyWith => + __$$SharedProperty0ImplCopyWithImpl( + this, + _$identity, + ); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String? name, int? age) person, + required TResult Function(String? name, int? population) city, + }) { + return person(name, age); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String? name, int? age)? person, + TResult? Function(String? name, int? population)? city, + }) { + return person?.call(name, age); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String? name, int? age)? person, + TResult Function(String? name, int? population)? city, + required TResult orElse(), + }) { + if (person != null) { + return person(name, age); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(SharedProperty0 value) person, + required TResult Function(SharedProperty1 value) city, + }) { + return person(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(SharedProperty0 value)? person, + TResult? Function(SharedProperty1 value)? city, + }) { + return person?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(SharedProperty0 value)? person, + TResult Function(SharedProperty1 value)? city, + required TResult orElse(), + }) { + if (person != null) { + return person(this); + } + return orElse(); + } +} + +/// @nodoc +abstract class _$$SharedProperty1ImplCopyWith<$Res> + implements $SharedPropertyCopyWith<$Res> { + factory _$$SharedProperty1ImplCopyWith( + SharedProperty1 value, + $Res Function(SharedProperty1) then, + ) = __$$SharedProperty1ImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String? name, int? population}); +} + +/// @nodoc +class __$$SharedProperty1ImplCopyWithImpl<$Res> + extends _$SharedPropertyCopyWithImpl<$Res, SharedProperty1> + implements _$$SharedProperty1ImplCopyWith<$Res> { + __$$SharedProperty1ImplCopyWithImpl( + SharedProperty1 _value, + $Res Function(SharedProperty1) _then, + ) : super(_value, _then); + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? name = freezed, Object? population = freezed}) { + return _then( + SharedProperty1( + name: + freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + population: + freezed == population + ? _value.population + : population // ignore: cast_nullable_to_non_nullable + as int?, + ), + ); + } +} + +/// @nodoc + +class SharedProperty1 implements SharedProperty { + SharedProperty1({this.name, this.population}); + + @override + final String? name; + final int? population; + + @override + String toString() { + return 'SharedProperty.city(name: $name, population: $population)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is SharedProperty1 && + (identical(other.name, name) || other.name == name) && + (identical(other.population, population) || + other.population == population)); + } + + @override + int get hashCode => Object.hash(runtimeType, name, population); + + /// Create a copy of SharedProperty + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$SharedProperty1ImplCopyWith get copyWith => + __$$SharedProperty1ImplCopyWithImpl( + this, + _$identity, + ); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String? name, int? age) person, + required TResult Function(String? name, int? population) city, + }) { + return city(name, population); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String? name, int? age)? person, + TResult? Function(String? name, int? population)? city, + }) { + return city?.call(name, population); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String? name, int? age)? person, + TResult Function(String? name, int? population)? city, + required TResult orElse(), + }) { + if (city != null) { + return city(name, population); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(SharedProperty0 value) person, + required TResult Function(SharedProperty1 value) city, + }) { + return city(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(SharedProperty0 value)? person, + TResult? Function(SharedProperty1 value)? city, + }) { + return city?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(SharedProperty0 value)? person, + TResult Function(SharedProperty1 value)? city, + required TResult orElse(), + }) { + if (city != null) { + return city(this); + } + return orElse(); + } +} diff --git a/pkgs/_augmentation_examples/lib/freezed_with_augs.ag.dart b/pkgs/_augmentation_examples/lib/freezed_with_augs.ag.dart new file mode 100644 index 0000000..1c91b6e --- /dev/null +++ b/pkgs/_augmentation_examples/lib/freezed_with_augs.ag.dart @@ -0,0 +1,43 @@ +// Generated code modified by hand to use augmenations. + +part of 'freezed_with_augs.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Data _$$DataImplFromJson(Map json) => + Data((json['value'] as num).toInt(), $type: json['runtimeType'] as String?); + +Map _$$DataImplToJson(Data instance) => { + 'value': instance.value, + 'runtimeType': instance.$type, +}; + +Loading _$$LoadingImplFromJson(Map json) => + Loading($type: json['runtimeType'] as String?); + +Map _$$LoadingImplToJson(Loading instance) => + {'runtimeType': instance.$type}; + +ErrorDetails _$$ErrorDetailsImplFromJson(Map json) => + ErrorDetails(json['message'] as String?, json['runtimeType'] as String?); + +Map _$$ErrorDetailsImplToJson(ErrorDetails instance) => + { + 'message': instance.message, + 'runtimeType': instance.$type, + }; + +Complex _$$ComplexImplFromJson(Map json) => Complex( + (json['a'] as num).toInt(), + json['b'] as String, + $type: json['runtimeType'] as String?, +); + +Map _$$ComplexImplToJson(Complex instance) => + { + 'a': instance.a, + 'b': instance.b, + 'runtimeType': instance.$type, + }; diff --git a/pkgs/_augmentation_examples/lib/freezed_with_augs.dart b/pkgs/_augmentation_examples/lib/freezed_with_augs.dart new file mode 100644 index 0000000..dfbdc91 --- /dev/null +++ b/pkgs/_augmentation_examples/lib/freezed_with_augs.dart @@ -0,0 +1,31 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'freezed_with_augs.a.dart'; +part 'freezed_with_augs.ag.dart'; + +// @freezed +class MyClass { + MyClass({String? a, int? b}); +} + +// @freezed +class Union { + const factory Union(int value) = Data; + const factory Union.loading() = Loading; + const factory Union.error([String? message]) = ErrorDetails; + const factory Union.complex(int a, String b) = Complex; + + factory Union.fromJson(Map json) => _$UnionFromJson(json); +} + +// @freezed +class SharedProperty { + factory SharedProperty.person({String? name, int? age}) = SharedProperty0; + + factory SharedProperty.city({String? name, int? population}) = + SharedProperty1; +} diff --git a/pkgs/_augmentation_examples/lib/json_serializable.dart b/pkgs/_augmentation_examples/lib/json_serializable.dart new file mode 100644 index 0000000..8c7a12c --- /dev/null +++ b/pkgs/_augmentation_examples/lib/json_serializable.dart @@ -0,0 +1,88 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:json_annotation/json_annotation.dart'; + +part 'json_serializable.g.dart'; + +@JsonSerializable() +class Person { + final String firstName; + @JsonKey(includeIfNull: false) + final String? middleName; + final String lastName; + + @JsonKey(name: 'date-of-birth') + final DateTime dateOfBirth; + + @JsonKey(name: 'last-order') + final DateTime? lastOrder; + + List orders; + + Person( + this.firstName, + this.lastName, + this.dateOfBirth, { + this.middleName, + this.lastOrder, + List? orders, + }) : orders = orders ?? []; + + factory Person.fromJson(Map json) => _$PersonFromJson(json); + + Map toJson() => _$PersonToJson(this); +} + +@JsonSerializable(includeIfNull: false) +class Order { + int? count; + int? itemNumber; + bool? isRushed; + Item? item; + + @JsonKey( + name: 'prep-time', + fromJson: _durationFromMilliseconds, + toJson: _durationToMilliseconds, + ) + Duration? prepTime; + + @JsonKey(fromJson: _dateTimeFromEpochUs, toJson: _dateTimeToEpochUs) + final DateTime date; + + Order(this.date); + + factory Order.fromJson(Map json) => _$OrderFromJson(json); + + Map toJson() => _$OrderToJson(this); + + static Duration? _durationFromMilliseconds(int? milliseconds) => + milliseconds == null ? null : Duration(milliseconds: milliseconds); + + static int? _durationToMilliseconds(Duration? duration) => + duration?.inMilliseconds; + + static DateTime _dateTimeFromEpochUs(int us) => + DateTime.fromMicrosecondsSinceEpoch(us); + + static int? _dateTimeToEpochUs(DateTime? dateTime) => + dateTime?.microsecondsSinceEpoch; +} + +@JsonSerializable() +class Item { + int? count; + int? itemNumber; + bool? isRushed; + + Item(); + + factory Item.fromJson(Map json) => _$ItemFromJson(json); + + Map toJson() => _$ItemToJson(this); +} + +@JsonLiteral('data.json') +Map get glossaryData => _$glossaryDataJsonLiteral; diff --git a/pkgs/_augmentation_examples/lib/json_serializable.g.dart b/pkgs/_augmentation_examples/lib/json_serializable.g.dart new file mode 100644 index 0000000..adf8443 --- /dev/null +++ b/pkgs/_augmentation_examples/lib/json_serializable.g.dart @@ -0,0 +1,90 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'json_serializable.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Person _$PersonFromJson(Map json) => Person( + json['firstName'] as String, + json['lastName'] as String, + DateTime.parse(json['date-of-birth'] as String), + middleName: json['middleName'] as String?, + lastOrder: json['last-order'] == null + ? null + : DateTime.parse(json['last-order'] as String), + orders: (json['orders'] as List?) + ?.map((e) => Order.fromJson(e as Map)) + .toList(), + ); + +Map _$PersonToJson(Person instance) => { + 'firstName': instance.firstName, + if (instance.middleName case final value?) 'middleName': value, + 'lastName': instance.lastName, + 'date-of-birth': instance.dateOfBirth.toIso8601String(), + 'last-order': instance.lastOrder?.toIso8601String(), + 'orders': instance.orders, + }; + +Order _$OrderFromJson(Map json) => Order( + Order._dateTimeFromEpochUs((json['date'] as num).toInt()), + ) + ..count = (json['count'] as num?)?.toInt() + ..itemNumber = (json['itemNumber'] as num?)?.toInt() + ..isRushed = json['isRushed'] as bool? + ..item = json['item'] == null + ? null + : Item.fromJson(json['item'] as Map) + ..prepTime = + Order._durationFromMilliseconds((json['prep-time'] as num?)?.toInt()); + +Map _$OrderToJson(Order instance) => { + if (instance.count case final value?) 'count': value, + if (instance.itemNumber case final value?) 'itemNumber': value, + if (instance.isRushed case final value?) 'isRushed': value, + if (instance.item case final value?) 'item': value, + if (Order._durationToMilliseconds(instance.prepTime) case final value?) + 'prep-time': value, + if (Order._dateTimeToEpochUs(instance.date) case final value?) + 'date': value, + }; + +Item _$ItemFromJson(Map json) => Item() + ..count = (json['count'] as num?)?.toInt() + ..itemNumber = (json['itemNumber'] as num?)?.toInt() + ..isRushed = json['isRushed'] as bool?; + +Map _$ItemToJson(Item instance) => { + 'count': instance.count, + 'itemNumber': instance.itemNumber, + 'isRushed': instance.isRushed, + }; + +// ************************************************************************** +// JsonLiteralGenerator +// ************************************************************************** + +final _$glossaryDataJsonLiteral = { + 'glossary': { + 'title': 'example glossary', + 'GlossDiv': { + 'title': 'S', + 'GlossList': { + 'GlossEntry': { + 'ID': 'SGML', + 'SortAs': 'SGML', + 'GlossTerm': 'Standard Generalized Markup Language', + 'Acronym': 'SGML', + 'Abbrev': 'ISO 8879:1986', + 'GlossDef': { + 'para': 'A meta-markup language, used to create markup languages.', + 'GlossSeeAlso': ['GML', 'XML'] + }, + 'GlossSee': 'markup' + } + } + } + } +}; diff --git a/pkgs/_augmentation_examples/lib/json_serializable_with_augs.a.dart b/pkgs/_augmentation_examples/lib/json_serializable_with_augs.a.dart new file mode 100644 index 0000000..5ade3dc --- /dev/null +++ b/pkgs/_augmentation_examples/lib/json_serializable_with_augs.a.dart @@ -0,0 +1,103 @@ +// Generated code modified by hand to use augmenations. + +part of 'json_serializable_with_augs.dart'; + +augment class Person { + factory Person.fromJson(Map json) => _$PersonFromJson(json); + + Map toJson() => _$PersonToJson(this); +} + +Person _$PersonFromJson(Map json) => Person( + json['firstName'] as String, + json['lastName'] as String, + DateTime.parse(json['date-of-birth'] as String), + middleName: json['middleName'] as String?, + lastOrder: + json['last-order'] == null + ? null + : DateTime.parse(json['last-order'] as String), + orders: + (json['orders'] as List?) + ?.map((e) => Order.fromJson(e as Map)) + .toList(), +); + +Map _$PersonToJson(Person instance) => { + 'firstName': instance.firstName, + if (instance.middleName case final value?) 'middleName': value, + 'lastName': instance.lastName, + 'date-of-birth': instance.dateOfBirth.toIso8601String(), + 'last-order': instance.lastOrder?.toIso8601String(), + 'orders': instance.orders, +}; + +augment class Order { + factory Order.fromJson(Map json) => _$OrderFromJson(json); + + Map toJson() => _$OrderToJson(this); +} + +Order _$OrderFromJson(Map json) => + Order(Order._dateTimeFromEpochUs((json['date'] as num).toInt())) + ..count = (json['count'] as num?)?.toInt() + ..itemNumber = (json['itemNumber'] as num?)?.toInt() + ..isRushed = json['isRushed'] as bool? + ..item = + json['item'] == null + ? null + : Item.fromJson(json['item'] as Map) + ..prepTime = Order._durationFromMilliseconds( + (json['prep-time'] as num?)?.toInt(), + ); + +Map _$OrderToJson(Order instance) => { + if (instance.count case final value?) 'count': value, + if (instance.itemNumber case final value?) 'itemNumber': value, + if (instance.isRushed case final value?) 'isRushed': value, + if (instance.item case final value?) 'item': value, + if (Order._durationToMilliseconds(instance.prepTime) case final value?) + 'prep-time': value, + if (Order._dateTimeToEpochUs(instance.date) case final value?) 'date': value, +}; + +augment class Item { + factory Item.fromJson(Map json) => _$ItemFromJson(json); + + Map toJson() => _$ItemToJson(this); +} + +Item _$ItemFromJson(Map json) => + Item() + ..count = (json['count'] as num?)?.toInt() + ..itemNumber = (json['itemNumber'] as num?)?.toInt() + ..isRushed = json['isRushed'] as bool?; + +Map _$ItemToJson(Item instance) => { + 'count': instance.count, + 'itemNumber': instance.itemNumber, + 'isRushed': instance.isRushed, +}; + +final _$glossaryDataJsonLiteral = { + 'glossary': { + 'title': 'example glossary', + 'GlossDiv': { + 'title': 'S', + 'GlossList': { + 'GlossEntry': { + 'ID': 'SGML', + 'SortAs': 'SGML', + 'GlossTerm': 'Standard Generalized Markup Language', + 'Acronym': 'SGML', + 'Abbrev': 'ISO 8879:1986', + 'GlossDef': { + 'para': 'A meta-markup language, used to create markup languages.', + 'GlossSeeAlso': ['GML', 'XML'], + }, + 'GlossSee': 'markup', + }, + }, + }, + }, +}; diff --git a/pkgs/_augmentation_examples/lib/json_serializable_with_augs.dart b/pkgs/_augmentation_examples/lib/json_serializable_with_augs.dart new file mode 100644 index 0000000..7c9888b --- /dev/null +++ b/pkgs/_augmentation_examples/lib/json_serializable_with_augs.dart @@ -0,0 +1,76 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:json_annotation/json_annotation.dart'; + +part 'json_serializable_with_augs.g.dart'; + +// @JsonSerializable() +class Person { + final String firstName; + @JsonKey(includeIfNull: false) + final String? middleName; + final String lastName; + + @JsonKey(name: 'date-of-birth') + final DateTime dateOfBirth; + + @JsonKey(name: 'last-order') + final DateTime? lastOrder; + + List orders; + + Person( + this.firstName, + this.lastName, + this.dateOfBirth, { + this.middleName, + this.lastOrder, + List? orders, + }) : orders = orders ?? []; +} + +// @JsonSerializable(includeIfNull: false) +class Order { + int? count; + int? itemNumber; + bool? isRushed; + Item? item; + + @JsonKey( + name: 'prep-time', + fromJson: _durationFromMilliseconds, + toJson: _durationToMilliseconds, + ) + Duration? prepTime; + + @JsonKey(fromJson: _dateTimeFromEpochUs, toJson: _dateTimeToEpochUs) + final DateTime date; + + Order(this.date); + + static Duration? _durationFromMilliseconds(int? milliseconds) => + milliseconds == null ? null : Duration(milliseconds: milliseconds); + + static int? _durationToMilliseconds(Duration? duration) => + duration?.inMilliseconds; + + static DateTime _dateTimeFromEpochUs(int us) => + DateTime.fromMicrosecondsSinceEpoch(us); + + static int? _dateTimeToEpochUs(DateTime? dateTime) => + dateTime?.microsecondsSinceEpoch; +} + +// @JsonSerializable() +class Item { + int? count; + int? itemNumber; + bool? isRushed; + + Item(); +} + +// @JsonLiteral('data.json') +Map get glossaryData => _$glossaryDataJsonLiteral; diff --git a/pkgs/_augmentation_examples/pubspec.yaml b/pkgs/_augmentation_examples/pubspec.yaml new file mode 100644 index 0000000..5308063 --- /dev/null +++ b/pkgs/_augmentation_examples/pubspec.yaml @@ -0,0 +1,22 @@ +name: _augmentation_examples +publish-to: none +description: Examples of codegen with and without augmentations. +# Can't use because build_runner doesn't support dart_style 3.0.0. +# resolution: workspace + +environment: + sdk: ^3.7.0-157.0.dev + +dependencies: + built_collection: ^5.1.1 + built_value: ^8.9.2 + freezed_annotation: ^2.4.4 + json_annotation: ^4.9.0 + +dev_dependencies: + build_runner: ^2.3.3 + built_value_generator: ^8.0.0 + dart_flutter_team_lints: ^3.0.0 + freezed: ^2.5.7 + json_serializable: ^6.8.0 + test: ^1.25.0