Skip to content

Commit

Permalink
Add closure of try-with-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnio committed Jan 28, 2021
1 parent 2207316 commit 0bf37d5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions modules/java/generator/gen_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,8 @@ def gen_func(self, ci, fi, prop_name=''):
jni_args = [ArgInfo([ "env", "env", "", [], "" ]), ArgInfo([ "cls", "", "", [], "" ])]
j_prologue = []
j_epilogue = []
#try-with-resources closures
j_twr_epilogue = []
c_prologue = []
c_epilogue = []
if type_dict[fi.ctype]["jni_type"] == "jdoubleArray":
Expand Down Expand Up @@ -743,7 +745,7 @@ def gen_func(self, ci, fi, prop_name=''):
else:
if not type_dict[a.ctype]["j_type"].startswith("MatOf"):
j_prologue.append( "try (Mat %(n)s_mat = Converters.%(t)s_to_Mat(%(n)s)) { //?3" % {"n" : a.name, "t" : a.ctype} )
j_epilogue.append( "} //?3-close" )
j_twr_epilogue.append( "} //?3-close" )
else:
j_prologue.append( "Mat %s_mat = %s;" % (a.name, a.name) )
c_prologue.append( "Mat_to_%(t)s( %(n)s_mat, %(n)s );" % {"n" : a.name, "t" : a.ctype} )
Expand Down Expand Up @@ -926,17 +928,19 @@ def gen_func(self, ci, fi, prop_name=''):
if fi.classname:
static = fi.static

j_code_twr_whitespace = "\n ".join(((""),*len(j_twr_epilogue))) if j_twr_epilogue else ""
j_code.write( Template(
""" public $static$j_type$j_name($j_args) {$prologue
$ret_val$jn_name($jn_args_call)$tail;$epilogue$ret
$ret_val$jn_name($jn_args_call)$tail;$epilogue$ret$twr
}
"""
).substitute(
ret = "\n " + ret if ret else "",
twr = "\n " + "\n ".join(j_twr_epilogue) if j_twr_epilogue else "",
ret = "\n " + j_code_twr_whitespace + ret if ret else "",
ret_val = ret_val,
tail = tail,
prologue = "\n " + "\n ".join(j_prologue) if j_prologue else "",
prologue = "\n " + j_code_twr_whitespace + "\n ".join(j_prologue) if j_prologue else "",
epilogue = "\n " + "\n ".join(j_epilogue) if j_epilogue else "",
static = static + " " if static else "",
j_type=type_dict[fi.ctype]["j_type"] + " " if type_dict[fi.ctype]["j_type"] else "",
Expand Down

0 comments on commit 0bf37d5

Please sign in to comment.