From d4846238a5f4245ac3cee8dbf3f196ad964564d5 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 5 Dec 2021 23:28:18 +0000 Subject: [PATCH] Override hashCode and equals for Rust objects that impl the equivalent --- java_strings.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/java_strings.py b/java_strings.py index 3827005a..ef4ada47 100644 --- a/java_strings.py +++ b/java_strings.py @@ -1187,6 +1187,7 @@ import javax.annotation.Nullable; out_java += (arg_conv_info.java_ty + " " + arg_conv_info.arg_name) out_java_struct = "" + extra_java_struct_out = "" if not args_known: out_java_struct += ("\t// Skipped " + method_name + "\n") else: @@ -1204,6 +1205,15 @@ import javax.annotation.Nullable; elif meth_n == "clone_ptr": out_java_struct += ("\t" + return_type_info.java_hu_ty + " " + meth_n + "(") else: + if meth_n == "hash" and return_type_info.java_hu_ty == "long": + extra_java_struct_out = "\t@Override public int hashCode() {\n" + extra_java_struct_out += "\t\treturn (int)this.hash();\n" + extra_java_struct_out += "\t}\n" + elif meth_n == "eq" and return_type_info.java_hu_ty == "boolean": + extra_java_struct_out = "\t@Override public boolean equals(Object o) {\n" + extra_java_struct_out += "\t\tif (!(o instanceof " + struct_meth + ")) return false;\n" + extra_java_struct_out += "\t\treturn this.eq((" + struct_meth + ")o);\n" + extra_java_struct_out += "\t}\n" out_java_struct += ("\tpublic " + return_type_info.java_hu_ty + " " + meth_n + "(") for idx, arg in enumerate(argument_types): if idx != 0: @@ -1326,4 +1336,4 @@ import javax.annotation.Nullable; out_java_struct += ("\t\treturn ret;\n") out_java_struct += ("\t}\n\n") - return (out_java, out_c, out_java_struct) + return (out_java, out_c, out_java_struct + extra_java_struct_out) -- 2.39.5