diff --git a/README.md b/README.md index 83290c6f..22f1dc65 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ verify the build and binary from the command line. - DataView for copy free data passing - DateRef for copy free data passing with ownership - Generating string names for C++ enums + - Omit optional parameters from record constructors + - Records are default mutable across all platforms - Bug fixes ## Using new features @@ -341,6 +343,38 @@ The C++ `Future` type has optional support for coroutines. If coroutines are availble (eg. compiling with C++20 or C++17 with -fcoroutines-ts), then you can use `co_await` on future objects. +## Requiring Optional Parameters in Individual Records +- By default, optionals will be omitted from the constructor in Djinni +- The Djinni code generator will generate two constructors for a record with optionals: one with all values and one with optionals omitted. This will minimize code disruption +- Optional behavior will be able to be switched via a usage flag for each platform. +- A new [deriving method](https://github.com/dropbox/djinni#derived-methods) specifier will be implemented so that individual records can still require all parameters + +### Deriving Record +Any record can be made to have all parameters be required by specifying it as a `req` deriving record: +``` +MyClass = record { + required: string; + optional: optional; +} deriving(req) +``` + +### Omitting Convenience Constructors +Extra convenience constructors which require all parameters can be removed from optional ObjC records with a new compiler flag: +``` +--objc-omit-full-convenience-constructor +``` + +## Reverting to Legacy Record Behavior +Djinni records are now mutable and do not require optionals in reocrd constructors by default. In order to reverse this behavior and make Java and ObjC records immutable with full constructors only, the following generation flags can be used: + +``` +--cpp-legacy-records +--java-legacy-records +--objc-legacy-records +``` + +Note that for C++, the legacy flag will only remove the optional-omitting constructor. Records were already mutable within C++. + ## FAQ Q. Do I need to use Bazel to build my project? diff --git a/examples/generated-src/java/com/dropbox/textsort/ItemList.java b/examples/generated-src/java/com/dropbox/textsort/ItemList.java index a29a7da5..e17571cb 100644 --- a/examples/generated-src/java/com/dropbox/textsort/ItemList.java +++ b/examples/generated-src/java/com/dropbox/textsort/ItemList.java @@ -10,7 +10,7 @@ /*package*/ final class ItemList { - /*package*/ final ArrayList mItems; + /*package*/ ArrayList mItems; public ItemList( @Nonnull ArrayList items) { @@ -22,6 +22,10 @@ public ArrayList getItems() { return mItems; } + public void setItems(@Nonnull ArrayList items) { + this.mItems = items; + } + @Override public String toString() { return "ItemList{" + diff --git a/examples/generated-src/objc/TXSItemList.h b/examples/generated-src/objc/TXSItemList.h index fccfebce..6b3514f2 100644 --- a/examples/generated-src/objc/TXSItemList.h +++ b/examples/generated-src/objc/TXSItemList.h @@ -9,6 +9,6 @@ - (nonnull instancetype)initWithItems:(nonnull NSArray *)items NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)itemListWithItems:(nonnull NSArray *)items; -@property (nonatomic, readonly, nonnull) NSArray * items; +@property (nonatomic, copy, nonnull) NSArray * items; @end diff --git a/perftest/generated-src/java/com/snapchat/djinni/benchmark/RecordSixInt.java b/perftest/generated-src/java/com/snapchat/djinni/benchmark/RecordSixInt.java index 5de1b076..3b547ad0 100644 --- a/perftest/generated-src/java/com/snapchat/djinni/benchmark/RecordSixInt.java +++ b/perftest/generated-src/java/com/snapchat/djinni/benchmark/RecordSixInt.java @@ -9,17 +9,17 @@ /*package*/ final class RecordSixInt { - /*package*/ final long mI1; + /*package*/ long mI1; - /*package*/ final long mI2; + /*package*/ long mI2; - /*package*/ final long mI3; + /*package*/ long mI3; - /*package*/ final long mI4; + /*package*/ long mI4; - /*package*/ final long mI5; + /*package*/ long mI5; - /*package*/ final long mI6; + /*package*/ long mI6; public RecordSixInt( long i1, @@ -40,26 +40,50 @@ public long getI1() { return mI1; } + public void setI1(long i1) { + this.mI1 = i1; + } + public long getI2() { return mI2; } + public void setI2(long i2) { + this.mI2 = i2; + } + public long getI3() { return mI3; } + public void setI3(long i3) { + this.mI3 = i3; + } + public long getI4() { return mI4; } + public void setI4(long i4) { + this.mI4 = i4; + } + public long getI5() { return mI5; } + public void setI5(long i5) { + this.mI5 = i5; + } + public long getI6() { return mI6; } + public void setI6(long i6) { + this.mI6 = i6; + } + @Override public String toString() { return "RecordSixInt{" + diff --git a/perftest/generated-src/objc/TXSRecordSixInt.h b/perftest/generated-src/objc/TXSRecordSixInt.h index 7fc51c37..bd7d552f 100644 --- a/perftest/generated-src/objc/TXSRecordSixInt.h +++ b/perftest/generated-src/objc/TXSRecordSixInt.h @@ -19,16 +19,16 @@ i5:(int64_t)i5 i6:(int64_t)i6; -@property (nonatomic, readonly) int64_t i1; +@property (nonatomic) int64_t i1; -@property (nonatomic, readonly) int64_t i2; +@property (nonatomic) int64_t i2; -@property (nonatomic, readonly) int64_t i3; +@property (nonatomic) int64_t i3; -@property (nonatomic, readonly) int64_t i4; +@property (nonatomic) int64_t i4; -@property (nonatomic, readonly) int64_t i5; +@property (nonatomic) int64_t i5; -@property (nonatomic, readonly) int64_t i6; +@property (nonatomic) int64_t i6; @end diff --git a/src/source/CppGenerator.scala b/src/source/CppGenerator.scala index 1426d598..31b0e709 100644 --- a/src/source/CppGenerator.scala +++ b/src/source/CppGenerator.scala @@ -221,6 +221,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) { writeCppTypeParams(w, params) w.w("struct " + actualSelf + cppFinal).bracedSemi { generateHppConstants(w, r.consts) + // Field definitions. for (f <- r.fields) { writeDoc(w, f.doc) @@ -243,18 +244,48 @@ class CppGenerator(spec: Spec) extends Generator(spec) { w.wl(s"friend bool operator>=(const $actualSelf& lhs, const $actualSelf& rhs);") } - // Constructor. - if(r.fields.nonEmpty) { - w.wl - if (r.fields.size == 1) { - w.wl("//NOLINTNEXTLINE(google-explicit-constructor)") + // Constructor generator + def writeConstructor(reqFields: Seq[Field]) { + // Only skip if there are no fields at all. If only optional + // fields exist, we should still create the trivial constructor + if(r.fields.nonEmpty) { + w.wl + if (reqFields.size == 1) { + w.wl("//NOLINTNEXTLINE(google-explicit-constructor)") + } + writeAlignedCall(w, actualSelf + "(", reqFields, ")", f => marshal.fieldType(f.ty) + " " + idCpp.local(f.ident) + "_") + w.wl + + // Determimne if we are writing a constructor omitting optionals or one requiring + // all parameters + if (r.fields.size != reqFields.size) { + writeAlignedCall(w, ": " + actualSelf + "(", r.fields, ")", f => { + var param = "std::move(" + idCpp.local(f.ident) + "_)" + if (isOptional(f.ty.resolved)) + if (isInterface(f.ty.resolved.args.head)) + param = s"nullptr" + else + param = s"${spec.cppNulloptValue}" + + param + }) + w.wl + } else { + // required constructor + val init = (f: Field) => idCpp.field(f.ident) + "(std::move(" + idCpp.local(f.ident) + "_))" + w.wl(": " + init(r.fields.head)) + r.fields.tail.map(f => ", " + init(f)).foreach(w.wl) + } + w.wl("{}") } - writeAlignedCall(w, actualSelf + "(", r.fields, ")", f => marshal.fieldType(f.ty) + " " + idCpp.local(f.ident) + "_") - w.wl - val init = (f: Field) => idCpp.field(f.ident) + "(std::move(" + idCpp.local(f.ident) + "_))" - w.wl(": " + init(r.fields.head)) - r.fields.tail.map(f => ", " + init(f)).foreach(w.wl) - w.wl("{}") + } + + // First write constructor requiring optionals, required for marshaling + writeConstructor(r.fields) + + // Next write optional omitting constructor if necessary + if (!spec.cppLegacyRecords && !r.derivingTypes.contains(DerivingType.Req) && r.reqFields.size != r.fields.size) { + writeConstructor(r.reqFields) } if (r.ext.cpp) { diff --git a/src/source/JavaGenerator.scala b/src/source/JavaGenerator.scala index 6481a841..0d831e3f 100644 --- a/src/source/JavaGenerator.scala +++ b/src/source/JavaGenerator.scala @@ -275,27 +275,46 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { generateJavaConstants(w, r.consts) // Field definitions. for (f <- r.fields) { + var fieldFinal = if (spec.javaLegacyRecords) "final " else if (r.derivingTypes.contains(DerivingType.Req) || !isOptional(f.ty.resolved)) "" else "/*optional*/ " w.wl - w.wl(s"/*package*/ final ${marshal.fieldType(f.ty)} ${idJava.field(f.ident)};") + w.wl(s"/*package*/ ${fieldFinal}${marshal.fieldType(f.ty)} ${idJava.field(f.ident)};") } - // Constructor. - w.wl - w.wl(s"public $self(").nestedN(2) { - val skipFirst = SkipFirst() - for (f <- r.fields) { - skipFirst { w.wl(",") } - marshal.nullityAnnotation(f.ty).map(annotation => w.w(annotation + " ")) - w.w(marshal.paramType(f.ty) + " " + idJava.local(f.ident)) + def writeConstructor(reqFields: Seq[Field]) { + w.wl + if (reqFields.isEmpty) + w.wl(s"public $self() {") + else + w.wl(s"public $self(").nestedN(2) { + val skipFirst = SkipFirst() + for (f <- reqFields) { + skipFirst { w.wl(",") } + marshal.nullityAnnotation(f.ty).map(annotation => w.w(annotation + " ")) + w.w(marshal.paramType(f.ty) + " " + idJava.local(f.ident)) + } + w.wl(") {") + } + w.nested { + // Optional constructor or full constructor + if (reqFields.size != r.fields.size) { + writeAlignedCall(w, "this(", r.fields, ");", f=> if (isOptional(f.ty.resolved)) "null" else idJava.local(f.ident)) + w.wl + } else { + for (f <- reqFields) { + w.wl(s"this.${idJava.field(f.ident)} = ${idJava.local(f.ident)};") + } + } } - w.wl(") {") + w.wl("}") } - w.nested { - for (f <- r.fields) { - w.wl(s"this.${idJava.field(f.ident)} = ${idJava.local(f.ident)};") - } + + // Constructor, requiring all parameters, used for marshaling + writeConstructor(r.fields) + + // Constructor, not requiring optionals, generated if necessary + if (!spec.javaLegacyRecords && !r.derivingTypes.contains(DerivingType.Req) && r.fields.size != r.reqFields.size) { + writeConstructor(r.reqFields) } - w.wl("}") // Accessors for (f <- r.fields) { @@ -305,6 +324,16 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { w.w("public " + marshal.returnType(Some(f.ty)) + " " + idJava.method("get_" + f.ident.name) + "()").braced { w.wl("return " + idJava.field(f.ident) + ";") } + + if (!spec.javaLegacyRecords) { + w.wl + // Check for null for setters used on required parameters + var nullability = if (isOptional(f.ty.resolved)) "" else marshal.nullityAnnotation(f.ty).map(_ + "").getOrElse("") + nullability = if (nullability.isEmpty) "" else nullability + " " + w.w("public void " + idJava.method("set_" + f.ident.name) + "(" + nullability + marshal.paramType(f.ty) + " " + idJava.local(f.ident) + ")").braced { + w.wl(s"this.${idJava.field(f.ident)} = ${idJava.local(f.ident)};") + } + } } if (r.derivingTypes.contains(DerivingType.Eq)) { diff --git a/src/source/Main.scala b/src/source/Main.scala index eb40c8c4..2fde4e75 100644 --- a/src/source/Main.scala +++ b/src/source/Main.scala @@ -35,11 +35,13 @@ object Main { var cppBaseLibIncludePrefix: String = "" var cppOptionalTemplate: String = "std::optional" var cppOptionalHeader: String = "" + var cppNulloptValue: String = "std::nullopt" var cppEnumHashWorkaround : Boolean = true var cppNnHeader: Option[String] = None var cppNnType: Option[String] = None var cppNnCheckExpression: Option[String] = None var cppUseWideStrings: Boolean = false + var cppLegacyRecords: Boolean = false var javaOutFolder: Option[File] = None var javaPackage: Option[String] = None var javaClassAccessModifier: JavaAccessModifier.Value = JavaAccessModifier.Public @@ -49,6 +51,7 @@ object Main { var javaNonnullAnnotation: Option[String] = None var javaImplementAndroidOsParcelable : Boolean = false var javaUseFinalForRecord: Boolean = true + var javaLegacyRecords: Boolean = false var javaGenInterface: Boolean = false var jniOutFolder: Option[File] = None var jniHeaderOutFolderOptional: Option[File] = None @@ -86,6 +89,8 @@ object Main { var objcppDisableExceptionTranslation: Boolean = false var objcFileIdentStyleOptional: Option[IdentConverter] = None var objcStrictProtocol: Boolean = true + var objcLegacyRecords: Boolean = false + var objcOmitFullConvenienceConstructor: Boolean = false var objcppNamespace: String = "djinni_generated" var objcBaseLibIncludePrefix: String = "" var wasmOutFolder: Option[File] = None @@ -141,6 +146,8 @@ object Main { .text("all generated java classes will implement the interface android.os.Parcelable") opt[Boolean]("java-use-final-for-record").valueName("").foreach(x => javaUseFinalForRecord = x) .text("Whether generated Java classes for records should be marked 'final' (default: true). ") + opt[Boolean]("java-legacy-records").valueName("").foreach(x => javaLegacyRecords = x) + .text("Use legacy record behavior for Java code (default: false)") opt[Boolean]("java-gen-interface").valueName("").foreach(x => javaGenInterface = x) .text("Generate Java interface instead of abstract class.") note("") @@ -162,6 +169,8 @@ object Main { .text("The template to use for optional values (default: \"std::optional\")") opt[String]("cpp-optional-header").valueName("
").foreach(x => cppOptionalHeader = x) .text("The header to use for optional values (default: \"\")") + opt[String]("cpp-nullopt-value").valueName("").foreach(x => cppNulloptValue = x) + .text("The value to use for nullopt defaults of optional values (default: \"std::nullopt\")") opt[Boolean]("cpp-enum-hash-workaround").valueName("").foreach(x => cppEnumHashWorkaround = x) .text("Work around LWG-2148 by generating std::hash specializations for C++ enums (default: true)") opt[String]("cpp-nn-header").valueName("
").foreach(x => cppNnHeader = Some(x)) @@ -172,6 +181,8 @@ object Main { .text("The expression to use for building non-nullable pointers") opt[Boolean]( "cpp-use-wide-strings").valueName("").foreach(x => cppUseWideStrings = x) .text("Use wide strings in C++ code (default: false)") + opt[Boolean]( "cpp-legacy-records").valueName("").foreach(x => cppLegacyRecords = x) + .text("Use legacy record behavior for C++ code (default: false)") note("") opt[File]("jni-out").valueName("").foreach(x => jniOutFolder = Some(x)) .text("The folder for the JNI C++ output files (Generator disabled if unspecified).") @@ -209,7 +220,13 @@ object Main { opt[Boolean]("objc-strict-protocols") .valueName("").foreach(x => objcStrictProtocol = x) .text("All generated @protocol will implement (default: true). ") + opt[Boolean]("objc-legacy-records") + .valueName("").foreach(x => objcLegacyRecords = x) + .text("Use legacy record behavior for ObjC code (default: false)") note("") + opt[Boolean]("objc-omit-full-convenience-constructor") + .valueName("").foreach(x => objcOmitFullConvenienceConstructor = x) + .text("Skips generation of the convenience constructor requiring all record parameters, if possible (default: false)") opt[File]("objcpp-out").valueName("").foreach(x => objcppOutFolder = Some(x)) .text("The output folder for private Objective-C++ files (Generator disabled if unspecified).") opt[String]("objcpp-ext").valueName("").foreach(objcppExt = _) @@ -377,6 +394,7 @@ object Main { javaImplementAndroidOsParcelable, javaUseFinalForRecord, javaGenInterface, + javaLegacyRecords, cppOutFolder, cppHeaderOutFolder, cppIncludePrefix, @@ -387,11 +405,13 @@ object Main { cppBaseLibIncludePrefix, cppOptionalTemplate, cppOptionalHeader, + cppNulloptValue, cppEnumHashWorkaround, cppNnHeader, cppNnType, cppNnCheckExpression, cppUseWideStrings, + cppLegacyRecords, jniOutFolder, jniHeaderOutFolder, jniIncludePrefix, @@ -425,6 +445,8 @@ object Main { objcDisableClassCtor, objcClosedEnums, objcStrictProtocol, + objcLegacyRecords, + objcOmitFullConvenienceConstructor, wasmOutFolder, wasmIncludePrefix, wasmIncludeCppPrefix, diff --git a/src/source/ObjcGenerator.scala b/src/source/ObjcGenerator.scala index dd0cd334..079cc982 100644 --- a/src/source/ObjcGenerator.scala +++ b/src/source/ObjcGenerator.scala @@ -198,8 +198,14 @@ class ObjcGenerator(spec: Spec) extends BaseObjcGenerator(spec) { case _ => false } + val requireOptionals = spec.objcLegacyRecords || r.derivingTypes.contains(DerivingType.Req) + val shouldWriteFullConvenienceConstructor = !spec.objcOmitFullConvenienceConstructor || requireOptionals || r.fields.size == r.reqFields.size + val firstInitializerArg = if(r.fields.isEmpty) "" else IdentStyle.camelUpper("with_" + r.fields.head.ident.name) + // Find the first required arg for the optional-omitting initializer + val firstReqInitializerArg = if(r.reqFields.isEmpty) "" else IdentStyle.camelUpper("with_" + r.fields.find(f => !isOptional(f.ty.resolved)).get.ident.name) + // Generate the header file for record writeObjcFile(marshal.headerName(objcName), origin, refs.header, w => { writeDoc(w, doc) @@ -210,26 +216,38 @@ class ObjcGenerator(spec: Spec) extends BaseObjcGenerator(spec) { w.wl(s"@interface $self : NSObject") } - def writeInitializer(sign: String, prefix: String) { - val decl = s"$sign (nonnull instancetype)$prefix$firstInitializerArg" - writeAlignedObjcCall(w, decl, r.fields, "", f => (idObjc.field(f.ident), s"(${marshal.paramType(f.ty)})${idObjc.local(f.ident)}")) + def writeInitializer(sign: String, prefix: String, firstArg: String, fields: Seq[Field]) { + val decl = s"$sign (nonnull instancetype)$prefix$firstArg" + writeAlignedObjcCall(w, decl, fields, "", f => (idObjc.field(f.ident), s"(${marshal.paramType(f.ty)})${idObjc.local(f.ident)}")) - if (prefix == "init") { + // Only define the designated initializer for the main constructor + if (prefix == "init" && fields.size == r.fields.size) { w.wl(" NS_DESIGNATED_INITIALIZER;") } else { w.wl(";") } } - if (r.fields.nonEmpty) { + if (r.reqFields.size > 0 || (requireOptionals && r.fields.nonEmpty)) { // NSObject init / new are marked unavailable. Only allow designated initializer // as records may have non-optional / nonnull fields. w.wl("- (nonnull instancetype)init NS_UNAVAILABLE;") w.wl("+ (nonnull instancetype)new NS_UNAVAILABLE;") } - writeInitializer("-", "init") - if (!r.ext.objc && !spec.objcDisableClassCtor) writeInitializer("+", IdentStyle.camelLower(objcName)) + // First write the required initializer + writeInitializer("-", "init", firstInitializerArg, r.fields) + + // Next write the full convencience constructor if it is required + if (shouldWriteFullConvenienceConstructor) { + if (!r.ext.objc && !spec.objcDisableClassCtor) writeInitializer("+", IdentStyle.camelLower(objcName), firstInitializerArg, r.fields) + } + + // Next write an optional-omitting constructor if applicable + if (!requireOptionals && r.fields.size != r.reqFields.size) { + writeInitializer("-", "init", firstReqInitializerArg, r.reqFields) + if (!r.ext.objc && !spec.objcDisableClassCtor) writeInitializer("+", IdentStyle.camelLower(objcName), firstReqInitializerArg, r.reqFields) + } for (c <- r.consts if !marshal.canBeConstVariable(c)) { w.wl @@ -241,7 +259,11 @@ class ObjcGenerator(spec: Spec) extends BaseObjcGenerator(spec) { w.wl writeDoc(w, f.doc) val nullability = marshal.nullability(f.ty.resolved).fold("")(", " + _) - w.wl(s"@property (nonatomic, readonly${nullability}) ${marshal.fqFieldType(f.ty)} ${idObjc.field(f.ident)};") + + // If using legacy constructors, add the readonly property. Otherwise determine if the + // copy property is necessary + val readOnly = if (spec.objcLegacyRecords) ", readonly" else if (checkMutable(f.ty.resolved)) ", copy" else "" + w.wl(s"@property (nonatomic${readOnly}${nullability}) ${marshal.fqFieldType(f.ty)} ${idObjc.field(f.ident)};") } if (r.derivingTypes.contains(DerivingType.Ord)) { w.wl @@ -264,38 +286,67 @@ class ObjcGenerator(spec: Spec) extends BaseObjcGenerator(spec) { // Generate the implementation file for record writeObjcFile(bodyName(objcName), origin, refs.body, w => { if (r.consts.nonEmpty) generateObjcConstants(w, r.consts, noBaseSelf, ObjcConstantType.ConstVariable) - + w.wl w.wl(s"@implementation $self") w.wl - // Constructor from all fields (not copying) - val init = s"- (nonnull instancetype)init$firstInitializerArg" - writeAlignedObjcCall(w, init, r.fields, "", f => (idObjc.field(f.ident), s"(${marshal.paramType(f.ty)})${idObjc.local(f.ident)}")) - w.wl - w.braced { - w.w("if (self = [super init])").braced { - for (f <- r.fields) { - if (checkMutable(f.ty.resolved)) - w.wl(s"_${idObjc.field(f.ident)} = [${idObjc.local(f.ident)} copy];") - else - w.wl(s"_${idObjc.field(f.ident)} = ${idObjc.local(f.ident)};") + + def writeConstructor(firstInitArg: String, reqFields: Seq[Field]) { + var init = s"- (nonnull instancetype)init$firstInitArg" + writeAlignedObjcCall(w, init, reqFields, "", f => (idObjc.field(f.ident), s"(${marshal.paramType(f.ty)})${idObjc.local(f.ident)}")) + w.wl + w.braced { + // Optional constructor or full constructor + if (reqFields.size != r.fields.size) { + val decl = s"self = [self init$firstInitializerArg" + writeAlignedObjcCall(w, decl, r.fields, "", f => { + (idObjc.field(f.ident), if (isOptional(f.ty.resolved)) "nil" else s"${idObjc.local(f.ident)}") + }) + w.wl("];") + } else { + w.w("if (self = [super init])").braced { + for (f <- reqFields) { + if (checkMutable(f.ty.resolved)) + w.wl(s"_${idObjc.field(f.ident)} = [${idObjc.local(f.ident)} copy];") + else + w.wl(s"_${idObjc.field(f.ident)} = ${idObjc.local(f.ident)};") + } + } } + w.wl("return self;") } - w.wl("return self;") + w.wl + } + + // Constructor from all fields (not copying) (requiring all) + writeConstructor(firstInitializerArg, r.fields) + + // Write constructor with optionals if necessary + if (!requireOptionals && r.reqFields.size != r.fields.size) { + writeConstructor(firstReqInitializerArg, r.reqFields) } - w.wl // Convenience initializer if(!r.ext.objc && !spec.objcDisableClassCtor) { - val decl = s"+ (nonnull instancetype)${IdentStyle.camelLower(objcName)}$firstInitializerArg" - writeAlignedObjcCall(w, decl, r.fields, "", f => (idObjc.field(f.ident), s"(${marshal.paramType(f.ty)})${idObjc.local(f.ident)}")) - w.wl - w.braced { - val call = s"return [[self alloc] init$firstInitializerArg" - writeAlignedObjcCall(w, call, r.fields, "", f => (idObjc.field(f.ident), s"${idObjc.local(f.ident)}")) - w.wl("];") + def writeConvenienceInitializer(firstInitArg: String, reqFields: Seq[Field]) = { + val decl = s"+ (nonnull instancetype)${IdentStyle.camelLower(objcName)}$firstInitArg" + writeAlignedObjcCall(w, decl, reqFields, "", f => (idObjc.field(f.ident), s"(${marshal.paramType(f.ty)})${idObjc.local(f.ident)}")) + w.wl + w.braced { + val call = s"return [[self alloc] init$firstInitArg" + writeAlignedObjcCall(w, call, reqFields, "", f => (idObjc.field(f.ident), s"${idObjc.local(f.ident)}")) + w.wl("];") + } + w.wl + } + + if (shouldWriteFullConvenienceConstructor) { + writeConvenienceInitializer(firstInitializerArg, r.fields) + } + + if (!requireOptionals && r.reqFields.size != r.fields.size) { + writeConvenienceInitializer(firstReqInitializerArg, r.reqFields) } - w.wl } if (r.consts.nonEmpty) generateObjcConstants(w, r.consts, noBaseSelf, ObjcConstantType.ConstMethod) diff --git a/src/source/YamlGenerator.scala b/src/source/YamlGenerator.scala index 91d160ce..ec75027a 100644 --- a/src/source/YamlGenerator.scala +++ b/src/source/YamlGenerator.scala @@ -124,6 +124,7 @@ class YamlGenerator(spec: Spec) extends Generator(spec) { case Record.DerivingType.Ord => "ord" case Record.DerivingType.AndroidParcelable => "parcelable" case Record.DerivingType.NSCopying => "nscopying" + case Record.DerivingType.Req => "req" }.mkString(" deriving(", ", ", ")") } } diff --git a/src/source/ast.scala b/src/source/ast.scala index 353c2a8b..e65a9da2 100644 --- a/src/source/ast.scala +++ b/src/source/ast.scala @@ -21,6 +21,7 @@ package djinni.ast import java.io.File import djinni.ast.Record.DerivingType.DerivingType import djinni.meta.MExpr +import djinni.meta.isOptional import djinni.syntax.Loc case class IdlFile(imports: Seq[FileRef], typeDecls: Seq[TypeDecl], flags: Seq[String]) @@ -75,11 +76,16 @@ object Enum { case class Option(ident: Ident, doc: Doc, specialFlag: scala.Option[SpecialFlag]) } -case class Record(ext: Ext, fields: Seq[Field], consts: Seq[Const], derivingTypes: Set[DerivingType]) extends TypeDef +case class Record(ext: Ext, fields: Seq[Field], consts: Seq[Const], derivingTypes: Set[DerivingType]) extends TypeDef { + // Returns only non-optional fields contained in the record + def reqFields = { + fields.filterNot(f => isOptional(f.ty.resolved)) + } +} object Record { object DerivingType extends Enumeration { type DerivingType = Value - val Eq, Ord, AndroidParcelable, NSCopying = Value + val Eq, Ord, AndroidParcelable, NSCopying, Req = Value } } diff --git a/src/source/generator.scala b/src/source/generator.scala index 907041d4..f9c1d319 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -42,6 +42,7 @@ package object generatorTools { javaImplementAndroidOsParcelable: Boolean, javaUseFinalForRecord: Boolean, javaGenInterface: Boolean, + javaLegacyRecords: Boolean, cppOutFolder: Option[File], cppHeaderOutFolder: Option[File], cppIncludePrefix: String, @@ -52,11 +53,13 @@ package object generatorTools { cppBaseLibIncludePrefix: String, cppOptionalTemplate: String, cppOptionalHeader: String, + cppNulloptValue: String, cppEnumHashWorkaround: Boolean, cppNnHeader: Option[String], cppNnType: Option[String], cppNnCheckExpression: Option[String], cppUseWideStrings: Boolean, + cppLegacyRecords: Boolean, jniOutFolder: Option[File], jniHeaderOutFolder: Option[File], jniIncludePrefix: String, @@ -90,6 +93,8 @@ package object generatorTools { objcDisableClassCtor: Boolean, objcClosedEnums: Boolean, objcStrictProtocol: Boolean, + objcLegacyRecords: Boolean, + objcOmitFullConvenienceConstructor: Boolean, wasmOutFolder: Option[File], wasmIncludePrefix: String, wasmIncludeCppPrefix: String, diff --git a/src/source/parser.scala b/src/source/parser.scala index 9f267710..98a40882 100644 --- a/src/source/parser.scala +++ b/src/source/parser.scala @@ -139,6 +139,7 @@ private object IdlParser extends RegexParsers { case "ord" => Record.DerivingType.Ord case "parcelable" => Record.DerivingType.AndroidParcelable case "nscopying" => Record.DerivingType.NSCopying + case "req" => Record.DerivingType.Req case _ => return err( s"""Unrecognized deriving type "${ident.name}"""") }).toSet } diff --git a/test-suite/djinni/optionals.djinni b/test-suite/djinni/optionals.djinni new file mode 100644 index 00000000..fa836368 --- /dev/null +++ b/test-suite/djinni/optionals.djinni @@ -0,0 +1,41 @@ +# Blank interface used for testing +optional_interface = interface +c { +} + +# Base record with a required value +base_record = record { + val: i32; +} + +# Record with a mix of optional and required values +mixed_record = record { + interfaceVal: optional; + reqInt: i32; + optRecord: optional; + reqRecord: base_record; +} + +# Record containing only optional values +optional_record = record { + optInt: optional; + optInterface: optional; + optRecord: optional; +} + +# Overridden optional record +override_record = record { + optInt: optional; + optFloat: optional; + reqInt: i32; + optDouble: optional; +} deriving(req) + +optional_test_helpers = interface +c { + static get_base_record() : base_record; + static optional_interface() : optional_interface; + static get_mixed_record() : mixed_record; + static get_optional_record() : optional_record; + + # Checks that translation occurs properly + static mixed_record_id(i: mixed_record) : mixed_record; +} \ No newline at end of file diff --git a/test-suite/generated-src/cpp/assorted_primitives.hpp b/test-suite/generated-src/cpp/assorted_primitives.hpp index fa30782e..ca9e03ad 100644 --- a/test-suite/generated-src/cpp/assorted_primitives.hpp +++ b/test-suite/generated-src/cpp/assorted_primitives.hpp @@ -57,6 +57,29 @@ struct AssortedPrimitives final { , o_fthirtytwo(std::move(o_fthirtytwo_)) , o_fsixtyfour(std::move(o_fsixtyfour_)) {} + + AssortedPrimitives(bool b_, + int8_t eight_, + int16_t sixteen_, + int32_t thirtytwo_, + int64_t sixtyfour_, + float fthirtytwo_, + double fsixtyfour_) + : AssortedPrimitives(std::move(b_), + std::move(eight_), + std::move(sixteen_), + std::move(thirtytwo_), + std::move(sixtyfour_), + std::move(fthirtytwo_), + std::move(fsixtyfour_), + std::experimental::nullopt, + std::experimental::nullopt, + std::experimental::nullopt, + std::experimental::nullopt, + std::experimental::nullopt, + std::experimental::nullopt, + std::experimental::nullopt) + {} }; } // namespace testsuite diff --git a/test-suite/generated-src/cpp/base_record.hpp b/test-suite/generated-src/cpp/base_record.hpp new file mode 100644 index 00000000..a7e4a29d --- /dev/null +++ b/test-suite/generated-src/cpp/base_record.hpp @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include +#include + +namespace testsuite { + +/** Base record with a required value */ +struct BaseRecord final { + int32_t val; + + //NOLINTNEXTLINE(google-explicit-constructor) + BaseRecord(int32_t val_) + : val(std::move(val_)) + {} +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/client_returned_record.hpp b/test-suite/generated-src/cpp/client_returned_record.hpp index 1e7d967c..1cb82d2e 100644 --- a/test-suite/generated-src/cpp/client_returned_record.hpp +++ b/test-suite/generated-src/cpp/client_returned_record.hpp @@ -23,6 +23,13 @@ struct ClientReturnedRecord final { , content(std::move(content_)) , misc(std::move(misc_)) {} + + ClientReturnedRecord(int64_t record_id_, + std::string content_) + : ClientReturnedRecord(std::move(record_id_), + std::move(content_), + std::experimental::nullopt) + {} }; } // namespace testsuite diff --git a/test-suite/generated-src/cpp/enum_usage_record.hpp b/test-suite/generated-src/cpp/enum_usage_record.hpp index ae5dd6a6..f9edfa53 100644 --- a/test-suite/generated-src/cpp/enum_usage_record.hpp +++ b/test-suite/generated-src/cpp/enum_usage_record.hpp @@ -30,6 +30,17 @@ struct EnumUsageRecord final { , s(std::move(s_)) , m(std::move(m_)) {} + + EnumUsageRecord(color e_, + std::vector l_, + std::unordered_set s_, + std::unordered_map m_) + : EnumUsageRecord(std::move(e_), + std::experimental::nullopt, + std::move(l_), + std::move(s_), + std::move(m_)) + {} }; } // namespace testsuite diff --git a/test-suite/generated-src/cpp/mixed_record.hpp b/test-suite/generated-src/cpp/mixed_record.hpp new file mode 100644 index 00000000..b9a7f3e9 --- /dev/null +++ b/test-suite/generated-src/cpp/mixed_record.hpp @@ -0,0 +1,42 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "../../handwritten-src/cpp/optional.hpp" +#include "base_record.hpp" +#include +#include +#include + +namespace testsuite { + +class OptionalInterface; + +/** Record with a mix of optional and required values */ +struct MixedRecord final { + /*nullable*/ std::shared_ptr interfaceVal; + int32_t reqInt; + std::experimental::optional optRecord; + BaseRecord reqRecord; + + MixedRecord(/*nullable*/ std::shared_ptr interfaceVal_, + int32_t reqInt_, + std::experimental::optional optRecord_, + BaseRecord reqRecord_) + : interfaceVal(std::move(interfaceVal_)) + , reqInt(std::move(reqInt_)) + , optRecord(std::move(optRecord_)) + , reqRecord(std::move(reqRecord_)) + {} + + MixedRecord(int32_t reqInt_, + BaseRecord reqRecord_) + : MixedRecord(nullptr, + std::move(reqInt_), + std::experimental::nullopt, + std::move(reqRecord_)) + {} +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/optional_interface.hpp b/test-suite/generated-src/cpp/optional_interface.hpp new file mode 100644 index 00000000..d52dcbdd --- /dev/null +++ b/test-suite/generated-src/cpp/optional_interface.hpp @@ -0,0 +1,14 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +namespace testsuite { + +/** Blank interface used for testing */ +class OptionalInterface { +public: + virtual ~OptionalInterface() = default; +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/optional_record.hpp b/test-suite/generated-src/cpp/optional_record.hpp new file mode 100644 index 00000000..0d126fe5 --- /dev/null +++ b/test-suite/generated-src/cpp/optional_record.hpp @@ -0,0 +1,37 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "../../handwritten-src/cpp/optional.hpp" +#include "base_record.hpp" +#include +#include +#include + +namespace testsuite { + +class OptionalInterface; + +/** Record containing only optional values */ +struct OptionalRecord final { + std::experimental::optional optInt; + /*nullable*/ std::shared_ptr optInterface; + std::experimental::optional optRecord; + + OptionalRecord(std::experimental::optional optInt_, + /*nullable*/ std::shared_ptr optInterface_, + std::experimental::optional optRecord_) + : optInt(std::move(optInt_)) + , optInterface(std::move(optInterface_)) + , optRecord(std::move(optRecord_)) + {} + + OptionalRecord() + : OptionalRecord(std::experimental::nullopt, + nullptr, + std::experimental::nullopt) + {} +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/optional_test_helpers.hpp b/test-suite/generated-src/cpp/optional_test_helpers.hpp new file mode 100644 index 00000000..d04ec3b3 --- /dev/null +++ b/test-suite/generated-src/cpp/optional_test_helpers.hpp @@ -0,0 +1,31 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include + +namespace testsuite { + +class OptionalInterface; +struct BaseRecord; +struct MixedRecord; +struct OptionalRecord; + +class OptionalTestHelpers { +public: + virtual ~OptionalTestHelpers() = default; + + static BaseRecord get_base_record(); + + static /*not-null*/ std::shared_ptr optional_interface(); + + static MixedRecord get_mixed_record(); + + static OptionalRecord get_optional_record(); + + /** Checks that translation occurs properly */ + static MixedRecord mixed_record_id(const MixedRecord & i); +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/override_record.hpp b/test-suite/generated-src/cpp/override_record.hpp new file mode 100644 index 00000000..40718d8b --- /dev/null +++ b/test-suite/generated-src/cpp/override_record.hpp @@ -0,0 +1,30 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "../../handwritten-src/cpp/optional.hpp" +#include +#include + +namespace testsuite { + +/** Overridden optional record */ +struct OverrideRecord final { + std::experimental::optional optInt; + std::experimental::optional optFloat; + int32_t reqInt; + std::experimental::optional optDouble; + + OverrideRecord(std::experimental::optional optInt_, + std::experimental::optional optFloat_, + int32_t reqInt_, + std::experimental::optional optDouble_) + : optInt(std::move(optInt_)) + , optFloat(std::move(optFloat_)) + , reqInt(std::move(reqInt_)) + , optDouble(std::move(optDouble_)) + {} +}; + +} // namespace testsuite diff --git a/test-suite/generated-src/cpp/test_optional_extern_interface_record.hpp b/test-suite/generated-src/cpp/test_optional_extern_interface_record.hpp index 03c7dcbb..0f9046df 100644 --- a/test-suite/generated-src/cpp/test_optional_extern_interface_record.hpp +++ b/test-suite/generated-src/cpp/test_optional_extern_interface_record.hpp @@ -15,4 +15,8 @@ struct TestOptionalExternInterfaceRecord final { TestOptionalExternInterfaceRecord(/*nullable*/ std::shared_ptr<::testsuite::SampleInterface> sample_interface_) : sample_interface(std::move(sample_interface_)) {} + + TestOptionalExternInterfaceRecord() + : TestOptionalExternInterfaceRecord(nullptr) + {} }; diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/AssortedPrimitives.java b/test-suite/generated-src/java/com/dropbox/djinni/test/AssortedPrimitives.java index f2185ed6..38eee6c9 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/AssortedPrimitives.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/AssortedPrimitives.java @@ -9,33 +9,33 @@ public class AssortedPrimitives implements android.os.Parcelable { - /*package*/ final boolean mB; + /*package*/ boolean mB; - /*package*/ final byte mEight; + /*package*/ byte mEight; - /*package*/ final short mSixteen; + /*package*/ short mSixteen; - /*package*/ final int mThirtytwo; + /*package*/ int mThirtytwo; - /*package*/ final long mSixtyfour; + /*package*/ long mSixtyfour; - /*package*/ final float mFthirtytwo; + /*package*/ float mFthirtytwo; - /*package*/ final double mFsixtyfour; + /*package*/ double mFsixtyfour; - /*package*/ final Boolean mOB; + /*package*/ /*optional*/ Boolean mOB; - /*package*/ final Byte mOEight; + /*package*/ /*optional*/ Byte mOEight; - /*package*/ final Short mOSixteen; + /*package*/ /*optional*/ Short mOSixteen; - /*package*/ final Integer mOThirtytwo; + /*package*/ /*optional*/ Integer mOThirtytwo; - /*package*/ final Long mOSixtyfour; + /*package*/ /*optional*/ Long mOSixtyfour; - /*package*/ final Float mOFthirtytwo; + /*package*/ /*optional*/ Float mOFthirtytwo; - /*package*/ final Double mOFsixtyfour; + /*package*/ /*optional*/ Double mOFsixtyfour; public AssortedPrimitives( boolean b, @@ -68,69 +68,149 @@ public AssortedPrimitives( this.mOFsixtyfour = oFsixtyfour; } + public AssortedPrimitives( + boolean b, + byte eight, + short sixteen, + int thirtytwo, + long sixtyfour, + float fthirtytwo, + double fsixtyfour) { + this(b, + eight, + sixteen, + thirtytwo, + sixtyfour, + fthirtytwo, + fsixtyfour, + null, + null, + null, + null, + null, + null, + null); + } + public boolean getB() { return mB; } + public void setB(boolean b) { + this.mB = b; + } + public byte getEight() { return mEight; } + public void setEight(byte eight) { + this.mEight = eight; + } + public short getSixteen() { return mSixteen; } + public void setSixteen(short sixteen) { + this.mSixteen = sixteen; + } + public int getThirtytwo() { return mThirtytwo; } + public void setThirtytwo(int thirtytwo) { + this.mThirtytwo = thirtytwo; + } + public long getSixtyfour() { return mSixtyfour; } + public void setSixtyfour(long sixtyfour) { + this.mSixtyfour = sixtyfour; + } + public float getFthirtytwo() { return mFthirtytwo; } + public void setFthirtytwo(float fthirtytwo) { + this.mFthirtytwo = fthirtytwo; + } + public double getFsixtyfour() { return mFsixtyfour; } + public void setFsixtyfour(double fsixtyfour) { + this.mFsixtyfour = fsixtyfour; + } + @CheckForNull public Boolean getOB() { return mOB; } + public void setOB(Boolean oB) { + this.mOB = oB; + } + @CheckForNull public Byte getOEight() { return mOEight; } + public void setOEight(Byte oEight) { + this.mOEight = oEight; + } + @CheckForNull public Short getOSixteen() { return mOSixteen; } + public void setOSixteen(Short oSixteen) { + this.mOSixteen = oSixteen; + } + @CheckForNull public Integer getOThirtytwo() { return mOThirtytwo; } + public void setOThirtytwo(Integer oThirtytwo) { + this.mOThirtytwo = oThirtytwo; + } + @CheckForNull public Long getOSixtyfour() { return mOSixtyfour; } + public void setOSixtyfour(Long oSixtyfour) { + this.mOSixtyfour = oSixtyfour; + } + @CheckForNull public Float getOFthirtytwo() { return mOFthirtytwo; } + public void setOFthirtytwo(Float oFthirtytwo) { + this.mOFthirtytwo = oFthirtytwo; + } + @CheckForNull public Double getOFsixtyfour() { return mOFsixtyfour; } + public void setOFsixtyfour(Double oFsixtyfour) { + this.mOFsixtyfour = oFsixtyfour; + } + @Override public boolean equals(@CheckForNull Object obj) { if (!(obj instanceof AssortedPrimitives)) { diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/BaseRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/BaseRecord.java new file mode 100644 index 00000000..123e3a16 --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/BaseRecord.java @@ -0,0 +1,35 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +package com.dropbox.djinni.test; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +/** Base record with a required value */ +public class BaseRecord { + + + /*package*/ int mVal; + + public BaseRecord( + int val) { + this.mVal = val; + } + + public int getVal() { + return mVal; + } + + public void setVal(int val) { + this.mVal = val; + } + + @Override + public String toString() { + return "BaseRecord{" + + "mVal=" + mVal + + "}"; + } + +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ClientReturnedRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ClientReturnedRecord.java index 43cac50f..6166d208 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ClientReturnedRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ClientReturnedRecord.java @@ -10,11 +10,11 @@ public class ClientReturnedRecord { - /*package*/ final long mRecordId; + /*package*/ long mRecordId; - /*package*/ final String mContent; + /*package*/ String mContent; - /*package*/ final String mMisc; + /*package*/ /*optional*/ String mMisc; public ClientReturnedRecord( long recordId, @@ -25,20 +25,40 @@ public ClientReturnedRecord( this.mMisc = misc; } + public ClientReturnedRecord( + long recordId, + @Nonnull String content) { + this(recordId, + content, + null); + } + public long getRecordId() { return mRecordId; } + public void setRecordId(long recordId) { + this.mRecordId = recordId; + } + @Nonnull public String getContent() { return mContent; } + public void setContent(@Nonnull String content) { + this.mContent = content; + } + @CheckForNull public String getMisc() { return mMisc; } + public void setMisc(String misc) { + this.mMisc = misc; + } + @Override public String toString() { return "ClientReturnedRecord{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ConstantRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ConstantRecord.java index 083bef5d..103c54e7 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ConstantRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ConstantRecord.java @@ -10,9 +10,9 @@ public class ConstantRecord { - /*package*/ final int mSomeInteger; + /*package*/ int mSomeInteger; - /*package*/ final String mSomeString; + /*package*/ String mSomeString; public ConstantRecord( int someInteger, @@ -25,11 +25,19 @@ public int getSomeInteger() { return mSomeInteger; } + public void setSomeInteger(int someInteger) { + this.mSomeInteger = someInteger; + } + @Nonnull public String getSomeString() { return mSomeString; } + public void setSomeString(@Nonnull String someString) { + this.mSomeString = someString; + } + @Override public String toString() { return "ConstantRecord{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ConstantWithEnum.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ConstantWithEnum.java index 4892f141..d2688f7f 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ConstantWithEnum.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ConstantWithEnum.java @@ -13,8 +13,7 @@ public class ConstantWithEnum { public static final ConstantEnum CONST_ENUM = ConstantEnum.SOME_VALUE; - public ConstantWithEnum( - ) { + public ConstantWithEnum() { } @Override diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/Constants.java b/test-suite/generated-src/java/com/dropbox/djinni/test/Constants.java index 045ab424..c6df650a 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/Constants.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/Constants.java @@ -75,8 +75,7 @@ public class Constants { public static final boolean DUMMY = false; - public Constants( - ) { + public Constants() { } @Override diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/DateRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/DateRecord.java index 5dcb6f56..89baf883 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/DateRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/DateRecord.java @@ -9,7 +9,7 @@ public class DateRecord implements Comparable, android.os.Parcelable { - /*package*/ final java.util.Date mCreatedAt; + /*package*/ java.util.Date mCreatedAt; public DateRecord( @Nonnull java.util.Date createdAt) { @@ -21,6 +21,10 @@ public java.util.Date getCreatedAt() { return mCreatedAt; } + public void setCreatedAt(@Nonnull java.util.Date createdAt) { + this.mCreatedAt = createdAt; + } + @Override public boolean equals(@CheckForNull Object obj) { if (!(obj instanceof DateRecord)) { diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/EmptyRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/EmptyRecord.java index 5f164d05..fe87259d 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/EmptyRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/EmptyRecord.java @@ -14,8 +14,7 @@ public class EmptyRecord { - public EmptyRecord( - ) { + public EmptyRecord() { } @Override diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/EnumUsageRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/EnumUsageRecord.java index 325f6446..ca399a3b 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/EnumUsageRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/EnumUsageRecord.java @@ -12,15 +12,15 @@ public class EnumUsageRecord implements android.os.Parcelable { - /*package*/ final Color mE; + /*package*/ Color mE; - /*package*/ final Color mO; + /*package*/ /*optional*/ Color mO; - /*package*/ final ArrayList mL; + /*package*/ ArrayList mL; - /*package*/ final HashSet mS; + /*package*/ HashSet mS; - /*package*/ final HashMap mM; + /*package*/ HashMap mM; public EnumUsageRecord( @Nonnull Color e, @@ -35,31 +35,63 @@ public EnumUsageRecord( this.mM = m; } + public EnumUsageRecord( + @Nonnull Color e, + @Nonnull ArrayList l, + @Nonnull HashSet s, + @Nonnull HashMap m) { + this(e, + null, + l, + s, + m); + } + @Nonnull public Color getE() { return mE; } + public void setE(@Nonnull Color e) { + this.mE = e; + } + @CheckForNull public Color getO() { return mO; } + public void setO(Color o) { + this.mO = o; + } + @Nonnull public ArrayList getL() { return mL; } + public void setL(@Nonnull ArrayList l) { + this.mL = l; + } + @Nonnull public HashSet getS() { return mS; } + public void setS(@Nonnull HashSet s) { + this.mS = s; + } + @Nonnull public HashMap getM() { return mM; } + public void setM(@Nonnull HashMap m) { + this.mM = m; + } + @Override public String toString() { return "EnumUsageRecord{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ExtendedRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ExtendedRecord.java index b299d6f2..c1a3c663 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ExtendedRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ExtendedRecord.java @@ -14,7 +14,7 @@ public class ExtendedRecord { true /* mFoo */ ); - /*package*/ final boolean mFoo; + /*package*/ boolean mFoo; public ExtendedRecord( boolean foo) { @@ -25,6 +25,10 @@ public boolean getFoo() { return mFoo; } + public void setFoo(boolean foo) { + this.mFoo = foo; + } + @Override public String toString() { return "ExtendedRecord{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/ExternRecordWithDerivings.java b/test-suite/generated-src/java/com/dropbox/djinni/test/ExternRecordWithDerivings.java index 44933a18..7dc965c3 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/ExternRecordWithDerivings.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/ExternRecordWithDerivings.java @@ -7,9 +7,9 @@ public final class ExternRecordWithDerivings implements Comparable { - /*package*/ final com.dropbox.djinni.test.RecordWithDerivings mMember; + /*package*/ com.dropbox.djinni.test.RecordWithDerivings mMember; - /*package*/ final com.dropbox.djinni.test.Color mE; + /*package*/ com.dropbox.djinni.test.Color mE; public ExternRecordWithDerivings( com.dropbox.djinni.test.RecordWithDerivings member, @@ -22,10 +22,18 @@ public com.dropbox.djinni.test.RecordWithDerivings getMember() { return mMember; } + public void setMember(com.dropbox.djinni.test.RecordWithDerivings member) { + this.mMember = member; + } + public com.dropbox.djinni.test.Color getE() { return mE; } + public void setE(com.dropbox.djinni.test.Color e) { + this.mE = e; + } + @Override public boolean equals(Object obj) { if (!(obj instanceof ExternRecordWithDerivings)) { diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/MapDateRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/MapDateRecord.java index c6a220c0..3a048426 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/MapDateRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/MapDateRecord.java @@ -10,7 +10,7 @@ public class MapDateRecord { - /*package*/ final HashMap mDatesById; + /*package*/ HashMap mDatesById; public MapDateRecord( @Nonnull HashMap datesById) { @@ -22,6 +22,10 @@ public HashMap getDatesById() { return mDatesById; } + public void setDatesById(@Nonnull HashMap datesById) { + this.mDatesById = datesById; + } + @Override public String toString() { return "MapDateRecord{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/MapListRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/MapListRecord.java index bf1f3dd7..f2bf078e 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/MapListRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/MapListRecord.java @@ -11,7 +11,7 @@ public class MapListRecord { - /*package*/ final ArrayList> mMapList; + /*package*/ ArrayList> mMapList; public MapListRecord( @Nonnull ArrayList> mapList) { @@ -23,6 +23,10 @@ public ArrayList> getMapList() { return mMapList; } + public void setMapList(@Nonnull ArrayList> mapList) { + this.mMapList = mapList; + } + @Override public String toString() { return "MapListRecord{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/MapRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/MapRecord.java index 07cca353..bf283aae 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/MapRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/MapRecord.java @@ -10,9 +10,9 @@ public class MapRecord { - /*package*/ final HashMap mMap; + /*package*/ HashMap mMap; - /*package*/ final HashMap mImap; + /*package*/ HashMap mImap; public MapRecord( @Nonnull HashMap map, @@ -26,11 +26,19 @@ public HashMap getMap() { return mMap; } + public void setMap(@Nonnull HashMap map) { + this.mMap = map; + } + @Nonnull public HashMap getImap() { return mImap; } + public void setImap(@Nonnull HashMap imap) { + this.mImap = imap; + } + @Override public String toString() { return "MapRecord{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/MixedRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/MixedRecord.java new file mode 100644 index 00000000..d4d7d123 --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/MixedRecord.java @@ -0,0 +1,86 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +package com.dropbox.djinni.test; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +/** Record with a mix of optional and required values */ +public class MixedRecord { + + + /*package*/ /*optional*/ OptionalInterface mInterfaceVal; + + /*package*/ int mReqInt; + + /*package*/ /*optional*/ BaseRecord mOptRecord; + + /*package*/ BaseRecord mReqRecord; + + public MixedRecord( + @CheckForNull OptionalInterface interfaceVal, + int reqInt, + @CheckForNull BaseRecord optRecord, + @Nonnull BaseRecord reqRecord) { + this.mInterfaceVal = interfaceVal; + this.mReqInt = reqInt; + this.mOptRecord = optRecord; + this.mReqRecord = reqRecord; + } + + public MixedRecord( + int reqInt, + @Nonnull BaseRecord reqRecord) { + this(null, + reqInt, + null, + reqRecord); + } + + @CheckForNull + public OptionalInterface getInterfaceVal() { + return mInterfaceVal; + } + + public void setInterfaceVal(OptionalInterface interfaceVal) { + this.mInterfaceVal = interfaceVal; + } + + public int getReqInt() { + return mReqInt; + } + + public void setReqInt(int reqInt) { + this.mReqInt = reqInt; + } + + @CheckForNull + public BaseRecord getOptRecord() { + return mOptRecord; + } + + public void setOptRecord(BaseRecord optRecord) { + this.mOptRecord = optRecord; + } + + @Nonnull + public BaseRecord getReqRecord() { + return mReqRecord; + } + + public void setReqRecord(@Nonnull BaseRecord reqRecord) { + this.mReqRecord = reqRecord; + } + + @Override + public String toString() { + return "MixedRecord{" + + "mInterfaceVal=" + mInterfaceVal + + "," + "mReqInt=" + mReqInt + + "," + "mOptRecord=" + mOptRecord + + "," + "mReqRecord=" + mReqRecord + + "}"; + } + +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/NativeTestIdentRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/NativeTestIdentRecord.java index 54915384..c662a1bb 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/NativeTestIdentRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/NativeTestIdentRecord.java @@ -15,9 +15,9 @@ public class NativeTestIdentRecord { public static final int XXXWEIRD_CASE = 1; - /*package*/ final int mFirstValue; + /*package*/ int mFirstValue; - /*package*/ final String mSecondValue; + /*package*/ String mSecondValue; public NativeTestIdentRecord( int FirstValue, @@ -30,11 +30,19 @@ public int getFirstValue() { return mFirstValue; } + public void setFirstValue(int FirstValue) { + this.mFirstValue = FirstValue; + } + @Nonnull public String getSecondValue() { return mSecondValue; } + public void setSecondValue(@Nonnull String secondValue) { + this.mSecondValue = secondValue; + } + @Override public String toString() { return "NativeTestIdentRecord{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/NestedCollection.java b/test-suite/generated-src/java/com/dropbox/djinni/test/NestedCollection.java index 528ac114..b9817dcf 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/NestedCollection.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/NestedCollection.java @@ -11,7 +11,7 @@ public class NestedCollection implements android.os.Parcelable { - /*package*/ final ArrayList> mSetList; + /*package*/ ArrayList> mSetList; public NestedCollection( @Nonnull ArrayList> setList) { @@ -23,6 +23,10 @@ public ArrayList> getSetList() { return mSetList; } + public void setSetList(@Nonnull ArrayList> setList) { + this.mSetList = setList; + } + @Override public String toString() { return "NestedCollection{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/NestedOutcome.java b/test-suite/generated-src/java/com/dropbox/djinni/test/NestedOutcome.java index 9a665e6c..0a81ddc7 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/NestedOutcome.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/NestedOutcome.java @@ -9,7 +9,7 @@ public class NestedOutcome { - /*package*/ final com.snapchat.djinni.Outcome mO; + /*package*/ com.snapchat.djinni.Outcome mO; public NestedOutcome( @Nonnull com.snapchat.djinni.Outcome o) { @@ -21,6 +21,10 @@ public com.snapchat.djinni.Outcome getO() { return mO; } + public void setO(@Nonnull com.snapchat.djinni.Outcome o) { + this.mO = o; + } + @Override public boolean equals(@CheckForNull Object obj) { if (!(obj instanceof NestedOutcome)) { diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/OptionalInterface.java b/test-suite/generated-src/java/com/dropbox/djinni/test/OptionalInterface.java new file mode 100644 index 00000000..290aebc8 --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/OptionalInterface.java @@ -0,0 +1,27 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +package com.dropbox.djinni.test; + +import com.snapchat.djinni.NativeObjectManager; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +/** Blank interface used for testing */ +public abstract class OptionalInterface { + + public static final class CppProxy extends OptionalInterface + { + private final long nativeRef; + private final AtomicBoolean destroyed = new AtomicBoolean(false); + + private CppProxy(long nativeRef) + { + if (nativeRef == 0) throw new RuntimeException("nativeRef is zero"); + this.nativeRef = nativeRef; + NativeObjectManager.register(this, nativeRef); + } + public static native void nativeDestroy(long nativeRef); + } +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/OptionalRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/OptionalRecord.java new file mode 100644 index 00000000..52e6e447 --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/OptionalRecord.java @@ -0,0 +1,70 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +package com.dropbox.djinni.test; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +/** Record containing only optional values */ +public class OptionalRecord { + + + /*package*/ /*optional*/ Integer mOptInt; + + /*package*/ /*optional*/ OptionalInterface mOptInterface; + + /*package*/ /*optional*/ BaseRecord mOptRecord; + + public OptionalRecord( + @CheckForNull Integer optInt, + @CheckForNull OptionalInterface optInterface, + @CheckForNull BaseRecord optRecord) { + this.mOptInt = optInt; + this.mOptInterface = optInterface; + this.mOptRecord = optRecord; + } + + public OptionalRecord() { + this(null, + null, + null); + } + + @CheckForNull + public Integer getOptInt() { + return mOptInt; + } + + public void setOptInt(Integer optInt) { + this.mOptInt = optInt; + } + + @CheckForNull + public OptionalInterface getOptInterface() { + return mOptInterface; + } + + public void setOptInterface(OptionalInterface optInterface) { + this.mOptInterface = optInterface; + } + + @CheckForNull + public BaseRecord getOptRecord() { + return mOptRecord; + } + + public void setOptRecord(BaseRecord optRecord) { + this.mOptRecord = optRecord; + } + + @Override + public String toString() { + return "OptionalRecord{" + + "mOptInt=" + mOptInt + + "," + "mOptInterface=" + mOptInterface + + "," + "mOptRecord=" + mOptRecord + + "}"; + } + +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/OptionalTestHelpers.java b/test-suite/generated-src/java/com/dropbox/djinni/test/OptionalTestHelpers.java new file mode 100644 index 00000000..90bc371b --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/OptionalTestHelpers.java @@ -0,0 +1,41 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +package com.dropbox.djinni.test; + +import com.snapchat.djinni.NativeObjectManager; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +public abstract class OptionalTestHelpers { + @Nonnull + public static native BaseRecord getBaseRecord(); + + @CheckForNull + public static native OptionalInterface optionalInterface(); + + @Nonnull + public static native MixedRecord getMixedRecord(); + + @Nonnull + public static native OptionalRecord getOptionalRecord(); + + /** Checks that translation occurs properly */ + @Nonnull + public static native MixedRecord mixedRecordId(@Nonnull MixedRecord i); + + public static final class CppProxy extends OptionalTestHelpers + { + private final long nativeRef; + private final AtomicBoolean destroyed = new AtomicBoolean(false); + + private CppProxy(long nativeRef) + { + if (nativeRef == 0) throw new RuntimeException("nativeRef is zero"); + this.nativeRef = nativeRef; + NativeObjectManager.register(this, nativeRef); + } + public static native void nativeDestroy(long nativeRef); + } +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/OverrideRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/OverrideRecord.java new file mode 100644 index 00000000..caa174af --- /dev/null +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/OverrideRecord.java @@ -0,0 +1,77 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +package com.dropbox.djinni.test; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; + +/** Overridden optional record */ +public class OverrideRecord { + + + /*package*/ Integer mOptInt; + + /*package*/ Float mOptFloat; + + /*package*/ int mReqInt; + + /*package*/ Double mOptDouble; + + public OverrideRecord( + @CheckForNull Integer optInt, + @CheckForNull Float optFloat, + int reqInt, + @CheckForNull Double optDouble) { + this.mOptInt = optInt; + this.mOptFloat = optFloat; + this.mReqInt = reqInt; + this.mOptDouble = optDouble; + } + + @CheckForNull + public Integer getOptInt() { + return mOptInt; + } + + public void setOptInt(Integer optInt) { + this.mOptInt = optInt; + } + + @CheckForNull + public Float getOptFloat() { + return mOptFloat; + } + + public void setOptFloat(Float optFloat) { + this.mOptFloat = optFloat; + } + + public int getReqInt() { + return mReqInt; + } + + public void setReqInt(int reqInt) { + this.mReqInt = reqInt; + } + + @CheckForNull + public Double getOptDouble() { + return mOptDouble; + } + + public void setOptDouble(Double optDouble) { + this.mOptDouble = optDouble; + } + + @Override + public String toString() { + return "OverrideRecord{" + + "mOptInt=" + mOptInt + + "," + "mOptFloat=" + mOptFloat + + "," + "mReqInt=" + mReqInt + + "," + "mOptDouble=" + mOptDouble + + "}"; + } + +} diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/PrimitiveList.java b/test-suite/generated-src/java/com/dropbox/djinni/test/PrimitiveList.java index 5e6c5f48..81f2afc6 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/PrimitiveList.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/PrimitiveList.java @@ -10,7 +10,7 @@ public class PrimitiveList { - /*package*/ final ArrayList mList; + /*package*/ ArrayList mList; public PrimitiveList( @Nonnull ArrayList list) { @@ -22,6 +22,10 @@ public ArrayList getList() { return mList; } + public void setList(@Nonnull ArrayList list) { + this.mList = list; + } + @Override public String toString() { return "PrimitiveList{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordUsingExtendedRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordUsingExtendedRecord.java index 6fb81db1..977c6923 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordUsingExtendedRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordUsingExtendedRecord.java @@ -14,7 +14,7 @@ public class RecordUsingExtendedRecord { false /* mFoo */ ) /* mEr */ ); - /*package*/ final ExtendedRecord mEr; + /*package*/ ExtendedRecord mEr; public RecordUsingExtendedRecord( @Nonnull ExtendedRecord er) { @@ -26,6 +26,10 @@ public ExtendedRecord getEr() { return mEr; } + public void setEr(@Nonnull ExtendedRecord er) { + this.mEr = er; + } + @Override public String toString() { return "RecordUsingExtendedRecord{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithDerivings.java b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithDerivings.java index 3071794d..59ba1eaf 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithDerivings.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithDerivings.java @@ -10,21 +10,21 @@ public class RecordWithDerivings implements Comparable { - /*package*/ final byte mEight; + /*package*/ byte mEight; - /*package*/ final short mSixteen; + /*package*/ short mSixteen; - /*package*/ final int mThirtytwo; + /*package*/ int mThirtytwo; - /*package*/ final long mSixtyfour; + /*package*/ long mSixtyfour; - /*package*/ final float mFthirtytwo; + /*package*/ float mFthirtytwo; - /*package*/ final double mFsixtyfour; + /*package*/ double mFsixtyfour; - /*package*/ final Date mD; + /*package*/ Date mD; - /*package*/ final String mS; + /*package*/ String mS; public RecordWithDerivings( byte eight, @@ -49,36 +49,68 @@ public byte getEight() { return mEight; } + public void setEight(byte eight) { + this.mEight = eight; + } + public short getSixteen() { return mSixteen; } + public void setSixteen(short sixteen) { + this.mSixteen = sixteen; + } + public int getThirtytwo() { return mThirtytwo; } + public void setThirtytwo(int thirtytwo) { + this.mThirtytwo = thirtytwo; + } + public long getSixtyfour() { return mSixtyfour; } + public void setSixtyfour(long sixtyfour) { + this.mSixtyfour = sixtyfour; + } + public float getFthirtytwo() { return mFthirtytwo; } + public void setFthirtytwo(float fthirtytwo) { + this.mFthirtytwo = fthirtytwo; + } + public double getFsixtyfour() { return mFsixtyfour; } + public void setFsixtyfour(double fsixtyfour) { + this.mFsixtyfour = fsixtyfour; + } + @Nonnull public Date getD() { return mD; } + public void setD(@Nonnull Date d) { + this.mD = d; + } + @Nonnull public String getS() { return mS; } + public void setS(@Nonnull String s) { + this.mS = s; + } + @Override public boolean equals(@CheckForNull Object obj) { if (!(obj instanceof RecordWithDerivings)) { diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithDurationAndDerivings.java b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithDurationAndDerivings.java index dee966e5..391e1c3e 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithDurationAndDerivings.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithDurationAndDerivings.java @@ -9,7 +9,7 @@ public class RecordWithDurationAndDerivings implements Comparable { - /*package*/ final java.time.Duration mDt; + /*package*/ java.time.Duration mDt; public RecordWithDurationAndDerivings( @Nonnull java.time.Duration dt) { @@ -21,6 +21,10 @@ public java.time.Duration getDt() { return mDt; } + public void setDt(@Nonnull java.time.Duration dt) { + this.mDt = dt; + } + @Override public boolean equals(@CheckForNull Object obj) { if (!(obj instanceof RecordWithDurationAndDerivings)) { diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithEmbeddedCppProto.java b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithEmbeddedCppProto.java index 58dc9624..ef474175 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithEmbeddedCppProto.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithEmbeddedCppProto.java @@ -10,7 +10,7 @@ public class RecordWithEmbeddedCppProto { - /*package*/ final PersistingState mState; + /*package*/ PersistingState mState; public RecordWithEmbeddedCppProto( @Nonnull PersistingState state) { @@ -22,6 +22,10 @@ public PersistingState getState() { return mState; } + public void setState(@Nonnull PersistingState state) { + this.mState = state; + } + @Override public String toString() { return "RecordWithEmbeddedCppProto{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithEmbeddedProto.java b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithEmbeddedProto.java index e26cc23f..5bbc3148 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithEmbeddedProto.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithEmbeddedProto.java @@ -10,7 +10,7 @@ public class RecordWithEmbeddedProto { - /*package*/ final Person mPerson; + /*package*/ Person mPerson; public RecordWithEmbeddedProto( @Nonnull Person person) { @@ -22,6 +22,10 @@ public Person getPerson() { return mPerson; } + public void setPerson(@Nonnull Person person) { + this.mPerson = person; + } + @Override public String toString() { return "RecordWithEmbeddedProto{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithFlags.java b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithFlags.java index 0e1d29fd..fe4923c0 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithFlags.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithFlags.java @@ -10,7 +10,7 @@ public class RecordWithFlags { - /*package*/ final EnumSet mAccess; + /*package*/ EnumSet mAccess; public RecordWithFlags( @Nonnull EnumSet access) { @@ -22,6 +22,10 @@ public EnumSet getAccess() { return mAccess; } + public void setAccess(@Nonnull EnumSet access) { + this.mAccess = access; + } + @Override public String toString() { return "RecordWithFlags{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithNestedDerivings.java b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithNestedDerivings.java index 0da02fe5..b01cd968 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithNestedDerivings.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/RecordWithNestedDerivings.java @@ -9,9 +9,9 @@ public class RecordWithNestedDerivings implements Comparable { - /*package*/ final int mKey; + /*package*/ int mKey; - /*package*/ final RecordWithDerivings mRec; + /*package*/ RecordWithDerivings mRec; public RecordWithNestedDerivings( int key, @@ -24,11 +24,19 @@ public int getKey() { return mKey; } + public void setKey(int key) { + this.mKey = key; + } + @Nonnull public RecordWithDerivings getRec() { return mRec; } + public void setRec(@Nonnull RecordWithDerivings rec) { + this.mRec = rec; + } + @Override public boolean equals(@CheckForNull Object obj) { if (!(obj instanceof RecordWithNestedDerivings)) { diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/SetRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/SetRecord.java index e5c1b431..5fa62de4 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/SetRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/SetRecord.java @@ -10,9 +10,9 @@ public class SetRecord { - /*package*/ final HashSet mSet; + /*package*/ HashSet mSet; - /*package*/ final HashSet mIset; + /*package*/ HashSet mIset; public SetRecord( @Nonnull HashSet set, @@ -26,11 +26,19 @@ public HashSet getSet() { return mSet; } + public void setSet(@Nonnull HashSet set) { + this.mSet = set; + } + @Nonnull public HashSet getIset() { return mIset; } + public void setIset(@Nonnull HashSet iset) { + this.mIset = iset; + } + @Override public String toString() { return "SetRecord{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/SupportCopying.java b/test-suite/generated-src/java/com/dropbox/djinni/test/SupportCopying.java index 2065d4b7..28642296 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/SupportCopying.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/SupportCopying.java @@ -9,7 +9,7 @@ public class SupportCopying { - /*package*/ final int mX; + /*package*/ int mX; public SupportCopying( int x) { @@ -20,6 +20,10 @@ public int getX() { return mX; } + public void setX(int x) { + this.mX = x; + } + @Override public String toString() { return "SupportCopying{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/TestOptionalExternInterfaceRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/TestOptionalExternInterfaceRecord.java index 32fcbc38..1dce2d20 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/TestOptionalExternInterfaceRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/TestOptionalExternInterfaceRecord.java @@ -6,17 +6,25 @@ public final class TestOptionalExternInterfaceRecord { - /*package*/ final com.dropbox.djinni.test.SampleInterface mSampleInterface; + /*package*/ /*optional*/ com.dropbox.djinni.test.SampleInterface mSampleInterface; public TestOptionalExternInterfaceRecord( com.dropbox.djinni.test.SampleInterface sampleInterface) { this.mSampleInterface = sampleInterface; } + public TestOptionalExternInterfaceRecord() { + this(null); + } + public com.dropbox.djinni.test.SampleInterface getSampleInterface() { return mSampleInterface; } + public void setSampleInterface(com.dropbox.djinni.test.SampleInterface sampleInterface) { + this.mSampleInterface = sampleInterface; + } + @Override public String toString() { return "TestOptionalExternInterfaceRecord{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameRecord.java b/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameRecord.java index c304ee7b..de9440aa 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameRecord.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/VarnameRecord.java @@ -14,7 +14,7 @@ public class VarnameRecord { - /*package*/ final byte mField; + /*package*/ byte mField; public VarnameRecord( byte Field) { @@ -25,6 +25,10 @@ public byte getField() { return mField; } + public void setField(byte Field) { + this.mField = Field; + } + @Override public String toString() { return "VarnameRecord{" + diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/Vec2.java b/test-suite/generated-src/java/com/dropbox/djinni/test/Vec2.java index 17c919f7..065b69b4 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/Vec2.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/Vec2.java @@ -9,9 +9,9 @@ public class Vec2 { - /*package*/ final int mX; + /*package*/ int mX; - /*package*/ final int mY; + /*package*/ int mY; public Vec2( int x, @@ -24,10 +24,18 @@ public int getX() { return mX; } + public void setX(int x) { + this.mX = x; + } + public int getY() { return mY; } + public void setY(int y) { + this.mY = y; + } + @Override public boolean equals(@CheckForNull Object obj) { if (!(obj instanceof Vec2)) { diff --git a/test-suite/generated-src/java/com/dropbox/djinni/test/WcharTestRec.java b/test-suite/generated-src/java/com/dropbox/djinni/test/WcharTestRec.java index 379635f7..15a0e7d3 100644 --- a/test-suite/generated-src/java/com/dropbox/djinni/test/WcharTestRec.java +++ b/test-suite/generated-src/java/com/dropbox/djinni/test/WcharTestRec.java @@ -9,7 +9,7 @@ public class WcharTestRec { - /*package*/ final String mS; + /*package*/ String mS; public WcharTestRec( @Nonnull String s) { @@ -21,6 +21,10 @@ public String getS() { return mS; } + public void setS(@Nonnull String s) { + this.mS = s; + } + @Override public String toString() { return "WcharTestRec{" + diff --git a/test-suite/generated-src/jni/NativeBaseRecord.cpp b/test-suite/generated-src/jni/NativeBaseRecord.cpp new file mode 100644 index 00000000..d7c12f12 --- /dev/null +++ b/test-suite/generated-src/jni/NativeBaseRecord.cpp @@ -0,0 +1,28 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "NativeBaseRecord.hpp" // my header +#include "Marshal.hpp" + +namespace djinni_generated { + +NativeBaseRecord::NativeBaseRecord() = default; + +NativeBaseRecord::~NativeBaseRecord() = default; + +auto NativeBaseRecord::fromCpp(JNIEnv* jniEnv, const CppType& c) -> ::djinni::LocalRef { + const auto& data = ::djinni::JniClass::get(); + auto r = ::djinni::LocalRef{jniEnv->NewObject(data.clazz.get(), data.jconstructor, + ::djinni::get(::djinni::I32::fromCpp(jniEnv, c.val)))}; + ::djinni::jniExceptionCheck(jniEnv); + return r; +} + +auto NativeBaseRecord::toCpp(JNIEnv* jniEnv, JniType j) -> CppType { + ::djinni::JniLocalScope jscope(jniEnv, 2); + assert(j != nullptr); + const auto& data = ::djinni::JniClass::get(); + return {::djinni::I32::toCpp(jniEnv, jniEnv->GetIntField(j, data.field_mVal))}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeBaseRecord.hpp b/test-suite/generated-src/jni/NativeBaseRecord.hpp new file mode 100644 index 00000000..89f51488 --- /dev/null +++ b/test-suite/generated-src/jni/NativeBaseRecord.hpp @@ -0,0 +1,32 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "base_record.hpp" +#include "djinni_support.hpp" + +namespace djinni_generated { + +class NativeBaseRecord final { +public: + using CppType = ::testsuite::BaseRecord; + using JniType = jobject; + + using Boxed = NativeBaseRecord; + + ~NativeBaseRecord(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j); + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c); + +private: + NativeBaseRecord(); + friend ::djinni::JniClass; + + const ::djinni::GlobalRef clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/BaseRecord") }; + const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "", "(I)V") }; + const jfieldID field_mVal { ::djinni::jniGetFieldID(clazz.get(), "mVal", "I") }; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeMixedRecord.cpp b/test-suite/generated-src/jni/NativeMixedRecord.cpp new file mode 100644 index 00000000..5015bfdc --- /dev/null +++ b/test-suite/generated-src/jni/NativeMixedRecord.cpp @@ -0,0 +1,36 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "NativeMixedRecord.hpp" // my header +#include "Marshal.hpp" +#include "NativeBaseRecord.hpp" +#include "NativeOptionalInterface.hpp" + +namespace djinni_generated { + +NativeMixedRecord::NativeMixedRecord() = default; + +NativeMixedRecord::~NativeMixedRecord() = default; + +auto NativeMixedRecord::fromCpp(JNIEnv* jniEnv, const CppType& c) -> ::djinni::LocalRef { + const auto& data = ::djinni::JniClass::get(); + auto r = ::djinni::LocalRef{jniEnv->NewObject(data.clazz.get(), data.jconstructor, + ::djinni::get(::djinni::Optional::fromCpp(jniEnv, c.interfaceVal)), + ::djinni::get(::djinni::I32::fromCpp(jniEnv, c.reqInt)), + ::djinni::get(::djinni::Optional::fromCpp(jniEnv, c.optRecord)), + ::djinni::get(::djinni_generated::NativeBaseRecord::fromCpp(jniEnv, c.reqRecord)))}; + ::djinni::jniExceptionCheck(jniEnv); + return r; +} + +auto NativeMixedRecord::toCpp(JNIEnv* jniEnv, JniType j) -> CppType { + ::djinni::JniLocalScope jscope(jniEnv, 5); + assert(j != nullptr); + const auto& data = ::djinni::JniClass::get(); + return {::djinni::Optional::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mInterfaceVal)), + ::djinni::I32::toCpp(jniEnv, jniEnv->GetIntField(j, data.field_mReqInt)), + ::djinni::Optional::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOptRecord)), + ::djinni_generated::NativeBaseRecord::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mReqRecord))}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeMixedRecord.hpp b/test-suite/generated-src/jni/NativeMixedRecord.hpp new file mode 100644 index 00000000..6fb04784 --- /dev/null +++ b/test-suite/generated-src/jni/NativeMixedRecord.hpp @@ -0,0 +1,35 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "mixed_record.hpp" + +namespace djinni_generated { + +class NativeMixedRecord final { +public: + using CppType = ::testsuite::MixedRecord; + using JniType = jobject; + + using Boxed = NativeMixedRecord; + + ~NativeMixedRecord(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j); + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c); + +private: + NativeMixedRecord(); + friend ::djinni::JniClass; + + const ::djinni::GlobalRef clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/MixedRecord") }; + const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "", "(Lcom/dropbox/djinni/test/OptionalInterface;ILcom/dropbox/djinni/test/BaseRecord;Lcom/dropbox/djinni/test/BaseRecord;)V") }; + const jfieldID field_mInterfaceVal { ::djinni::jniGetFieldID(clazz.get(), "mInterfaceVal", "Lcom/dropbox/djinni/test/OptionalInterface;") }; + const jfieldID field_mReqInt { ::djinni::jniGetFieldID(clazz.get(), "mReqInt", "I") }; + const jfieldID field_mOptRecord { ::djinni::jniGetFieldID(clazz.get(), "mOptRecord", "Lcom/dropbox/djinni/test/BaseRecord;") }; + const jfieldID field_mReqRecord { ::djinni::jniGetFieldID(clazz.get(), "mReqRecord", "Lcom/dropbox/djinni/test/BaseRecord;") }; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeOptionalInterface.cpp b/test-suite/generated-src/jni/NativeOptionalInterface.cpp new file mode 100644 index 00000000..24fad4cd --- /dev/null +++ b/test-suite/generated-src/jni/NativeOptionalInterface.cpp @@ -0,0 +1,20 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "NativeOptionalInterface.hpp" // my header + +namespace djinni_generated { + +NativeOptionalInterface::NativeOptionalInterface() : ::djinni::JniInterface<::testsuite::OptionalInterface, NativeOptionalInterface>("com/dropbox/djinni/test/OptionalInterface$CppProxy") {} + +NativeOptionalInterface::~NativeOptionalInterface() = default; + + +CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_OptionalInterface_00024CppProxy_nativeDestroy(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef) +{ + try { + delete reinterpret_cast<::djinni::CppProxyHandle<::testsuite::OptionalInterface>*>(nativeRef); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, ) +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeOptionalInterface.hpp b/test-suite/generated-src/jni/NativeOptionalInterface.hpp new file mode 100644 index 00000000..39c5f36d --- /dev/null +++ b/test-suite/generated-src/jni/NativeOptionalInterface.hpp @@ -0,0 +1,32 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "optional_interface.hpp" + +namespace djinni_generated { + +class NativeOptionalInterface final : ::djinni::JniInterface<::testsuite::OptionalInterface, NativeOptionalInterface> { +public: + using CppType = std::shared_ptr<::testsuite::OptionalInterface>; + using CppOptType = std::shared_ptr<::testsuite::OptionalInterface>; + using JniType = jobject; + + using Boxed = NativeOptionalInterface; + + ~NativeOptionalInterface(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j) { return ::djinni::JniClass::get()._fromJava(jniEnv, j); } + static ::djinni::LocalRef fromCppOpt(JNIEnv* jniEnv, const CppOptType& c) { return {jniEnv, ::djinni::JniClass::get()._toJava(jniEnv, c)}; } + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) { return fromCppOpt(jniEnv, c); } + +private: + NativeOptionalInterface(); + friend ::djinni::JniClass; + friend ::djinni::JniInterface<::testsuite::OptionalInterface, NativeOptionalInterface>; + +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeOptionalRecord.cpp b/test-suite/generated-src/jni/NativeOptionalRecord.cpp new file mode 100644 index 00000000..31a9bc1d --- /dev/null +++ b/test-suite/generated-src/jni/NativeOptionalRecord.cpp @@ -0,0 +1,34 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "NativeOptionalRecord.hpp" // my header +#include "Marshal.hpp" +#include "NativeBaseRecord.hpp" +#include "NativeOptionalInterface.hpp" + +namespace djinni_generated { + +NativeOptionalRecord::NativeOptionalRecord() = default; + +NativeOptionalRecord::~NativeOptionalRecord() = default; + +auto NativeOptionalRecord::fromCpp(JNIEnv* jniEnv, const CppType& c) -> ::djinni::LocalRef { + const auto& data = ::djinni::JniClass::get(); + auto r = ::djinni::LocalRef{jniEnv->NewObject(data.clazz.get(), data.jconstructor, + ::djinni::get(::djinni::Optional::fromCpp(jniEnv, c.optInt)), + ::djinni::get(::djinni::Optional::fromCpp(jniEnv, c.optInterface)), + ::djinni::get(::djinni::Optional::fromCpp(jniEnv, c.optRecord)))}; + ::djinni::jniExceptionCheck(jniEnv); + return r; +} + +auto NativeOptionalRecord::toCpp(JNIEnv* jniEnv, JniType j) -> CppType { + ::djinni::JniLocalScope jscope(jniEnv, 4); + assert(j != nullptr); + const auto& data = ::djinni::JniClass::get(); + return {::djinni::Optional::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOptInt)), + ::djinni::Optional::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOptInterface)), + ::djinni::Optional::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOptRecord))}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeOptionalRecord.hpp b/test-suite/generated-src/jni/NativeOptionalRecord.hpp new file mode 100644 index 00000000..b8e6f9ef --- /dev/null +++ b/test-suite/generated-src/jni/NativeOptionalRecord.hpp @@ -0,0 +1,34 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "optional_record.hpp" + +namespace djinni_generated { + +class NativeOptionalRecord final { +public: + using CppType = ::testsuite::OptionalRecord; + using JniType = jobject; + + using Boxed = NativeOptionalRecord; + + ~NativeOptionalRecord(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j); + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c); + +private: + NativeOptionalRecord(); + friend ::djinni::JniClass; + + const ::djinni::GlobalRef clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/OptionalRecord") }; + const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "", "(Ljava/lang/Integer;Lcom/dropbox/djinni/test/OptionalInterface;Lcom/dropbox/djinni/test/BaseRecord;)V") }; + const jfieldID field_mOptInt { ::djinni::jniGetFieldID(clazz.get(), "mOptInt", "Ljava/lang/Integer;") }; + const jfieldID field_mOptInterface { ::djinni::jniGetFieldID(clazz.get(), "mOptInterface", "Lcom/dropbox/djinni/test/OptionalInterface;") }; + const jfieldID field_mOptRecord { ::djinni::jniGetFieldID(clazz.get(), "mOptRecord", "Lcom/dropbox/djinni/test/BaseRecord;") }; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeOptionalTestHelpers.cpp b/test-suite/generated-src/jni/NativeOptionalTestHelpers.cpp new file mode 100644 index 00000000..b6783ea2 --- /dev/null +++ b/test-suite/generated-src/jni/NativeOptionalTestHelpers.cpp @@ -0,0 +1,64 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "NativeOptionalTestHelpers.hpp" // my header +#include "NativeBaseRecord.hpp" +#include "NativeMixedRecord.hpp" +#include "NativeOptionalInterface.hpp" +#include "NativeOptionalRecord.hpp" + +namespace djinni_generated { + +NativeOptionalTestHelpers::NativeOptionalTestHelpers() : ::djinni::JniInterface<::testsuite::OptionalTestHelpers, NativeOptionalTestHelpers>("com/dropbox/djinni/test/OptionalTestHelpers$CppProxy") {} + +NativeOptionalTestHelpers::~NativeOptionalTestHelpers() = default; + + +CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_OptionalTestHelpers_00024CppProxy_nativeDestroy(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef) +{ + try { + delete reinterpret_cast<::djinni::CppProxyHandle<::testsuite::OptionalTestHelpers>*>(nativeRef); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, ) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_OptionalTestHelpers_getBaseRecord(JNIEnv* jniEnv, jobject /*this*/) +{ + try { + auto r = ::testsuite::OptionalTestHelpers::get_base_record(); + return ::djinni::release(::djinni_generated::NativeBaseRecord::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_OptionalTestHelpers_optionalInterface(JNIEnv* jniEnv, jobject /*this*/) +{ + try { + auto r = ::testsuite::OptionalTestHelpers::optional_interface(); + return ::djinni::release(::djinni_generated::NativeOptionalInterface::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_OptionalTestHelpers_getMixedRecord(JNIEnv* jniEnv, jobject /*this*/) +{ + try { + auto r = ::testsuite::OptionalTestHelpers::get_mixed_record(); + return ::djinni::release(::djinni_generated::NativeMixedRecord::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_OptionalTestHelpers_getOptionalRecord(JNIEnv* jniEnv, jobject /*this*/) +{ + try { + auto r = ::testsuite::OptionalTestHelpers::get_optional_record(); + return ::djinni::release(::djinni_generated::NativeOptionalRecord::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_OptionalTestHelpers_mixedRecordId(JNIEnv* jniEnv, jobject /*this*/, jobject j_i) +{ + try { + auto r = ::testsuite::OptionalTestHelpers::mixed_record_id(::djinni_generated::NativeMixedRecord::toCpp(jniEnv, j_i)); + return ::djinni::release(::djinni_generated::NativeMixedRecord::fromCpp(jniEnv, r)); + } JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */) +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeOptionalTestHelpers.hpp b/test-suite/generated-src/jni/NativeOptionalTestHelpers.hpp new file mode 100644 index 00000000..1aa4aabe --- /dev/null +++ b/test-suite/generated-src/jni/NativeOptionalTestHelpers.hpp @@ -0,0 +1,32 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "optional_test_helpers.hpp" + +namespace djinni_generated { + +class NativeOptionalTestHelpers final : ::djinni::JniInterface<::testsuite::OptionalTestHelpers, NativeOptionalTestHelpers> { +public: + using CppType = std::shared_ptr<::testsuite::OptionalTestHelpers>; + using CppOptType = std::shared_ptr<::testsuite::OptionalTestHelpers>; + using JniType = jobject; + + using Boxed = NativeOptionalTestHelpers; + + ~NativeOptionalTestHelpers(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j) { return ::djinni::JniClass::get()._fromJava(jniEnv, j); } + static ::djinni::LocalRef fromCppOpt(JNIEnv* jniEnv, const CppOptType& c) { return {jniEnv, ::djinni::JniClass::get()._toJava(jniEnv, c)}; } + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c) { return fromCppOpt(jniEnv, c); } + +private: + NativeOptionalTestHelpers(); + friend ::djinni::JniClass; + friend ::djinni::JniInterface<::testsuite::OptionalTestHelpers, NativeOptionalTestHelpers>; + +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeOverrideRecord.cpp b/test-suite/generated-src/jni/NativeOverrideRecord.cpp new file mode 100644 index 00000000..3dda559a --- /dev/null +++ b/test-suite/generated-src/jni/NativeOverrideRecord.cpp @@ -0,0 +1,34 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "NativeOverrideRecord.hpp" // my header +#include "Marshal.hpp" + +namespace djinni_generated { + +NativeOverrideRecord::NativeOverrideRecord() = default; + +NativeOverrideRecord::~NativeOverrideRecord() = default; + +auto NativeOverrideRecord::fromCpp(JNIEnv* jniEnv, const CppType& c) -> ::djinni::LocalRef { + const auto& data = ::djinni::JniClass::get(); + auto r = ::djinni::LocalRef{jniEnv->NewObject(data.clazz.get(), data.jconstructor, + ::djinni::get(::djinni::Optional::fromCpp(jniEnv, c.optInt)), + ::djinni::get(::djinni::Optional::fromCpp(jniEnv, c.optFloat)), + ::djinni::get(::djinni::I32::fromCpp(jniEnv, c.reqInt)), + ::djinni::get(::djinni::Optional::fromCpp(jniEnv, c.optDouble)))}; + ::djinni::jniExceptionCheck(jniEnv); + return r; +} + +auto NativeOverrideRecord::toCpp(JNIEnv* jniEnv, JniType j) -> CppType { + ::djinni::JniLocalScope jscope(jniEnv, 5); + assert(j != nullptr); + const auto& data = ::djinni::JniClass::get(); + return {::djinni::Optional::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOptInt)), + ::djinni::Optional::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOptFloat)), + ::djinni::I32::toCpp(jniEnv, jniEnv->GetIntField(j, data.field_mReqInt)), + ::djinni::Optional::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOptDouble))}; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/jni/NativeOverrideRecord.hpp b/test-suite/generated-src/jni/NativeOverrideRecord.hpp new file mode 100644 index 00000000..5208238e --- /dev/null +++ b/test-suite/generated-src/jni/NativeOverrideRecord.hpp @@ -0,0 +1,35 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "djinni_support.hpp" +#include "override_record.hpp" + +namespace djinni_generated { + +class NativeOverrideRecord final { +public: + using CppType = ::testsuite::OverrideRecord; + using JniType = jobject; + + using Boxed = NativeOverrideRecord; + + ~NativeOverrideRecord(); + + static CppType toCpp(JNIEnv* jniEnv, JniType j); + static ::djinni::LocalRef fromCpp(JNIEnv* jniEnv, const CppType& c); + +private: + NativeOverrideRecord(); + friend ::djinni::JniClass; + + const ::djinni::GlobalRef clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/OverrideRecord") }; + const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "", "(Ljava/lang/Integer;Ljava/lang/Float;ILjava/lang/Double;)V") }; + const jfieldID field_mOptInt { ::djinni::jniGetFieldID(clazz.get(), "mOptInt", "Ljava/lang/Integer;") }; + const jfieldID field_mOptFloat { ::djinni::jniGetFieldID(clazz.get(), "mOptFloat", "Ljava/lang/Float;") }; + const jfieldID field_mReqInt { ::djinni::jniGetFieldID(clazz.get(), "mReqInt", "I") }; + const jfieldID field_mOptDouble { ::djinni::jniGetFieldID(clazz.get(), "mOptDouble", "Ljava/lang/Double;") }; +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBAssortedPrimitives.h b/test-suite/generated-src/objc/DBAssortedPrimitives.h index 87dab879..9c1e8d1f 100644 --- a/test-suite/generated-src/objc/DBAssortedPrimitives.h +++ b/test-suite/generated-src/objc/DBAssortedPrimitives.h @@ -34,33 +34,47 @@ oSixtyfour:(nullable NSNumber *)oSixtyfour oFthirtytwo:(nullable NSNumber *)oFthirtytwo oFsixtyfour:(nullable NSNumber *)oFsixtyfour; +- (nonnull instancetype)initWithB:(BOOL)b + eight:(int8_t)eight + sixteen:(int16_t)sixteen + thirtytwo:(int32_t)thirtytwo + sixtyfour:(int64_t)sixtyfour + fthirtytwo:(float)fthirtytwo + fsixtyfour:(double)fsixtyfour; ++ (nonnull instancetype)assortedPrimitivesWithB:(BOOL)b + eight:(int8_t)eight + sixteen:(int16_t)sixteen + thirtytwo:(int32_t)thirtytwo + sixtyfour:(int64_t)sixtyfour + fthirtytwo:(float)fthirtytwo + fsixtyfour:(double)fsixtyfour; -@property (nonatomic, readonly) BOOL b; +@property (nonatomic) BOOL b; -@property (nonatomic, readonly) int8_t eight; +@property (nonatomic) int8_t eight; -@property (nonatomic, readonly) int16_t sixteen; +@property (nonatomic) int16_t sixteen; -@property (nonatomic, readonly) int32_t thirtytwo; +@property (nonatomic) int32_t thirtytwo; -@property (nonatomic, readonly) int64_t sixtyfour; +@property (nonatomic) int64_t sixtyfour; -@property (nonatomic, readonly) float fthirtytwo; +@property (nonatomic) float fthirtytwo; -@property (nonatomic, readonly) double fsixtyfour; +@property (nonatomic) double fsixtyfour; -@property (nonatomic, readonly, nullable) NSNumber * oB; +@property (nonatomic, nullable) NSNumber * oB; -@property (nonatomic, readonly, nullable) NSNumber * oEight; +@property (nonatomic, nullable) NSNumber * oEight; -@property (nonatomic, readonly, nullable) NSNumber * oSixteen; +@property (nonatomic, nullable) NSNumber * oSixteen; -@property (nonatomic, readonly, nullable) NSNumber * oThirtytwo; +@property (nonatomic, nullable) NSNumber * oThirtytwo; -@property (nonatomic, readonly, nullable) NSNumber * oSixtyfour; +@property (nonatomic, nullable) NSNumber * oSixtyfour; -@property (nonatomic, readonly, nullable) NSNumber * oFthirtytwo; +@property (nonatomic, nullable) NSNumber * oFthirtytwo; -@property (nonatomic, readonly, nullable) NSNumber * oFsixtyfour; +@property (nonatomic, nullable) NSNumber * oFsixtyfour; @end diff --git a/test-suite/generated-src/objc/DBAssortedPrimitives.mm b/test-suite/generated-src/objc/DBAssortedPrimitives.mm index 4ac88b46..869a90b6 100644 --- a/test-suite/generated-src/objc/DBAssortedPrimitives.mm +++ b/test-suite/generated-src/objc/DBAssortedPrimitives.mm @@ -40,6 +40,31 @@ - (nonnull instancetype)initWithB:(BOOL)b return self; } +- (nonnull instancetype)initWithB:(BOOL)b + eight:(int8_t)eight + sixteen:(int16_t)sixteen + thirtytwo:(int32_t)thirtytwo + sixtyfour:(int64_t)sixtyfour + fthirtytwo:(float)fthirtytwo + fsixtyfour:(double)fsixtyfour +{ + self = [self initWithB:b + eight:eight + sixteen:sixteen + thirtytwo:thirtytwo + sixtyfour:sixtyfour + fthirtytwo:fthirtytwo + fsixtyfour:fsixtyfour + oB:nil + oEight:nil + oSixteen:nil + oThirtytwo:nil + oSixtyfour:nil + oFthirtytwo:nil + oFsixtyfour:nil]; + return self; +} + + (nonnull instancetype)assortedPrimitivesWithB:(BOOL)b eight:(int8_t)eight sixteen:(int16_t)sixteen @@ -71,6 +96,23 @@ + (nonnull instancetype)assortedPrimitivesWithB:(BOOL)b oFsixtyfour:oFsixtyfour]; } ++ (nonnull instancetype)assortedPrimitivesWithB:(BOOL)b + eight:(int8_t)eight + sixteen:(int16_t)sixteen + thirtytwo:(int32_t)thirtytwo + sixtyfour:(int64_t)sixtyfour + fthirtytwo:(float)fthirtytwo + fsixtyfour:(double)fsixtyfour +{ + return [[self alloc] initWithB:b + eight:eight + sixteen:sixteen + thirtytwo:thirtytwo + sixtyfour:sixtyfour + fthirtytwo:fthirtytwo + fsixtyfour:fsixtyfour]; +} + - (BOOL)isEqual:(id)other { if (![other isKindOfClass:[DBAssortedPrimitives class]]) { diff --git a/test-suite/generated-src/objc/DBBaseRecord+Private.h b/test-suite/generated-src/objc/DBBaseRecord+Private.h new file mode 100644 index 00000000..a00eaba1 --- /dev/null +++ b/test-suite/generated-src/objc/DBBaseRecord+Private.h @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBBaseRecord.h" +#include "base_record.hpp" + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBBaseRecord; + +namespace djinni_generated { + +struct BaseRecord +{ + using CppType = ::testsuite::BaseRecord; + using ObjcType = DBBaseRecord*; + + using Boxed = BaseRecord; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCpp(const CppType& cpp); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBBaseRecord+Private.mm b/test-suite/generated-src/objc/DBBaseRecord+Private.mm new file mode 100644 index 00000000..8d73b458 --- /dev/null +++ b/test-suite/generated-src/objc/DBBaseRecord+Private.mm @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBBaseRecord+Private.h" +#import "DJIMarshal+Private.h" +#include + +namespace djinni_generated { + +auto BaseRecord::toCpp(ObjcType obj) -> CppType +{ + assert(obj); + return {::djinni::I32::toCpp(obj.val)}; +} + +auto BaseRecord::fromCpp(const CppType& cpp) -> ObjcType +{ + return [[DBBaseRecord alloc] initWithVal:(::djinni::I32::fromCpp(cpp.val))]; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBBaseRecord.h b/test-suite/generated-src/objc/DBBaseRecord.h new file mode 100644 index 00000000..b95ac563 --- /dev/null +++ b/test-suite/generated-src/objc/DBBaseRecord.h @@ -0,0 +1,15 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import + +/** Base record with a required value */ +@interface DBBaseRecord : NSObject +- (nonnull instancetype)init NS_UNAVAILABLE; ++ (nonnull instancetype)new NS_UNAVAILABLE; +- (nonnull instancetype)initWithVal:(int32_t)val NS_DESIGNATED_INITIALIZER; ++ (nonnull instancetype)baseRecordWithVal:(int32_t)val; + +@property (nonatomic) int32_t val; + +@end diff --git a/test-suite/generated-src/objc/DBBaseRecord.mm b/test-suite/generated-src/objc/DBBaseRecord.mm new file mode 100644 index 00000000..e81e8459 --- /dev/null +++ b/test-suite/generated-src/objc/DBBaseRecord.mm @@ -0,0 +1,29 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBBaseRecord.h" + + +@implementation DBBaseRecord + +- (nonnull instancetype)initWithVal:(int32_t)val +{ + if (self = [super init]) { + _val = val; + } + return self; +} + ++ (nonnull instancetype)baseRecordWithVal:(int32_t)val +{ + return [[self alloc] initWithVal:val]; +} + +#ifndef DJINNI_DISABLE_DESCRIPTION_METHODS +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@ %p val:%@>", self.class, (void *)self, @(self.val)]; +} + +#endif +@end diff --git a/test-suite/generated-src/objc/DBClientReturnedRecord.h b/test-suite/generated-src/objc/DBClientReturnedRecord.h index 4e324f92..c8956178 100644 --- a/test-suite/generated-src/objc/DBClientReturnedRecord.h +++ b/test-suite/generated-src/objc/DBClientReturnedRecord.h @@ -13,11 +13,15 @@ + (nonnull instancetype)clientReturnedRecordWithRecordId:(int64_t)recordId content:(nonnull NSString *)content misc:(nullable NSString *)misc; +- (nonnull instancetype)initWithRecordId:(int64_t)recordId + content:(nonnull NSString *)content; ++ (nonnull instancetype)clientReturnedRecordWithRecordId:(int64_t)recordId + content:(nonnull NSString *)content; -@property (nonatomic, readonly) int64_t recordId; +@property (nonatomic) int64_t recordId; -@property (nonatomic, readonly, nonnull) NSString * content; +@property (nonatomic, copy, nonnull) NSString * content; -@property (nonatomic, readonly, nullable) NSString * misc; +@property (nonatomic, copy, nullable) NSString * misc; @end diff --git a/test-suite/generated-src/objc/DBClientReturnedRecord.mm b/test-suite/generated-src/objc/DBClientReturnedRecord.mm index 0ae8bdd5..d9525dd8 100644 --- a/test-suite/generated-src/objc/DBClientReturnedRecord.mm +++ b/test-suite/generated-src/objc/DBClientReturnedRecord.mm @@ -18,6 +18,15 @@ - (nonnull instancetype)initWithRecordId:(int64_t)recordId return self; } +- (nonnull instancetype)initWithRecordId:(int64_t)recordId + content:(nonnull NSString *)content +{ + self = [self initWithRecordId:recordId + content:content + misc:nil]; + return self; +} + + (nonnull instancetype)clientReturnedRecordWithRecordId:(int64_t)recordId content:(nonnull NSString *)content misc:(nullable NSString *)misc @@ -27,6 +36,13 @@ + (nonnull instancetype)clientReturnedRecordWithRecordId:(int64_t)recordId misc:misc]; } ++ (nonnull instancetype)clientReturnedRecordWithRecordId:(int64_t)recordId + content:(nonnull NSString *)content +{ + return [[self alloc] initWithRecordId:recordId + content:content]; +} + #ifndef DJINNI_DISABLE_DESCRIPTION_METHODS - (NSString *)description { diff --git a/test-suite/generated-src/objc/DBConstantRecord.h b/test-suite/generated-src/objc/DBConstantRecord.h index 004bbac8..7825975e 100644 --- a/test-suite/generated-src/objc/DBConstantRecord.h +++ b/test-suite/generated-src/objc/DBConstantRecord.h @@ -12,8 +12,8 @@ + (nonnull instancetype)constantRecordWithSomeInteger:(int32_t)someInteger someString:(nonnull NSString *)someString; -@property (nonatomic, readonly) int32_t someInteger; +@property (nonatomic) int32_t someInteger; -@property (nonatomic, readonly, nonnull) NSString * someString; +@property (nonatomic, copy, nonnull) NSString * someString; @end diff --git a/test-suite/generated-src/objc/DBDateRecord.h b/test-suite/generated-src/objc/DBDateRecord.h index cc96ff83..3bf66d20 100644 --- a/test-suite/generated-src/objc/DBDateRecord.h +++ b/test-suite/generated-src/objc/DBDateRecord.h @@ -9,7 +9,7 @@ - (nonnull instancetype)initWithCreatedAt:(nonnull NSDate *)createdAt NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)dateRecordWithCreatedAt:(nonnull NSDate *)createdAt; -@property (nonatomic, readonly, nonnull) NSDate * createdAt; +@property (nonatomic, nonnull) NSDate * createdAt; - (NSComparisonResult)compare:(nonnull DBDateRecord *)other; diff --git a/test-suite/generated-src/objc/DBEnumUsageRecord.h b/test-suite/generated-src/objc/DBEnumUsageRecord.h index 9537f2cf..c9e2a354 100644 --- a/test-suite/generated-src/objc/DBEnumUsageRecord.h +++ b/test-suite/generated-src/objc/DBEnumUsageRecord.h @@ -17,15 +17,23 @@ l:(nonnull NSArray *)l s:(nonnull NSSet *)s m:(nonnull NSDictionary *)m; +- (nonnull instancetype)initWithE:(DBColor)e + l:(nonnull NSArray *)l + s:(nonnull NSSet *)s + m:(nonnull NSDictionary *)m; ++ (nonnull instancetype)enumUsageRecordWithE:(DBColor)e + l:(nonnull NSArray *)l + s:(nonnull NSSet *)s + m:(nonnull NSDictionary *)m; -@property (nonatomic, readonly) DBColor e; +@property (nonatomic) DBColor e; -@property (nonatomic, readonly, nullable) NSNumber * o; +@property (nonatomic, nullable) NSNumber * o; -@property (nonatomic, readonly, nonnull) NSArray * l; +@property (nonatomic, copy, nonnull) NSArray * l; -@property (nonatomic, readonly, nonnull) NSSet * s; +@property (nonatomic, copy, nonnull) NSSet * s; -@property (nonatomic, readonly, nonnull) NSDictionary * m; +@property (nonatomic, copy, nonnull) NSDictionary * m; @end diff --git a/test-suite/generated-src/objc/DBEnumUsageRecord.mm b/test-suite/generated-src/objc/DBEnumUsageRecord.mm index d86fd8a6..47140018 100644 --- a/test-suite/generated-src/objc/DBEnumUsageRecord.mm +++ b/test-suite/generated-src/objc/DBEnumUsageRecord.mm @@ -22,6 +22,19 @@ - (nonnull instancetype)initWithE:(DBColor)e return self; } +- (nonnull instancetype)initWithE:(DBColor)e + l:(nonnull NSArray *)l + s:(nonnull NSSet *)s + m:(nonnull NSDictionary *)m +{ + self = [self initWithE:e + o:nil + l:l + s:s + m:m]; + return self; +} + + (nonnull instancetype)enumUsageRecordWithE:(DBColor)e o:(nullable NSNumber *)o l:(nonnull NSArray *)l @@ -35,6 +48,17 @@ + (nonnull instancetype)enumUsageRecordWithE:(DBColor)e m:m]; } ++ (nonnull instancetype)enumUsageRecordWithE:(DBColor)e + l:(nonnull NSArray *)l + s:(nonnull NSSet *)s + m:(nonnull NSDictionary *)m +{ + return [[self alloc] initWithE:e + l:l + s:s + m:m]; +} + #ifndef DJINNI_DISABLE_DESCRIPTION_METHODS - (NSString *)description { diff --git a/test-suite/generated-src/objc/DBExtendedRecord.h b/test-suite/generated-src/objc/DBExtendedRecord.h index 8085acaf..d058ca55 100644 --- a/test-suite/generated-src/objc/DBExtendedRecord.h +++ b/test-suite/generated-src/objc/DBExtendedRecord.h @@ -12,7 +12,7 @@ + (nonnull instancetype)extendedRecordWithFoo:(BOOL)foo; + (DBExtendedRecord * __nonnull)extendedRecordConst; -@property (nonatomic, readonly) BOOL foo; +@property (nonatomic) BOOL foo; @end diff --git a/test-suite/generated-src/objc/DBExternRecordWithDerivings.h b/test-suite/generated-src/objc/DBExternRecordWithDerivings.h index 971b0acb..8b6a2e47 100644 --- a/test-suite/generated-src/objc/DBExternRecordWithDerivings.h +++ b/test-suite/generated-src/objc/DBExternRecordWithDerivings.h @@ -14,9 +14,9 @@ + (nonnull instancetype)externRecordWithDerivingsWithMember:(nonnull DBRecordWithDerivings *)member e:(DBColor)e; -@property (nonatomic, readonly, nonnull) DBRecordWithDerivings * member; +@property (nonatomic, nonnull) DBRecordWithDerivings * member; -@property (nonatomic, readonly) DBColor e; +@property (nonatomic) DBColor e; - (NSComparisonResult)compare:(nonnull DBExternRecordWithDerivings *)other; diff --git a/test-suite/generated-src/objc/DBMapDateRecord.h b/test-suite/generated-src/objc/DBMapDateRecord.h index ba98834d..7c89b673 100644 --- a/test-suite/generated-src/objc/DBMapDateRecord.h +++ b/test-suite/generated-src/objc/DBMapDateRecord.h @@ -9,6 +9,6 @@ - (nonnull instancetype)initWithDatesById:(nonnull NSDictionary *)datesById NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)mapDateRecordWithDatesById:(nonnull NSDictionary *)datesById; -@property (nonatomic, readonly, nonnull) NSDictionary * datesById; +@property (nonatomic, copy, nonnull) NSDictionary * datesById; @end diff --git a/test-suite/generated-src/objc/DBMapListRecord.h b/test-suite/generated-src/objc/DBMapListRecord.h index b2abc0b1..cc27bdbe 100644 --- a/test-suite/generated-src/objc/DBMapListRecord.h +++ b/test-suite/generated-src/objc/DBMapListRecord.h @@ -9,6 +9,6 @@ - (nonnull instancetype)initWithMapList:(nonnull NSArray *> *)mapList NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)mapListRecordWithMapList:(nonnull NSArray *> *)mapList; -@property (nonatomic, readonly, nonnull) NSArray *> * mapList; +@property (nonatomic, copy, nonnull) NSArray *> * mapList; @end diff --git a/test-suite/generated-src/objc/DBMapRecord.h b/test-suite/generated-src/objc/DBMapRecord.h index ef674060..56d323ac 100644 --- a/test-suite/generated-src/objc/DBMapRecord.h +++ b/test-suite/generated-src/objc/DBMapRecord.h @@ -11,8 +11,8 @@ + (nonnull instancetype)mapRecordWithMap:(nonnull NSDictionary *)map imap:(nonnull NSDictionary *)imap; -@property (nonatomic, readonly, nonnull) NSDictionary * map; +@property (nonatomic, copy, nonnull) NSDictionary * map; -@property (nonatomic, readonly, nonnull) NSDictionary * imap; +@property (nonatomic, copy, nonnull) NSDictionary * imap; @end diff --git a/test-suite/generated-src/objc/DBMixedRecord+Private.h b/test-suite/generated-src/objc/DBMixedRecord+Private.h new file mode 100644 index 00000000..264f52b2 --- /dev/null +++ b/test-suite/generated-src/objc/DBMixedRecord+Private.h @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBMixedRecord.h" +#include "mixed_record.hpp" + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBMixedRecord; + +namespace djinni_generated { + +struct MixedRecord +{ + using CppType = ::testsuite::MixedRecord; + using ObjcType = DBMixedRecord*; + + using Boxed = MixedRecord; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCpp(const CppType& cpp); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBMixedRecord+Private.mm b/test-suite/generated-src/objc/DBMixedRecord+Private.mm new file mode 100644 index 00000000..49ddb39c --- /dev/null +++ b/test-suite/generated-src/objc/DBMixedRecord+Private.mm @@ -0,0 +1,29 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBMixedRecord+Private.h" +#import "DBBaseRecord+Private.h" +#import "DBOptionalInterface+Private.h" +#import "DJIMarshal+Private.h" +#include + +namespace djinni_generated { + +auto MixedRecord::toCpp(ObjcType obj) -> CppType +{ + assert(obj); + return {::djinni::Optional::toCpp(obj.interfaceVal), + ::djinni::I32::toCpp(obj.reqInt), + ::djinni::Optional::toCpp(obj.optRecord), + ::djinni_generated::BaseRecord::toCpp(obj.reqRecord)}; +} + +auto MixedRecord::fromCpp(const CppType& cpp) -> ObjcType +{ + return [[DBMixedRecord alloc] initWithInterfaceVal:(::djinni::Optional::fromCpp(cpp.interfaceVal)) + reqInt:(::djinni::I32::fromCpp(cpp.reqInt)) + optRecord:(::djinni::Optional::fromCpp(cpp.optRecord)) + reqRecord:(::djinni_generated::BaseRecord::fromCpp(cpp.reqRecord))]; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBMixedRecord.h b/test-suite/generated-src/objc/DBMixedRecord.h new file mode 100644 index 00000000..80936d8b --- /dev/null +++ b/test-suite/generated-src/objc/DBMixedRecord.h @@ -0,0 +1,33 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBBaseRecord.h" +#import +@class DBOptionalInterface; + +/** Record with a mix of optional and required values */ +@interface DBMixedRecord : NSObject +- (nonnull instancetype)init NS_UNAVAILABLE; ++ (nonnull instancetype)new NS_UNAVAILABLE; +- (nonnull instancetype)initWithInterfaceVal:(nullable DBOptionalInterface *)interfaceVal + reqInt:(int32_t)reqInt + optRecord:(nullable DBBaseRecord *)optRecord + reqRecord:(nonnull DBBaseRecord *)reqRecord NS_DESIGNATED_INITIALIZER; ++ (nonnull instancetype)mixedRecordWithInterfaceVal:(nullable DBOptionalInterface *)interfaceVal + reqInt:(int32_t)reqInt + optRecord:(nullable DBBaseRecord *)optRecord + reqRecord:(nonnull DBBaseRecord *)reqRecord; +- (nonnull instancetype)initWithReqInt:(int32_t)reqInt + reqRecord:(nonnull DBBaseRecord *)reqRecord; ++ (nonnull instancetype)mixedRecordWithReqInt:(int32_t)reqInt + reqRecord:(nonnull DBBaseRecord *)reqRecord; + +@property (nonatomic, nullable) DBOptionalInterface * interfaceVal; + +@property (nonatomic) int32_t reqInt; + +@property (nonatomic, nullable) DBBaseRecord * optRecord; + +@property (nonatomic, nonnull) DBBaseRecord * reqRecord; + +@end diff --git a/test-suite/generated-src/objc/DBMixedRecord.mm b/test-suite/generated-src/objc/DBMixedRecord.mm new file mode 100644 index 00000000..4e4e085b --- /dev/null +++ b/test-suite/generated-src/objc/DBMixedRecord.mm @@ -0,0 +1,58 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBMixedRecord.h" + + +@implementation DBMixedRecord + +- (nonnull instancetype)initWithInterfaceVal:(nullable DBOptionalInterface *)interfaceVal + reqInt:(int32_t)reqInt + optRecord:(nullable DBBaseRecord *)optRecord + reqRecord:(nonnull DBBaseRecord *)reqRecord +{ + if (self = [super init]) { + _interfaceVal = interfaceVal; + _reqInt = reqInt; + _optRecord = optRecord; + _reqRecord = reqRecord; + } + return self; +} + +- (nonnull instancetype)initWithReqInt:(int32_t)reqInt + reqRecord:(nonnull DBBaseRecord *)reqRecord +{ + self = [self initWithInterfaceVal:nil + reqInt:reqInt + optRecord:nil + reqRecord:reqRecord]; + return self; +} + ++ (nonnull instancetype)mixedRecordWithInterfaceVal:(nullable DBOptionalInterface *)interfaceVal + reqInt:(int32_t)reqInt + optRecord:(nullable DBBaseRecord *)optRecord + reqRecord:(nonnull DBBaseRecord *)reqRecord +{ + return [[self alloc] initWithInterfaceVal:interfaceVal + reqInt:reqInt + optRecord:optRecord + reqRecord:reqRecord]; +} + ++ (nonnull instancetype)mixedRecordWithReqInt:(int32_t)reqInt + reqRecord:(nonnull DBBaseRecord *)reqRecord +{ + return [[self alloc] initWithReqInt:reqInt + reqRecord:reqRecord]; +} + +#ifndef DJINNI_DISABLE_DESCRIPTION_METHODS +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@ %p interfaceVal:%@ reqInt:%@ optRecord:%@ reqRecord:%@>", self.class, (void *)self, self.interfaceVal, @(self.reqInt), self.optRecord, self.reqRecord]; +} + +#endif +@end diff --git a/test-suite/generated-src/objc/DBNestedCollection.h b/test-suite/generated-src/objc/DBNestedCollection.h index e9bf5e01..6da28878 100644 --- a/test-suite/generated-src/objc/DBNestedCollection.h +++ b/test-suite/generated-src/objc/DBNestedCollection.h @@ -9,6 +9,6 @@ - (nonnull instancetype)initWithSetList:(nonnull NSArray *> *)setList NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)nestedCollectionWithSetList:(nonnull NSArray *> *)setList; -@property (nonatomic, readonly, nonnull) NSArray *> * setList; +@property (nonatomic, copy, nonnull) NSArray *> * setList; @end diff --git a/test-suite/generated-src/objc/DBNestedOutcome.h b/test-suite/generated-src/objc/DBNestedOutcome.h index 7f84ab04..0cefad18 100644 --- a/test-suite/generated-src/objc/DBNestedOutcome.h +++ b/test-suite/generated-src/objc/DBNestedOutcome.h @@ -10,6 +10,6 @@ - (nonnull instancetype)initWithO:(nonnull DJOutcome *)o NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)nestedOutcomeWithO:(nonnull DJOutcome *)o; -@property (nonatomic, readonly, nonnull) DJOutcome * o; +@property (nonatomic, nonnull) DJOutcome * o; @end diff --git a/test-suite/generated-src/objc/DBOptionalInterface+Private.h b/test-suite/generated-src/objc/DBOptionalInterface+Private.h new file mode 100644 index 00000000..e7d29c04 --- /dev/null +++ b/test-suite/generated-src/objc/DBOptionalInterface+Private.h @@ -0,0 +1,31 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "optional_interface.hpp" +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBOptionalInterface; + +namespace djinni_generated { + +class OptionalInterface +{ +public: + using CppType = std::shared_ptr<::testsuite::OptionalInterface>; + using CppOptType = std::shared_ptr<::testsuite::OptionalInterface>; + using ObjcType = DBOptionalInterface*; + + using Boxed = OptionalInterface; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCppOpt(const CppOptType& cpp); + static ObjcType fromCpp(const CppType& cpp) { return fromCppOpt(cpp); } + +private: + class ObjcProxy; +}; + +} // namespace djinni_generated + diff --git a/test-suite/generated-src/objc/DBOptionalInterface+Private.mm b/test-suite/generated-src/objc/DBOptionalInterface+Private.mm new file mode 100644 index 00000000..2077ed43 --- /dev/null +++ b/test-suite/generated-src/objc/DBOptionalInterface+Private.mm @@ -0,0 +1,52 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBOptionalInterface+Private.h" +#import "DBOptionalInterface.h" +#import "DJICppWrapperCache+Private.h" +#import "DJIError.h" +#include +#include +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@interface DBOptionalInterface () + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::OptionalInterface>&)cppRef; + +@end + +@implementation DBOptionalInterface { + ::djinni::CppProxyCache::Handle> _cppRefHandle; +} + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::OptionalInterface>&)cppRef +{ + if (self = [super init]) { + _cppRefHandle.assign(cppRef); + } + return self; +} + +namespace djinni_generated { + +auto OptionalInterface::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + return objc->_cppRefHandle.get(); +} + +auto OptionalInterface::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + return ::djinni::get_cpp_proxy(cpp); +} + +} // namespace djinni_generated + +@end diff --git a/test-suite/generated-src/objc/DBOptionalInterface.h b/test-suite/generated-src/objc/DBOptionalInterface.h new file mode 100644 index 00000000..f2bdb9fd --- /dev/null +++ b/test-suite/generated-src/objc/DBOptionalInterface.h @@ -0,0 +1,10 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import + + +/** Blank interface used for testing */ +@interface DBOptionalInterface : NSObject + +@end diff --git a/test-suite/generated-src/objc/DBOptionalRecord+Private.h b/test-suite/generated-src/objc/DBOptionalRecord+Private.h new file mode 100644 index 00000000..3e12fc6f --- /dev/null +++ b/test-suite/generated-src/objc/DBOptionalRecord+Private.h @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBOptionalRecord.h" +#include "optional_record.hpp" + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBOptionalRecord; + +namespace djinni_generated { + +struct OptionalRecord +{ + using CppType = ::testsuite::OptionalRecord; + using ObjcType = DBOptionalRecord*; + + using Boxed = OptionalRecord; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCpp(const CppType& cpp); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBOptionalRecord+Private.mm b/test-suite/generated-src/objc/DBOptionalRecord+Private.mm new file mode 100644 index 00000000..664c23b4 --- /dev/null +++ b/test-suite/generated-src/objc/DBOptionalRecord+Private.mm @@ -0,0 +1,27 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBOptionalRecord+Private.h" +#import "DBBaseRecord+Private.h" +#import "DBOptionalInterface+Private.h" +#import "DJIMarshal+Private.h" +#include + +namespace djinni_generated { + +auto OptionalRecord::toCpp(ObjcType obj) -> CppType +{ + assert(obj); + return {::djinni::Optional::toCpp(obj.optInt), + ::djinni::Optional::toCpp(obj.optInterface), + ::djinni::Optional::toCpp(obj.optRecord)}; +} + +auto OptionalRecord::fromCpp(const CppType& cpp) -> ObjcType +{ + return [[DBOptionalRecord alloc] initWithOptInt:(::djinni::Optional::fromCpp(cpp.optInt)) + optInterface:(::djinni::Optional::fromCpp(cpp.optInterface)) + optRecord:(::djinni::Optional::fromCpp(cpp.optRecord))]; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBOptionalRecord.h b/test-suite/generated-src/objc/DBOptionalRecord.h new file mode 100644 index 00000000..880efd2a --- /dev/null +++ b/test-suite/generated-src/objc/DBOptionalRecord.h @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBBaseRecord.h" +#import +@class DBOptionalInterface; + +/** Record containing only optional values */ +@interface DBOptionalRecord : NSObject +- (nonnull instancetype)initWithOptInt:(nullable NSNumber *)optInt + optInterface:(nullable DBOptionalInterface *)optInterface + optRecord:(nullable DBBaseRecord *)optRecord NS_DESIGNATED_INITIALIZER; ++ (nonnull instancetype)optionalRecordWithOptInt:(nullable NSNumber *)optInt + optInterface:(nullable DBOptionalInterface *)optInterface + optRecord:(nullable DBBaseRecord *)optRecord; +- (nonnull instancetype)init; ++ (nonnull instancetype)optionalRecord; + +@property (nonatomic, nullable) NSNumber * optInt; + +@property (nonatomic, nullable) DBOptionalInterface * optInterface; + +@property (nonatomic, nullable) DBBaseRecord * optRecord; + +@end diff --git a/test-suite/generated-src/objc/DBOptionalRecord.mm b/test-suite/generated-src/objc/DBOptionalRecord.mm new file mode 100644 index 00000000..4f21ca39 --- /dev/null +++ b/test-suite/generated-src/objc/DBOptionalRecord.mm @@ -0,0 +1,50 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBOptionalRecord.h" + + +@implementation DBOptionalRecord + +- (nonnull instancetype)initWithOptInt:(nullable NSNumber *)optInt + optInterface:(nullable DBOptionalInterface *)optInterface + optRecord:(nullable DBBaseRecord *)optRecord +{ + if (self = [super init]) { + _optInt = optInt; + _optInterface = optInterface; + _optRecord = optRecord; + } + return self; +} + +- (nonnull instancetype)init +{ + self = [self initWithOptInt:nil + optInterface:nil + optRecord:nil]; + return self; +} + ++ (nonnull instancetype)optionalRecordWithOptInt:(nullable NSNumber *)optInt + optInterface:(nullable DBOptionalInterface *)optInterface + optRecord:(nullable DBBaseRecord *)optRecord +{ + return [[self alloc] initWithOptInt:optInt + optInterface:optInterface + optRecord:optRecord]; +} + ++ (nonnull instancetype)optionalRecord +{ + return [[self alloc] init]; +} + +#ifndef DJINNI_DISABLE_DESCRIPTION_METHODS +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@ %p optInt:%@ optInterface:%@ optRecord:%@>", self.class, (void *)self, self.optInt, self.optInterface, self.optRecord]; +} + +#endif +@end diff --git a/test-suite/generated-src/objc/DBOptionalTestHelpers+Private.h b/test-suite/generated-src/objc/DBOptionalTestHelpers+Private.h new file mode 100644 index 00000000..c15a6b38 --- /dev/null +++ b/test-suite/generated-src/objc/DBOptionalTestHelpers+Private.h @@ -0,0 +1,31 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "optional_test_helpers.hpp" +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBOptionalTestHelpers; + +namespace djinni_generated { + +class OptionalTestHelpers +{ +public: + using CppType = std::shared_ptr<::testsuite::OptionalTestHelpers>; + using CppOptType = std::shared_ptr<::testsuite::OptionalTestHelpers>; + using ObjcType = DBOptionalTestHelpers*; + + using Boxed = OptionalTestHelpers; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCppOpt(const CppOptType& cpp); + static ObjcType fromCpp(const CppType& cpp) { return fromCppOpt(cpp); } + +private: + class ObjcProxy; +}; + +} // namespace djinni_generated + diff --git a/test-suite/generated-src/objc/DBOptionalTestHelpers+Private.mm b/test-suite/generated-src/objc/DBOptionalTestHelpers+Private.mm new file mode 100644 index 00000000..736abe56 --- /dev/null +++ b/test-suite/generated-src/objc/DBOptionalTestHelpers+Private.mm @@ -0,0 +1,91 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBOptionalTestHelpers+Private.h" +#import "DBOptionalTestHelpers.h" +#import "DBBaseRecord+Private.h" +#import "DBMixedRecord+Private.h" +#import "DBOptionalInterface+Private.h" +#import "DBOptionalRecord+Private.h" +#import "DJICppWrapperCache+Private.h" +#import "DJIError.h" +#include +#include +#include + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@interface DBOptionalTestHelpers () + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::OptionalTestHelpers>&)cppRef; + +@end + +@implementation DBOptionalTestHelpers { + ::djinni::CppProxyCache::Handle> _cppRefHandle; +} + +- (id)initWithCpp:(const std::shared_ptr<::testsuite::OptionalTestHelpers>&)cppRef +{ + if (self = [super init]) { + _cppRefHandle.assign(cppRef); + } + return self; +} + ++ (nonnull DBBaseRecord *)getBaseRecord { + try { + auto objcpp_result_ = ::testsuite::OptionalTestHelpers::get_base_record(); + return ::djinni_generated::BaseRecord::fromCpp(objcpp_result_); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + ++ (nullable DBOptionalInterface *)optionalInterface { + try { + auto objcpp_result_ = ::testsuite::OptionalTestHelpers::optional_interface(); + return ::djinni_generated::OptionalInterface::fromCpp(objcpp_result_); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + ++ (nonnull DBMixedRecord *)getMixedRecord { + try { + auto objcpp_result_ = ::testsuite::OptionalTestHelpers::get_mixed_record(); + return ::djinni_generated::MixedRecord::fromCpp(objcpp_result_); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + ++ (nonnull DBOptionalRecord *)getOptionalRecord { + try { + auto objcpp_result_ = ::testsuite::OptionalTestHelpers::get_optional_record(); + return ::djinni_generated::OptionalRecord::fromCpp(objcpp_result_); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + ++ (nonnull DBMixedRecord *)mixedRecordId:(nonnull DBMixedRecord *)i { + try { + auto objcpp_result_ = ::testsuite::OptionalTestHelpers::mixed_record_id(::djinni_generated::MixedRecord::toCpp(i)); + return ::djinni_generated::MixedRecord::fromCpp(objcpp_result_); + } DJINNI_TRANSLATE_EXCEPTIONS() +} + +namespace djinni_generated { + +auto OptionalTestHelpers::toCpp(ObjcType objc) -> CppType +{ + if (!objc) { + return nullptr; + } + return objc->_cppRefHandle.get(); +} + +auto OptionalTestHelpers::fromCppOpt(const CppOptType& cpp) -> ObjcType +{ + if (!cpp) { + return nil; + } + return ::djinni::get_cpp_proxy(cpp); +} + +} // namespace djinni_generated + +@end diff --git a/test-suite/generated-src/objc/DBOptionalTestHelpers.h b/test-suite/generated-src/objc/DBOptionalTestHelpers.h new file mode 100644 index 00000000..f324485a --- /dev/null +++ b/test-suite/generated-src/objc/DBOptionalTestHelpers.h @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBBaseRecord.h" +#import "DBMixedRecord.h" +#import "DBOptionalRecord.h" +#import +@class DBOptionalInterface; + + +@interface DBOptionalTestHelpers : NSObject + ++ (nonnull DBBaseRecord *)getBaseRecord; + ++ (nullable DBOptionalInterface *)optionalInterface; + ++ (nonnull DBMixedRecord *)getMixedRecord; + ++ (nonnull DBOptionalRecord *)getOptionalRecord; + +/** Checks that translation occurs properly */ ++ (nonnull DBMixedRecord *)mixedRecordId:(nonnull DBMixedRecord *)i; + +@end diff --git a/test-suite/generated-src/objc/DBOverrideRecord+Private.h b/test-suite/generated-src/objc/DBOverrideRecord+Private.h new file mode 100644 index 00000000..64569dd4 --- /dev/null +++ b/test-suite/generated-src/objc/DBOverrideRecord+Private.h @@ -0,0 +1,24 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBOverrideRecord.h" +#include "override_record.hpp" + +static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file"); + +@class DBOverrideRecord; + +namespace djinni_generated { + +struct OverrideRecord +{ + using CppType = ::testsuite::OverrideRecord; + using ObjcType = DBOverrideRecord*; + + using Boxed = OverrideRecord; + + static CppType toCpp(ObjcType objc); + static ObjcType fromCpp(const CppType& cpp); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBOverrideRecord+Private.mm b/test-suite/generated-src/objc/DBOverrideRecord+Private.mm new file mode 100644 index 00000000..1414a2b3 --- /dev/null +++ b/test-suite/generated-src/objc/DBOverrideRecord+Private.mm @@ -0,0 +1,27 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBOverrideRecord+Private.h" +#import "DJIMarshal+Private.h" +#include + +namespace djinni_generated { + +auto OverrideRecord::toCpp(ObjcType obj) -> CppType +{ + assert(obj); + return {::djinni::Optional::toCpp(obj.optInt), + ::djinni::Optional::toCpp(obj.optFloat), + ::djinni::I32::toCpp(obj.reqInt), + ::djinni::Optional::toCpp(obj.optDouble)}; +} + +auto OverrideRecord::fromCpp(const CppType& cpp) -> ObjcType +{ + return [[DBOverrideRecord alloc] initWithOptInt:(::djinni::Optional::fromCpp(cpp.optInt)) + optFloat:(::djinni::Optional::fromCpp(cpp.optFloat)) + reqInt:(::djinni::I32::fromCpp(cpp.reqInt)) + optDouble:(::djinni::Optional::fromCpp(cpp.optDouble))]; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/objc/DBOverrideRecord.h b/test-suite/generated-src/objc/DBOverrideRecord.h new file mode 100644 index 00000000..b260f0a4 --- /dev/null +++ b/test-suite/generated-src/objc/DBOverrideRecord.h @@ -0,0 +1,27 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import + +/** Overridden optional record */ +@interface DBOverrideRecord : NSObject +- (nonnull instancetype)init NS_UNAVAILABLE; ++ (nonnull instancetype)new NS_UNAVAILABLE; +- (nonnull instancetype)initWithOptInt:(nullable NSNumber *)optInt + optFloat:(nullable NSNumber *)optFloat + reqInt:(int32_t)reqInt + optDouble:(nullable NSNumber *)optDouble NS_DESIGNATED_INITIALIZER; ++ (nonnull instancetype)overrideRecordWithOptInt:(nullable NSNumber *)optInt + optFloat:(nullable NSNumber *)optFloat + reqInt:(int32_t)reqInt + optDouble:(nullable NSNumber *)optDouble; + +@property (nonatomic, nullable) NSNumber * optInt; + +@property (nonatomic, nullable) NSNumber * optFloat; + +@property (nonatomic) int32_t reqInt; + +@property (nonatomic, nullable) NSNumber * optDouble; + +@end diff --git a/test-suite/generated-src/objc/DBOverrideRecord.mm b/test-suite/generated-src/objc/DBOverrideRecord.mm new file mode 100644 index 00000000..df21a673 --- /dev/null +++ b/test-suite/generated-src/objc/DBOverrideRecord.mm @@ -0,0 +1,41 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#import "DBOverrideRecord.h" + + +@implementation DBOverrideRecord + +- (nonnull instancetype)initWithOptInt:(nullable NSNumber *)optInt + optFloat:(nullable NSNumber *)optFloat + reqInt:(int32_t)reqInt + optDouble:(nullable NSNumber *)optDouble +{ + if (self = [super init]) { + _optInt = optInt; + _optFloat = optFloat; + _reqInt = reqInt; + _optDouble = optDouble; + } + return self; +} + ++ (nonnull instancetype)overrideRecordWithOptInt:(nullable NSNumber *)optInt + optFloat:(nullable NSNumber *)optFloat + reqInt:(int32_t)reqInt + optDouble:(nullable NSNumber *)optDouble +{ + return [[self alloc] initWithOptInt:optInt + optFloat:optFloat + reqInt:reqInt + optDouble:optDouble]; +} + +#ifndef DJINNI_DISABLE_DESCRIPTION_METHODS +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@ %p optInt:%@ optFloat:%@ reqInt:%@ optDouble:%@>", self.class, (void *)self, self.optInt, self.optFloat, @(self.reqInt), self.optDouble]; +} + +#endif +@end diff --git a/test-suite/generated-src/objc/DBPrimitiveList.h b/test-suite/generated-src/objc/DBPrimitiveList.h index f7b037be..0df7c4bd 100644 --- a/test-suite/generated-src/objc/DBPrimitiveList.h +++ b/test-suite/generated-src/objc/DBPrimitiveList.h @@ -9,6 +9,6 @@ - (nonnull instancetype)initWithList:(nonnull NSArray *)list NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)primitiveListWithList:(nonnull NSArray *)list; -@property (nonatomic, readonly, nonnull) NSArray * list; +@property (nonatomic, copy, nonnull) NSArray * list; @end diff --git a/test-suite/generated-src/objc/DBRecordUsingExtendedRecord.h b/test-suite/generated-src/objc/DBRecordUsingExtendedRecord.h index 76f533d9..b0e1704c 100644 --- a/test-suite/generated-src/objc/DBRecordUsingExtendedRecord.h +++ b/test-suite/generated-src/objc/DBRecordUsingExtendedRecord.h @@ -12,7 +12,7 @@ + (nonnull instancetype)recordUsingExtendedRecordWithEr:(nonnull DBExtendedRecord *)er; + (DBRecordUsingExtendedRecord * __nonnull)cr; -@property (nonatomic, readonly, nonnull) DBExtendedRecord * er; +@property (nonatomic, nonnull) DBExtendedRecord * er; @end diff --git a/test-suite/generated-src/objc/DBRecordWithDerivings.h b/test-suite/generated-src/objc/DBRecordWithDerivings.h index 26ae4cdc..184c0230 100644 --- a/test-suite/generated-src/objc/DBRecordWithDerivings.h +++ b/test-suite/generated-src/objc/DBRecordWithDerivings.h @@ -23,21 +23,21 @@ d:(nonnull NSDate *)d s:(nonnull NSString *)s; -@property (nonatomic, readonly) int8_t eight; +@property (nonatomic) int8_t eight; -@property (nonatomic, readonly) int16_t sixteen; +@property (nonatomic) int16_t sixteen; -@property (nonatomic, readonly) int32_t thirtytwo; +@property (nonatomic) int32_t thirtytwo; -@property (nonatomic, readonly) int64_t sixtyfour; +@property (nonatomic) int64_t sixtyfour; -@property (nonatomic, readonly) float fthirtytwo; +@property (nonatomic) float fthirtytwo; -@property (nonatomic, readonly) double fsixtyfour; +@property (nonatomic) double fsixtyfour; -@property (nonatomic, readonly, nonnull) NSDate * d; +@property (nonatomic, nonnull) NSDate * d; -@property (nonatomic, readonly, nonnull) NSString * s; +@property (nonatomic, copy, nonnull) NSString * s; - (NSComparisonResult)compare:(nonnull DBRecordWithDerivings *)other; diff --git a/test-suite/generated-src/objc/DBRecordWithDurationAndDerivings.h b/test-suite/generated-src/objc/DBRecordWithDurationAndDerivings.h index 4add5420..ae7ba127 100644 --- a/test-suite/generated-src/objc/DBRecordWithDurationAndDerivings.h +++ b/test-suite/generated-src/objc/DBRecordWithDurationAndDerivings.h @@ -9,7 +9,7 @@ - (nonnull instancetype)initWithDt:(NSTimeInterval)dt NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)recordWithDurationAndDerivingsWithDt:(NSTimeInterval)dt; -@property (nonatomic, readonly) NSTimeInterval dt; +@property (nonatomic) NSTimeInterval dt; - (NSComparisonResult)compare:(nonnull DBRecordWithDurationAndDerivings *)other; diff --git a/test-suite/generated-src/objc/DBRecordWithEmbeddedCppProto.h b/test-suite/generated-src/objc/DBRecordWithEmbeddedCppProto.h index 81b071a8..08866ee0 100644 --- a/test-suite/generated-src/objc/DBRecordWithEmbeddedCppProto.h +++ b/test-suite/generated-src/objc/DBRecordWithEmbeddedCppProto.h @@ -10,6 +10,6 @@ - (nonnull instancetype)initWithState:(const djinni::test2::PersistingState & )state NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)RecordWithEmbeddedCppProtoWithState:(const djinni::test2::PersistingState & )state; -@property (nonatomic, readonly) djinni::test2::PersistingState state; +@property (nonatomic) djinni::test2::PersistingState state; @end diff --git a/test-suite/generated-src/objc/DBRecordWithEmbeddedProto.h b/test-suite/generated-src/objc/DBRecordWithEmbeddedProto.h index 419ef9ac..7b4b5e35 100644 --- a/test-suite/generated-src/objc/DBRecordWithEmbeddedProto.h +++ b/test-suite/generated-src/objc/DBRecordWithEmbeddedProto.h @@ -10,6 +10,6 @@ - (nonnull instancetype)initWithPerson:(nonnull DJTestPerson *)person NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)RecordWithEmbeddedProtoWithPerson:(nonnull DJTestPerson *)person; -@property (nonatomic, readonly, nonnull) DJTestPerson * person; +@property (nonatomic, nonnull) DJTestPerson * person; @end diff --git a/test-suite/generated-src/objc/DBRecordWithFlags.h b/test-suite/generated-src/objc/DBRecordWithFlags.h index d6174dc2..292db445 100644 --- a/test-suite/generated-src/objc/DBRecordWithFlags.h +++ b/test-suite/generated-src/objc/DBRecordWithFlags.h @@ -10,6 +10,6 @@ - (nonnull instancetype)initWithAccess:(DBAccessFlags)access NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)recordWithFlagsWithAccess:(DBAccessFlags)access; -@property (nonatomic, readonly) DBAccessFlags access; +@property (nonatomic) DBAccessFlags access; @end diff --git a/test-suite/generated-src/objc/DBRecordWithNestedDerivings.h b/test-suite/generated-src/objc/DBRecordWithNestedDerivings.h index 51a75936..db81d434 100644 --- a/test-suite/generated-src/objc/DBRecordWithNestedDerivings.h +++ b/test-suite/generated-src/objc/DBRecordWithNestedDerivings.h @@ -12,9 +12,9 @@ + (nonnull instancetype)recordWithNestedDerivingsWithKey:(int32_t)key rec:(nonnull DBRecordWithDerivings *)rec; -@property (nonatomic, readonly) int32_t key; +@property (nonatomic) int32_t key; -@property (nonatomic, readonly, nonnull) DBRecordWithDerivings * rec; +@property (nonatomic, nonnull) DBRecordWithDerivings * rec; - (NSComparisonResult)compare:(nonnull DBRecordWithNestedDerivings *)other; diff --git a/test-suite/generated-src/objc/DBSetRecord.h b/test-suite/generated-src/objc/DBSetRecord.h index 88cc83a7..b67d4e64 100644 --- a/test-suite/generated-src/objc/DBSetRecord.h +++ b/test-suite/generated-src/objc/DBSetRecord.h @@ -11,8 +11,8 @@ + (nonnull instancetype)setRecordWithSet:(nonnull NSSet *)set iset:(nonnull NSSet *)iset; -@property (nonatomic, readonly, nonnull) NSSet * set; +@property (nonatomic, copy, nonnull) NSSet * set; -@property (nonatomic, readonly, nonnull) NSSet * iset; +@property (nonatomic, copy, nonnull) NSSet * iset; @end diff --git a/test-suite/generated-src/objc/DBSupportCopying.h b/test-suite/generated-src/objc/DBSupportCopying.h index 2aed76db..ffe8bbe5 100644 --- a/test-suite/generated-src/objc/DBSupportCopying.h +++ b/test-suite/generated-src/objc/DBSupportCopying.h @@ -9,6 +9,6 @@ - (nonnull instancetype)initWithX:(int32_t)x NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)supportCopyingWithX:(int32_t)x; -@property (nonatomic, readonly) int32_t x; +@property (nonatomic) int32_t x; @end diff --git a/test-suite/generated-src/objc/DBTestIdentRecord.h b/test-suite/generated-src/objc/DBTestIdentRecord.h index 4f3cdb91..5704e396 100644 --- a/test-suite/generated-src/objc/DBTestIdentRecord.h +++ b/test-suite/generated-src/objc/DBTestIdentRecord.h @@ -11,9 +11,9 @@ + (nonnull instancetype)testIdentRecordWithFirstValue:(int32_t)FirstValue secondValue:(nonnull NSString *)secondValue; -@property (nonatomic, readonly) int32_t FirstValue; +@property (nonatomic) int32_t FirstValue; -@property (nonatomic, readonly, nonnull) NSString * secondValue; +@property (nonatomic, copy, nonnull) NSString * secondValue; @end diff --git a/test-suite/generated-src/objc/DBTestOptionalExternInterfaceRecord.h b/test-suite/generated-src/objc/DBTestOptionalExternInterfaceRecord.h index c795018e..5d355f79 100644 --- a/test-suite/generated-src/objc/DBTestOptionalExternInterfaceRecord.h +++ b/test-suite/generated-src/objc/DBTestOptionalExternInterfaceRecord.h @@ -5,11 +5,10 @@ #import @interface DBTestOptionalExternInterfaceRecord : NSObject -- (nonnull instancetype)init NS_UNAVAILABLE; -+ (nonnull instancetype)new NS_UNAVAILABLE; - (nonnull instancetype)initWithSampleInterface:(nullable DBSampleInterface *)sampleInterface NS_DESIGNATED_INITIALIZER; -+ (nonnull instancetype)testOptionalExternInterfaceRecordWithSampleInterface:(nullable DBSampleInterface *)sampleInterface; +- (nonnull instancetype)init; ++ (nonnull instancetype)testOptionalExternInterfaceRecord; -@property (nonatomic, readonly, nullable) DBSampleInterface * sampleInterface; +@property (nonatomic, nullable) DBSampleInterface * sampleInterface; @end diff --git a/test-suite/generated-src/objc/DBTestOptionalExternInterfaceRecord.mm b/test-suite/generated-src/objc/DBTestOptionalExternInterfaceRecord.mm index 3b404754..a0ca8d65 100644 --- a/test-suite/generated-src/objc/DBTestOptionalExternInterfaceRecord.mm +++ b/test-suite/generated-src/objc/DBTestOptionalExternInterfaceRecord.mm @@ -14,9 +14,15 @@ - (nonnull instancetype)initWithSampleInterface:(nullable DBSampleInterface *)sa return self; } -+ (nonnull instancetype)testOptionalExternInterfaceRecordWithSampleInterface:(nullable DBSampleInterface *)sampleInterface +- (nonnull instancetype)init { - return [[self alloc] initWithSampleInterface:sampleInterface]; + self = [self initWithSampleInterface:nil]; + return self; +} + ++ (nonnull instancetype)testOptionalExternInterfaceRecord +{ + return [[self alloc] init]; } #ifndef DJINNI_DISABLE_DESCRIPTION_METHODS diff --git a/test-suite/generated-src/objc/DBVarnameRecord.h b/test-suite/generated-src/objc/DBVarnameRecord.h index 01349fc4..18a63682 100644 --- a/test-suite/generated-src/objc/DBVarnameRecord.h +++ b/test-suite/generated-src/objc/DBVarnameRecord.h @@ -14,6 +14,6 @@ - (nonnull instancetype)initWithField:(int8_t)Field NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)VarnameRecordWithField:(int8_t)Field; -@property (nonatomic, readonly) int8_t Field; +@property (nonatomic) int8_t Field; @end diff --git a/test-suite/generated-src/objc/DBVec2.h b/test-suite/generated-src/objc/DBVec2.h index a85921b6..eca09cf4 100644 --- a/test-suite/generated-src/objc/DBVec2.h +++ b/test-suite/generated-src/objc/DBVec2.h @@ -11,8 +11,8 @@ + (nonnull instancetype)vec2WithX:(int32_t)x y:(int32_t)y; -@property (nonatomic, readonly) int32_t x; +@property (nonatomic) int32_t x; -@property (nonatomic, readonly) int32_t y; +@property (nonatomic) int32_t y; @end diff --git a/test-suite/generated-src/objc/DBWcharTestRec.h b/test-suite/generated-src/objc/DBWcharTestRec.h index 0e21ecd7..d2ab0ce3 100644 --- a/test-suite/generated-src/objc/DBWcharTestRec.h +++ b/test-suite/generated-src/objc/DBWcharTestRec.h @@ -9,6 +9,6 @@ - (nonnull instancetype)initWithS:(nonnull NSString *)s NS_DESIGNATED_INITIALIZER; + (nonnull instancetype)wcharTestRecWithS:(nonnull NSString *)s; -@property (nonatomic, readonly, nonnull) NSString * s; +@property (nonatomic, copy, nonnull) NSString * s; @end diff --git a/test-suite/generated-src/ts/test_optional.ts b/test-suite/generated-src/ts/test_optional.ts new file mode 100644 index 00000000..bf4c7272 --- /dev/null +++ b/test-suite/generated-src/ts/test_optional.ts @@ -0,0 +1,55 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + + +/** Blank interface used for testing */ +export interface OptionalInterface { +} + +/** Base record with a required value */ +export interface /*record*/ BaseRecord { + val: number; +} + +/** Record with a mix of optional and required values */ +export interface /*record*/ MixedRecord { + interfaceVal?: OptionalInterface; + reqInt: number; + optRecord?: BaseRecord; + reqRecord: BaseRecord; +} + +/** Record containing only optional values */ +export interface /*record*/ OptionalRecord { + optInt?: number; + optInterface?: OptionalInterface; + optRecord?: BaseRecord; +} + +/** Overridden optional record */ +export interface /*record*/ OverrideRecord { + optInt?: number; + optFloat?: number; + reqInt: number; + optDouble?: number; +} + +export interface OptionalTestHelpers { +} +export interface OptionalTestHelpers_statics { + getBaseRecord(): BaseRecord; + optionalInterface(): OptionalInterface; + getMixedRecord(): MixedRecord; + getOptionalRecord(): OptionalRecord; + /** Checks that translation occurs properly */ + mixedRecordId(i: MixedRecord): MixedRecord; +} + +export interface ns_testsuite { + OptionalTestHelpers: OptionalTestHelpers_statics; +} +export interface TestOptional_statics { + testsuite_OptionalTestHelpers: OptionalTestHelpers_statics; + + testsuite: ns_testsuite; +} diff --git a/test-suite/generated-src/wasm/NativeBaseRecord.cpp b/test-suite/generated-src/wasm/NativeBaseRecord.cpp new file mode 100644 index 00000000..047d2a41 --- /dev/null +++ b/test-suite/generated-src/wasm/NativeBaseRecord.cpp @@ -0,0 +1,17 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "NativeBaseRecord.hpp" // my header + +namespace djinni_generated { + +auto NativeBaseRecord::toCpp(const JsType& j) -> CppType { + return {::djinni::I32::Boxed::toCpp(j["val"])}; +} +auto NativeBaseRecord::fromCpp(const CppType& c) -> JsType { + em::val js = em::val::object(); + js.set("val", ::djinni::I32::Boxed::fromCpp(c.val)); + return js; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeBaseRecord.hpp b/test-suite/generated-src/wasm/NativeBaseRecord.hpp new file mode 100644 index 00000000..22a1fe1f --- /dev/null +++ b/test-suite/generated-src/wasm/NativeBaseRecord.hpp @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "base_record.hpp" +#include "djinni_wasm.hpp" + +namespace djinni_generated { + +struct NativeBaseRecord +{ + using CppType = ::testsuite::BaseRecord; + using JsType = em::val; + using Boxed = NativeBaseRecord; + + static CppType toCpp(const JsType& j); + static JsType fromCpp(const CppType& c); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeMixedRecord.cpp b/test-suite/generated-src/wasm/NativeMixedRecord.cpp new file mode 100644 index 00000000..3fcd71e4 --- /dev/null +++ b/test-suite/generated-src/wasm/NativeMixedRecord.cpp @@ -0,0 +1,25 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "NativeMixedRecord.hpp" // my header +#include "NativeBaseRecord.hpp" +#include "NativeOptionalInterface.hpp" + +namespace djinni_generated { + +auto NativeMixedRecord::toCpp(const JsType& j) -> CppType { + return {::djinni::Optional::Boxed::toCpp(j["interfaceVal"]), + ::djinni::I32::Boxed::toCpp(j["reqInt"]), + ::djinni::Optional::Boxed::toCpp(j["optRecord"]), + ::djinni_generated::NativeBaseRecord::Boxed::toCpp(j["reqRecord"])}; +} +auto NativeMixedRecord::fromCpp(const CppType& c) -> JsType { + em::val js = em::val::object(); + js.set("interfaceVal", ::djinni::Optional::Boxed::fromCpp(c.interfaceVal)); + js.set("reqInt", ::djinni::I32::Boxed::fromCpp(c.reqInt)); + js.set("optRecord", ::djinni::Optional::Boxed::fromCpp(c.optRecord)); + js.set("reqRecord", ::djinni_generated::NativeBaseRecord::Boxed::fromCpp(c.reqRecord)); + return js; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeMixedRecord.hpp b/test-suite/generated-src/wasm/NativeMixedRecord.hpp new file mode 100644 index 00000000..02fb3cc7 --- /dev/null +++ b/test-suite/generated-src/wasm/NativeMixedRecord.hpp @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "djinni_wasm.hpp" +#include "mixed_record.hpp" + +namespace djinni_generated { + +struct NativeMixedRecord +{ + using CppType = ::testsuite::MixedRecord; + using JsType = em::val; + using Boxed = NativeMixedRecord; + + static CppType toCpp(const JsType& j); + static JsType fromCpp(const CppType& c); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeOptionalInterface.cpp b/test-suite/generated-src/wasm/NativeOptionalInterface.cpp new file mode 100644 index 00000000..74f7c7e6 --- /dev/null +++ b/test-suite/generated-src/wasm/NativeOptionalInterface.cpp @@ -0,0 +1,22 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "NativeOptionalInterface.hpp" // my header + +namespace djinni_generated { + +em::val NativeOptionalInterface::cppProxyMethods() { + static const em::val methods = em::val::array(std::vector { + }); + return methods; +} + + +EMSCRIPTEN_BINDINGS(testsuite_optional_interface) { + ::djinni::DjinniClass_<::testsuite::OptionalInterface>("testsuite_OptionalInterface", "testsuite.OptionalInterface") + .smart_ptr>("testsuite_OptionalInterface") + .function("nativeDestroy", &NativeOptionalInterface::nativeDestroy) + ; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeOptionalInterface.hpp b/test-suite/generated-src/wasm/NativeOptionalInterface.hpp new file mode 100644 index 00000000..7a75af07 --- /dev/null +++ b/test-suite/generated-src/wasm/NativeOptionalInterface.hpp @@ -0,0 +1,29 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "djinni_wasm.hpp" +#include "optional_interface.hpp" + +namespace djinni_generated { + +struct NativeOptionalInterface : ::djinni::JsInterface<::testsuite::OptionalInterface, NativeOptionalInterface> { + using CppType = std::shared_ptr<::testsuite::OptionalInterface>; + using CppOptType = std::shared_ptr<::testsuite::OptionalInterface>; + using JsType = em::val; + using Boxed = NativeOptionalInterface; + + static CppType toCpp(JsType j) { return _fromJs(j); } + static JsType fromCppOpt(const CppOptType& c) { return {_toJs(c)}; } + static JsType fromCpp(const CppType& c) { + ::djinni::checkForNull(c.get(), "NativeOptionalInterface::fromCpp"); + return fromCppOpt(c); + } + + static em::val cppProxyMethods(); + + +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeOptionalRecord.cpp b/test-suite/generated-src/wasm/NativeOptionalRecord.cpp new file mode 100644 index 00000000..0df293ea --- /dev/null +++ b/test-suite/generated-src/wasm/NativeOptionalRecord.cpp @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "NativeOptionalRecord.hpp" // my header +#include "NativeBaseRecord.hpp" +#include "NativeOptionalInterface.hpp" + +namespace djinni_generated { + +auto NativeOptionalRecord::toCpp(const JsType& j) -> CppType { + return {::djinni::Optional::Boxed::toCpp(j["optInt"]), + ::djinni::Optional::Boxed::toCpp(j["optInterface"]), + ::djinni::Optional::Boxed::toCpp(j["optRecord"])}; +} +auto NativeOptionalRecord::fromCpp(const CppType& c) -> JsType { + em::val js = em::val::object(); + js.set("optInt", ::djinni::Optional::Boxed::fromCpp(c.optInt)); + js.set("optInterface", ::djinni::Optional::Boxed::fromCpp(c.optInterface)); + js.set("optRecord", ::djinni::Optional::Boxed::fromCpp(c.optRecord)); + return js; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeOptionalRecord.hpp b/test-suite/generated-src/wasm/NativeOptionalRecord.hpp new file mode 100644 index 00000000..a9a44bbd --- /dev/null +++ b/test-suite/generated-src/wasm/NativeOptionalRecord.hpp @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "djinni_wasm.hpp" +#include "optional_record.hpp" + +namespace djinni_generated { + +struct NativeOptionalRecord +{ + using CppType = ::testsuite::OptionalRecord; + using JsType = em::val; + using Boxed = NativeOptionalRecord; + + static CppType toCpp(const JsType& j); + static JsType fromCpp(const CppType& c); +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeOptionalTestHelpers.cpp b/test-suite/generated-src/wasm/NativeOptionalTestHelpers.cpp new file mode 100644 index 00000000..71d59374 --- /dev/null +++ b/test-suite/generated-src/wasm/NativeOptionalTestHelpers.cpp @@ -0,0 +1,76 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "NativeOptionalTestHelpers.hpp" // my header +#include "NativeBaseRecord.hpp" +#include "NativeMixedRecord.hpp" +#include "NativeOptionalInterface.hpp" +#include "NativeOptionalRecord.hpp" + +namespace djinni_generated { + +em::val NativeOptionalTestHelpers::cppProxyMethods() { + static const em::val methods = em::val::array(std::vector { + }); + return methods; +} + +em::val NativeOptionalTestHelpers::get_base_record() { + try { + auto r = ::testsuite::OptionalTestHelpers::get_base_record(); + return ::djinni_generated::NativeBaseRecord::fromCpp(r); + } + catch(const std::exception& e) { + return ::djinni::ExceptionHandlingTraits<::djinni_generated::NativeBaseRecord>::handleNativeException(e); + } +} +em::val NativeOptionalTestHelpers::optional_interface() { + try { + auto r = ::testsuite::OptionalTestHelpers::optional_interface(); + return ::djinni_generated::NativeOptionalInterface::fromCpp(r); + } + catch(const std::exception& e) { + return ::djinni::ExceptionHandlingTraits<::djinni_generated::NativeOptionalInterface>::handleNativeException(e); + } +} +em::val NativeOptionalTestHelpers::get_mixed_record() { + try { + auto r = ::testsuite::OptionalTestHelpers::get_mixed_record(); + return ::djinni_generated::NativeMixedRecord::fromCpp(r); + } + catch(const std::exception& e) { + return ::djinni::ExceptionHandlingTraits<::djinni_generated::NativeMixedRecord>::handleNativeException(e); + } +} +em::val NativeOptionalTestHelpers::get_optional_record() { + try { + auto r = ::testsuite::OptionalTestHelpers::get_optional_record(); + return ::djinni_generated::NativeOptionalRecord::fromCpp(r); + } + catch(const std::exception& e) { + return ::djinni::ExceptionHandlingTraits<::djinni_generated::NativeOptionalRecord>::handleNativeException(e); + } +} +em::val NativeOptionalTestHelpers::mixed_record_id(const em::val& w_i) { + try { + auto r = ::testsuite::OptionalTestHelpers::mixed_record_id(::djinni_generated::NativeMixedRecord::toCpp(w_i)); + return ::djinni_generated::NativeMixedRecord::fromCpp(r); + } + catch(const std::exception& e) { + return ::djinni::ExceptionHandlingTraits<::djinni_generated::NativeMixedRecord>::handleNativeException(e); + } +} + +EMSCRIPTEN_BINDINGS(testsuite_optional_test_helpers) { + ::djinni::DjinniClass_<::testsuite::OptionalTestHelpers>("testsuite_OptionalTestHelpers", "testsuite.OptionalTestHelpers") + .smart_ptr>("testsuite_OptionalTestHelpers") + .function("nativeDestroy", &NativeOptionalTestHelpers::nativeDestroy) + .class_function("getBaseRecord", NativeOptionalTestHelpers::get_base_record) + .class_function("optionalInterface", NativeOptionalTestHelpers::optional_interface) + .class_function("getMixedRecord", NativeOptionalTestHelpers::get_mixed_record) + .class_function("getOptionalRecord", NativeOptionalTestHelpers::get_optional_record) + .class_function("mixedRecordId", NativeOptionalTestHelpers::mixed_record_id) + ; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeOptionalTestHelpers.hpp b/test-suite/generated-src/wasm/NativeOptionalTestHelpers.hpp new file mode 100644 index 00000000..547092ef --- /dev/null +++ b/test-suite/generated-src/wasm/NativeOptionalTestHelpers.hpp @@ -0,0 +1,34 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "djinni_wasm.hpp" +#include "optional_test_helpers.hpp" + +namespace djinni_generated { + +struct NativeOptionalTestHelpers : ::djinni::JsInterface<::testsuite::OptionalTestHelpers, NativeOptionalTestHelpers> { + using CppType = std::shared_ptr<::testsuite::OptionalTestHelpers>; + using CppOptType = std::shared_ptr<::testsuite::OptionalTestHelpers>; + using JsType = em::val; + using Boxed = NativeOptionalTestHelpers; + + static CppType toCpp(JsType j) { return _fromJs(j); } + static JsType fromCppOpt(const CppOptType& c) { return {_toJs(c)}; } + static JsType fromCpp(const CppType& c) { + ::djinni::checkForNull(c.get(), "NativeOptionalTestHelpers::fromCpp"); + return fromCppOpt(c); + } + + static em::val cppProxyMethods(); + + static em::val get_base_record(); + static em::val optional_interface(); + static em::val get_mixed_record(); + static em::val get_optional_record(); + static em::val mixed_record_id(const em::val& w_i); + +}; + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeOverrideRecord.cpp b/test-suite/generated-src/wasm/NativeOverrideRecord.cpp new file mode 100644 index 00000000..4e5dd795 --- /dev/null +++ b/test-suite/generated-src/wasm/NativeOverrideRecord.cpp @@ -0,0 +1,23 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#include "NativeOverrideRecord.hpp" // my header + +namespace djinni_generated { + +auto NativeOverrideRecord::toCpp(const JsType& j) -> CppType { + return {::djinni::Optional::Boxed::toCpp(j["optInt"]), + ::djinni::Optional::Boxed::toCpp(j["optFloat"]), + ::djinni::I32::Boxed::toCpp(j["reqInt"]), + ::djinni::Optional::Boxed::toCpp(j["optDouble"])}; +} +auto NativeOverrideRecord::fromCpp(const CppType& c) -> JsType { + em::val js = em::val::object(); + js.set("optInt", ::djinni::Optional::Boxed::fromCpp(c.optInt)); + js.set("optFloat", ::djinni::Optional::Boxed::fromCpp(c.optFloat)); + js.set("reqInt", ::djinni::I32::Boxed::fromCpp(c.reqInt)); + js.set("optDouble", ::djinni::Optional::Boxed::fromCpp(c.optDouble)); + return js; +} + +} // namespace djinni_generated diff --git a/test-suite/generated-src/wasm/NativeOverrideRecord.hpp b/test-suite/generated-src/wasm/NativeOverrideRecord.hpp new file mode 100644 index 00000000..f7da5df9 --- /dev/null +++ b/test-suite/generated-src/wasm/NativeOverrideRecord.hpp @@ -0,0 +1,21 @@ +// AUTOGENERATED FILE - DO NOT MODIFY! +// This file was generated by Djinni from optionals.djinni + +#pragma once + +#include "djinni_wasm.hpp" +#include "override_record.hpp" + +namespace djinni_generated { + +struct NativeOverrideRecord +{ + using CppType = ::testsuite::OverrideRecord; + using JsType = em::val; + using Boxed = NativeOverrideRecord; + + static CppType toCpp(const JsType& j); + static JsType fromCpp(const CppType& c); +}; + +} // namespace djinni_generated diff --git a/test-suite/handwritten-src/cpp/optional_test_helpers.cpp b/test-suite/handwritten-src/cpp/optional_test_helpers.cpp new file mode 100644 index 00000000..20a938a0 --- /dev/null +++ b/test-suite/handwritten-src/cpp/optional_test_helpers.cpp @@ -0,0 +1,34 @@ +#include "optional_interface.hpp" +#include "mixed_record.hpp" +#include "optional_record.hpp" +#include "optional_test_helpers.hpp" + +namespace testsuite { + std::shared_ptr gOptInterface = std::make_shared(); + const BaseRecord gBaseRecord = {7}; + + BaseRecord OptionalTestHelpers::get_base_record() { + return gBaseRecord; + } + + std::shared_ptr OptionalTestHelpers::optional_interface() { + return gOptInterface; + } + + MixedRecord OptionalTestHelpers::get_mixed_record() { + auto mixedRecord = MixedRecord(5, gBaseRecord); + mixedRecord.interfaceVal = gOptInterface; + return mixedRecord; + } + + OptionalRecord OptionalTestHelpers::get_optional_record() { + auto optionalRecord = OptionalRecord(); + optionalRecord.optInt = 6; + return optionalRecord; + } + + /** Checks that translation occurs properly */ + MixedRecord OptionalTestHelpers::mixed_record_id(const MixedRecord & i) { + return i; + } +} // namespace testsuite diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java index 6515a311..a64169e0 100644 --- a/test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java @@ -31,6 +31,7 @@ public static Test suite() { mySuite.addTestSuite(DataTest.class); mySuite.addTestSuite(AsyncTest.class); mySuite.addTestSuite(InterfaceAndAbstractClass.class); + mySuite.addTestSuite(OptionalsTest.class); return mySuite; } diff --git a/test-suite/handwritten-src/java/com/dropbox/djinni/test/OptionalsTest.java b/test-suite/handwritten-src/java/com/dropbox/djinni/test/OptionalsTest.java new file mode 100644 index 00000000..0f70274c --- /dev/null +++ b/test-suite/handwritten-src/java/com/dropbox/djinni/test/OptionalsTest.java @@ -0,0 +1,37 @@ +package com.dropbox.djinni.test; + +import junit.framework.TestCase; + +public class OptionalsTest extends TestCase { + public void testMixedRecordTranslation() { + MixedRecord rec = new MixedRecord(5, OptionalTestHelpers.getBaseRecord()); + rec.setInterfaceVal(OptionalTestHelpers.optionalInterface()); + + MixedRecord expected = OptionalTestHelpers.getMixedRecord(); + assertEquals(rec.getReqInt(), expected.getReqInt()); + assertEquals(rec.getReqRecord().getVal(), expected.getReqRecord().getVal()); + assertEquals(rec.getOptRecord(), null); + assertEquals(rec.getInterfaceVal(), expected.getInterfaceVal()); + } + + public void testOptionalRecordTranslation() { + OptionalRecord rec = new OptionalRecord(); + rec.setOptInt(6); + + OptionalRecord expected = OptionalTestHelpers.getOptionalRecord(); + assertEquals(rec.getOptInt(), expected.getOptInt()); + assertEquals(rec.getOptInterface(), null); + assertEquals(rec.getOptRecord(), null); + } + + public void testTranslation() { + MixedRecord rec = new MixedRecord(1, OptionalTestHelpers.getBaseRecord()); + rec.setOptRecord(new BaseRecord(5)); + + MixedRecord translatedRec = OptionalTestHelpers.mixedRecordId(rec); + assertEquals(rec.getReqInt(), translatedRec.getReqInt()); + assertEquals(rec.getReqRecord().getVal(), translatedRec.getReqRecord().getVal()); + assertEquals(rec.getOptRecord().getVal(), translatedRec.getOptRecord().getVal()); + assertEquals(rec.getInterfaceVal(), null); + } +} diff --git a/test-suite/handwritten-src/objc/tests/DBOptionalsTest.m b/test-suite/handwritten-src/objc/tests/DBOptionalsTest.m new file mode 100644 index 00000000..26eff8c6 --- /dev/null +++ b/test-suite/handwritten-src/objc/tests/DBOptionalsTest.m @@ -0,0 +1,61 @@ +#import +#import + +#import "DBOptionalInterface.h" +#import "DBOptionalTestHelpers.h" + +@interface DBOptionalsTest : XCTestCase + +@end + +@implementation DBOptionalsTest + +- (void)setUp +{ + [super setUp]; +} + +- (void)tearDown +{ + [super tearDown]; +} + +- (void)testMixedRecordTranslation +{ + DBMixedRecord * rec = [DBMixedRecord mixedRecordWithReqInt:(int32_t)5 + reqRecord:[DBOptionalTestHelpers getBaseRecord]]; + rec.interfaceVal = [DBOptionalTestHelpers optionalInterface]; + + DBMixedRecord * expectedRec = [DBOptionalTestHelpers getMixedRecord]; + + XCTAssertEqualObjects(rec.interfaceVal, expectedRec.interfaceVal); + XCTAssertEqual(rec.reqInt, expectedRec.reqInt); + XCTAssertEqualObjects(rec.optRecord, expectedRec.optRecord); + XCTAssertEqual(rec.reqRecord.val, expectedRec.reqRecord.val); +} + +- (void)testOptionalRecordTranslation +{ + DBOptionalRecord * rec = [DBOptionalRecord optionalRecord]; + rec.optInt = [NSNumber numberWithInt:6]; + + XCTAssertEqualObjects(rec.optInterface, [[DBOptionalTestHelpers getOptionalRecord] optInterface]); + XCTAssertEqualObjects(rec.optRecord, [[DBOptionalTestHelpers getOptionalRecord] optRecord]); + XCTAssertEqualObjects(rec.optInt, [[DBOptionalTestHelpers getOptionalRecord] optInt]); +} + +- (void)testTranslation +{ + DBMixedRecord * rec = [DBMixedRecord mixedRecordWithReqInt:(int32_t)1 + reqRecord:[DBOptionalTestHelpers getBaseRecord]]; + rec.optRecord = [DBBaseRecord baseRecordWithVal:(int32_t)5]; + + DBMixedRecord * translatedRec = [DBOptionalTestHelpers mixedRecordId:rec]; + + XCTAssertEqualObjects(rec.interfaceVal, translatedRec.interfaceVal); + XCTAssertEqual(rec.reqInt, translatedRec.reqInt); + XCTAssertEqual(rec.optRecord.val, translatedRec.optRecord.val); + XCTAssertEqual(rec.reqRecord.val, translatedRec.reqRecord.val); +} + +@end diff --git a/test-suite/handwritten-src/objc/tests/DBPrimitivesTests.m b/test-suite/handwritten-src/objc/tests/DBPrimitivesTests.m index e7812b06..55a50f2c 100644 --- a/test-suite/handwritten-src/objc/tests/DBPrimitivesTests.m +++ b/test-suite/handwritten-src/objc/tests/DBPrimitivesTests.m @@ -46,6 +46,23 @@ - (void)testEmptyRecord (void)[DBEmptyRecord emptyRecord]; } +- (void)testOptionalRecord +{ + DBAssortedPrimitives * p = [DBAssortedPrimitives assortedPrimitivesWithB:YES + eight:(int8_t)123 + sixteen:(int16_t)20000 + thirtytwo:(int32_t)1000000000 + sixtyfour:(int64_t)1234567890123456789L + fthirtytwo:(float)1.23 + fsixtyfour:1.23]; + + // Set a few of the optional values + p.oB = [NSNumber numberWithBool:YES]; + p.oSixteen = [NSNumber numberWithShort:20000]; + + XCTAssertEqualObjects(p, [DBTestHelpers assortedPrimitivesId:p]); +} + - (void)testObjcToCppConverter { } diff --git a/test-suite/run_djinni.sh b/test-suite/run_djinni.sh index 61328b40..3623248d 100755 --- a/test-suite/run_djinni.sh +++ b/test-suite/run_djinni.sh @@ -28,6 +28,7 @@ wchar_in_relative="djinni/wchar_test.djinni" prologue_in_relative="djinni/function_prologue.djinni" ident_explicit_in_relative="djinni/ident_explicit.djinni" interface_and_abstract_class_in_relative="djinni/interface_and_abstract_class.djinni" +optional_in_relative="djinni/optionals.djinni" temp_out_relative="djinni-output-temp" cpp_out="$base_dir/generated-src/cpp" @@ -81,6 +82,7 @@ fi --ident-cpp-enum-type foo_bar \ --cpp-optional-template "std::experimental::optional" \ --cpp-optional-header "\"../../handwritten-src/cpp/optional.hpp\"" \ + --cpp-nullopt-value "std::experimental::nullopt" \ --cpp-extended-record-include-prefix "../../handwritten-src/cpp/" \ --cpp-use-wide-strings true \ \ @@ -116,6 +118,7 @@ fi --ident-cpp-enum-type foo_bar \ --cpp-optional-template "std::experimental::optional" \ --cpp-optional-header "\"../../handwritten-src/cpp/optional.hpp\"" \ + --cpp-nullopt-value "std::experimental::nullopt" \ --cpp-extended-record-include-prefix "../../handwritten-src/cpp/" \ \ --jni-out "$temp_out_relative/jni" \ @@ -154,6 +157,7 @@ fi --ident-cpp-enum-type foo_bar \ --cpp-optional-template "std::experimental::optional" \ --cpp-optional-header "\"../../handwritten-src/cpp/optional.hpp\"" \ + --cpp-nullopt-value "std::experimental::nullopt" \ --cpp-extended-record-include-prefix "../../handwritten-src/cpp/" \ \ --jni-out "$temp_out_relative/jni" \ @@ -182,6 +186,7 @@ fi --ident-cpp-enum-type foo_bar! \ --cpp-optional-template "std::experimental::optional" \ --cpp-optional-header "\"../../handwritten-src/cpp/optional.hpp\"" \ + --cpp-nullopt-value "std::experimental::nullopt" \ --cpp-extended-record-include-prefix "../../handwritten-src/cpp/" \ \ --jni-out "$temp_out_relative/jni" \ @@ -198,6 +203,36 @@ fi --ident-objc-const NativeFooBar! \ \ --idl "$ident_explicit_in_relative" && \ +"$base_dir/../src/run-assume-built" \ + --java-out "$temp_out_relative/java" \ + --java-package $java_package \ + --java-nullable-annotation "javax.annotation.CheckForNull" \ + --java-nonnull-annotation "javax.annotation.Nonnull" \ + --java-use-final-for-record false \ + --ident-java-field mFooBar \ + \ + --cpp-out "$temp_out_relative/cpp" \ + --cpp-namespace testsuite \ + --ident-cpp-enum-type foo_bar \ + --cpp-optional-template "std::experimental::optional" \ + --cpp-optional-header "\"../../handwritten-src/cpp/optional.hpp\"" \ + --cpp-nullopt-value "std::experimental::nullopt" \ + --cpp-extended-record-include-prefix "../../handwritten-src/cpp/" \ + \ + --jni-out "$temp_out_relative/jni" \ + --ident-jni-class NativeFooBar \ + --ident-jni-file NativeFooBar \ + \ + --objc-out "$temp_out_relative/objc" \ + --objcpp-out "$temp_out_relative/objc" \ + --objc-type-prefix DB \ + \ + --wasm-out "$temp_out_relative/wasm" \ + --wasm-namespace "testsuite" \ + --ts-out "$temp_out_relative/ts" \ + --ts-module "test_optional" \ + \ + --idl "$optional_in_relative" && \ "$base_dir/../src/run-assume-built" \ --java-out "$temp_out_relative/java" \ --java-package $java_package \ @@ -213,6 +248,7 @@ fi --ident-cpp-enum-type foo_bar \ --cpp-optional-template "std::experimental::optional" \ --cpp-optional-header "\"../../handwritten-src/cpp/optional.hpp\"" \ + --cpp-nullopt-value "std::experimental::nullopt" \ --cpp-extended-record-include-prefix "../../handwritten-src/cpp/" \ \ --jni-out "$temp_out_relative/jni" \ @@ -223,6 +259,7 @@ fi --objc-out "$temp_out_relative/objc" \ --objcpp-out "$temp_out_relative/objc" \ --objc-type-prefix DB \ + --objc-omit-full-convenience-constructor true \ \ --yaml-out "$temp_out_relative/yaml" \ --yaml-out-file "yaml-interface-test.yaml" \ @@ -244,6 +281,7 @@ cp "$base_dir/djinni/yaml-test.djinni" "$temp_out/yaml" --ident-cpp-enum-type foo_bar \ --cpp-optional-template "std::experimental::optional" \ --cpp-optional-header "\"../../handwritten-src/cpp/optional.hpp\"" \ + --cpp-nullopt-value "std::experimental::nullopt" \ \ --jni-out "$temp_out_relative/jni" \ --jni-use-on-load-initializer false \ @@ -253,6 +291,7 @@ cp "$base_dir/djinni/yaml-test.djinni" "$temp_out/yaml" --objc-out "$temp_out_relative/objc" \ --objcpp-out "$temp_out_relative/objc" \ --objc-type-prefix DB \ + --objc-omit-full-convenience-constructor true \ \ --wasm-out "$temp_out_relative/wasm" \ --wasm-namespace "testsuite" \