Skip to content

Commit

Permalink
Allow @Deprecated on constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
HGuillemet committed Jun 4, 2024
1 parent 4b68052 commit 4256f5e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 4256f5e

Please sign in to comment.