Skip to content

Commit

Permalink
* Fix Parser failing to place annotations on default constructors …
Browse files Browse the repository at this point in the history
…(pull #699)
  • Loading branch information
HGuillemet committed Aug 8, 2023
1 parent 8646e97 commit 283e87a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Fix `Parser` failing to place annotations on default constructors ([pull #699](https://github.com/bytedeco/javacpp/pull/699))
* Let `Parser` output `reset()` methods for basic containers like `std::optional` ([pull #696](https://github.com/bytedeco/javacpp/pull/696))
* Let `Parser` define `front()` and `back()` for one-dimensional basic containers ([pull #695](https://github.com/bytedeco/javacpp/pull/695))
* Let `Parser` map iterators of basic containers systematically ([pull #694](https://github.com/bytedeco/javacpp/pull/694))
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3669,6 +3669,14 @@ boolean group(Context context, DeclarationList declList) throws ParserException
boolean implicitConstructor = true, arrayConstructor = false, defaultConstructor = false, longConstructor = false,
pointerConstructor = false, abstractClass = info != null && info.purify && !ctx.virtualize,
allPureConst = true, haveVariables = false;

String constructorName = Templates.strip(originalName);
int constructorNamespace = constructorName.lastIndexOf("::");
if (constructorNamespace >= 0) {
constructorName = constructorName.substring(constructorNamespace + 2);
}
Info constructorInfo = infoMap.getFirst(type.cppName + "::" + constructorName);

for (Declaration d : declList2) {
if (d.declarator != null && d.declarator.type != null && d.declarator.type.using && decl.text != null) {
// inheriting constructors
Expand Down Expand Up @@ -3735,14 +3743,21 @@ boolean group(Context context, DeclarationList declList) throws ParserException
decl.text += modifiers + "class " + shortName + " extends " + base.javaName + " {\n" +
" static { Loader.load(); }\n";

String constructorAnnotations = "";
if (constructorInfo != null && constructorInfo.annotations != null) {
for (String a: constructorInfo.annotations) {
constructorAnnotations += a + " ";
}
}

if (implicitConstructor && (info == null || !info.purify) && (!abstractClass || ctx.virtualize)) {
constructors += " /** Default native constructor. */\n" +
" public " + shortName + "() { super((Pointer)null); allocate(); }\n" +
" /** Native array allocator. Access with {@link Pointer#position(long)}. */\n" +
" public " + shortName + "(long size) { super((Pointer)null); allocateArray(size); }\n" +
" /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */\n" +
" public " + shortName + "(Pointer p) { super(p); }\n" +
" private native void allocate();\n" +
" " + constructorAnnotations + "private native void allocate();\n" +
" private native void allocateArray(long size);\n" +
" @Override public " + shortName + " position(long position) {\n" +
" return (" + shortName + ")super.position(position);\n" +
Expand Down Expand Up @@ -3807,12 +3822,6 @@ boolean group(Context context, DeclarationList declList) throws ParserException
}
}

String constructorName = Templates.strip(originalName);
int namespace2 = constructorName.lastIndexOf("::");
if (namespace2 >= 0) {
constructorName = constructorName.substring(namespace2 + 2);
}
Info constructorInfo = infoMap.getFirst(type.cppName + "::" + constructorName);
if (/*(context.templateMap == null || context.templateMap.full()) &&*/ constructorInfo == null) {
infoMap.put(constructorInfo = new Info(type.cppName + "::" + constructorName));
}
Expand Down

0 comments on commit 283e87a

Please sign in to comment.