Merge pull request #39 from TheBlueMatt/main
[ldk-java] / java_strings.py
index 82efd47b72be17330f3a27a09ee0c16007b9273c..2ddecab7539aed909fc8f544515f4ec3497e1a0a 100644 (file)
@@ -484,6 +484,7 @@ import javax.annotation.Nullable;
         self.ptr_native_ty = "long"
         self.result_c_ty = "jclass"
         self.ptr_arr = "jobjectArray"
+        self.is_arr_some_check = ("", " != NULL")
         self.get_native_arr_len_call = ("(*env)->GetArrayLength(env, ", ")")
 
     def construct_jenv(self):
@@ -848,7 +849,7 @@ import javax.annotation.Nullable;
                 elif not fn_line.ret_ty_info.passed_as_ptr:
                     out_c += "\t" + fn_line.ret_ty_info.c_ty + " ret = (*env)->Call" + fn_line.ret_ty_info.java_ty.title() + "Method(env, obj, j_calls->" + fn_line.fn_name + "_meth"
                 else:
-                    out_c = out_c + "\t" + fn_line.ret_ty_info.rust_obj + "* ret = (" + fn_line.ret_ty_info.rust_obj + "*)(*env)->CallLongMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
+                    out_c = out_c + "\tuint64_t ret = (*env)->CallLongMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
 
                 for idx, arg_info in enumerate(fn_line.args_ty):
                     if arg_info.ret_conv is not None:
@@ -1023,7 +1024,7 @@ import javax.annotation.Nullable;
             init_meth_params = ""
             init_meth_body = ""
             hu_conv_body = ""
-            for idx, field_ty in enumerate(var.fields):
+            for idx, (field_ty, field_docs) in enumerate(var.fields):
                 if idx > 0:
                     init_meth_params = init_meth_params + ", "
 
@@ -1034,7 +1035,12 @@ import javax.annotation.Nullable;
                     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"
-                    java_hu_subclasses = java_hu_subclasses + "\t\tpublic final " + field_ty.java_hu_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
                 init_meth_body = init_meth_body + "this." + field_ty.arg_name + " = " + field_ty.arg_name + "; "
                 if field_ty.to_hu_conv is not None:
@@ -1068,7 +1074,7 @@ import javax.annotation.Nullable;
         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):
+            for idx, (field_map, field_docs) 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"))
                     if var.tuple_variant:
@@ -1167,7 +1173,10 @@ import javax.annotation.Nullable;
                     else:
                         if arg.nullable:
                             out_java_struct += "@Nullable "
-                        out_java_struct += (arg.java_hu_ty + " " + arg.arg_name)
+                        ty_string = arg.java_hu_ty
+                        if arg.java_fn_ty_arg[0] == "L" and arg.java_fn_ty_arg[len(arg.java_fn_ty_arg) - 1] == ";":
+                            ty_string = arg.java_fn_ty_arg.strip("L;").replace("/", ".")
+                        out_java_struct += ty_string + " " + arg.arg_name
         out_java += (");\n")
         out_c += (") {\n")
         if out_java_struct is not None: