diff --git a/example/test/deleteMe.dart b/example/test/deleteMe.dart new file mode 100644 index 0000000..6dc3792 --- /dev/null +++ b/example/test/deleteMe.dart @@ -0,0 +1,5 @@ +import 'ex21_custom_constructors_test.dart' as A; + +main(){ + A.A_Factory(); +} \ No newline at end of file diff --git a/example/test/ex11_generic_subclass_test.dart b/example/test/ex11_generic_subclass_test.dart index bc4061e..253e209 100644 --- a/example/test/ex11_generic_subclass_test.dart +++ b/example/test/ex11_generic_subclass_test.dart @@ -1,5 +1,5 @@ -import 'package:test/test.dart'; import 'package:morphy_annotation/morphy_annotation.dart'; +import 'package:test/test.dart'; part 'ex11_generic_subclass_test.morphy.dart'; @@ -8,6 +8,7 @@ part 'ex11_generic_subclass_test.morphy.dart'; @morphy abstract class $$A { T1 get x; + T2 get y; const $$A(); @@ -31,13 +32,13 @@ main() { test("1 ba copy with", () { var b = B(x: 1, y: "y", z: "z"); - var ba_copy = b.copyWith_A(x: Opt(2), y: Opt("Y")); + var ba_copy = b.copyWith_A(x: () => 2, y: () => "Y"); expect(ba_copy.toString(), "(B-x:2|y:Y|z:z)"); }); test("2 bb copy with", () { var b = B(x: 1, y: "y", z: "z"); - var bb_copy = b.copyWith_B(x: Opt(2), y: Opt("Y"), z: Opt("Z")); + var bb_copy = b.copyWith_B(x: () => 2, y: () => "Y", z: () => "Z"); expect(bb_copy.toString(), "(B-x:2|y:Y|z:Z)"); }); } diff --git a/example/test/ex13_copywith_test.dart b/example/test/ex13_copywith_test.dart index 1a3b2df..92bc2cd 100644 --- a/example/test/ex13_copywith_test.dart +++ b/example/test/ex13_copywith_test.dart @@ -2,6 +2,7 @@ import 'package:morphy_annotation/morphy_annotation.dart'; import 'package:test/test.dart'; part 'ex13_copywith_test.morphy.dart'; +// part 'ex13_copywith_test.morphy_manual.dart'; // ignore_for_file: UNNECESSARY_CAST @@ -28,28 +29,28 @@ main() { var b = B(a: "A", b: 1); var c = C(a: "A", b: 1, c: true); - var a1 = a.copyWith_A(a: Opt("Aa1")); + var a1 = a.copyWith_A(a: () => "Aa1"); expect(a1.a, "Aa1"); - var b1 = b.copyWith_A(a: Opt("Ab1")); + var b1 = b.copyWith_A(a: () => "Ab1"); expect(b1.a, "Ab1"); expect((b1 as B).b, 1); - var b2 = b.copyWith_B(a: Opt("Ab2"), b: Opt(2)); + var b2 = b.copyWith_B(a: () => "Ab2", b: () => 2); expect(b2.a, "Ab2"); expect(b2.b, 2); - var c1 = c.copyWith_A(a: Opt("Ac1")); + var c1 = c.copyWith_A(a: () => "Ac1"); expect(c1.a, "Ac1"); expect((c1 as C).b, 1); expect((c1).c, true); - var c2 = c.copyWith_B(a: Opt("Ac1"), b: Opt(3)); + var c2 = c.copyWith_B(a: () => "Ac1", b: () => 3); expect(c2.a, "Ac1"); expect(c2.b, 3); expect((c2 as C).c, true); - var c3 = c.copyWith_C(a: Opt("Ac1"), b: Opt(3), c: Opt(false)); + var c3 = c.copyWith_C(a: () => "Ac1", b: () => 3, c: () => false); expect(c3.a, "Ac1"); expect(c3.b, 3); expect(c3.c, false); diff --git a/example/test/ex21_custom_constructors_test.dart b/example/test/ex21_custom_constructors_test.dart index 94689b6..7e35c87 100644 --- a/example/test/ex21_custom_constructors_test.dart +++ b/example/test/ex21_custom_constructors_test.dart @@ -18,11 +18,16 @@ part 'ex21_custom_constructors_test.morphy.dart'; @Morphy(hidePublicConstructor: true) abstract class $A { String get a; + + $A blah(String a) { + return A._(a: a); + } } void main() { test("0 default value", () { var a = A._(a: "my default value"); + expect(a.a, "my default value"); }); diff --git a/example/test/ex29_copywith_subclasses_test.dart b/example/test/ex29_copywith_subclasses_test.dart index 9fa719e..cdec31b 100644 --- a/example/test/ex29_copywith_subclasses_test.dart +++ b/example/test/ex29_copywith_subclasses_test.dart @@ -1,5 +1,5 @@ -import 'package:test/test.dart'; import 'package:morphy_annotation/morphy_annotation.dart'; +import 'package:test/test.dart'; // ignore_for_file: UNNECESSARY_CAST @@ -17,6 +17,7 @@ abstract class $$A { @morphy abstract class $B implements $$A { String get a; + T1 get b; } @@ -24,13 +25,16 @@ abstract class $B implements $$A { @morphy abstract class $C implements $B { String get a; + T1 get b; + bool get c; } @morphy abstract class $D implements $B { String get a; + T1 get b; } @@ -45,49 +49,49 @@ abstract class $Y implements $$X { main() { test("ba", () { A ba = B(b: 5, a: "A"); - A ba_copy = ba.copyWith_A(a: Opt("a")); + A ba_copy = ba.copyWith_A(a: () => "a"); expect(ba_copy.toString(), "(B-a:a|b:5)"); }); test("bb", () { B bb = B(b: 5, a: "A"); - B bb_copy = bb.copyWith_B(a: Opt("a"), b: Opt(6)); + B bb_copy = bb.copyWith_B(a: () => "a", b: () => 6); expect(bb_copy.toString(), "(B-a:a|b:6)"); }); test("ca", () { A ca = C(b: 5, a: "A", c: true); - A ca_copy = ca.copyWith_A(a: Opt("a")); + A ca_copy = ca.copyWith_A(a: () => "a"); expect(ca_copy.toString(), "(C-a:a|b:5|c:true)"); }); test("cb", () { B cb = C(b: 5, a: "A", c: true); - B cb_copy = cb.copyWith_B(a: Opt("a"), b: Opt(6)); + B cb_copy = cb.copyWith_B(a: () => "a", b: () => 6); expect(cb_copy.toString(), "(C-a:a|b:6|c:true)"); }); test("cc", () { C cc = C(b: 5, a: "A", c: true); - var cc_copy = cc.copyWith_C(a: Opt("a"), b: Opt(6), c: Opt(false)); + var cc_copy = cc.copyWith_C(a: () => "a", b: () => 6, c: () => false); expect(cc_copy.toString(), "(C-a:a|b:6|c:false)"); }); test("da", () { D da = D(b: 5, a: "A"); - var da_copy = da.copyWith_A(a: Opt("a")); + var da_copy = da.copyWith_A(a: () => "a"); expect(da_copy.toString(), "(D-a:a|b:5)"); }); test("db", () { D db = D(b: 5, a: "A"); - var db_copy = db.copyWith_B(a: Opt("a"), b: Opt(6)); + var db_copy = db.copyWith_B(a: () => "a", b: () => 6); expect(db_copy.toString(), "(D-a:a|b:6)"); }); test("dd", () { D dd = D(b: 5, a: "A"); - var dd_copy = dd.copyWith_D(a: Opt("a"), b: Opt(6)); + var dd_copy = dd.copyWith_D(a: () => "a", b: () => 6); expect(dd_copy.toString(), "(D-a:a|b:6)"); }); @@ -99,7 +103,7 @@ main() { test("yY", () { Y yy = Y(a: "A"); - var yy_copy = yy.copyWith_Y(a: Opt("a")); + var yy_copy = yy.copyWith_Y(a: () => "a"); expect(yy_copy.toString(), "(Y-a:a)"); }); } diff --git a/example/test/ex31_constant_constructor_test.dart b/example/test/ex31_constant_constructor_test.dart index 109fb55..102d7ea 100644 --- a/example/test/ex31_constant_constructor_test.dart +++ b/example/test/ex31_constant_constructor_test.dart @@ -23,5 +23,10 @@ main() { var a = A.constant(a: 1); expect(a.a, 1); + + //you can't change a constant object but you can copy and then change one + var copya = a.copyWith_A(); + + expect(copya.a, 1); }); } diff --git a/example/test/ex38_cw_vs_copyTo_test.dart b/example/test/ex38_cw_vs_copyTo_test.dart index 3889ab3..cc1a55f 100644 --- a/example/test/ex38_cw_vs_copyTo_test.dart +++ b/example/test/ex38_cw_vs_copyTo_test.dart @@ -35,7 +35,7 @@ main() { expect(b_copy1.toString(), "(SubB-z:z|cs:[(C-m:m)]|x:x)"); //copywith from SubB to SubB (traditional copy with) - var b_copy2 = b.copyWith_SubB(cs: Opt([C(m: "m2")])); + var b_copy2 = b.copyWith_SubB(cs: () => [C(m: "m2")]); expect(b_copy2.toString(), "(SubB-z:z|cs:[(C-m:m2)]|x:x)"); //copy TO from one sibling to another diff --git a/example/test/ex45_copyWithPolymorphic_test.dart b/example/test/ex45_copyWithPolymorphic_test.dart index bd40864..5c164c5 100644 --- a/example/test/ex45_copyWithPolymorphic_test.dart +++ b/example/test/ex45_copyWithPolymorphic_test.dart @@ -36,7 +36,7 @@ main() { //copyWith_Super called on both Super & Sub objects var result = supers.map((e) => // - e.copyWith_Super(id: Opt(e.id + "_"))).toList(); + e.copyWith_Super(id: () => e.id + "_")).toList(); //they both retain their original type expect(result[0] is Sub, false); diff --git a/example/test/ex57_change_to_parent_test.dart b/example/test/ex57_change_to_parent_test.dart new file mode 100644 index 0000000..94c8c8f --- /dev/null +++ b/example/test/ex57_change_to_parent_test.dart @@ -0,0 +1,42 @@ +// ignore_for_file: unnecessary_cast +// ignore_for_file: unused_element + +import 'package:morphy_annotation/morphy_annotation.dart'; +import 'package:test/test.dart'; + +part 'ex57_change_to_parent_test.morphy.dart'; + +main() { + test("1 toJson", () { + var aList = [ + A(id: "1"), + B(id: "2", blah: "sdf"), + C(id: "3", xyz: "my custom"), + ]; + + var result = aList.map((e) => e.changeTo_A()).toList(); + + final expected = [ + A(id: "1"), + A(id: "2"), + A(id: "3"), + ]; + + expect(result, expected); + }); +} + +@Morphy(explicitSubTypes: [$B, $C]) +abstract class $A { + String get id; +} + +@Morphy() +abstract class $B implements $A { + String get blah; +} + +@Morphy() +abstract class $C implements $A { + String get xyz; +} diff --git a/example/test/ex58_copywith_nullable.dart b/example/test/ex58_copywith_nullable.dart new file mode 100644 index 0000000..b60d73b --- /dev/null +++ b/example/test/ex58_copywith_nullable.dart @@ -0,0 +1,46 @@ +import 'package:morphy_annotation/morphy_annotation.dart'; +import 'package:test/test.dart'; + +part 'ex58_copywith_nullable.morphy.dart'; + +//nullable types and copyWith + +@morphy +abstract class $Pet { + String? get type; + + String get name; +} + +main() { + test("1", () { + var a = Pet(type: "cat", name: "bob"); + + var expected = Pet(type: "cat", name: "bob"); + expect(a, expected); + + //set type to null + var a_copy = a.copyWith_Pet(type: () => null); + + var expected2 = Pet(type: null, name: "bob"); + expect(a_copy, expected2); + + //copy just one param + var a_copy3 = a.copyWith_Pet(name: () => "bobby"); + + var expected3 = Pet(type: "cat", name: "bobby"); + expect(a_copy3, expected3); + + //set type to null initially + var a4 = Pet(type: null, name: "bob"); + + var expected4 = Pet(type: null, name: "bob"); + expect(a4, expected4); + + //type not specified + var a5 = Pet(name: "bob"); + + var expected5 = Pet(type: null, name: "bob"); + expect(a5, expected5); + }); +} diff --git a/example/test/ex7_override_properties_test.dart b/example/test/ex7_override_properties_test.dart index 3d7ed53..956a84c 100644 --- a/example/test/ex7_override_properties_test.dart +++ b/example/test/ex7_override_properties_test.dart @@ -38,37 +38,37 @@ main() { test("2 aa copy with", () { var a = A(a: Person("1")); - var a_copy = a.copyWith_A(a: Opt(Person("X"))); + var a_copy = a.copyWith_A(a: () => Person("X")); expect(a_copy.toString(), "(A-a:X)"); }); test("2 ba copy with", () { var b = B(a: Employee("1", "2")); - var ba_copy = b.copyWith_A(a: Opt(Employee("X", "Y"))); + var ba_copy = b.copyWith_A(a: () => Employee("X", "Y")); expect(ba_copy.toString(), "(B-a:X|Y)"); }); test("3 bb copy with", () { var b = B(a: Employee("1", "2")); - var bb_copy = b.copyWith_B(a: Opt(Employee("X", "Y"))); + var bb_copy = b.copyWith_B(a: () => Employee("X", "Y")); expect(bb_copy.toString(), "(B-a:X|Y)"); }); test("4 ca copy with", () { var c = C(a: Manager("1", "2", "3")); - var ca_copy = c.copyWith_A(a: Opt(Manager("X", "Y", "Z"))); + var ca_copy = c.copyWith_A(a: () => Manager("X", "Y", "Z")); expect(ca_copy.toString(), "(C-a:X|Y|Z)"); }); test("5 cb copy with", () { var c = C(a: Manager("1", "2", "3")); - var cb_copy = c.copyWith_B(a: Opt(Manager("X", "Y", "Z"))); + var cb_copy = c.copyWith_B(a: () => Manager("X", "Y", "Z")); expect(cb_copy.toString(), "(C-a:X|Y|Z)"); }); test("6 cc copy with", () { var c = C(a: Manager("1", "2", "3")); - var cc_copy = c.copyWith_C(a: Opt(Manager("X", "Y", "Z"))); + var cc_copy = c.copyWith_C(a: () => Manager("X", "Y", "Z")); expect(cc_copy.toString(), "(C-a:X|Y|Z)"); }); } diff --git a/example/test/readme_test.dart b/example/test/readme_test.dart index 2ac3b84..1a442f4 100644 --- a/example/test/readme_test.dart +++ b/example/test/readme_test.dart @@ -86,7 +86,7 @@ main() { test("3 CopyWith simple", () { var flossy = Pet(name: "Flossy", age: 5); - var plossy = flossy.copyWith_Pet(name: Opt("Plossy")); + var plossy = flossy.copyWith_Pet(name: () => "Plossy"); expect(flossy.age, plossy.age); }); @@ -110,7 +110,7 @@ main() { ]; var petsOlder = pets // - .map((e) => e.copyWith_Pet(age: Opt(e.age + 1))) + .map((e) => e.copyWith_Pet(age: () => e.age + 1)) .toList(); expect(petsOlder[0].age, 5); @@ -151,12 +151,12 @@ main() { expect(frankie is Dog, true); }); - A a_Constructor(String val) { + A A_FactoryFunction(String val) { return A._(val: val, timestamp: DateTime(2023, 11, 25)); } test("11 Custom Constructor", () { - var a = a_Constructor("my value"); + var a = A_FactoryFunction("my value"); expect(a.timestamp, DateTime(2023, 11, 25)); }); diff --git a/morphy/CHANGELOG.md b/morphy/CHANGELOG.md index c94fc93..ec1762d 100644 --- a/morphy/CHANGELOG.md +++ b/morphy/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.1.0 +- Breaking change! copywith / change to, the Opt class has been removed and now we favour the () => syntax for optional parameters + +## 1.0.8 +- change_to added for a subclass to change the type back to a superclass + ## 1.0.7 - morphy_annotation must now be in the dependencies and morphy must be in the dev dependencies, cleaned this up diff --git a/morphy/README.md b/morphy/README.md index ac42c80..0d84f63 100644 --- a/morphy/README.md +++ b/morphy/README.md @@ -9,9 +9,7 @@ We need a way to simplify our Dart classes, keep things cleaner and provide more ### Why Not Freezed or Built Value? Well the main reason; I actually wrote this before Freezed was released. Freezed is really good, established and well used. -However if you prefer more of an inheritance based approach to code gen this might suit your needs. -Build Value is also good but I find Morphy more concise than Built Value. - +However if you want to use both inheritance and composition in your data classes use Morphy. ### Solution: use morphy @@ -34,14 +32,29 @@ To create a new class. } ``` -3. `$Pet` is the class definition name. The generated class, the one you use to create objects, will drop the dollar, ie `Pet` -4. your fields are defined using public getters, ie `String get type` -5. and that's it; you then get loads of functionality and create your objects! +3. run the build_runner +``` + dart run build_runner build +``` + +and that's it! You can then create your objects! ``` var cat = Pet(type: "cat"); ``` +`$Pet` is the class definition name. The generated class, the one you use to create objects, will drop the dollar, ie `Pet`. + +### Rules + +As in the simplest example above, `morphy` class definitions must +1. start with a dollar (the generated class removes the dollar) +2. be made abstract (the generated class is not made abstract, details below on how to make classes abstract) +3. have the @morphy annotation added directly to the class name +4. have the part file added to the top of the file, ie `part 'Pet.morphy.dart';` +5. import the morphy_annotation package, ie `import 'package:morphy_annotation/morphy_annotation.dart';` +6. and all properties must be defined as getters, ie `String get type;` + ## Basic features (comes with every class) ### Equality (and hashCode) @@ -66,14 +79,14 @@ var cat1 = Pet(type: "cat"); ### CopyWith A simple copy with implementation comes with every class. -Just specify the fields you want to copy and the others will be copied over. -New values must be wrapped in an optional `Opt` class. +We pass a function to the copyWith_Pet method that returns a new value to set the property. +You can pass any value you like, including null if the property is nullable. ``` -var flossy = Pet(name: "Flossy", age: 5); -var plossy = flossy.copyWith_Pet(name: Opt("Plossy")); + var flossy = Pet(name: "Flossy", age: 5); + var plossy = flossy.copyWith_Pet(name: () => "Plossy"); -expect(flossy.age, plossy.age); + expect(flossy.age, plossy.age); ``` ### ToString @@ -112,7 +125,7 @@ then the copyWith still works whilst preserving the underlying type. ]; var petsOlder = pets // - .map((e) => e.copyWith_Pet(age: Opt(e.age + 1))) + .map((e) => e.copyWith_Pet(age: () => e.age + 1)) .toList(); expect(petsOlder[0].age, 5); @@ -255,18 +268,25 @@ We also allow multiple inheritance. ### Custom Constructors -To allow custom constructors you can simply create a factory function that creates a new class. -If you'd like to hide the automatic constructor set the `privateConstructor` on the Morphy annotation to true. -If you hide the constructor the custom one should belong in the same file that you defined your class. +To allow custom constructors you can simply create a publicly accessible factory function that calls the constructor (ie just a method that calls the default constructor). +If you'd like to hide the automatic constructor set the `hidePublicConstructor` on the Morphy annotation to true. +If you do hide the default constructor, +then in order for the custom factory function (A_FactoryFunction in the example below) to be able to call the hidden (or private) default constructor, +your factory function should live in the same file you defined your class. + + @Morphy(hidePublicConstructor: true) + abstract class $A { + String get val; + DateTime get timestamp; + } - @Morphy(privateConstructor: true) - A a_Factory(String val){ - return A._(val: val, timestamp: DateTime(2023,11,25)); + A A_FactoryFunction(String val) { + return A._(val: val, timestamp: DateTime(2023, 11, 25)); } - var a = a_Factory("my value"); + var a = A_FactoryFunction("my value"); - expect(a.timestamp, DateTime(2023,11,25)); + expect(a.timestamp, DateTime(2023, 11, 25)); ### Optional Parameters diff --git a/morphy/lib/src/createMorphy.dart b/morphy/lib/src/createMorphy.dart index 05d24ff..1165ffb 100644 --- a/morphy/lib/src/createMorphy.dart +++ b/morphy/lib/src/createMorphy.dart @@ -128,6 +128,20 @@ String createMorphy( sb.writeln(); sb.writeln("extension ${className}_changeTo_E on ${className} {"); + if(!isAbstract){ + sb.writeln( + getCopyWith( + classFields: allFields, + interfaceFields: allFields, + interfaceName: className, + className: className, + isClassAbstract: isAbstract, + interfaceGenerics: classGenerics, + isExplicitSubType: true, + ), + ); + } + interfacesX.where((element) => element.isExplicitSubType).forEach((x) { sb.writeln( getCopyWith( diff --git a/morphy/lib/src/helpers.dart b/morphy/lib/src/helpers.dart index 5ca341f..43b20b1 100644 --- a/morphy/lib/src/helpers.dart +++ b/morphy/lib/src/helpers.dart @@ -292,7 +292,8 @@ String getCopyWith({ sb.write(fieldsForSignature.map((e) { var interfaceType = interfaceFields.firstWhere((element) => element.name == e.name).type; - return "Opt<${getDataTypeWithoutDollars(interfaceType!)}>? ${e.name},\n"; + return "${getDataTypeWithoutDollars(interfaceType!)} Function()? ${e.name},\n"; + // return "Opt<${getDataTypeWithoutDollars(interfaceType!)}>? ${e.name},\n"; }).join()); if (fieldsForSignature.isNotEmpty) // @@ -320,7 +321,7 @@ String getCopyWith({ sb.write(fieldsForSignature // .map((e) { var classType = getDataTypeWithoutDollars(classFields.firstWhere((element) => element.name == e.name).type!); - return "${e.name}: ${e.name} == null ? this.${e.name} as $classType : ${e.name}.value as $classType,\n"; + return "${e.name}: ${e.name} == null ? this.${e.name} as $classType : ${e.name}() as $classType,\n"; }).join()); var fieldsNotInSignature = classFields // diff --git a/morphy/pubspec.yaml b/morphy/pubspec.yaml index 07f7149..1eab478 100644 --- a/morphy/pubspec.yaml +++ b/morphy/pubspec.yaml @@ -1,6 +1,6 @@ name: morphy description: Provides a clean class definition with extra functionality including; copy with, json serializable, tostring, equals that supports inheritance and polymorphism -version: 1.0.7 +version: 1.1.0 homepage: https://github.com/atreeon/morphy environment: @@ -11,7 +11,7 @@ environment: # path: ../morphy_annotation dependencies: - morphy_annotation: ^1.0.7 + morphy_annotation: ^1.1.0 analyzer: '>=6.0.0 <=7.0.0' build: ^2.1.0 source_gen: ^1.1.1 diff --git a/morphy/test/helpers_test.dart b/morphy/test/helpers_test.dart index f59fde3..bec8219 100644 --- a/morphy/test/helpers_test.dart +++ b/morphy/test/helpers_test.dart @@ -509,7 +509,7 @@ a == other.a && b == other.b && c == other.c;"""; interfaceGenerics: [], ); expectS(result, """A copyWith_A({ -Opt? a, +String Function()? a, });"""); }); @@ -528,7 +528,7 @@ Opt? a, interfaceGenerics: [], ); expectS(result, """B copyWith_A({ -Opt? a, +int Function()? a, });"""); }); @@ -546,10 +546,10 @@ Opt? a, interfaceGenerics: [], ); expectS(result, """A copyWith_A({ -Opt? a, +String Function()? a, }) { return A._( -a: a == null ? this.a as String : a.value as String, +a: a == null ? this.a as String : a() as String, ); }"""); }); @@ -569,10 +569,10 @@ a: a == null ? this.a as String : a.value as String, interfaceGenerics: [], ); expectS(result, """B copyWith_A({ -Opt? a, +String Function()? a, }) { return B._( -a: a == null ? this.a as String : a.value as String, +a: a == null ? this.a as String : a() as String, b: (this as B).b, ); }"""); @@ -594,12 +594,12 @@ b: (this as B).b, interfaceGenerics: [], ); expectS(result, """B copyWith_B({ -Opt? a, -Opt? b, +String Function()? a, +T1 Function()? b, }) { return B._( -a: a == null ? this.a as String : a.value as String, -b: b == null ? this.b as T1 : b.value as T1, +a: a == null ? this.a as String : a() as String, +b: b == null ? this.b as T1 : b() as T1, ); }"""); }); @@ -620,10 +620,10 @@ b: b == null ? this.b as T1 : b.value as T1, interfaceGenerics: [], ); expectS(result, """C copyWith_A({ -Opt? a, +String Function()? a, }) { return C._( -a: a == null ? this.a as String : a.value as String, +a: a == null ? this.a as String : a() as String, b: (this as C).b, c: (this as C).c, ); @@ -647,12 +647,12 @@ c: (this as C).c, interfaceGenerics: [], ); expectS(result, """C copyWith_B({ -Opt? a, -Opt? b, +String Function()? a, +T1 Function()? b, }) { return C._( -a: a == null ? this.a as String : a.value as String, -b: b == null ? this.b as T1 : b.value as T1, +a: a == null ? this.a as String : a() as String, +b: b == null ? this.b as T1 : b() as T1, c: (this as C).c, ); }"""); @@ -676,14 +676,14 @@ c: (this as C).c, interfaceGenerics: [], ); expectS(result, """C copyWith_C({ -Opt? a, -Opt? b, -Opt? c, +String Function()? a, +T1 Function()? b, +bool Function()? c, }) { return C._( -a: a == null ? this.a as String : a.value as String, -b: b == null ? this.b as T1 : b.value as T1, -c: c == null ? this.c as bool : c.value as bool, +a: a == null ? this.a as String : a() as String, +b: b == null ? this.b as T1 : b() as T1, +c: c == null ? this.c as bool : c() as bool, ); }"""); }); @@ -703,10 +703,10 @@ c: c == null ? this.c as bool : c.value as bool, interfaceGenerics: [], ); expectS(result, """D copyWith_A({ -Opt? a, +String Function()? a, }) { return D._( -a: a == null ? this.a as String : a.value as String, +a: a == null ? this.a as String : a() as String, b: (this as D).b, ); }"""); @@ -728,12 +728,12 @@ b: (this as D).b, interfaceGenerics: [], ); expectS(result, """D copyWith_B({ -Opt? a, -Opt? b, +String Function()? a, +T1 Function()? b, }) { return D._( -a: a == null ? this.a as String : a.value as String, -b: b == null ? this.b as T1 : b.value as T1, +a: a == null ? this.a as String : a() as String, +b: b == null ? this.b as T1 : b() as T1, ); }"""); }); @@ -754,12 +754,12 @@ b: b == null ? this.b as T1 : b.value as T1, interfaceGenerics: [], ); expectS(result, """D copyWith_D({ -Opt? a, -Opt? b, +String Function()? a, +T1 Function()? b, }) { return D._( -a: a == null ? this.a as String : a.value as String, -b: b == null ? this.b as T1 : b.value as T1, +a: a == null ? this.a as String : a() as String, +b: b == null ? this.b as T1 : b() as T1, ); }"""); }); @@ -810,10 +810,10 @@ a: (this as Y).a, interfaceGenerics: [], ); expectS(result, """Y copyWith_Y({ -Opt? a, +String Function()? a, }) { return Y._( -a: a == null ? this.a as String : a.value as String, +a: a == null ? this.a as String : a() as String, ); }"""); }); @@ -832,10 +832,10 @@ a: a == null ? this.a as String : a.value as String, interfaceGenerics: [], ); expectS(result, """A copyWith_A({ -Opt? a, +Person Function()? a, }) { return A._( -a: a == null ? this.a as Person : a.value as Person, +a: a == null ? this.a as Person : a() as Person, ); }"""); }); @@ -854,10 +854,10 @@ a: a == null ? this.a as Person : a.value as Person, interfaceGenerics: [], ); expectS(result, """B copyWith_A({ -Opt? a, +Person Function()? a, }) { return B._( -a: a == null ? this.a as Employee : a.value as Employee, +a: a == null ? this.a as Employee : a() as Employee, ); }"""); }); @@ -876,10 +876,10 @@ a: a == null ? this.a as Employee : a.value as Employee, interfaceGenerics: [], ); expectS(result, """B copyWith_B({ -Opt? a, +Employee Function()? a, }) { return B._( -a: a == null ? this.a as Employee : a.value as Employee, +a: a == null ? this.a as Employee : a() as Employee, ); }"""); }); @@ -898,10 +898,10 @@ a: a == null ? this.a as Employee : a.value as Employee, interfaceGenerics: [], ); expectS(result, """C copyWith_A({ -Opt? a, +Person Function()? a, }) { return C._( -a: a == null ? this.a as Manager : a.value as Manager, +a: a == null ? this.a as Manager : a() as Manager, ); }"""); }); @@ -920,10 +920,10 @@ a: a == null ? this.a as Manager : a.value as Manager, interfaceGenerics: [], ); expectS(result, """C copyWith_B({ -Opt? a, +Employee Function()? a, }) { return C._( -a: a == null ? this.a as Manager : a.value as Manager, +a: a == null ? this.a as Manager : a() as Manager, ); }"""); }); @@ -942,10 +942,10 @@ a: a == null ? this.a as Manager : a.value as Manager, interfaceGenerics: [], ); expectS(result, """C copyWith_C({ -Opt? a, +Manager Function()? a, }) { return C._( -a: a == null ? this.a as Manager : a.value as Manager, +a: a == null ? this.a as Manager : a() as Manager, ); }"""); }); @@ -967,12 +967,12 @@ a: a == null ? this.a as Manager : a.value as Manager, isClassAbstract: false, ); expectS(result, """B copyWith_A({ -Opt? x, -Opt? y, +T1 Function()? x, +T2 Function()? y, }) { return B._( -x: x == null ? this.x as int : x.value as int, -y: y == null ? this.y as String : y.value as String, +x: x == null ? this.x as int : x() as int, +y: y == null ? this.y as String : y() as String, z: (this as B).z, ); }"""); @@ -996,14 +996,14 @@ z: (this as B).z, isClassAbstract: false, ); expectS(result, """B copyWith_B({ -Opt? x, -Opt? y, -Opt? z, +int Function()? x, +String Function()? y, +String Function()? z, }) { return B._( -x: x == null ? this.x as int : x.value as int, -y: y == null ? this.y as String : y.value as String, -z: z == null ? this.z as String : z.value as String, +x: x == null ? this.x as int : x() as int, +y: y == null ? this.y as String : y() as String, +z: z == null ? this.z as String : z() as String, ); }"""); }); @@ -1022,7 +1022,7 @@ z: z == null ? this.z as String : z.value as String, isClassAbstract: true, ); expectS(result, """A copyWith_A({ -Opt? x, +T Function()? x, });"""); }); @@ -1042,10 +1042,10 @@ Opt? x, isClassAbstract: false, ); expectS(result, """B copyWith_A({ -Opt? x, +T Function()? x, }) { return B._( -x: x == null ? this.x as int : x.value as int, +x: x == null ? this.x as int : x() as int, y: (this as B).y, ); }"""); @@ -1065,10 +1065,10 @@ y: (this as B).y, isClassAbstract: false, ); expectS(result, """A copyWith_A({ -Opt? a, +String Function()? a, }) { return A._( -a: a == null ? this.a as String : a.value as String, +a: a == null ? this.a as String : a() as String, ); }"""); }); @@ -1087,10 +1087,10 @@ a: a == null ? this.a as String : a.value as String, isClassAbstract: false, ); expectS(result, """X copyWith_X({ -Opt? fn, +bool Function(\$X) Function()? fn, }) { return X._( -fn: fn == null ? this.fn as bool Function(\$X) : fn.value as bool Function(\$X), +fn: fn == null ? this.fn as bool Function(\$X) : fn() as bool Function(\$X), ); }"""); }); @@ -1112,11 +1112,11 @@ fn: fn == null ? this.fn as bool Function(\$X) : fn.value as bool Function(\$X), ); expectS(result, """B changeTo_B({ required String y, -Opt? x, +String Function()? x, }) { return B._( y: y as String, -x: x == null ? this.x as String : x.value as String, +x: x == null ? this.x as String : x() as String, ); }"""); }); @@ -1140,12 +1140,12 @@ x: x == null ? this.x as String : x.value as String, expectS(result, """B changeTo_B({ required String y, required Z z, -Opt? x, +String Function()? x, }) { return B._( y: y as String, z: z as Z, -x: x == null ? this.x as String : x.value as String, +x: x == null ? this.x as String : x() as String, ); }"""); }); @@ -1169,12 +1169,12 @@ x: x == null ? this.x as String : x.value as String, expectS(result, """B changeTo_B({ required String y, required Z z, -Opt? x, +String Function()? x, }) { return B._( y: y as String, z: z as Z, -x: x == null ? this.x as String : x.value as String, +x: x == null ? this.x as String : x() as String, ); }"""); }); @@ -1197,14 +1197,14 @@ x: x == null ? this.x as String : x.value as String, isClassAbstract: false, ); expectS(result, """B copyWith_B({ -Opt? x, -Opt>? cs, -Opt? z, +String Function()? x, +List Function()? cs, +Z Function()? z, }) { return B._( -x: x == null ? this.x as String : x.value as String, -cs: cs == null ? this.cs as List : cs.value as List, -z: z == null ? this.z as Z : z.value as Z, +x: x == null ? this.x as String : x() as String, +cs: cs == null ? this.cs as List : cs() as List, +z: z == null ? this.z as Z : z() as Z, ); }"""); }); @@ -1226,11 +1226,11 @@ z: z == null ? this.z as Z : z.value as Z, ); expectS(result, """B changeTo_B({ required String y, -Opt? x, +String Function()? x, }) { return B._( y: y as String, -x: x == null ? this.x as String : x.value as String, +x: x == null ? this.x as String : x() as String, ); }"""); }); @@ -1254,12 +1254,12 @@ x: x == null ? this.x as String : x.value as String, expectS(result, """B changeTo_B({ required String y, required Z z, -Opt? x, +String Function()? x, }) { return B._( y: y as String, z: z as Z, -x: x == null ? this.x as String : x.value as String, +x: x == null ? this.x as String : x() as String, ); }"""); }); diff --git a/morphy_annotation/pubspec.yaml b/morphy_annotation/pubspec.yaml index fb0a219..48693e1 100644 --- a/morphy_annotation/pubspec.yaml +++ b/morphy_annotation/pubspec.yaml @@ -1,6 +1,6 @@ name: morphy_annotation description: annotation for morphy which provides a clean class definition with extra functionality including; copy with, json serializable, tostring, equals that supports inheritance and polymorphism -version: 1.0.7 +version: 1.1.0 homepage: https://github.com/atreeon/morphy environment: diff --git a/release/3_releaseMorphy.sh b/release/3_releaseMorphy.sh index 0272d27..303d58d 100755 --- a/release/3_releaseMorphy.sh +++ b/release/3_releaseMorphy.sh @@ -61,7 +61,7 @@ else exit 0 fi -read -p "Do you want to tag morphy as $versionMorphyLocal? (y/n): " choice +read -p "Do you want to tag morphy as $versionMorphyLocal? (use 'i' to insert, ':' to finish editing, 'wq' to save (y/n): " choice if [ "$choice" = "y" ]; then clear git tag "$versionMorphyLocal" -a