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<StereoMatcher> createRightMatcher(Ptr<StereoMatcher> matcher_left)"
  where, "StereoMather" is from another package (calib3d)
pull/10495/head
Alexander Alekhin 7 years ago
parent 1237faef80
commit a362fd80df
  1. 23
      modules/java/generator/gen_java.py
  2. 3
      modules/java/generator/templates/java_class.prolog
  3. 3
      modules/java/generator/templates/java_class_inherited.prolog

@ -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 = ""

@ -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); }

@ -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); }

Loading…
Cancel
Save