Use explicit return type var names instead of guessing
[ldk-java] / genbindings.py
index 32980aa3c4e7cf8071ebcff248bac9d1ca9993d2..11e659277cf1586272e3edd8cabce64040b720b2 100755 (executable)
@@ -408,7 +408,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java:
         else:
             struct_meth = method_name.split("_")[0]
 
-        return_type_info = type_mapping_generator.map_type(method_return_type, True, ret_arr_len, False, False)
+        return_type_info = type_mapping_generator.map_type(method_return_type.strip() + " ret", True, ret_arr_len, False, False)
 
         argument_types = []
         default_constructor_args = {}
@@ -468,8 +468,8 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java:
                 or expected_struct in complex_enums or expected_cstruct in complex_enums
                 or expected_cstruct in result_types) and not is_free:
             out_java_struct = open(f"{sys.argv[3]}/structs/{struct_meth}{consts.file_ext}", "a")
-        elif method_name.startswith("C2Tuple_") and method_name.endswith("_read"):
-            struct_meth = method_name.rsplit("_", 1)[0]
+        elif (method_name.startswith("C2Tuple_") and method_name.endswith("_read")) or \
+                (return_type_info.rust_obj is not None and "Result" in return_type_info.rust_obj and "from" in method_name):
             out_java_struct = open(f"{sys.argv[3]}/structs/UtilMethods{consts.file_ext}", "a")
         if out_java_struct is not None:
             out_java_struct.write(out_java_struct_delta)
@@ -545,7 +545,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java:
 
             field_fns = []
             for fn_docs, fn_line in trait_fn_lines:
-                ret_ty_info = type_mapping_generator.map_type(fn_line.group(2), True, None, False, False)
+                ret_ty_info = type_mapping_generator.map_type(fn_line.group(2).strip() + " ret", True, None, False, False)
                 is_const = fn_line.group(4) is not None
 
                 arg_tys = []