RFR: 8298352: apple.laf.JRSUIUtils class creates many indirections
SWinxy
duke at openjdk.org
Tue Dec 13 19:43:37 UTC 2022
`JRSUIUtils.java` structurally does things weirdly. The utility class mostly passes parameters from functions to other functions. The indirection makes things harder to understand the eventual purpose.
Take `AquaInternalFrameBorderMetrics.java`. It has a `static boolean` that caches a call to `shouldUseLegacyBorderMetrics()`, which returns `isSnowLeopardOrBelow`, itself a cached call to `isMacOSXSnowLeopardOrBelow()`, which is what finally calls `currentMacOSXVersionMatchesGivenVersionRange()`. When looking at the code, it takes time to unravel the path it takes. Instead of that, a `public static final boolean` can expose the cached value and, in doing so, exposes the *meaning* behind the check.
In `AquaLookAndFeel.java`, the value of `TabbedPaneUI` is calculated using `JRSUIUtils.TabbedPane.shouldUseTabbedPaneContrastUI()`, but that could mean any reason for why `"AquaTabbedPaneContrastUI"` may be the value as opposed to `"AquaTabbedPaneUI"`. Replacing it with `JRSUIUtils.isSnowLeopardOrBelow` reveals that it actually has to do with the OS version being, well, Snow Leopard or below.
These change makes understanding the code easier and quicker. Also more optimized.
Changes:
* add JRSUIConstants.ScrollBarPart.ordinal() to return the property's ordinal value, which is not public
* change 3 access modifiers in JRSUIControl to public allowing for access outside the package
* JRSUIConstants.NineSliceMetricsProvider changed to a normal Function<>
* cache `isMacOSXBigSurOrAbove` rather than calling it twice
* inline the functions for clarity
* change static initialization to group all version checks together
* document JRSUIUtils
-------------
Commit messages:
- Group OSX version getting into one static block
- Update copyright year
- apple.laf.JRSUIUtils does not indicate what is checked, and passes things unnecessarily
Changes: https://git.openjdk.org/jdk/pull/10326/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=10326&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8298352
Stats: 190 lines in 13 files changed: 19 ins; 89 del; 82 mod
Patch: https://git.openjdk.org/jdk/pull/10326.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/10326/head:pull/10326
PR: https://git.openjdk.org/jdk/pull/10326
More information about the client-libs-dev
mailing list