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

Reflective enumeration of styleable properties #1299

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mstr2
Copy link
Collaborator

@mstr2 mstr2 commented Dec 4, 2023


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1299/head:pull/1299
$ git checkout pull/1299

Update a local copy of the PR:
$ git checkout pull/1299
$ git pull https://git.openjdk.org/jfx.git pull/1299/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1299

View PR using the GUI difftool:
$ git pr show -t 1299

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1299.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 4, 2023

👋 Welcome back mstrauss! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea.
Could the amount of boilerplate code be reduced even further?

}

private static final List<CssMetaData<? extends Styleable, ?>> classCssMetaData = CssMetaData.of(new Node() {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps it should be <S extends Styleable> CssMetaData.of(Class<S>) ?


@Override
public StyleableProperty<BlendMode> getStyleableProperty(Node node) {
return (StyleableProperty<BlendMode>)node.blendModeProperty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two methods can be implemented in the base class if we add a
setGetter(Function<S, StyleableProperty<V>> getter)
and also
setIsSettable(Predicate<S>)
?

This way we don't even need to declare a new class each time.

Just a thought.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this can be further simplified.

private CssMetaDataCache() {}

public synchronized static List<CssMetaData<? extends Styleable, ?>> getCssMetaData(Styleable node) {
List<CssMetaData<? extends Styleable, ?>> list = cache.get(node.getClass());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this fail in the case of a skin change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control/Skin metadata is also cached in the Control class. This particular method will only discover the styleable properties declared on the specified node, but not on its skin.

@@ -1364,7 +1364,30 @@ public final boolean isVisible() {
public final BooleanProperty visibleProperty() {
if (visible == null) {
visible = new StyleableBooleanProperty(true) {
static final CssMetaData<Node, Boolean> METADATA = new CssMetaData<>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One problem: this idea requires creation of an instance, bc METADATA static objects get created when an instance is created.
I'd rather avoid this inversion...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're fully inflating a single instance of each particular class once to gather all metadata. After that, all further instances don't need to be fully inflated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if this is an abstract custom Node/Control?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would never expect to encounter an instance of an abstract class. Generally, metadata reflection is done the first time we call getCssMetaData for any particular class, which we can only do if we have an instance of that class.

The only exceptions to this are the preexisting static getClassCssMetaData methods, which are initialized once with a throwaway instance of the class they are declared in, for example in the case of the Node class:

private static final List<CssMetaData<? extends Styleable, ?>> classCssMetaData =
    CssMetaData.of(new Node() {});

New classes should not copy this pattern of having a static getClassCssMetaData method, so the problem shouldn't exist for these classes.

return node.nodeTransformation == null
|| node.nodeTransformation.translateX == null
|| node.nodeTransformation.canSetTranslateX();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an example of a more complex isSettable() logic.

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 31, 2024

@mstr2 This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@openjdk
Copy link

openjdk bot commented Mar 13, 2024

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@bridgekeeper
Copy link

bridgekeeper bot commented May 9, 2024

@mstr2 This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants