diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d04034a..908e7f6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ + * Let `Parser` annotate Java constructors with `@Deprecated` when appropriate ([pull #757](https://github.com/bytedeco/javacpp/pull/757)) + * Add to `InfoMap.defaults` more names that are reserved in Java, but not in C++ ([pull #757](https://github.com/bytedeco/javacpp/pull/757)) * Bundle `libomp` from Visual Studio to fix presets using OpenMP on Windows ([pull #755](https://github.com/bytedeco/javacpp/pull/755)) * Fix inconsistencies when using `@Platform(inherit=..., library=...)` together ([pull #747](https://github.com/bytedeco/javacpp/pull/747)) * Let `Parser` support templates with unnamed type parameters ([pull #742](https://github.com/bytedeco/javacpp/pull/742)) diff --git a/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java b/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java index a380b167..8f4fef77 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java +++ b/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java @@ -110,18 +110,23 @@ public class InfoMap extends HashMap> { .put(new Info("std::vector").annotations("@StdVector")) .put(new Info("abstract").javaNames("_abstract")) + .put(new Info("assert").javaNames("_assert")) .put(new Info("boolean").javaNames("_boolean")) .put(new Info("byte").javaNames("_byte")) .put(new Info("extends").javaNames("_extends")) + .put(new Info("final").javaNames("_final")) .put(new Info("finally").javaNames("_finally")) .put(new Info("implements").javaNames("_implements")) .put(new Info("import").javaNames("_import")) .put(new Info("instanceof").javaNames("_instanceof")) + .put(new Info("interface").javaNames("_interface")) .put(new Info("native").javaNames("_native")) .put(new Info("null").javaNames("_null")) .put(new Info("package").javaNames("_package")) + .put(new Info("strictfp").javaNames("_strictfp")) .put(new Info("super").javaNames("_super")) .put(new Info("synchronized").javaNames("_synchronized")) + .put(new Info("throws").javaNames("_throws")) .put(new Info("transient").javaNames("_transient")) .put(new Info("operator ->").javaNames("access")) diff --git a/src/main/java/org/bytedeco/javacpp/tools/Parser.java b/src/main/java/org/bytedeco/javacpp/tools/Parser.java index a86cf3dd..eaaf3222 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/Parser.java +++ b/src/main/java/org/bytedeco/javacpp/tools/Parser.java @@ -127,6 +127,10 @@ static String desugarVarargs(String s) { return s.trim().endsWith("...") ? s.trim().substring(0, s.length() - 3) + "[]" : s; } + static String filterJavaAnnotations(String s) { + return s.contains("@Deprecated") ? "@Deprecated " : ""; + } + static String upcastMethodName(String javaName) { String shortName = javaName.substring(javaName.lastIndexOf('.') + 1); return "as" + Character.toUpperCase(shortName.charAt(0)) + shortName.substring(1); @@ -357,7 +361,7 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio if (dim < 2 && !javaName.equals("int") && !javaName.equals("long")) { decl.text += " public " + containerType.javaName + "(" + javaName + " value) { this(1); put(0, value); }\n"; } - decl.text += " public " + containerType.javaName + "(" + javaName + arrayBrackets + " ... array) { this(array.length); put(array); }\n"; + decl.text += " public " + containerType.javaName + "(" + desugarVarargs(javaName) + arrayBrackets + " ... array) { this(array.length); put(array); }\n"; } } else if (indexType == null && dim == 0 && !constant && !purify) { int n = 0; @@ -597,7 +601,7 @@ void containers(Context context, DeclarationList declList) throws ParserExceptio + " return put(0, value);\n" + " }\n"; } - decl.text += " public " + containerType.javaName + " put(" + javaName + arrayBrackets + " ... array) {\n"; + decl.text += " public " + containerType.javaName + " put(" + desugarVarargs(javaName) + arrayBrackets + " ... array) {\n"; String indent = " ", indices = "", args = ""; separator = ""; for (int i = 0; i < dim; i++) { @@ -2740,7 +2744,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti } } if (type.constructor && params != null) { - decl.text += "public " + context.shorten(context.javaName) + dcl.parameters.list + " { super((Pointer)null); allocate" + params.names + "; }\n" + + decl.text += filterJavaAnnotations(type.annotations) + "public " + context.shorten(context.javaName) + dcl.parameters.list + " { super((Pointer)null); allocate" + params.names + "; }\n" + type.annotations + "private native void allocate" + dcl.parameters.list + ";\n"; } else { String modifiers2 = modifiers; @@ -3494,7 +3498,7 @@ String downcast(Type derived, Type base, boolean virtual) { } String shortName = derived.javaName.substring(derived.javaName.lastIndexOf('.') + 1); String res = " /** Downcast constructor. */\n" - + " public " + shortName + "(" + base.javaName + " pointer) { super((Pointer)null); allocate(pointer); }\n"; + + " " + filterJavaAnnotations(annotations) + "public " + shortName + "(" + base.javaName + " pointer) { super((Pointer)null); allocate(pointer); }\n"; if (annotations.isEmpty()) { res += " @Namespace private native @Name(\"" + downcastType + "_cast<" + derived.cppName + "*>\") void allocate(" + base.javaName + " pointer);\n"; } else { @@ -3931,7 +3935,7 @@ boolean group(Context context, DeclarationList declList) throws ParserException if (implicitConstructor && (info == null || !info.purify) && (!abstractClass || ctx.virtualize)) { constructors += " /** Default native constructor. */\n" + - " public " + shortName + "() { super((Pointer)null); allocate(); }\n"; + " " + filterJavaAnnotations(constructorAnnotations) + "public " + shortName + "() { super((Pointer)null); allocate(); }\n"; if (constructorAnnotations.isEmpty()) { constructors += " /** Native array allocator. Access with {@link Pointer#position(long)}. */\n" + " public " + shortName + "(long size) { super((Pointer)null); allocateArray(size); }\n";