From b4cf59a13697b606efa4deb0f6bd2697abeda6fd Mon Sep 17 00:00:00 2001 From: Samuel Audet Date: Fri, 4 Jun 2021 12:47:13 +0900 Subject: [PATCH] * Allow `Parser` to use `Info.javaNames` for function names containing parameters as well (issue #492) * Fix `Parser` producing incorrect calls to function templates with non-type parameters (issue #491) --- CHANGELOG.md | 2 ++ .../org/bytedeco/javacpp/tools/Generator.java | 6 +++--- .../java/org/bytedeco/javacpp/tools/Parser.java | 15 +++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b79e3d98..44d9a1c1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ + * Allow `Parser` to use `Info.javaNames` for function names containing parameters as well ([issue #492](https://github.com/bytedeco/javacpp/issues/492)) + * Fix `Parser` producing incorrect calls to function templates with non-type parameters ([issue #491](https://github.com/bytedeco/javacpp/issues/491)) * Add missing `presets/package-info.java` required for OSGi and add profile for M2Eclipse ([pull #490](https://github.com/bytedeco/javacpp/pull/490)) * Remove unnecessary mutex lock for pthreads on callbacks in `Generator` ([pull #489](https://github.com/bytedeco/javacpp/pull/489)) * Fix `@AsUtf16` handling for setter methods paired with getters in `Generator` ([pull #488](https://github.com/bytedeco/javacpp/pull/488)) diff --git a/src/main/java/org/bytedeco/javacpp/tools/Generator.java b/src/main/java/org/bytedeco/javacpp/tools/Generator.java index f9f73071c..056bb32a1 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/Generator.java +++ b/src/main/java/org/bytedeco/javacpp/tools/Generator.java @@ -3723,7 +3723,7 @@ static Allocator allocator(Class cls, Method method) { } org.bytedeco.javacpp.annotation.Properties classProperties = cls.getAnnotation(org.bytedeco.javacpp.annotation.Properties.class); - if (classProperties != null) { + if (Pointer.class.isAssignableFrom(cls) && classProperties != null) { for (Class c : classProperties.inherit()) { if ((a = allocator(c, method)) != null) { break; @@ -3748,7 +3748,7 @@ static boolean criticalRegion(Class cls, Method method) { } org.bytedeco.javacpp.annotation.Properties classProperties = cls.getAnnotation(org.bytedeco.javacpp.annotation.Properties.class); - if (classProperties != null) { + if (Pointer.class.isAssignableFrom(cls) && classProperties != null) { for (Class c : classProperties.inherit()) { if (criticalRegion = criticalRegion(c, method)) { break; @@ -3773,7 +3773,7 @@ static boolean noException(Class cls, Method method) { } org.bytedeco.javacpp.annotation.Properties classProperties = cls.getAnnotation(org.bytedeco.javacpp.annotation.Properties.class); - if (classProperties != null) { + if (Pointer.class.isAssignableFrom(cls) && classProperties != null) { for (Class c : classProperties.inherit()) { if (noException = noException(c, method)) { break; diff --git a/src/main/java/org/bytedeco/javacpp/tools/Parser.java b/src/main/java/org/bytedeco/javacpp/tools/Parser.java index 9daedf484..304a64b30 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/Parser.java +++ b/src/main/java/org/bytedeco/javacpp/tools/Parser.java @@ -1606,9 +1606,7 @@ Declarator declarator(Context context, String defaultName, int infoNumber, boole if (context.namespace != null && localName.startsWith(context.namespace + "::")) { localName = dcl.cppName.substring(context.namespace.length() + 2); } - int template = localName.lastIndexOf('<'); - String simpleName = template >= 0 ? localName.substring(0, template) : localName; - if (!simpleName.equals(dcl.javaName) && (!localName.contains("::") || context.javaName == null)) { + if (!localName.equals(dcl.javaName) && (!localName.contains("::") || context.javaName == null)) { type.annotations += "@Name(\"" + localName + "\") "; } } @@ -2213,7 +2211,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti if (info == null) { info = infoMap.getFirst(dcl.cppName); } - if (!type.constructor && !type.destructor && !type.operator) { + if (!type.constructor && !type.destructor && !type.operator && (context.templateMap == null || context.templateMap.full())) { infoMap.put(info != null ? new Info(info).cppNames(fullname) : new Info(fullname)); } } @@ -2342,6 +2340,15 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti } } + // use Java names that we may get here but that declarator() did not catch + if (fullInfo != null && fullInfo.javaNames != null && fullInfo.javaNames.length > 0 && !dcl.javaName.equals(fullInfo.javaNames[0])) { + dcl.javaName = fullInfo.javaNames[0]; + dcl.signature = dcl.javaName + dcl.parameters.signature; + if (!localName.equals(dcl.javaName) && !type.annotations.contains("@Name(")) { + type.annotations += "@Name(\"" + localName + "\") "; + } + } + // check for const, other attributes, and pure virtual functions, ignoring the body if present for (Token token = tokens.get(); !token.match(Token.EOF); token = tokens.get()) { if (token.match(Token.CONST, Token.__CONST, Token.CONSTEXPR)) {