On Sat, 8 Apr 2023 20:33:43 GMT, John Hendrikx <jhendr...@openjdk.org> wrote:

>> The class `PseudoClassState` is private API, but was exposed erroneously in 
>> the CSS API. Instead, `Set<PseudoClass>` should have been used. This PR 
>> corrects this.
>
> John Hendrikx has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Ensure Set PseudoClass and StyleClass are immutable in CSS API
>   
>   Updated documentation, fixed warnings and removed some unnecessary code

I think this is the best that can be done for now.  There are still some 
mutable aspects to `Selector` (you can change the `Rule` and the ordinal of 
one).  I'm really not quite sure why it is done that way, it seems there was 
may have been some vision that these classes could be used to "edit" a 
stylesheet -- something that's probably best done with a different set of 
classes to avoid burdening regular read-only CSS work with editable variants, 
requiring defensive copying everywhere.

Ideally, `Selector` and `Match` would have been interfaces, and the private 
code should work with the CSS classes only through those.  Changing them to 
interfaces now seems impossible, it's not binary compatible, and I don't see a 
deprecation route to get there.

However, it is still possible to improve the situation a bit (in another PR 
perhaps), as the private code only requires a few additional methods to be made 
public API on `Selector` to remove its direct dependencies on `SimpleSelector` 
and `CompoundSelector`:

- getName() which returns the java class name to which the selector is applied
- getId() returns the CSS id (if any) of a Selector
- getStyleClassSet() returns the (immutable) style classes of a Selector

These three methods are implemented by `SimpleSelector`, but not by 
`CompoundSelector`.  Instead, its last selector is extracted (which is always a 
`SimpleSelector`) and the methods are called on those. These methods could be 
made part of `Selector`, then `CompoundSelector` implements them by directing 
them to its last `SimpleSelector`, and the private code would not need to care 
about the selector type anymore. These selector classes could then be hidden 
completely.

-------------

PR Comment: https://git.openjdk.org/jfx/pull/1070#issuecomment-1500980591

Reply via email to