From a362fd80dffb830a01945038744a9cea72d18a03 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 3 Jan 2018 17:18:39 +0000 Subject: [PATCH] java: fix bindings generator - fix imports override. Problem is observed with BoostDesc. - add Ptr<> handling (constructor is protected from other packages). Observed in ximgproc: Ptr createRightMatcher(Ptr matcher_left)" where, "StereoMather" is from another package (calib3d) --- modules/java/generator/gen_java.py | 23 +++++++++++++------ .../generator/templates/java_class.prolog | 3 +++ .../templates/java_class_inherited.prolog | 3 +++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index 07962e76b3..41c14b8ea5 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -350,16 +350,22 @@ class JavaWrapperGenerator(object): if name in type_dict and not classinfo.base: logging.warning('duplicated: %s', classinfo) return - type_dict[name] = \ + type_dict.setdefault(name, {}).update( { "j_type" : classinfo.jname, "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),), "jni_name" : "(*("+classinfo.fullName(isCPP=True)+"*)%(n)s_nativeObj)", "jni_type" : "jlong", - "suffix" : "J" } - type_dict[name+'*'] = \ + "suffix" : "J", + "j_import" : "org.opencv.%s.%s" % (self.module, classinfo.jname) + } + ) + type_dict.setdefault(name+'*', {}).update( { "j_type" : classinfo.jname, "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),), "jni_name" : "("+classinfo.fullName(isCPP=True)+"*)%(n)s_nativeObj", "jni_type" : "jlong", - "suffix" : "J" } + "suffix" : "J", + "j_import" : "org.opencv.%s.%s" % (self.module, classinfo.jname) + } + ) # missing_consts { Module : { public : [[name, val],...], private : [[]...] } } if name in missing_consts: @@ -379,11 +385,14 @@ class JavaWrapperGenerator(object): if classinfo.base: classinfo.addImports(classinfo.base) - type_dict["Ptr_"+name] = \ + type_dict.setdefault("Ptr_"+name, {}).update( { "j_type" : classinfo.jname, "jn_type" : "long", "jn_args" : (("__int64", ".getNativeObjAddr()"),), "jni_name" : "*((Ptr<"+classinfo.fullName(isCPP=True)+">*)%(n)s_nativeObj)", "jni_type" : "jlong", - "suffix" : "J" } + "suffix" : "J", + "j_import" : "org.opencv.%s.%s" % (self.module, classinfo.jname) + } + ) logging.info('ok: class %s, name: %s, base: %s', classinfo, name, classinfo.base) def add_const(self, decl): # [ "const cname", val, [], [] ] @@ -713,7 +722,7 @@ class JavaWrapperGenerator(object): j_prologue.append( j_type + ' retVal = new Array' + j_type+'();') j_epilogue.append('Converters.Mat_to_' + ret_type + '(retValMat, retVal);') elif ret_type.startswith("Ptr_"): - ret_val = type_dict[fi.ctype]["j_type"] + " retVal = new " + type_dict[ret_type]["j_type"] + "(" + ret_val = type_dict[fi.ctype]["j_type"] + " retVal = " + type_dict[ret_type]["j_type"] + ".__fromPtr__(" tail = ")" elif ret_type == "void": ret_val = "" diff --git a/modules/java/generator/templates/java_class.prolog b/modules/java/generator/templates/java_class.prolog index b771be9439..49404cb440 100644 --- a/modules/java/generator/templates/java_class.prolog +++ b/modules/java/generator/templates/java_class.prolog @@ -13,3 +13,6 @@ public class $jname { protected $jname(long addr) { nativeObj = addr; } public long getNativeObjAddr() { return nativeObj; } + + // internal usage only + public static $jname __fromPtr__(long addr) { return new $jname(addr); } diff --git a/modules/java/generator/templates/java_class_inherited.prolog b/modules/java/generator/templates/java_class_inherited.prolog index e7b32080cf..17d5528a73 100644 --- a/modules/java/generator/templates/java_class_inherited.prolog +++ b/modules/java/generator/templates/java_class_inherited.prolog @@ -10,3 +10,6 @@ $annotation public class $jname extends $base { protected $jname(long addr) { super(addr); } + + // internal usage only + public static $jname __fromPtr__(long addr) { return new $jname(addr); }