java-gi icon indicating copy to clipboard operation
java-gi copied to clipboard

Add annotation processors to register classes and compile resources

Open jwharm opened this issue 1 year ago • 3 comments

Implement an annotation processor to find @RegisteredType- and @GtkTemplate-annotated classes, and save the names in a resource file. On startup, the static class initializers in the global GObject and Gtk classes will read the resource file, and automatically register the types as GObject classes.

A new TypeCache method will be necessary to retrieve the gtype for a Class<? extends GObject>. (Currently the TypeCache only supports the reverse.)

Taking the idea a step further, an annotation processor could trigger a GResource compile step for UI files that are used in Gtk composite template classes. This would allow users to define the UI as an annotation inside the Java file. It would even be possible to call the Blueprint compiler automatically if the annotation processor recognizes a blueprint template.

jwharm avatar Aug 31 '24 15:08 jwharm

Congratulations and thanks on a great library! This issue might be related to a GSettings problem I'm stuck at. I have a .ui file compiled in /app/share/glib-2.0/schemas but flatpak run returns GLib-GIO-ERROR **: 17:34:02.022: Settings schema 'ca.footeware.java.texty3' is not installed. If this is something on your radar I'll just wait.

I posted on stackoverflow. I'd appreciate it if you could take a look. I am using a maven plugin to build rather than gradle but I don't think that matters. The app runs fine in development and the error occurs after installing with flatpak-builder. I think it's a .yml issue but I don't know. Your statement of "...allow users to define the UI as an annotation inside the Java file..." sounds close to me. What do you think?

P.S. I tried to look into https://matrix.to/#/#java-gi:matrix.org but got an error about not being invited. Link was at bottom of your home page.

CraigFoote avatar Apr 14 '25 15:04 CraigFoote

Well this is embarrassing. u/chrisawi on r/flathub saw the fix for my error. In gschema.xml:

<schema id="texty3" path="/ca/footeware/java/texty3/">

...id should be "ca.footeware.java.texty3". Sorry for the false alarm.

CraigFoote avatar Apr 14 '25 17:04 CraigFoote

OK that's good news!

Regarding the matrix room; last week I temporarily changed it to invite-only, since matrix.org seems to be targeted by spammers and I can't monitor the room 24/7. I sent you an invite.

jwharm avatar Apr 14 '25 17:04 jwharm

I'm closing this issue. Since Java-GI 0.12, classes are automatically registered as a GType when the first instance is constructed.

The second part of the issue, an annotation processor that compiles a GResource for UI definitions embedded in the Java source code of Gtk composite template classes, is a somewhat-nice-to-have, but not enough to keep the issue active.

jwharm avatar May 14 '25 18:05 jwharm