From 98747a00ff696072f95e758761f4db690e9bac52 Mon Sep 17 00:00:00 2001 From: Haim Grosman Date: Thu, 5 Nov 2015 15:24:23 -0800 Subject: [PATCH 1/3] [ObjC] generating: `- (NSDictionary *) toDict;' for Objective C records can also switch the `- (NSString *) description` implementation to just: `return [[self toDict] description]` --- src/source/ObjcGenerator.scala | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/source/ObjcGenerator.scala b/src/source/ObjcGenerator.scala index 4529ae13f..a6c126477 100644 --- a/src/source/ObjcGenerator.scala +++ b/src/source/ObjcGenerator.scala @@ -205,6 +205,8 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { writeInitializer("-", "init") if (!r.ext.objc) writeInitializer("+", IdentStyle.camelLower(objcName)) + w.wl(s""); + w.wl(s"- (nonnull NSDictionary *) toDict;"); for (f <- r.fields) { w.wl @@ -398,6 +400,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { w.w(", ") f.ty.resolved.base match { case MOptional => w.w(s"self.${idObjc.field(f.ident)}") + case t: MPrimitive => w.w(s"@(self.${idObjc.field(f.ident)})") case df: MDef => df.defType match { case DEnum => w.w(s"@(self.${idObjc.field(f.ident)})") @@ -417,6 +420,44 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { } w.wl + w.wl("- (NSDictionary *)toDict") + w.braced { + w.wl("#define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null]))") + w.wl("") + w.w(s"return ").nestedN(2) { + w.w("@{") + w.w("@\"__class_name__\": [self.class description]") + + for (f <- r.fields) { + w.w(", @\"") + w.w(idObjc.field(f.ident)) + w.w("\": ") + + w.w("_djinni_hide_null_(") + + f.ty.resolved.base match { + case MOptional => w.w(s"self.${idObjc.field(f.ident)}") + case t: MPrimitive => w.w(s"@(self.${idObjc.field(f.ident)})") + case df: MDef => df.defType match { + case DEnum => w.w(s"@(self.${idObjc.field(f.ident)})") + case _ => w.w(s"self.${idObjc.field(f.ident)}") + } + case e: MExtern => + if (e.objc.pointer) { + w.w(s"self.${idObjc.field(f.ident)}") + } else { + w.w(s"@(self.${idObjc.field(f.ident)})") + } + case _ => w.w(s"self.${idObjc.field(f.ident)}") + } + + w.w(")") + } + } + w.wl("};") + } + w.wl + w.wl("@end") }) } From 78678adc922c52757ecb826c8371f29c3c2eb8b4 Mon Sep 17 00:00:00 2001 From: Haim Grosman Date: Tue, 10 Nov 2015 08:43:25 -0800 Subject: [PATCH 2/3] making `[description]` use the new `[toDict]` method --- src/source/ObjcGenerator.scala | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/src/source/ObjcGenerator.scala b/src/source/ObjcGenerator.scala index a6c126477..9f03e8304 100644 --- a/src/source/ObjcGenerator.scala +++ b/src/source/ObjcGenerator.scala @@ -391,32 +391,10 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) { w.wl("- (NSString *)description") w.braced { w.w(s"return ").nestedN(2) { - w.w("[NSString stringWithFormat:@\"<%@ %p") - - for (f <- r.fields) w.w(s" ${idObjc.field(f.ident)}:%@") - w.w(">\", self.class, self") - - for (f <- r.fields) { - w.w(", ") - f.ty.resolved.base match { - case MOptional => w.w(s"self.${idObjc.field(f.ident)}") - - case t: MPrimitive => w.w(s"@(self.${idObjc.field(f.ident)})") - case df: MDef => df.defType match { - case DEnum => w.w(s"@(self.${idObjc.field(f.ident)})") - case _ => w.w(s"self.${idObjc.field(f.ident)}") - } - case e: MExtern => - if (e.objc.pointer) { - w.w(s"self.${idObjc.field(f.ident)}") - } else { - w.w(s"@(self.${idObjc.field(f.ident)})") - } - case _ => w.w(s"self.${idObjc.field(f.ident)}") - } - } + w.w("[NSString stringWithFormat:@\"<%@ %p: dict, %@") + w.w(">\", self.class, self, [[self toDict] description]") + w.wl("];") } - w.wl("];") } w.wl From 9b94082ef26d7dbf627a2c6972ece5ed0a274d6a Mon Sep 17 00:00:00 2001 From: Haim Grosman Date: Tue, 10 Nov 2015 08:44:09 -0800 Subject: [PATCH 3/3] updating generated test files --- example/generated-src/objc/TXSItemList.h | 2 ++ example/generated-src/objc/TXSItemList.mm | 9 ++++++++- test-suite/generated-src/objc/DBAssortedPrimitives.h | 2 ++ test-suite/generated-src/objc/DBAssortedPrimitives.mm | 9 ++++++++- test-suite/generated-src/objc/DBClientReturnedRecord.h | 2 ++ test-suite/generated-src/objc/DBClientReturnedRecord.mm | 9 ++++++++- test-suite/generated-src/objc/DBConstants.h | 2 ++ test-suite/generated-src/objc/DBConstants.mm | 9 ++++++++- test-suite/generated-src/objc/DBDateRecord.h | 2 ++ test-suite/generated-src/objc/DBDateRecord.mm | 9 ++++++++- test-suite/generated-src/objc/DBEmptyRecord.h | 2 ++ test-suite/generated-src/objc/DBEmptyRecord.mm | 9 ++++++++- .../generated-src/objc/DBExternRecordWithDerivings.h | 2 ++ .../generated-src/objc/DBExternRecordWithDerivings.mm | 9 ++++++++- test-suite/generated-src/objc/DBMapDateRecord.h | 2 ++ test-suite/generated-src/objc/DBMapDateRecord.mm | 9 ++++++++- test-suite/generated-src/objc/DBMapListRecord.h | 2 ++ test-suite/generated-src/objc/DBMapListRecord.mm | 9 ++++++++- test-suite/generated-src/objc/DBMapRecord.h | 2 ++ test-suite/generated-src/objc/DBMapRecord.mm | 9 ++++++++- test-suite/generated-src/objc/DBNestedCollection.h | 2 ++ test-suite/generated-src/objc/DBNestedCollection.mm | 9 ++++++++- test-suite/generated-src/objc/DBOptColorRecord.h | 2 ++ test-suite/generated-src/objc/DBOptColorRecord.mm | 9 ++++++++- test-suite/generated-src/objc/DBPrimitiveList.h | 2 ++ test-suite/generated-src/objc/DBPrimitiveList.mm | 9 ++++++++- test-suite/generated-src/objc/DBRecordWithDerivings.h | 2 ++ test-suite/generated-src/objc/DBRecordWithDerivings.mm | 9 ++++++++- .../objc/DBRecordWithDurationAndDerivings.h | 2 ++ .../objc/DBRecordWithDurationAndDerivings.mm | 9 ++++++++- .../generated-src/objc/DBRecordWithNestedDerivings.h | 2 ++ .../generated-src/objc/DBRecordWithNestedDerivings.mm | 9 ++++++++- test-suite/generated-src/objc/DBSetRecord.h | 2 ++ test-suite/generated-src/objc/DBSetRecord.mm | 9 ++++++++- 34 files changed, 170 insertions(+), 17 deletions(-) diff --git a/example/generated-src/objc/TXSItemList.h b/example/generated-src/objc/TXSItemList.h index 5be77959b..09f4e6fde 100644 --- a/example/generated-src/objc/TXSItemList.h +++ b/example/generated-src/objc/TXSItemList.h @@ -7,6 +7,8 @@ - (nonnull instancetype)initWithItems:(nonnull NSArray *)items; + (nonnull instancetype)itemListWithItems:(nonnull NSArray *)items; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly, nonnull) NSArray * items; @end diff --git a/example/generated-src/objc/TXSItemList.mm b/example/generated-src/objc/TXSItemList.mm index 0400b7766..4ab6756a7 100644 --- a/example/generated-src/objc/TXSItemList.mm +++ b/example/generated-src/objc/TXSItemList.mm @@ -21,7 +21,14 @@ + (nonnull instancetype)itemListWithItems:(nonnull NSArray *)items - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p items:%@>", self.class, self, self.items]; + return [NSString stringWithFormat:@"", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"items": _djinni_hide_null_(self.items)}; } @end diff --git a/test-suite/generated-src/objc/DBAssortedPrimitives.h b/test-suite/generated-src/objc/DBAssortedPrimitives.h index 500a10ee8..4704e311b 100644 --- a/test-suite/generated-src/objc/DBAssortedPrimitives.h +++ b/test-suite/generated-src/objc/DBAssortedPrimitives.h @@ -33,6 +33,8 @@ oFthirtytwo:(nullable NSNumber *)oFthirtytwo oFsixtyfour:(nullable NSNumber *)oFsixtyfour; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly) BOOL b; @property (nonatomic, readonly) int8_t eight; diff --git a/test-suite/generated-src/objc/DBAssortedPrimitives.mm b/test-suite/generated-src/objc/DBAssortedPrimitives.mm index 3aeb700ee..c8510b3d7 100644 --- a/test-suite/generated-src/objc/DBAssortedPrimitives.mm +++ b/test-suite/generated-src/objc/DBAssortedPrimitives.mm @@ -114,7 +114,14 @@ - (NSUInteger)hash - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p b:%@ eight:%@ sixteen:%@ thirtytwo:%@ sixtyfour:%@ fthirtytwo:%@ fsixtyfour:%@ oB:%@ oEight:%@ oSixteen:%@ oThirtytwo:%@ oSixtyfour:%@ oFthirtytwo:%@ oFsixtyfour:%@>", self.class, self, @(self.b), @(self.eight), @(self.sixteen), @(self.thirtytwo), @(self.sixtyfour), @(self.fthirtytwo), @(self.fsixtyfour), self.oB, self.oEight, self.oSixteen, self.oThirtytwo, self.oSixtyfour, self.oFthirtytwo, self.oFsixtyfour]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"b": _djinni_hide_null_(@(self.b)), @"eight": _djinni_hide_null_(@(self.eight)), @"sixteen": _djinni_hide_null_(@(self.sixteen)), @"thirtytwo": _djinni_hide_null_(@(self.thirtytwo)), @"sixtyfour": _djinni_hide_null_(@(self.sixtyfour)), @"fthirtytwo": _djinni_hide_null_(@(self.fthirtytwo)), @"fsixtyfour": _djinni_hide_null_(@(self.fsixtyfour)), @"oB": _djinni_hide_null_(self.oB), @"oEight": _djinni_hide_null_(self.oEight), @"oSixteen": _djinni_hide_null_(self.oSixteen), @"oThirtytwo": _djinni_hide_null_(self.oThirtytwo), @"oSixtyfour": _djinni_hide_null_(self.oSixtyfour), @"oFthirtytwo": _djinni_hide_null_(self.oFthirtytwo), @"oFsixtyfour": _djinni_hide_null_(self.oFsixtyfour)}; } @end diff --git a/test-suite/generated-src/objc/DBClientReturnedRecord.h b/test-suite/generated-src/objc/DBClientReturnedRecord.h index cbadd28d9..d24f74749 100644 --- a/test-suite/generated-src/objc/DBClientReturnedRecord.h +++ b/test-suite/generated-src/objc/DBClientReturnedRecord.h @@ -12,6 +12,8 @@ content:(nonnull NSString *)content misc:(nullable NSString *)misc; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly) int64_t recordId; @property (nonatomic, readonly, nonnull) NSString * content; diff --git a/test-suite/generated-src/objc/DBClientReturnedRecord.mm b/test-suite/generated-src/objc/DBClientReturnedRecord.mm index e5627d9a7..ac6f81070 100644 --- a/test-suite/generated-src/objc/DBClientReturnedRecord.mm +++ b/test-suite/generated-src/objc/DBClientReturnedRecord.mm @@ -29,7 +29,14 @@ + (nonnull instancetype)clientReturnedRecordWithRecordId:(int64_t)recordId - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p recordId:%@ content:%@ misc:%@>", self.class, self, @(self.recordId), self.content, self.misc]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"recordId": _djinni_hide_null_(@(self.recordId)), @"content": _djinni_hide_null_(self.content), @"misc": _djinni_hide_null_(self.misc)}; } @end diff --git a/test-suite/generated-src/objc/DBConstants.h b/test-suite/generated-src/objc/DBConstants.h index ed72b6381..d3cdaf49b 100644 --- a/test-suite/generated-src/objc/DBConstants.h +++ b/test-suite/generated-src/objc/DBConstants.h @@ -11,6 +11,8 @@ + (nonnull instancetype)constantsWithSomeInteger:(int32_t)someInteger someString:(nonnull NSString *)someString; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly) int32_t someInteger; @property (nonatomic, readonly, nonnull) NSString * someString; diff --git a/test-suite/generated-src/objc/DBConstants.mm b/test-suite/generated-src/objc/DBConstants.mm index 177422349..9dc8cfe88 100644 --- a/test-suite/generated-src/objc/DBConstants.mm +++ b/test-suite/generated-src/objc/DBConstants.mm @@ -50,7 +50,14 @@ + (nonnull instancetype)constantsWithSomeInteger:(int32_t)someInteger - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p someInteger:%@ someString:%@>", self.class, self, @(self.someInteger), self.someString]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"someInteger": _djinni_hide_null_(@(self.someInteger)), @"someString": _djinni_hide_null_(self.someString)}; } @end diff --git a/test-suite/generated-src/objc/DBDateRecord.h b/test-suite/generated-src/objc/DBDateRecord.h index 039d05433..661ba1434 100644 --- a/test-suite/generated-src/objc/DBDateRecord.h +++ b/test-suite/generated-src/objc/DBDateRecord.h @@ -7,6 +7,8 @@ - (nonnull instancetype)initWithCreatedAt:(nonnull NSDate *)createdAt; + (nonnull instancetype)dateRecordWithCreatedAt:(nonnull NSDate *)createdAt; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly, nonnull) NSDate * createdAt; - (NSComparisonResult)compare:(nonnull DBDateRecord *)other; diff --git a/test-suite/generated-src/objc/DBDateRecord.mm b/test-suite/generated-src/objc/DBDateRecord.mm index a79ac2089..909a55de0 100644 --- a/test-suite/generated-src/objc/DBDateRecord.mm +++ b/test-suite/generated-src/objc/DBDateRecord.mm @@ -46,7 +46,14 @@ - (NSComparisonResult)compare:(DBDateRecord *)other - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p createdAt:%@>", self.class, self, self.createdAt]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"createdAt": _djinni_hide_null_(self.createdAt)}; } @end diff --git a/test-suite/generated-src/objc/DBEmptyRecord.h b/test-suite/generated-src/objc/DBEmptyRecord.h index 1dc120e42..2d6065fb2 100644 --- a/test-suite/generated-src/objc/DBEmptyRecord.h +++ b/test-suite/generated-src/objc/DBEmptyRecord.h @@ -12,4 +12,6 @@ - (nonnull instancetype)init; + (nonnull instancetype)emptyRecord; +- (nonnull NSDictionary *) toDict; + @end diff --git a/test-suite/generated-src/objc/DBEmptyRecord.mm b/test-suite/generated-src/objc/DBEmptyRecord.mm index 7f65e2b85..895aee4d0 100644 --- a/test-suite/generated-src/objc/DBEmptyRecord.mm +++ b/test-suite/generated-src/objc/DBEmptyRecord.mm @@ -20,7 +20,14 @@ + (nonnull instancetype)emptyRecord - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p>", self.class, self]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description]}; } @end diff --git a/test-suite/generated-src/objc/DBExternRecordWithDerivings.h b/test-suite/generated-src/objc/DBExternRecordWithDerivings.h index fb4b12ee3..ca37da8e1 100644 --- a/test-suite/generated-src/objc/DBExternRecordWithDerivings.h +++ b/test-suite/generated-src/objc/DBExternRecordWithDerivings.h @@ -12,6 +12,8 @@ + (nonnull instancetype)externRecordWithDerivingsWithMember:(nonnull DBRecordWithDerivings *)member e:(DBColor)e; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly, nonnull) DBRecordWithDerivings * member; @property (nonatomic, readonly) DBColor e; diff --git a/test-suite/generated-src/objc/DBExternRecordWithDerivings.mm b/test-suite/generated-src/objc/DBExternRecordWithDerivings.mm index a6f4011cb..8d4d761db 100644 --- a/test-suite/generated-src/objc/DBExternRecordWithDerivings.mm +++ b/test-suite/generated-src/objc/DBExternRecordWithDerivings.mm @@ -62,7 +62,14 @@ - (NSComparisonResult)compare:(DBExternRecordWithDerivings *)other - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p member:%@ e:%@>", self.class, self, self.member, @(self.e)]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"member": _djinni_hide_null_(self.member), @"e": _djinni_hide_null_(@(self.e))}; } @end diff --git a/test-suite/generated-src/objc/DBMapDateRecord.h b/test-suite/generated-src/objc/DBMapDateRecord.h index a31b346af..212d6a4a4 100644 --- a/test-suite/generated-src/objc/DBMapDateRecord.h +++ b/test-suite/generated-src/objc/DBMapDateRecord.h @@ -7,6 +7,8 @@ - (nonnull instancetype)initWithDatesById:(nonnull NSDictionary *)datesById; + (nonnull instancetype)mapDateRecordWithDatesById:(nonnull NSDictionary *)datesById; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly, nonnull) NSDictionary * datesById; @end diff --git a/test-suite/generated-src/objc/DBMapDateRecord.mm b/test-suite/generated-src/objc/DBMapDateRecord.mm index e39b91b9c..ef1e0e3d0 100644 --- a/test-suite/generated-src/objc/DBMapDateRecord.mm +++ b/test-suite/generated-src/objc/DBMapDateRecord.mm @@ -21,7 +21,14 @@ + (nonnull instancetype)mapDateRecordWithDatesById:(nonnull NSDictionary", self.class, self, self.datesById]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"datesById": _djinni_hide_null_(self.datesById)}; } @end diff --git a/test-suite/generated-src/objc/DBMapListRecord.h b/test-suite/generated-src/objc/DBMapListRecord.h index b86fb1a0a..d0fb4e8ff 100644 --- a/test-suite/generated-src/objc/DBMapListRecord.h +++ b/test-suite/generated-src/objc/DBMapListRecord.h @@ -7,6 +7,8 @@ - (nonnull instancetype)initWithMapList:(nonnull NSArray *> *)mapList; + (nonnull instancetype)mapListRecordWithMapList:(nonnull NSArray *> *)mapList; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly, nonnull) NSArray *> * mapList; @end diff --git a/test-suite/generated-src/objc/DBMapListRecord.mm b/test-suite/generated-src/objc/DBMapListRecord.mm index c9c5a59e3..5ac02084b 100644 --- a/test-suite/generated-src/objc/DBMapListRecord.mm +++ b/test-suite/generated-src/objc/DBMapListRecord.mm @@ -21,7 +21,14 @@ + (nonnull instancetype)mapListRecordWithMapList:(nonnull NSArray", self.class, self, self.mapList]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"mapList": _djinni_hide_null_(self.mapList)}; } @end diff --git a/test-suite/generated-src/objc/DBMapRecord.h b/test-suite/generated-src/objc/DBMapRecord.h index 2f0dd7d91..3fd13e97e 100644 --- a/test-suite/generated-src/objc/DBMapRecord.h +++ b/test-suite/generated-src/objc/DBMapRecord.h @@ -9,6 +9,8 @@ + (nonnull instancetype)mapRecordWithMap:(nonnull NSDictionary *)map imap:(nonnull NSDictionary *)imap; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly, nonnull) NSDictionary * map; @property (nonatomic, readonly, nonnull) NSDictionary * imap; diff --git a/test-suite/generated-src/objc/DBMapRecord.mm b/test-suite/generated-src/objc/DBMapRecord.mm index 4eedd6b53..6874f9189 100644 --- a/test-suite/generated-src/objc/DBMapRecord.mm +++ b/test-suite/generated-src/objc/DBMapRecord.mm @@ -25,7 +25,14 @@ + (nonnull instancetype)mapRecordWithMap:(nonnull NSDictionary", self.class, self, self.map, self.imap]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"map": _djinni_hide_null_(self.map), @"imap": _djinni_hide_null_(self.imap)}; } @end diff --git a/test-suite/generated-src/objc/DBNestedCollection.h b/test-suite/generated-src/objc/DBNestedCollection.h index 1af0699f8..21bba6b29 100644 --- a/test-suite/generated-src/objc/DBNestedCollection.h +++ b/test-suite/generated-src/objc/DBNestedCollection.h @@ -7,6 +7,8 @@ - (nonnull instancetype)initWithSetList:(nonnull NSArray *> *)setList; + (nonnull instancetype)nestedCollectionWithSetList:(nonnull NSArray *> *)setList; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly, nonnull) NSArray *> * setList; @end diff --git a/test-suite/generated-src/objc/DBNestedCollection.mm b/test-suite/generated-src/objc/DBNestedCollection.mm index 18edd8921..cf2bd89c6 100644 --- a/test-suite/generated-src/objc/DBNestedCollection.mm +++ b/test-suite/generated-src/objc/DBNestedCollection.mm @@ -21,7 +21,14 @@ + (nonnull instancetype)nestedCollectionWithSetList:(nonnull NSArray", self.class, self, self.setList]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"setList": _djinni_hide_null_(self.setList)}; } @end diff --git a/test-suite/generated-src/objc/DBOptColorRecord.h b/test-suite/generated-src/objc/DBOptColorRecord.h index a8e16a476..612c68114 100644 --- a/test-suite/generated-src/objc/DBOptColorRecord.h +++ b/test-suite/generated-src/objc/DBOptColorRecord.h @@ -8,6 +8,8 @@ - (nonnull instancetype)initWithMyColor:(nullable NSNumber *)myColor; + (nonnull instancetype)optColorRecordWithMyColor:(nullable NSNumber *)myColor; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly, nullable) NSNumber * myColor; @end diff --git a/test-suite/generated-src/objc/DBOptColorRecord.mm b/test-suite/generated-src/objc/DBOptColorRecord.mm index 08e99a6cf..db807c4d3 100644 --- a/test-suite/generated-src/objc/DBOptColorRecord.mm +++ b/test-suite/generated-src/objc/DBOptColorRecord.mm @@ -21,7 +21,14 @@ + (nonnull instancetype)optColorRecordWithMyColor:(nullable NSNumber *)myColor - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p myColor:%@>", self.class, self, self.myColor]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"myColor": _djinni_hide_null_(self.myColor)}; } @end diff --git a/test-suite/generated-src/objc/DBPrimitiveList.h b/test-suite/generated-src/objc/DBPrimitiveList.h index f08ac4f16..6b76e6d5c 100644 --- a/test-suite/generated-src/objc/DBPrimitiveList.h +++ b/test-suite/generated-src/objc/DBPrimitiveList.h @@ -7,6 +7,8 @@ - (nonnull instancetype)initWithList:(nonnull NSArray *)list; + (nonnull instancetype)primitiveListWithList:(nonnull NSArray *)list; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly, nonnull) NSArray * list; @end diff --git a/test-suite/generated-src/objc/DBPrimitiveList.mm b/test-suite/generated-src/objc/DBPrimitiveList.mm index d68ef58f9..b143d6bcf 100644 --- a/test-suite/generated-src/objc/DBPrimitiveList.mm +++ b/test-suite/generated-src/objc/DBPrimitiveList.mm @@ -21,7 +21,14 @@ + (nonnull instancetype)primitiveListWithList:(nonnull NSArray *)lis - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p list:%@>", self.class, self, self.list]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"list": _djinni_hide_null_(self.list)}; } @end diff --git a/test-suite/generated-src/objc/DBRecordWithDerivings.h b/test-suite/generated-src/objc/DBRecordWithDerivings.h index f9681755f..c8c515a86 100644 --- a/test-suite/generated-src/objc/DBRecordWithDerivings.h +++ b/test-suite/generated-src/objc/DBRecordWithDerivings.h @@ -9,6 +9,8 @@ + (nonnull instancetype)recordWithDerivingsWithKey1:(int32_t)key1 key2:(nonnull NSString *)key2; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly) int32_t key1; @property (nonatomic, readonly, nonnull) NSString * key2; diff --git a/test-suite/generated-src/objc/DBRecordWithDerivings.mm b/test-suite/generated-src/objc/DBRecordWithDerivings.mm index 60076afa3..dad5caedf 100644 --- a/test-suite/generated-src/objc/DBRecordWithDerivings.mm +++ b/test-suite/generated-src/objc/DBRecordWithDerivings.mm @@ -62,7 +62,14 @@ - (NSComparisonResult)compare:(DBRecordWithDerivings *)other - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p key1:%@ key2:%@>", self.class, self, @(self.key1), self.key2]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"key1": _djinni_hide_null_(@(self.key1)), @"key2": _djinni_hide_null_(self.key2)}; } @end diff --git a/test-suite/generated-src/objc/DBRecordWithDurationAndDerivings.h b/test-suite/generated-src/objc/DBRecordWithDurationAndDerivings.h index f9b2dd149..c1b08c2cc 100644 --- a/test-suite/generated-src/objc/DBRecordWithDurationAndDerivings.h +++ b/test-suite/generated-src/objc/DBRecordWithDurationAndDerivings.h @@ -7,6 +7,8 @@ - (nonnull instancetype)initWithDt:(NSTimeInterval)dt; + (nonnull instancetype)recordWithDurationAndDerivingsWithDt:(NSTimeInterval)dt; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly) NSTimeInterval dt; - (NSComparisonResult)compare:(nonnull DBRecordWithDurationAndDerivings *)other; diff --git a/test-suite/generated-src/objc/DBRecordWithDurationAndDerivings.mm b/test-suite/generated-src/objc/DBRecordWithDurationAndDerivings.mm index 26528b214..b15b06fa7 100644 --- a/test-suite/generated-src/objc/DBRecordWithDurationAndDerivings.mm +++ b/test-suite/generated-src/objc/DBRecordWithDurationAndDerivings.mm @@ -52,7 +52,14 @@ - (NSComparisonResult)compare:(DBRecordWithDurationAndDerivings *)other - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p dt:%@>", self.class, self, @(self.dt)]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"dt": _djinni_hide_null_(@(self.dt))}; } @end diff --git a/test-suite/generated-src/objc/DBRecordWithNestedDerivings.h b/test-suite/generated-src/objc/DBRecordWithNestedDerivings.h index a31ccc5c6..3ac9992c2 100644 --- a/test-suite/generated-src/objc/DBRecordWithNestedDerivings.h +++ b/test-suite/generated-src/objc/DBRecordWithNestedDerivings.h @@ -10,6 +10,8 @@ + (nonnull instancetype)recordWithNestedDerivingsWithKey:(int32_t)key rec:(nonnull DBRecordWithDerivings *)rec; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly) int32_t key; @property (nonatomic, readonly, nonnull) DBRecordWithDerivings * rec; diff --git a/test-suite/generated-src/objc/DBRecordWithNestedDerivings.mm b/test-suite/generated-src/objc/DBRecordWithNestedDerivings.mm index d0ac0ba44..5906c819e 100644 --- a/test-suite/generated-src/objc/DBRecordWithNestedDerivings.mm +++ b/test-suite/generated-src/objc/DBRecordWithNestedDerivings.mm @@ -62,7 +62,14 @@ - (NSComparisonResult)compare:(DBRecordWithNestedDerivings *)other - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p key:%@ rec:%@>", self.class, self, @(self.key), self.rec]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"key": _djinni_hide_null_(@(self.key)), @"rec": _djinni_hide_null_(self.rec)}; } @end diff --git a/test-suite/generated-src/objc/DBSetRecord.h b/test-suite/generated-src/objc/DBSetRecord.h index 4c0f19013..cb25bacb0 100644 --- a/test-suite/generated-src/objc/DBSetRecord.h +++ b/test-suite/generated-src/objc/DBSetRecord.h @@ -9,6 +9,8 @@ + (nonnull instancetype)setRecordWithSet:(nonnull NSSet *)set iset:(nonnull NSSet *)iset; +- (nonnull NSDictionary *) toDict; + @property (nonatomic, readonly, nonnull) NSSet * set; @property (nonatomic, readonly, nonnull) NSSet * iset; diff --git a/test-suite/generated-src/objc/DBSetRecord.mm b/test-suite/generated-src/objc/DBSetRecord.mm index 691c2d5cf..8dde221e6 100644 --- a/test-suite/generated-src/objc/DBSetRecord.mm +++ b/test-suite/generated-src/objc/DBSetRecord.mm @@ -25,7 +25,14 @@ + (nonnull instancetype)setRecordWithSet:(nonnull NSSet *)set - (NSString *)description { - return [NSString stringWithFormat:@"<%@ %p set:%@ iset:%@>", self.class, self, self.set, self.iset]; + return [NSString stringWithFormat:@"<%@ %p: dict, %@>", self.class, self, [[self toDict] description]]; +} + +- (NSDictionary *)toDict +{ + #define _djinni_hide_null_(_o_) ((_o_)?(_o_):([NSNull null])) + + return @{@"__class_name__": [self.class description], @"set": _djinni_hide_null_(self.set), @"iset": _djinni_hide_null_(self.iset)}; } @end