X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=java_strings.py;h=6abfe42701edaea931a92e7593b4d948b48c34d9;hb=1ef2dc8b8a3e0e244ad82ac08e286df489eca4b7;hp=8fcc3e5cf13cf6bcf6b59c1671a94f2d5710bee9;hpb=64bcaa6a2a2f05653c14b9cb8bb97ab2480eaaa5;p=ldk-java diff --git a/java_strings.py b/java_strings.py index 8fcc3e5c..6abfe427 100644 --- a/java_strings.py +++ b/java_strings.py @@ -630,6 +630,8 @@ import javax.annotation.Nullable; return arr_name + " != null ? Arrays.stream(" + arr_name + ").mapToLong(" + conv_name + " -> " + elem_ty.from_hu_conv[0] + ").toArray() : null" elif elem_ty.java_ty == "long": return arr_name + " != null ? Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + elem_ty.from_hu_conv[0] + ").toArray() : null" + elif elem_ty.java_hu_ty == "UInt5": + return arr_name + " != null ? InternalUtils.convUInt5Array(" + arr_name + ") : null" else: return arr_name + " != null ? Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + elem_ty.from_hu_conv[0] + ").toArray(" + arr_ty.java_ty + "::new) : null" @@ -673,6 +675,8 @@ import javax.annotation.Nullable; # Do a bit of a dance to move any excess [] to the end conv += "[" + ty_info.subty.java_hu_ty.split("<")[0].split("[")[1] return conv + def cleanup_converted_native_array(self, ty_info, arr_name): + return None def primitive_arr_from_hu(self, mapped_ty, fixed_len, arr_name): if fixed_len is not None: @@ -697,6 +701,15 @@ import javax.annotation.Nullable; def add_ref(self, holder, referent): return holder + ".ptrs_to.add(" + referent + ")" + def fully_qualified_hu_ty_path(self, ty): + if ty.java_fn_ty_arg.startswith("L") and ty.java_fn_ty_arg.endswith(";"): + return ty.java_fn_ty_arg.strip("L;").replace("/", ".") + if ty.java_hu_ty == "UnqualifiedError" or ty.java_hu_ty == "UInt5": + return "org.ldk.util." + ty.java_hu_ty + if ty.rust_obj is not None and not "[]" in ty.java_hu_ty: + return "org.ldk.structs." + ty.java_hu_ty + return ty.java_hu_ty + def native_c_unitary_enum_map(self, struct_name, variants, enum_doc_comment): out_java_enum = "package org.ldk.enums;\n\n" out_java = "" @@ -878,7 +891,8 @@ import javax.annotation.Nullable; else: java_trait_constr = java_trait_constr + arg_info.arg_name - java_trait_constr = java_trait_constr + ");\n" + java_trait_constr += ");\n" + java_trait_constr += "\t\t\t\tReference.reachabilityFence(arg);\n" if fn_line.ret_ty_info.java_ty != "void": if fn_line.ret_ty_info.from_hu_conv is not None: java_trait_constr = java_trait_constr + "\t\t\t\t" + fn_line.ret_ty_info.java_ty + " result = " + fn_line.ret_ty_info.from_hu_conv[0] + ";\n" @@ -1161,20 +1175,19 @@ import javax.annotation.Nullable; if idx > 0: init_meth_params = init_meth_params + ", " - if field_ty.java_hu_ty == var.var_name: - field_path = field_ty.java_fn_ty_arg.strip("L;").replace("/", ".") - out_java += "\t\t\tpublic " + field_path + " " + field_ty.arg_name + ";\n" - java_hu_subclasses = java_hu_subclasses + "\t\tpublic final " + field_path + " " + field_ty.arg_name + ";\n" - init_meth_params = init_meth_params + field_path + " " + field_ty.arg_name - else: - out_java += "\t\t\tpublic " + field_ty.java_ty + " " + field_ty.arg_name + ";\n" - if field_docs is not None: - java_hu_subclasses += "\t\t/**\n\t\t * " + field_docs.replace("\n", "\n\t\t * ") + "\n\t\t*/\n" - java_hu_subclasses += "\t\t" - if field_ty.nullable: - java_hu_subclasses += "@Nullable " - java_hu_subclasses += "public final " + field_ty.java_hu_ty + " " + field_ty.arg_name + ";\n" - init_meth_params = init_meth_params + field_ty.java_ty + " " + field_ty.arg_name + java_ty = field_ty.java_ty + if field_ty.java_fn_ty_arg.startswith("L") and field_ty.java_fn_ty_arg.endswith(";"): + # If this is a simple enum, we have to reference it in the low-level bindings differently: + java_ty = field_ty.java_fn_ty_arg.strip("L;").replace("/", ".") + out_java += "\t\t\tpublic " + java_ty + " " + field_ty.arg_name + ";\n" + if field_docs is not None: + java_hu_subclasses += "\t\t/**\n\t\t * " + field_docs.replace("\n", "\n\t\t * ") + "\n\t\t*/\n" + java_hu_subclasses += "\t\t" + if field_ty.nullable: + java_hu_subclasses += "@Nullable " + java_hu_subclasses += "public final " + self.fully_qualified_hu_ty_path(field_ty) + " " + field_ty.arg_name + ";\n" + init_meth_params = init_meth_params + java_ty + " " + field_ty.arg_name + init_meth_body = init_meth_body + "this." + field_ty.arg_name + " = " + field_ty.arg_name + "; " if field_ty.to_hu_conv is not None: hu_conv_body = hu_conv_body + "\t\t\t" + field_ty.java_ty + " " + field_ty.arg_name + " = obj." + field_ty.arg_name + ";\n"