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 inherited option to @Virtual #660

Merged
merged 5 commits into from
Apr 1, 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 @@

* Provide `@Virtual(subclasses=false)` to prevent `Generator` from subclassing subclasses ([pull #660](https://github.com/bytedeco/javacpp/pull/660))
* Fix `Loader.getPlatform()` detection for `linux-armhf` with Temurin JDK ([issue bytedeco/javacv#2001](https://github.com/bytedeco/javacv/issues/2001))
* Fix `Parser` ignoring `Info.skip` for enumerators that do not get translated ([issue bytedeco/javacpp-presets#1315](https://github.com/bytedeco/javacpp-presets/issues/1315))
* Fix `Parser` error on C++17 style namespace declarations containing `::` separators ([issue #595](https://github.com/bytedeco/javacpp/issues/595))
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/bytedeco/javacpp/annotation/Virtual.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
public @interface Virtual {
/** Pure (abstract) or not. */
boolean value() default false;
boolean subclasses() default true;
}
2 changes: 1 addition & 1 deletion src/main/java/org/bytedeco/javacpp/tools/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ boolean methods(Class<?> cls) {
while (c != null && c != Object.class && !Modifier.isAbstract(cls.getModifiers())) {
// consider non-duplicate virtual functions from superclasses as well, unless abstract anyway
for (Method m : c.getDeclaredMethods()) {
if (m.isAnnotationPresent(Virtual.class)) {
if (m.isAnnotationPresent(Virtual.class) && m.getAnnotation(Virtual.class).subclasses()) {
boolean found = false;
String name = m.getName();
Class<?>[] types = m.getParameterTypes();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2357,7 +2357,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti

type = functionAfter(context, decl, dcl, type);
context = new Context(context);
context.virtualize &= type.virtual;
context.virtualize = (context.virtualize && type.virtual) || (info != null && info.virtualize);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You changed a bit the logic here.
Now methods with info.virtualize will have context.virtualize true, even if not virtual (and trigger annotations etc...).
Not a big deal since there is no reason to add the info on a non virtual function, but the previous code seems more logical to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's intentional, and I thought that was fine, I guess...?


List<Declarator> prevDcl = new ArrayList<Declarator>();
boolean first = true;
Expand Down Expand Up @@ -2516,7 +2516,7 @@ boolean function(Context context, DeclarationList declList) throws ParserExcepti
}

// add @Virtual annotation on user request only, inherited through context
if (context.virtualize) {
if (context.virtualize && !type.annotations.contains("@Virtual")) {
modifiers = "@Virtual" + (decl.abstractMember ? "(true) " : " ")
+ (context.inaccessible ? "protected native " : "public native ");
}
Expand Down