self.util_fn_pfx = """package org.ldk.structs;
import org.ldk.impl.bindings;
import java.util.Arrays;
+import javax.annotation.Nullable;
import org.ldk.enums.*;
public class UtilMethods {
class CommonBase {
long ptr;
LinkedList<Object> ptrs_to = new LinkedList();
- protected CommonBase(long ptr) { this.ptr = ptr; }
+ protected CommonBase(long ptr) { assert ptr > 1024; this.ptr = ptr; }
}
"""
import org.ldk.enums.*;
import org.ldk.util.*;
import java.util.Arrays;
+import javax.annotation.Nullable;
"""
self.c_fn_ty_pfx = "JNIEXPORT "
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):
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:
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 + ", "
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:
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:
meth_n = method_name[len(struct_meth) + 1 if len(struct_meth) != 0 else 0:].strip("_")
if doc_comment is not None:
out_java_struct += "\t/**\n\t * " + doc_comment.replace("\n", "\n\t * ") + "\n\t */\n"
+ if return_type_info.nullable:
+ out_java_struct += "\t@Nullable\n"
if not takes_self:
if meth_n == "new":
out_java_struct += "\tpublic static " + return_type_info.java_hu_ty + " of("
continue
if arg.java_ty != "void":
if arg.arg_name in default_constructor_args:
+ assert not arg.nullable
for explode_idx, explode_arg in enumerate(default_constructor_args[arg.arg_name]):
if explode_idx != 0:
out_java_struct += (", ")
out_java_struct += (
explode_arg.java_hu_ty + " " + arg.arg_name + "_" + explode_arg.arg_name)
else:
- out_java_struct += (arg.java_hu_ty + " " + arg.arg_name)
+ if arg.nullable:
+ out_java_struct += "@Nullable "
+ 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:
else:
out_java_struct += (info.arg_name)
out_java_struct += (");\n")
+ if return_type_info.java_ty == "long" and return_type_info.java_hu_ty != "long":
+ out_java_struct += "\t\tif (ret < 1024) { return null; }\n"
+
if return_type_info.to_hu_conv is not None:
if not takes_self:
out_java_struct += ("\t\t" + return_type_info.to_hu_conv.replace("\n", "\n\t\t").replace("this",