RFR: 8298352: apple.laf.JRSUIUtils class creates many indirections

SWinxy duke at openjdk.org
Tue Dec 13 19:43:38 UTC 2022


On Sun, 18 Sep 2022 21:23:12 GMT, SWinxy <duke at openjdk.org> wrote:

> `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

Since it only concerns macOS, the Linux builds are irrelevant. The failures are due to toolchain dependencies and GitHub actions.

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

PR: https://git.openjdk.org/jdk/pull/10326



More information about the client-libs-dev mailing list