Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add annotations from info on default constructor #699

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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