From c319fc3812e558075cbdb7def8edebdffedae221 Mon Sep 17 00:00:00 2001 From: Aleksandar Kurtakov Date: Tue, 5 Aug 2025 21:58:40 +0300 Subject: [PATCH] Use pattern matching in CTabFolder test --- ...est_org_eclipse_swt_custom_CTabFolder.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java index 536d4f9715c..46b8c3c04e9 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java @@ -540,8 +540,8 @@ private ToolItem showChevron() { */ private ToolItem getChevron(CTabFolder tabFolder) { for (Control child : tabFolder.getChildren()) { - if (child instanceof ToolBar) { - for (ToolItem toolItem : ((ToolBar)child).getItems()) { + if (child instanceof ToolBar toolBar) { + for (ToolItem toolItem : toolBar.getItems()) { if ((toolItem.getStyle() & SWT.PUSH) != 0 && toolItem.getText().isEmpty() && SWT.getMessage("SWT_ShowList").equals(toolItem.getToolTipText()) @@ -561,25 +561,25 @@ private void checkElementOverlap(CTabFolder tabFolder) { subControls.addAll(Arrays.asList(tabFolder.getItems())); for (int i = 0; i < subControls.size(); i++) { Rectangle boundsA = null; - if (subControls.get(i) instanceof Control) { - if (!((Control) subControls.get(i)).isVisible()) + if (subControls.get(i) instanceof Control c) { + if (!c.isVisible()) continue; - boundsA = ((Control) subControls.get(i)).getBounds(); - } else if (subControls.get(i) instanceof CTabItem) { - if (!((CTabItem) subControls.get(i)).isShowing()) + boundsA = c.getBounds(); + } else if (subControls.get(i) instanceof CTabItem cTab) { + if (!cTab.isShowing()) continue; - boundsA = ((CTabItem) subControls.get(i)).getBounds(); + boundsA = cTab.getBounds(); } for (int j = i + 1; j < subControls.size(); j++) { Rectangle boundsB = null; - if (subControls.get(j) instanceof Control) { - if (!((Control) subControls.get(j)).isVisible()) + if (subControls.get(j) instanceof Control c) { + if (!c.isVisible()) continue; - boundsB = ((Control) subControls.get(j)).getBounds(); - } else if (subControls.get(j) instanceof CTabItem) { - if (!((CTabItem) subControls.get(j)).isShowing()) + boundsB = c.getBounds(); + } else if (subControls.get(j) instanceof CTabItem cTab) { + if (!cTab.isShowing()) continue; - boundsB = ((CTabItem) subControls.get(j)).getBounds(); + boundsB = cTab.getBounds(); } assertFalse("Overlap between <" + subControls.get(i) + "> and <" + subControls.get(j) + ">\n" + boundsA + " overlaps " + boundsB, boundsA.intersects(boundsB)); @@ -608,8 +608,8 @@ private void assertTabElementsInLine() { List tabBarElementBounds = new ArrayList<>(); Arrays.stream(ctabFolder.getItems()).filter(CTabItem::isShowing).map(this::getBoundsInShell).forEach(tabBarElementBounds::add); for (Control child : ctabFolder.getChildren()) { - if (child instanceof ToolBar) { - for (ToolItem toolItem : ((ToolBar)child).getItems()) { + if (child instanceof ToolBar toolBarChild) { + for (ToolItem toolItem : toolBarChild.getItems()) { if (toolItem.getImage() != null) { tabBarElementBounds.add(getBoundsInShell(toolItem)); } @@ -632,15 +632,15 @@ private void assertTabElementsInLine() { private Rectangle getBoundsInShell(Widget control) { Control parent; Rectangle bounds; - if (control instanceof Control) { - parent = ((Control)control).getParent(); - bounds = ((Control)control).getBounds(); - } else if (control instanceof CTabItem) { - parent = ((CTabItem)control).getParent(); - bounds = ((CTabItem)control).getBounds(); - } else if (control instanceof ToolItem) { - parent = ((ToolItem)control).getParent(); - bounds = ((ToolItem)control).getBounds(); + if (control instanceof Control c) { + parent = c.getParent(); + bounds = c.getBounds(); + } else if (control instanceof CTabItem cTab) { + parent = cTab.getParent(); + bounds = cTab.getBounds(); + } else if (control instanceof ToolItem toolItem) { + parent = toolItem.getParent(); + bounds = toolItem.getBounds(); } else { throw new UnsupportedOperationException("Widget must provide bounds and parent"); }