On Wed, 21 Jan 2026 20:03:37 GMT, Michael Strauß <[email protected]> wrote:
>> Implementation of [enhanced property >> metadata](https://gist.github.com/mstr2/2fec0303fc440b8eaeb126befc76eb5c). >> >> ### New API >> This PR includes the following API additions: >> >> 1. `ReadOnlyProperty.getDeclaringClass()` and its default implementation. >> 2. The `javafx.beans.property.AttachedProperty` interface. >> 3. New constructors for all `Simple<*>Property` and `ReadOnly<*>Wrapper` >> classes, accepting the declaring class of the property. >> >> The declaring class is stored in a new field in the `Simple<*>Property` >> classes. If a legacy constructor is used that doesn't specify the declaring >> class, the `ReadOnlyProperty.getDeclaringClass()` default implementation is >> called the first time the `Simple<*>Property.getDeclaringClass()` method is >> called, and its result is stored for future retrieval. >> >> ### Testing >> For testing, this PR also includes the >> `test.util.property.PropertyMetadataVerifier` tool. It systematically tests >> all public and protected properties of a class, and ensures conformance to >> the following rules: >> * `ReadOnlyProperty.getBean()` returns the object instance of the enclosing >> class, or the target object instance if the property is an attached property. >> * `ReadOnlyProperty.getName()` returns the name of the property, which must >> correspond to the name of the property getter (excluding the word >> "Property"). >> * `ReadOnlyProperty.getDeclaringClass()` returns the enclosing class of the >> property getter. >> * The declaring class of a `Simple<*>Property` or `ReadOnly<*>Wrapper` must >> be specified in the constructor, not resolved at runtime. >> * `getBean()`, `getName()`, and `getDeclaringClass()` must not be overridden >> in subclasses of `Simple<*>Property` or `ReadOnly<*>Wrapper`. >> * An instance property does not implement `AttachedProperty`. >> * An instance property has a parameterless property getter. >> * An attached property implements `AttachedProperty`. >> * An attached property has a static single-argument property getter that >> accepts the target object. >> * `AttachedProperty.getTargetClass()` returns the class of the single >> parameter of the static property getter. >> * A property getter does not return an instance of `ReadOnly<*>Wrapper`, it >> returns the result of calling `ReadOnly<*>Wrapper.getReadOnlyProperty()`. >> >> Many properties in existing JavaFX classes violate the >> `PropertyMetadataVerifier` rules in some way or shape. This PR won't address >> these issues, this will be done in a future cleanup PR. > > Michael Strauß has updated the pull request incrementally with one additional > commit since the last revision: > > review changes > Hm, perhaps now that the idea here has had some time to sink in, perhaps the > initial version with attachedness directly specified on the > `ReadOnlyProperty` interface was better (also in light of the hoops we now > need to jump through in the wrappers). Unless of course you think this _is_ > the better solution. I think it is the better solution, as it also provides a place for the `getTargetClass()` API. > It seems to me that since we're already adding some weight to all the > `Simple` property classes, and now additional mini-classes just to implement > `AttachedProperty`, a solution where there is one or two default methods on > `ReadOnlyProperty` is lighter, even if they may seem out of place (like I > said, the idea needed some time to sink in, and there may be a good enough > case to have this on simply **all** properties, UI related or not). We're not adding weight to _all_ simple property classes. With some sensible assumptions (memory alignment is not guaranteed, the VM is free to do anything it wants), the following classes will grow from 40 to 48 bytes: `SimpleFloatProperty` `SimpleIntegerProperty` `SimpleObjectProperty` `SimpleStringProperty` The following classes have enough unused space in their layout to accomodate the new field: `SimpleBooleanProperty` (40) `SimpleDoubleProperty` (48) `SimpleLongProperty` (48) `SimpleListProperty` (56) `SimpleMapProperty` (56) `SimpleSetProperty` (56) > The included `HeaderBar` changes may be better done separately. Also are you > sure this will work for styleable properties as well? I don't see why it wouldn't. This PR doesn't add much functionality in any case. Making this work for styleable properties will require a fair bit of additional work, something along the lines of what you've proposed a few months ago. ------------- PR Comment: https://git.openjdk.org/jfx/pull/2015#issuecomment-3780935410
