Skip to content

Commit 0608227

Browse files
abratchikalalek
authored andcommitted
Merge pull request opencv#9698 from abratchik:parse.doxygen
Support @deprecated tag in java wrappers (opencv#9698)
1 parent 6506194 commit 0608227

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

modules/dnn/misc/java/test/DnnTensorFlowTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.opencv.core.Size;
1010
import org.opencv.dnn.DictValue;
1111
import org.opencv.dnn.Dnn;
12-
import org.opencv.dnn.Importer;
1312
import org.opencv.dnn.Layer;
1413
import org.opencv.dnn.Net;
1514
import org.opencv.imgcodecs.Imgcodecs;

modules/features2d/misc/java/src/cpp/features2d_manual.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
namespace cv
1313
{
1414

15+
/**
16+
* @deprecated Please use direct instantiation of Feature2D classes
17+
*/
1518
class CV_EXPORTS_AS(FeatureDetector) javaFeatureDetector
1619
{
1720
public:
@@ -87,8 +90,11 @@ class CV_EXPORTS_AS(FeatureDetector) javaFeatureDetector
8790
DYNAMIC_AKAZE = DYNAMICDETECTOR + AKAZE
8891
};
8992

90-
//supported: FAST STAR SIFT SURF ORB MSER GFTT HARRIS BRISK AKAZE Grid(XXXX) Pyramid(XXXX) Dynamic(XXXX)
91-
//not supported: SimpleBlob, Dense
93+
/**
94+
* supported: FAST STAR SIFT SURF ORB MSER GFTT HARRIS BRISK AKAZE Grid(XXXX) Pyramid(XXXX) Dynamic(XXXX)
95+
* not supported: SimpleBlob, Dense
96+
* @deprecated
97+
*/
9298
CV_WRAP static Ptr<javaFeatureDetector> create( int detectorType )
9399
{
94100
//String name;
@@ -179,6 +185,9 @@ class CV_EXPORTS_AS(FeatureDetector) javaFeatureDetector
179185
Ptr<FeatureDetector> wrapped;
180186
};
181187

188+
/**
189+
* @deprecated
190+
*/
182191
class CV_EXPORTS_AS(DescriptorExtractor) javaDescriptorExtractor
183192
{
184193
public:

modules/java/generator/gen_java.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ def libVersionBlock():
9191
9292
$imports
9393
94-
// C++: class $name
95-
//javadoc: $name
94+
$docs
95+
$annotation
9696
public class $jname extends $base {
9797
9898
protected $jname(long addr) { super(addr); }
@@ -107,8 +107,8 @@ def libVersionBlock():
107107
108108
$imports
109109
110-
// C++: class $name
111-
//javadoc: $name
110+
$docs
111+
$annotation
112112
public class $jname {
113113
114114
protected final long nativeObj;
@@ -125,6 +125,8 @@ def libVersionBlock():
125125
126126
$imports
127127
128+
$docs
129+
$annotation
128130
public class $jname {
129131
"""
130132

@@ -182,8 +184,22 @@ def libVersionBlock():
182184
"""
183185

184186
class GeneralInfo():
185-
def __init__(self, name, namespaces):
186-
self.namespace, self.classpath, self.classname, self.name = self.parseName(name, namespaces)
187+
def __init__(self, type, decl, namespaces):
188+
self.namespace, self.classpath, self.classname, self.name = self.parseName(decl[0], namespaces)
189+
190+
# parse doxygen comments
191+
self.params={}
192+
self.annotation=[]
193+
if type == "class":
194+
docstring="// C++: class " + self.name + "\n//javadoc: " + self.name
195+
else:
196+
docstring=""
197+
if len(decl)>5 and decl[5]:
198+
logging.info('docstring: %s', decl[5])
199+
if re.search("(@|\\\\)deprecated", decl[5]):
200+
self.annotation.append("@Deprecated")
201+
202+
self.docstring = docstring
187203

188204
def parseName(self, name, namespaces):
189205
'''
@@ -218,7 +234,7 @@ def fullClass(self, isCPP=False):
218234

219235
class ConstInfo(GeneralInfo):
220236
def __init__(self, decl, addedManually=False, namespaces=[]):
221-
GeneralInfo.__init__(self, decl[0], namespaces)
237+
GeneralInfo.__init__(self, "const", decl, namespaces)
222238
self.cname = self.name.replace(".", "::")
223239
self.value = decl[1]
224240
self.addedManually = addedManually
@@ -245,7 +261,7 @@ def __repr__(self):
245261

246262
class ClassInfo(GeneralInfo):
247263
def __init__(self, decl, namespaces=[]): # [ 'class/struct cname', ': base', [modlist] ]
248-
GeneralInfo.__init__(self, decl[0], namespaces)
264+
GeneralInfo.__init__(self, "class", decl, namespaces)
249265
self.cname = self.name.replace(".", "::")
250266
self.methods = []
251267
self.methods_suffixes = {}
@@ -335,6 +351,8 @@ def generateJavaCode(self, m, M):
335351
name = self.name,
336352
jname = self.jname,
337353
imports = "\n".join(self.getAllImports(M)),
354+
docs = self.docstring,
355+
annotation = "\n".join(self.annotation),
338356
base = self.base)
339357

340358
def generateCppCode(self):
@@ -364,7 +382,7 @@ def __repr__(self):
364382

365383
class FuncInfo(GeneralInfo):
366384
def __init__(self, decl, namespaces=[]): # [ funcname, return_ctype, [modifiers], [args] ]
367-
GeneralInfo.__init__(self, decl[0], namespaces)
385+
GeneralInfo.__init__(self, "func", decl, namespaces)
368386
self.cname = self.name.replace(".", "::")
369387
self.jname = self.name
370388
self.isconstructor = self.name == self.classname
@@ -741,6 +759,13 @@ def gen_func(self, ci, fi, prop_name=''):
741759
java_doc = "//javadoc: " + f_name + "(%s)" % ", ".join([a.name for a in args if a.ctype])
742760
j_code.write(" "*4 + java_doc + "\n")
743761

762+
if fi.docstring:
763+
lines = StringIO(fi.docstring)
764+
for line in lines:
765+
j_code.write(" "*4 + line + "\n")
766+
if fi.annotation:
767+
j_code.write(" "*4 + "\n".join(fi.annotation) + "\n")
768+
744769
# public java wrapper method impl (calling native one above)
745770
# e.g.
746771
# public static void add( Mat src1, Mat src2, Mat dst, Mat mask, int dtype )

0 commit comments

Comments
 (0)