Skip to content

Commit a506820

Browse files
authored
* Let Parser annotate Java constructors with @Deprecated when appropriate (pull bytedeco#757)
* Add to `InfoMap.defaults` more names that are reserved in Java, but not in C++ (pull bytedeco#757)
1 parent eba6b7f commit a506820

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
* Let `Parser` annotate Java constructors with `@Deprecated` when appropriate ([pull #757](https://github.com/bytedeco/javacpp/pull/757))
3+
* Add to `InfoMap.defaults` more names that are reserved in Java, but not in C++ ([pull #757](https://github.com/bytedeco/javacpp/pull/757))
24
* Bundle `libomp` from Visual Studio to fix presets using OpenMP on Windows ([pull #755](https://github.com/bytedeco/javacpp/pull/755))
35
* Fix inconsistencies when using `@Platform(inherit=..., library=...)` together ([pull #747](https://github.com/bytedeco/javacpp/pull/747))
46
* Let `Parser` support templates with unnamed type parameters ([pull #742](https://github.com/bytedeco/javacpp/pull/742))

src/main/java/org/bytedeco/javacpp/tools/InfoMap.java

+5
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,23 @@ public class InfoMap extends HashMap<String,List<Info>> {
110110
.put(new Info("std::vector").annotations("@StdVector"))
111111

112112
.put(new Info("abstract").javaNames("_abstract"))
113+
.put(new Info("assert").javaNames("_assert"))
113114
.put(new Info("boolean").javaNames("_boolean"))
114115
.put(new Info("byte").javaNames("_byte"))
115116
.put(new Info("extends").javaNames("_extends"))
117+
.put(new Info("final").javaNames("_final"))
116118
.put(new Info("finally").javaNames("_finally"))
117119
.put(new Info("implements").javaNames("_implements"))
118120
.put(new Info("import").javaNames("_import"))
119121
.put(new Info("instanceof").javaNames("_instanceof"))
122+
.put(new Info("interface").javaNames("_interface"))
120123
.put(new Info("native").javaNames("_native"))
121124
.put(new Info("null").javaNames("_null"))
122125
.put(new Info("package").javaNames("_package"))
126+
.put(new Info("strictfp").javaNames("_strictfp"))
123127
.put(new Info("super").javaNames("_super"))
124128
.put(new Info("synchronized").javaNames("_synchronized"))
129+
.put(new Info("throws").javaNames("_throws"))
125130
.put(new Info("transient").javaNames("_transient"))
126131

127132
.put(new Info("operator ->").javaNames("access"))

src/main/java/org/bytedeco/javacpp/tools/Parser.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ static String desugarVarargs(String s) {
127127
return s.trim().endsWith("...") ? s.trim().substring(0, s.length() - 3) + "[]" : s;
128128
}
129129

130+
static String filterJavaAnnotations(String s) {
131+
return s.contains("@Deprecated") ? "@Deprecated " : "";
132+
}
133+
130134
static String upcastMethodName(String javaName) {
131135
String shortName = javaName.substring(javaName.lastIndexOf('.') + 1);
132136
return "as" + Character.toUpperCase(shortName.charAt(0)) + shortName.substring(1);
@@ -357,7 +361,7 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
357361
if (dim < 2 && !javaName.equals("int") && !javaName.equals("long")) {
358362
decl.text += " public " + containerType.javaName + "(" + javaName + " value) { this(1); put(0, value); }\n";
359363
}
360-
decl.text += " public " + containerType.javaName + "(" + javaName + arrayBrackets + " ... array) { this(array.length); put(array); }\n";
364+
decl.text += " public " + containerType.javaName + "(" + desugarVarargs(javaName) + arrayBrackets + " ... array) { this(array.length); put(array); }\n";
361365
}
362366
} else if (indexType == null && dim == 0 && !constant && !purify) {
363367
int n = 0;
@@ -597,7 +601,7 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio
597601
+ " return put(0, value);\n"
598602
+ " }\n";
599603
}
600-
decl.text += " public " + containerType.javaName + " put(" + javaName + arrayBrackets + " ... array) {\n";
604+
decl.text += " public " + containerType.javaName + " put(" + desugarVarargs(javaName) + arrayBrackets + " ... array) {\n";
601605
String indent = " ", indices = "", args = "";
602606
separator = "";
603607
for (int i = 0; i < dim; i++) {
@@ -2740,7 +2744,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
27402744
}
27412745
}
27422746
if (type.constructor && params != null) {
2743-
decl.text += "public " + context.shorten(context.javaName) + dcl.parameters.list + " { super((Pointer)null); allocate" + params.names + "; }\n" +
2747+
decl.text += filterJavaAnnotations(type.annotations) + "public " + context.shorten(context.javaName) + dcl.parameters.list + " { super((Pointer)null); allocate" + params.names + "; }\n" +
27442748
type.annotations + "private native void allocate" + dcl.parameters.list + ";\n";
27452749
} else {
27462750
String modifiers2 = modifiers;
@@ -3494,7 +3498,7 @@ String downcast(Type derived, Type base, boolean virtual) {
34943498
}
34953499
String shortName = derived.javaName.substring(derived.javaName.lastIndexOf('.') + 1);
34963500
String res = " /** Downcast constructor. */\n"
3497-
+ " public " + shortName + "(" + base.javaName + " pointer) { super((Pointer)null); allocate(pointer); }\n";
3501+
+ " " + filterJavaAnnotations(annotations) + "public " + shortName + "(" + base.javaName + " pointer) { super((Pointer)null); allocate(pointer); }\n";
34983502
if (annotations.isEmpty()) {
34993503
res += " @Namespace private native @Name(\"" + downcastType + "_cast<" + derived.cppName + "*>\") void allocate(" + base.javaName + " pointer);\n";
35003504
} else {
@@ -3931,7 +3935,7 @@ boolean group(Context context, DeclarationList declList) throws ParserException
39313935

39323936
if (implicitConstructor && (info == null || !info.purify) && (!abstractClass || ctx.virtualize)) {
39333937
constructors += " /** Default native constructor. */\n" +
3934-
" public " + shortName + "() { super((Pointer)null); allocate(); }\n";
3938+
" " + filterJavaAnnotations(constructorAnnotations) + "public " + shortName + "() { super((Pointer)null); allocate(); }\n";
39353939
if (constructorAnnotations.isEmpty()) {
39363940
constructors += " /** Native array allocator. Access with {@link Pointer#position(long)}. */\n" +
39373941
" public " + shortName + "(long size) { super((Pointer)null); allocateArray(size); }\n";

0 commit comments

Comments
 (0)