Refactor gobject constructors #195

Merged
jwharm merged 8 commits from refactor-gobject-constructors into main 2025-02-06 22:36:30 +01:00
jwharm commented 2025-02-06 22:34:04 +01:00 (Migrated from github.com)

This PR refactors the Java-GI logic for registration and construction of GObject-derived classes.

  • All generated GObject-derived classes now have a public constructor that takes a varargs parameter of property names and values.
  • User-defined GObject-derived classes can user super(...) during construction. The MemorySegment constructor is not necessary anymore.
  • When constructing an instance of a user-defined GObject-derived Java class, the Java instance will first be created (pointing to memory address null) and then g_object_new will be called. The Java instance will then be used for the instance initialization, and the memory address will be updated to the new GObject's address. This means it is no longer necessary to use static factory methods for construction.
  • When a GType is not explicitly registered for a Java class, it is automatically registered. The call to Types.register() or TemplateTypes.register() is now optional.

As a result, all remaining boilerplate that was necessary for GObject-derived classes in Java has now become optional.

This PR refactors the Java-GI logic for registration and construction of GObject-derived classes. - All generated GObject-derived classes now have a public constructor that takes a varargs parameter of property names and values. - User-defined GObject-derived classes can user `super(...)` during construction. The `MemorySegment` constructor is not necessary anymore. - When constructing an instance of a user-defined GObject-derived Java class, the Java instance will first be created (pointing to memory address `null`) and then `g_object_new` will be called. The Java instance will then be used for the instance initialization, and the memory address will be updated to the new GObject's address. This means it is no longer necessary to use static factory methods for construction. - When a GType is not explicitly registered for a Java class, it is automatically registered. The call to `Types.register()` or `TemplateTypes.register()` is now optional. As a result, all remaining boilerplate that was necessary for GObject-derived classes in Java has now become optional.
jwharm commented 2025-02-06 22:36:25 +01:00 (Migrated from github.com)

This will (finally) fix #90

This will (finally) fix #90
Sign in to join this conversation.
No description provided.