+
+ def map_complex_enum(self, struct_name, variant_list, camel_to_snake):
+ java_hu_type = struct_name.replace("LDK", "")
+
+ out_java_enum = ""
+ out_java = ""
+ out_c = ""
+
+ out_java_enum += (self.hu_struct_file_prefix)
+ out_java_enum += ("export default class " + java_hu_type + " extends CommonBase {\n")
+ out_java_enum += ("\tprotected constructor(_dummy: object, ptr: number) { super(ptr); }\n")
+ out_java_enum += ("\tprotected finalize() {\n")
+ out_java_enum += ("\t\tsuper.finalize();\n")
+ out_java_enum += ("\t\tif (this.ptr != 0) { bindings." + java_hu_type + "_free(this.ptr); }\n")
+ out_java_enum += ("\t}\n")
+ out_java_enum += f"\tstatic constr_from_ptr(ptr: number): {java_hu_type} {{\n"
+ out_java_enum += (f"\t\tconst raw_val: bindings.{struct_name} = bindings." + struct_name + "_ref_from_ptr(ptr);\n")
+ java_hu_subclasses = ""
+
+ out_java += ("\tpublic static class " + struct_name + " {\n")
+ out_java += ("\t\tprivate " + struct_name + "() {}\n")
+ for var in variant_list:
+ out_java += ("\t\texport class " + var.var_name + " extends " + struct_name + " {\n")
+ java_hu_subclasses = java_hu_subclasses + "export class " + var.var_name + " extends " + java_hu_type + " {\n"
+ out_java_enum += ("\t\tif (raw_val instanceof bindings." + struct_name + "." + var.var_name + ") {\n")
+ out_java_enum += ("\t\t\treturn new " + var.var_name + "(this.ptr, raw_val);\n")
+ init_meth_params = ""
+ init_meth_body = ""
+ hu_conv_body = ""
+ for idx, field_ty in enumerate(var.fields):
+ out_java += ("\t\t\tpublic " + field_ty.java_ty + " " + field_ty.arg_name + ";\n")
+ java_hu_subclasses = java_hu_subclasses + "\tpublic " + field_ty.arg_name + f": {field_ty.java_hu_ty};\n"
+ if field_ty.to_hu_conv is not None:
+ hu_conv_body = hu_conv_body + "\t\tconst " + field_ty.arg_name + f": {field_ty.java_ty} = obj." + field_ty.arg_name + ";\n"
+ hu_conv_body = hu_conv_body + "\t\t" + field_ty.to_hu_conv.replace("\n", "\n\t\t\t") + "\n"
+ hu_conv_body = hu_conv_body + "\t\tthis." + field_ty.arg_name + " = " + field_ty.to_hu_conv_name + ";\n"
+ else:
+ hu_conv_body = hu_conv_body + "\t\tthis." + field_ty.arg_name + " = obj." + field_ty.arg_name + ";\n"
+ if idx > 0:
+ init_meth_params = init_meth_params + ", "
+ init_meth_params = init_meth_params + field_ty.java_ty + " " + field_ty.arg_name
+ init_meth_body = init_meth_body + "this." + field_ty.arg_name + " = " + field_ty.arg_name + "; "
+ out_java += ("\t\t\t" + var.var_name + "(" + init_meth_params + ") { ")
+ out_java += (init_meth_body)
+ out_java += ("}\n")
+ out_java += ("\t\t}\n")
+ out_java_enum += ("\t\t}\n")
+ java_hu_subclasses = java_hu_subclasses + "\tprivate constructor(ptr: number, obj: bindings." + struct_name + "." + var.var_name + ") {\n\t\tsuper(null, ptr);\n"
+ java_hu_subclasses = java_hu_subclasses + hu_conv_body
+ java_hu_subclasses = java_hu_subclasses + "\t}\n}\n"
+ out_java += ("\t\tstatic native void init();\n")
+ out_java += ("\t}\n")
+ out_java_enum += ("\t\tthrow new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface\n\t}\n\n")
+ out_java += ("\tstatic { " + struct_name + ".init(); }\n")
+ out_java += ("\tpublic static native " + struct_name + " " + struct_name + "_ref_from_ptr(long ptr);\n");
+
+ out_c += (self.c_fn_ty_pfx + self.c_complex_enum_pass_ty(struct_name) + " " + self.c_fn_name_pfx + struct_name.replace("_", "_1") + "_1ref_1from_1ptr (" + self.c_fn_args_pfx + ", " + self.ptr_c_ty + " ptr) {\n")
+ out_c += ("\t" + struct_name + " *obj = (" + struct_name + "*)ptr;\n")
+ out_c += ("\tswitch(obj->tag) {\n")
+ for var in variant_list:
+ out_c += ("\t\tcase " + struct_name + "_" + var.var_name + ": {\n")
+ c_params = []
+ for idx, field_map in enumerate(var.fields):
+ if field_map.ret_conv is not None:
+ out_c += ("\t\t\t" + field_map.ret_conv[0].replace("\n", "\n\t\t\t"))
+ out_c += ("obj->" + camel_to_snake(var.var_name) + "." + field_map.arg_name)
+ out_c += (field_map.ret_conv[1].replace("\n", "\n\t\t\t") + "\n")
+ c_params.append(field_map.ret_conv_name)
+ else:
+ c_params.append("obj->" + camel_to_snake(var.var_name) + "." + field_map.arg_name)
+ out_c += ("\t\t\treturn " + self.c_constr_native_complex_enum(struct_name, var.var_name, c_params) + ";\n")
+ out_c += ("\t\t}\n")
+ out_c += ("\t\tdefault: abort();\n")
+ out_c += ("\t}\n}\n")
+ out_java_enum += ("}\n")
+ out_java_enum += (java_hu_subclasses)
+ return (out_java, out_java_enum, out_c)