Skip to content

Commit c25606b

Browse files
committed
[PATCH] Pattern matching of instanceof in java.desktop shared code
1 parent f95af74 commit c25606b

File tree

347 files changed

+969
-1751
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

347 files changed

+969
-1751
lines changed

src/java.desktop/macosx/classes/apple/laf/JRSUIControl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ public int hashCode() {
345345

346346
@Override
347347
public boolean equals(final Object obj) {
348-
if (!(obj instanceof JRSUIControl)) return false;
349-
final JRSUIControl other = (JRSUIControl)obj;
348+
if (!(obj instanceof JRSUIControl other)) return false;
350349
if (currentEncodedProperties != other.currentEncodedProperties) return false;
351350
if (!nativeMap.equals(other.nativeMap)) return false;
352351
if (!changes.equals(other.changes)) return false;

src/java.desktop/macosx/classes/com/apple/eawt/FullScreenUtilities.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public final class FullScreenUtilities {
6363
* @throws IllegalArgumentException if window is not a {@link RootPaneContainer}
6464
*/
6565
public static void setWindowCanFullScreen(final Window window, final boolean canFullScreen) {
66-
if (!(window instanceof RootPaneContainer)) throw new IllegalArgumentException("Can't mark a non-RootPaneContainer as full screen-able");
67-
final RootPaneContainer rpc = (RootPaneContainer)window;
66+
if (!(window instanceof RootPaneContainer rpc)) throw new IllegalArgumentException("Can't mark a non-RootPaneContainer as full screen-able");
6867
rpc.getRootPane().putClientProperty(CPlatformWindow.WINDOW_FULLSCREENABLE, Boolean.valueOf(canFullScreen));
6968
}
7069

src/java.desktop/macosx/classes/com/apple/laf/AquaButtonUI.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ public void applySizeFor(final JComponent c, final Size size) {
130130
protected void setThemeBorder(final AbstractButton b) {
131131
// Set the correct border
132132
final ButtonUI genericUI = b.getUI();
133-
if (!(genericUI instanceof AquaButtonUI)) return;
134-
final AquaButtonUI ui = (AquaButtonUI)genericUI;
133+
if (!(genericUI instanceof AquaButtonUI ui)) return;
135134

136135
Border border = b.getBorder();
137136
if (!ui.isBorderFromProperty(b) && (border == null || border instanceof UIResource || border instanceof AquaButtonBorder)) {
@@ -196,12 +195,11 @@ public boolean isBorderFromProperty(final AbstractButton button) {
196195
}
197196

198197
protected boolean setButtonType(final AbstractButton b, final Object prop) {
199-
if (!(prop instanceof String)) {
198+
if (!(prop instanceof String buttonType)) {
200199
b.putClientProperty(BUTTON_TYPE, null); // so we know to use the automatic button type
201200
return false;
202201
}
203202

204-
final String buttonType = (String)prop;
205203
boolean iconFont = true;
206204

207205
final TypeSpecifier specifier = AquaButtonExtendedTypes.getSpecifierByName(buttonType);
@@ -590,9 +588,8 @@ public void hierarchyChanged(final HierarchyEvent e) {
590588
if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) == 0) return;
591589

592590
final Object o = e.getSource();
593-
if (!(o instanceof AbstractButton)) return;
591+
if (!(o instanceof AbstractButton b)) return;
594592

595-
final AbstractButton b = (AbstractButton)o;
596593
final ButtonUI ui = b.getUI();
597594
if (!(ui instanceof AquaButtonUI)) return;
598595

src/java.desktop/macosx/classes/com/apple/laf/AquaComboBoxUI.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ public void itemStateChanged(final ItemEvent e) {
151151

152152
final JList<Object> itemList = popup.getList();
153153
final ListUI listUI = itemList.getUI();
154-
if (!(listUI instanceof AquaListUI)) return;
155-
final AquaListUI aquaListUI = (AquaListUI)listUI;
154+
if (!(listUI instanceof AquaListUI aquaListUI)) return;
156155

157156
final int selectedIndex = comboBox.getSelectedIndex();
158157
final ListModel<Object> dataModel = itemList.getModel();
@@ -637,8 +636,7 @@ void performComboBoxAction(final AquaComboBoxUI ui) {
637636
public void applySizeFor(final JComponent c, final Size size) {
638637
if (arrowButton == null) return;
639638
final Border border = arrowButton.getBorder();
640-
if (!(border instanceof AquaButtonBorder)) return;
641-
final AquaButtonBorder aquaBorder = (AquaButtonBorder)border;
639+
if (!(border instanceof AquaButtonBorder aquaBorder)) return;
642640
arrowButton.setBorder(aquaBorder.deriveBorderForSize(size));
643641
}
644642

src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameBorder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,7 @@ public Insets getBorderInsets(final Component c) {
419419
if (fBorderInsets == null) fBorderInsets = new Insets(0, 0, 0, 0);
420420

421421
// Paranoia check
422-
if (!(c instanceof JInternalFrame)) return fBorderInsets;
423-
424-
final JInternalFrame frame = (JInternalFrame)c;
422+
if (!(c instanceof JInternalFrame frame)) return fBorderInsets;
425423

426424
// Set the contentRect to an arbitrary value (in case the current real one is too small)
427425
setInBounds(0, 0, kContentTester, kContentTester);

src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFramePaneUI.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ public boolean isBorderOpaque() {
182182

183183
@Override
184184
public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) {
185-
if (!(g instanceof Graphics2D)) return;
186-
final Graphics2D g2d = (Graphics2D)g;
185+
if (!(g instanceof Graphics2D g2d)) return;
187186

188187
final int height = getHeight();
189188
final int width = getWidth();

src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameUI.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,7 @@ boolean didForwardEventInternal(final MouseEvent e) {
626626
if (!isEventInWindowShadow(originalPoint)) return false;
627627

628628
final Container parent = frame.getParent();
629-
if (!(parent instanceof JDesktopPane)) return false;
630-
final JDesktopPane pane = (JDesktopPane)parent;
629+
if (!(parent instanceof JDesktopPane pane)) return false;
631630
final Point parentPoint = SwingUtilities.convertPoint(frame, originalPoint, parent);
632631

633632
/* // debug drawing

src/java.desktop/macosx/classes/com/apple/laf/AquaLabelUI.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ protected Color getDisabledLabelColor(final JLabel label) {
9999
final Color fg = label.getForeground();
100100

101101
final Object colorProperty = label.getClientProperty(DISABLED_COLOR_KEY);
102-
if (colorProperty instanceof Color) {
103-
final Color disabledColor = (Color)colorProperty;
102+
if (colorProperty instanceof Color disabledColor) {
104103
if ((fg.getRGB() << 8) == (disabledColor.getRGB() << 8)) return disabledColor;
105104
}
106105

src/java.desktop/macosx/classes/com/apple/laf/AquaMenuBorder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,11 @@ protected static Insets getPopupInsets() {
8383
*/
8484
@Override
8585
public Insets getBorderInsets(final Component c) {
86-
if (!(c instanceof JPopupMenu)) {
86+
if (!(c instanceof JPopupMenu menu)) {
8787
return getItemInsets();
8888
}
8989

9090
// for more info on this issue, see AquaComboBoxPopup.updateContents()
91-
final JPopupMenu menu = (JPopupMenu)c;
9291
final int nChildren = menu.getComponentCount();
9392
if (nChildren > 0) {
9493
final Component firstChild = menu.getComponent(0);

src/java.desktop/macosx/classes/com/apple/laf/AquaMenuItemUI.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,14 @@ public void propertyChange(final PropertyChangeEvent evt) {
182182
if (!CLIENT_PROPERTY_KEY.equalsIgnoreCase(key)) return;
183183

184184
final Object source = evt.getSource();
185-
if (!(source instanceof JMenuItem)) return;
185+
if (!(source instanceof JMenuItem c)) return;
186186

187-
final JMenuItem c = (JMenuItem)source;
188187
apply(c, evt.getNewValue());
189188
}
190189

191190
static void apply(final JMenuItem menuItem, final Object value) {
192191
final ButtonUI ui = menuItem.getUI();
193-
if (!(ui instanceof AquaMenuItemUI)) return;
194-
195-
final AquaMenuItemUI aquaUI = (AquaMenuItemUI)ui;
192+
if (!(ui instanceof AquaMenuItemUI aquaUI)) return;
196193

197194
if (aquaUI.fIsIndeterminate = "indeterminate".equals(value)) {
198195
aquaUI.checkIcon = UIManager.getIcon(aquaUI.getPropertyPrefix() + ".dashIcon");

0 commit comments

Comments
 (0)