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

Improve virtual methods #79

Merged
merged 4 commits into from
Nov 8, 2023
Merged

Improve virtual methods #79

merged 4 commits into from
Nov 8, 2023

Conversation

jwharm
Copy link
Owner

@jwharm jwharm commented Nov 8, 2023

Until now, Java-GI generated public Java methods for GObject virtual methods. The Java method would lookup the function pointer in the typeclass and invoke it. When also a regular method existed, it would be hidden from the Java API in favor of the virtual method.

This is not correct, because GObject virtual methods are not supposed to be treated as the API. The regular methods should be the public methods in the Java classes, and the virtual methods should only be available for "chaining up" from an overridden method in a derived class. In other words, virtual methods are supposed to have protected visibility in the Java API.

When generating a Java class, the Java-GI bindings generator look for matching pairs of regular methods and virtual methods, with the same name and type signature:

  • When only a regular method is found, the Java API will contain a method with public visibility. The method invokes the regular C method.
  • When only a virtual method is found, the Java API will contain a method with protected visibility. When called, the function pointer of the parent typeclass is invoked.
  • When a matching pair (a regular method and a virtual method with the same name and type signature) is found, the Java API will contain one method with public visibility. Under normal circumstances, the method invokes the regular C method. When chaining up (with asParent()), the function pointer of the parent typeclass is invoked. The asParent() method itself has protected visibility so this is only exposed to derived types.

Virtual methods in an interface are not exposed in the Java bindings, because Java interfaces cannot contain protected methods.

As a result, a virtual method will never be exposed directly as part of the API. It is, however, available for chaining up, from a method override in a derived class.

@jwharm jwharm merged commit a62ec30 into main Nov 8, 2023
@jwharm jwharm deleted the virtual-methods branch November 8, 2023 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant