Skip to content

Commit

Permalink
* Provide @Virtual(subclasses=false) to prevent Generator from s…
Browse files Browse the repository at this point in the history
…ubclassing subclasses (pull #660)
  • Loading branch information
HGuillemet authored Apr 1, 2023
1 parent f9b0746 commit 940221e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
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);

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

0 comments on commit 940221e

Please sign in to comment.