From 210718f8d13b59cb4176e7240bf294d4090719c4 Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Sat, 18 Apr 2026 21:35:27 +0200 Subject: [PATCH 1/2] Migrate Swing Model Component tests to use text blocks --- .../model/component/AbstractButtonTest.java | 36 +- .../swing/model/component/AppletTest.java | 211 ++- .../swing/model/component/BeanInfoTest.java | 60 +- .../swing/model/component/ComponentTest.java | 302 ++-- .../swing/model/component/ContainerTest.java | 515 +++--- .../swing/model/component/JComboBoxTest.java | 31 +- .../swing/model/component/JDialogTest.java | 229 ++- .../model/component/JInternalFrameTest.java | 64 +- .../swing/model/component/JLabelTest.java | 90 +- .../model/component/JLayeredPaneTest.java | 286 ++-- .../swing/model/component/JListTest.java | 178 +-- .../model/component/JScrollPaneTest.java | 302 ++-- .../swing/model/component/JSliderTest.java | 21 +- .../swing/model/component/JSpinnerTest.java | 55 +- .../swing/model/component/JSplitPaneTest.java | 454 +++--- .../model/component/JTabbedPaneTest.java | 1402 ++++++++--------- .../swing/model/component/JTableTest.java | 621 ++++---- .../swing/model/component/JTextFieldTest.java | 24 +- .../swing/model/component/JToolBarTest.java | 512 +++--- .../swing/model/component/JTreeTest.java | 138 +- .../model/component/SomeComponentsTest.java | 52 +- .../model/component/SwingLiveManagerTest.java | 131 +- .../model/component/menu/JMenuBarTest.java | 569 ++++--- .../model/component/menu/JMenuItemTest.java | 33 +- .../swing/model/component/menu/JMenuTest.java | 1163 +++++++------- .../model/component/menu/JPopupMenuTest.java | 498 +++--- 26 files changed, 3874 insertions(+), 4103 deletions(-) diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/AbstractButtonTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/AbstractButtonTest.java index 77b8433b7f..52533a45af 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/AbstractButtonTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/AbstractButtonTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -38,34 +38,22 @@ public class AbstractButtonTest extends SwingModelTest { //////////////////////////////////////////////////////////////////////////// @Test public void test_horizontal() throws Exception { - ContainerInfo panel = - (ContainerInfo) parseSource( - "test", - "Test.java", - getSourceDQ( - "package test;", - "import javax.swing.*;", - "class Test extends JPanel {", - " Test() {", - " add(new JButton());", - " }", - "}")); + ContainerInfo panel = (ContainerInfo) parseSource("test", "Test.java", """ + package test; + import javax.swing.*; + class Test extends JPanel { + Test() { + add(new JButton()); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); - checkStaticFieldsProperty(button, "horizontalAlignment", new String[]{ - "LEFT", - "CENTER", - "RIGHT", - "LEADING", - "TRAILING"}); - checkStaticFieldsProperty(button, "verticalTextPosition", new String[]{ - "TOP", - "CENTER", - "BOTTOM"}); + checkStaticFieldsProperty(button, "horizontalAlignment", "LEFT", "CENTER", "RIGHT", "LEADING", "TRAILING"); + checkStaticFieldsProperty(button, "verticalTextPosition", "TOP", "CENTER", "BOTTOM"); } private void checkStaticFieldsProperty(ComponentInfo button, String propertyTitle, - String[] expectedNames) throws Exception, NoSuchFieldException, IllegalAccessException { + String... expectedNames) throws Exception, NoSuchFieldException, IllegalAccessException { // prepare property Property property = button.getPropertyByTitle(propertyTitle); assertNotNull(property); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/AppletTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/AppletTest.java index 292ff57b35..d806fe372a 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/AppletTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/AppletTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -53,17 +53,16 @@ public void _test_exit() throws Exception { */ @Test public void test_Applet_bounds() throws Exception { - ContainerInfo applet = - parseContainer( - "import java.applet.Applet;", - "public class Test extends Applet {", - " public Test() {", - " {", - " JButton button = new JButton();", - " add(button);", - " }", - " }", - "}"); + ContainerInfo applet = parseContainer(""" + import java.applet.Applet; + public class Test extends Applet { + public Test() { + { + JButton button = new JButton(); + add(button); + } + } + }"""); applet.refresh(); ComponentInfo button = getJavaInfoByName("button"); // @@ -82,17 +81,16 @@ public void test_Applet_bounds() throws Exception { */ @Test public void test_JApplet_bounds() throws Exception { - ContainerInfo applet = - parseContainer( - "// filler filler filler filler filler", - "public class Test extends JApplet {", - " public Test() {", - " {", - " JButton button = new JButton();", - " getContentPane().add(button);", - " }", - " }", - "}"); + ContainerInfo applet = parseContainer(""" + // filler filler filler filler filler + public class Test extends JApplet { + public Test() { + { + JButton button = new JButton(); + getContentPane().add(button); + } + } + }"""); applet.refresh(); ComponentInfo contentPane = applet.getChildrenComponents().get(0); ComponentInfo button = getJavaInfoByName("button"); @@ -109,21 +107,20 @@ public void test_JApplet_bounds() throws Exception { */ @Test public void test_JApplet_getParent() throws Exception { - ContainerInfo applet = - parseContainer( - "public class Test extends JApplet {", - " public Test() {", - " }", - " public void init() {", - " super.getParent();", - " }", - "}"); + ContainerInfo applet = parseContainer(""" + public class Test extends JApplet { + public Test() { + } + public void init() { + super.getParent(); + } + }"""); applet.refresh(); assertNoErrors(applet); - assertHierarchy( - "{this: javax.swing.JApplet} {this} {}", - " {method: public java.awt.Container javax.swing.JApplet.getContentPane()} {property} {}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}"); + assertHierarchy(""" + {this: javax.swing.JApplet} {this} {} + {method: public java.awt.Container javax.swing.JApplet.getContentPane()} {property} {} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}"""); } //////////////////////////////////////////////////////////////////////////// @@ -138,14 +135,13 @@ public void test_JApplet_getParent() throws Exception { */ @Test public void test_Applet_screenShot() throws Exception { - ContainerInfo applet = - parseContainer( - "import java.applet.Applet;", - "public class Test extends Applet {", - " public Test() {", - " setBackground(Color.RED);", - " }", - "}"); + ContainerInfo applet = parseContainer(""" + import java.applet.Applet; + public class Test extends Applet { + public Test() { + setBackground(Color.RED); + } + }"""); applet.refresh(); // assertHasRedPixel(applet); @@ -158,14 +154,13 @@ public void test_Applet_screenShot() throws Exception { */ @Test public void test_JApplet_screenShot() throws Exception { - ContainerInfo applet = - parseContainer( - "// filler filler filler filler filler", - "public class Test extends JApplet {", - " public Test() {", - " getContentPane().setBackground(Color.RED);", - " }", - "}"); + ContainerInfo applet = parseContainer(""" + // filler filler filler filler filler + public class Test extends JApplet { + public Test() { + getContentPane().setBackground(Color.RED); + } + }"""); applet.refresh(); assertHasRedPixel(applet); } @@ -184,19 +179,18 @@ private static void assertHasRedPixel(ContainerInfo applet) { //////////////////////////////////////////////////////////////////////////// @Test public void test_GUI_inConstructor() throws Exception { - ContainerInfo applet = - parseContainer( - "public class Test extends JApplet {", - " public Test() {", - " getContentPane().add(new JButton());", - " }", - "}"); + ContainerInfo applet = parseContainer(""" + public class Test extends JApplet { + public Test() { + getContentPane().add(new JButton()); + } + }"""); assertNoErrors(applet); - assertHierarchy( - "{this: javax.swing.JApplet} {this} {}", - " {method: public java.awt.Container javax.swing.JApplet.getContentPane()} {property} {/getContentPane().add(new JButton())/}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}", - " {new: javax.swing.JButton} {empty} {/getContentPane().add(new JButton())/}"); + assertHierarchy(""" + {this: javax.swing.JApplet} {this} {} + {method: public java.awt.Container javax.swing.JApplet.getContentPane()} {property} {/getContentPane().add(new JButton())/} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {} + {new: javax.swing.JButton} {empty} {/getContentPane().add(new JButton())/}"""); // refresh() applet.refresh(); assertNotNull(applet.getComponent()); @@ -205,21 +199,20 @@ public void test_GUI_inConstructor() throws Exception { @Test public void test_GUI_inMethod_init() throws Exception { - ContainerInfo applet = - parseContainer( - "public class Test extends JApplet {", - " public Test() {", - " }", - " public void init() {", - " getContentPane().add(new JButton());", - " }", - "}"); + ContainerInfo applet = parseContainer(""" + public class Test extends JApplet { + public Test() { + } + public void init() { + getContentPane().add(new JButton()); + } + }"""); assertNoErrors(applet); - assertHierarchy( - "{this: javax.swing.JApplet} {this} {}", - " {method: public java.awt.Container javax.swing.JApplet.getContentPane()} {property} {/getContentPane().add(new JButton())/}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}", - " {new: javax.swing.JButton} {empty} {/getContentPane().add(new JButton())/}"); + assertHierarchy(""" + {this: javax.swing.JApplet} {this} {} + {method: public java.awt.Container javax.swing.JApplet.getContentPane()} {property} {/getContentPane().add(new JButton())/} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {} + {new: javax.swing.JButton} {empty} {/getContentPane().add(new JButton())/}"""); // refresh() applet.refresh(); assertNotNull(applet.getComponent()); @@ -228,34 +221,31 @@ public void test_GUI_inMethod_init() throws Exception { @Test public void test_GUI_initInExecutionFlow() throws Exception { - setFileContentSrc( - "test/MyApplet.java", - getTestSource( - "public class MyApplet extends JApplet {", - " public void init() {", - " myInit();", - " }", - " protected void myInit() {", - " }", - "}")); + setFileContentSrc("test/MyApplet.java", getTestSource(""" + public class MyApplet extends JApplet { + public void init() { + myInit(); + } + protected void myInit() { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo applet = - parseContainer( - "public class Test extends MyApplet {", - " public Test() {", - " }", - " protected void myInit() {", - " getContentPane().add(new JButton());", - " }", - "}"); + ContainerInfo applet = parseContainer(""" + public class Test extends MyApplet { + public Test() { + } + protected void myInit() { + getContentPane().add(new JButton()); + } + }"""); applet.refresh(); assertNoErrors(applet); - assertHierarchy( - "{this: test.MyApplet} {this} {}", - " {method: public java.awt.Container javax.swing.JApplet.getContentPane()} {property} {/getContentPane().add(new JButton())/}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}", - " {new: javax.swing.JButton} {empty} {/getContentPane().add(new JButton())/}"); + assertHierarchy(""" + {this: test.MyApplet} {this} {} + {method: public java.awt.Container javax.swing.JApplet.getContentPane()} {property} {/getContentPane().add(new JButton())/} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {} + {new: javax.swing.JButton} {empty} {/getContentPane().add(new JButton())/}"""); } //////////////////////////////////////////////////////////////////////////// @@ -266,15 +256,14 @@ public void test_GUI_initInExecutionFlow() throws Exception { @Test public void test_applet_in_applet() throws Exception { // this should just parse - ContainerInfo applet = - parseContainer( - "public class Test extends JApplet {", - " private JApplet internalApplet = new JApplet();", - " public Test() {", - " }", - " public void init() {", - " }", - "}"); + ContainerInfo applet = parseContainer(""" + public class Test extends JApplet { + private JApplet internalApplet = new JApplet(); + public Test() { + } + public void init() { + } + }"""); applet.refresh(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/BeanInfoTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/BeanInfoTest.java index 08e7e80dea..9fa346498e 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/BeanInfoTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/BeanInfoTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -45,13 +45,12 @@ public void _test_exit() throws Exception { @Test public void test_isContainer_true() throws Exception { prepareComponentFor_isContainer("Boolean.TRUE"); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyComponent {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyComponent { + public Test() { + } + }"""); assertTrue(panel.hasLayout()); } @@ -62,35 +61,30 @@ public void test_isContainer_true() throws Exception { @Test public void test_isContainer_false() throws Exception { prepareComponentFor_isContainer("Boolean.FALSE"); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyComponent {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyComponent { + public Test() { + } + }"""); assertFalse(panel.hasLayout()); } private void prepareComponentFor_isContainer(String value) throws Exception { - setFileContentSrc( - "test/MyComponent.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class MyComponent extends JPanel {", - "}")); - setFileContentSrc( - "test/MyComponentBeanInfo.java", - getTestSource( - "import java.beans.*;", - "public class MyComponentBeanInfo extends SimpleBeanInfo {", - " public BeanDescriptor getBeanDescriptor() {", - " BeanDescriptor descriptor = new BeanDescriptor(MyComponent.class);", - " descriptor.setValue('isContainer', " + value + ");", - " return descriptor;", - " }", - "}")); + setFileContentSrc("test/MyComponent.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class MyComponent extends JPanel { + }""")); + setFileContentSrc("test/MyComponentBeanInfo.java", getTestSource(""" + import java.beans.*; + public class MyComponentBeanInfo extends SimpleBeanInfo { + public BeanDescriptor getBeanDescriptor() { + BeanDescriptor descriptor = new BeanDescriptor(MyComponent.class); + descriptor.setValue("isContainer", %s); + return descriptor; + } + }""".formatted(value))); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/ComponentTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/ComponentTest.java index 4a5e230eef..f6b21a9970 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/ComponentTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/ComponentTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -64,23 +64,20 @@ public void _test_exit() throws Exception { */ @Test public void test_clearSwingTree_removeAll_NPE() throws Exception { - setFileContentSrc( - "test/MyContainer.java", - getTestSource( - "public class MyContainer extends JPanel {", - " public void removeAll() {", - " throw new NullPointerException();", - " }", - "}")); + setFileContentSrc("test/MyContainer.java", getTestSource(""" + public class MyContainer extends JPanel { + public void removeAll() { + throw new NullPointerException(); + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new MyContainer());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new MyContainer()); + } + }"""); panel.refresh(); assertNoErrors(panel); } @@ -91,14 +88,13 @@ public void test_clearSwingTree_removeAll_NPE() throws Exception { @Disabled @Test public void test_zeroSize() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends Frame {", - " public Test() {", - " setUndecorated(true);", - " setSize(0, 0);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends Frame { + public Test() { + setUndecorated(true); + setSize(0, 0); + } + }"""); panel.refresh(); assertNoErrors(panel); // check bounds @@ -115,24 +111,23 @@ public void test_zeroSize() throws Exception { */ @Test public void test_JLabel_withHTML() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new BorderLayout());", - " {", - " JPanel inner = new JPanel();", - " add(inner, BorderLayout.NORTH);", - " inner.setLayout(new GridLayout());", - " inner.setBackground(Color.GREEN);", - " {", - " JLabel label = new JLabel('aaaaaaaaa bbbbbbbb cccccccccc ddddddddd" - + " eeeeeeeeeee fffffffffffff ggggggggg hhhhhhhhhhhh');", - " inner.add(label);", - " }", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new BorderLayout()); + { + JPanel inner = new JPanel(); + add(inner, BorderLayout.NORTH); + inner.setLayout(new GridLayout()); + inner.setBackground(Color.GREEN); + { + JLabel label = new JLabel("aaaaaaaaa bbbbbbbb cccccccccc ddddddddd" + + " eeeeeeeeeee fffffffffffff ggggggggg hhhhhhhhhhhh"); + inner.add(label); + } + } + } + }"""); panel.refresh(); panel.getTopBoundsSupport().setSize(175, 300); panel.refresh(); @@ -153,27 +148,24 @@ public void test_JLabel_withHTML() throws Exception { */ @Test public void test_addPanel_withExposedChildren() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " private final JButton m_button = new JButton();", - " public MyPanel() {", - " add(m_button);", - " }", - " public JButton getButton() {", - " return m_button;", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + private final JButton m_button = new JButton(); + public MyPanel() { + add(m_button); + } + public JButton getButton() { + return m_button; + } + }""")); waitForAutoBuild(); // - final ContainerInfo panel = - parseJavaInfo( - "// filler filler filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + final ContainerInfo panel = parseJavaInfo(""" + // filler filler filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); panel.refresh(); // ExecutionUtils.run(panel, new RunnableEx() { @@ -183,22 +175,22 @@ public void run() throws Exception { ((FlowLayoutInfo) panel.getLayout()).add(myPanel, null); } }); - assertEditor( - "// filler filler filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " MyPanel myPanel = new MyPanel();", - " add(myPanel);", - " }", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/add(myPanel)/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: test.MyPanel} {local-unique: myPanel} {/new MyPanel()/ /add(myPanel)/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {method: public javax.swing.JButton test.MyPanel.getButton()} {property} {}"); + assertEditor(""" + // filler filler filler filler filler + public class Test extends JPanel { + public Test() { + { + MyPanel myPanel = new MyPanel(); + add(myPanel); + } + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/add(myPanel)/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: test.MyPanel} {local-unique: myPanel} {/new MyPanel()/ /add(myPanel)/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {method: public javax.swing.JButton test.MyPanel.getButton()} {property} {}"""); } //////////////////////////////////////////////////////////////////////////// @@ -211,26 +203,25 @@ public void run() throws Exception { */ @Test public void test_variableName_setName() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + add(button); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // no "variable name in component" configured, just name modification expected { button.getVariableSupport().setName("button2"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " JButton button2 = new JButton();", - " add(button2);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + JButton button2 = new JButton(); + add(button2); + } + }"""); } // do with "variable name in component" PreferencesRepairer preferences = @@ -241,27 +232,27 @@ public void test_variableName_setName() throws Exception { { button.getVariableSupport().setName("button3"); panel.refresh(); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " JButton button3 = new JButton();", - " button3.setName('button3');", - " add(button3);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + JButton button3 = new JButton(); + button3.setName("button3"); + add(button3); + } + }"""); } // setName() for "button" exists, should be updated { button.getVariableSupport().setName("button4"); panel.refresh(); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " JButton button4 = new JButton();", - " button4.setName('button4');", - " add(button4);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + JButton button4 = new JButton(); + button4.setName("button4"); + add(button4); + } + }"""); } } finally { preferences.restore(); @@ -273,13 +264,12 @@ public void test_variableName_setName() throws Exception { */ @Test public void test_variableName_setName_forLazy() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); panel.refresh(); FlowLayoutInfo layout = (FlowLayoutInfo) panel.getLayout(); ComponentInfo newButton = createJButton(); @@ -292,46 +282,46 @@ public void test_variableName_setName_forLazy() throws Exception { LazyVariableDescription.INSTANCE, LazyStatementGeneratorDescription.INSTANCE); layout.add(newButton, null); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " private JButton button;", - " public Test() {", - " add(getButton());", - " }", - " private JButton getButton() {", - " if (button == null) {", - " button = new JButton();", - " button.setName('button');", - " }", - " return button;", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/add(getButton())/ /add(getButton())/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: javax.swing.JButton empty} {lazy: button getButton()} {/new JButton()/ /add(getButton())/ /button.setName('button')/}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + private JButton button; + public Test() { + add(getButton()); + } + private JButton getButton() { + if (button == null) { + button = new JButton(); + button.setName("button"); + } + return button; + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/add(getButton())/ /add(getButton())/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: javax.swing.JButton empty} {lazy: button getButton()} {/new JButton()/ /add(getButton())/ /button.setName("button")/}"""); // set new name newButton.getVariableSupport().setName("button2"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " private JButton button2;", - " public Test() {", - " add(getButton2());", - " }", - " private JButton getButton2() {", - " if (button2 == null) {", - " button2 = new JButton();", - " button2.setName('button2');", - " }", - " return button2;", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/add(getButton2())/ /add(getButton2())/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: javax.swing.JButton empty} {lazy: button2 getButton2()} {/new JButton()/ /add(getButton2())/ /button2.setName('button2')/}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + private JButton button2; + public Test() { + add(getButton2()); + } + private JButton getButton2() { + if (button2 == null) { + button2 = new JButton(); + button2.setName("button2"); + } + return button2; + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/add(getButton2())/ /add(getButton2())/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: javax.swing.JButton empty} {lazy: button2 getButton2()} {/new JButton()/ /add(getButton2())/ /button2.setName("button2")/}"""); } /** @@ -352,9 +342,9 @@ public MyDialog() { } } """); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}"); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}"""); dialog.refresh(); assertNoErrors(dialog); } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/ContainerTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/ContainerTest.java index b172783970..e3736beae6 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/ContainerTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/ContainerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -71,17 +71,17 @@ public void _test_exit() throws Exception { */ @Test public void test_association_noConstraints() throws Exception { - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JButton button = new JButton();", - " add(button);", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/add(button)/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: javax.swing.JButton} {local-unique: button} {/new JButton()/ /add(button)/}"); + parseContainer(""" + class Test extends JPanel { + Test() { + JButton button = new JButton(); + add(button); + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/add(button)/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: javax.swing.JButton} {local-unique: button} {/new JButton()/ /add(button)/}"""); ComponentInfo button = getJavaInfoByName("button"); assertEquals("add(button)", ((InvocationChildAssociation) button.getAssociation()).getSource()); } @@ -91,17 +91,17 @@ public void test_association_noConstraints() throws Exception { */ @Test public void test_association_addDeprecated() throws Exception { - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JButton button = new JButton();", - " add('name', button);", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/add('name', button)/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: javax.swing.JButton} {local-unique: button} {/new JButton()/ /add('name', button)/}"); + parseContainer(""" + class Test extends JPanel { + Test() { + JButton button = new JButton(); + add("name", button); + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/add("name", button)/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: javax.swing.JButton} {local-unique: button} {/new JButton()/ /add("name", button)/}"""); ComponentInfo button = getJavaInfoByName("button"); assertEquals("add(\"name\", button)", button.getAssociation().getSource()); } @@ -116,13 +116,12 @@ public void test_association_addDeprecated() throws Exception { */ @Test public void test_implicitLayout() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); LayoutInfo layout = panel.getLayout(); assertInstanceOf(ImplicitLayoutCreationSupport.class, layout.getCreationSupport()); assertInstanceOf(ImplicitLayoutVariableSupport.class, layout.getVariableSupport()); @@ -136,21 +135,20 @@ public void test_implicitLayout() throws Exception { */ @Test public void test_getInsets_getClientAreaInsets() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " {", - " JButton button_1 = new JButton();", - " add(button_1);", - " button_1.setBorder(new LineBorder(Color.RED, 10));", - " }", - " {", - " Button button_2 = new Button();", - " add(button_2);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + { + JButton button_1 = new JButton(); + add(button_1); + button_1.setBorder(new LineBorder(Color.RED, 10)); + } + { + Button button_2 = new Button(); + add(button_2); + } + } + }"""); assert_creation(panel); assertEquals(new Insets(0, 0, 0, 0), panel.getClientAreaInsets()); assertEquals(new Insets(0, 0, 0, 0), panel.getInsets()); @@ -177,20 +175,19 @@ public void test_getInsets_getClientAreaInsets() throws Exception { */ @Test public void test_shouldDrawDotsBorder() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new Container());", - " add(new JPanel());", - " add(new JTabbedPane());", - " {", - " JPanel panel = new JPanel();", - " panel.setBorder(new LineBorder(Color.red));", - " add(panel);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new Container()); + add(new JPanel()); + add(new JTabbedPane()); + { + JPanel panel = new JPanel(); + panel.setBorder(new LineBorder(Color.red)); + add(panel); + } + } + }"""); panel.refresh(); // prepare containers ContainerInfo container_AWT = (ContainerInfo) panel.getChildrenComponents().get(0); @@ -216,36 +213,35 @@ public void test_shouldDrawDotsBorder() throws Exception { */ @Test public void test_setLayout() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(true);", - " add(new JButton());", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/setEnabled(true)/ /add(new JButton())/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: javax.swing.JButton} {empty} {/add(new JButton())/}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setEnabled(true); + add(new JButton()); + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/setEnabled(true)/ /add(new JButton())/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: javax.swing.JButton} {empty} {/add(new JButton())/}"""); panel.refresh(); // prepare new Layout LayoutInfo newLayout = createJavaInfo("java.awt.GridLayout"); assertInstanceOf(ComponentOrderBeforeSibling.class, newLayout.getDescription().getOrder()); // set Layout panel.setLayout(newLayout); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(true);", - " setLayout(new GridLayout(0, 1, 0, 0));", - " add(new JButton());", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/setEnabled(true)/ /add(new JButton())/ /setLayout(new GridLayout(0, 1, 0, 0))/}", - " {new: java.awt.GridLayout} {empty} {/setLayout(new GridLayout(0, 1, 0, 0))/}", - " {new: javax.swing.JButton} {empty} {/add(new JButton())/}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setEnabled(true); + setLayout(new GridLayout(0, 1, 0, 0)); + add(new JButton()); + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/setEnabled(true)/ /add(new JButton())/ /setLayout(new GridLayout(0, 1, 0, 0))/} + {new: java.awt.GridLayout} {empty} {/setLayout(new GridLayout(0, 1, 0, 0))/} + {new: javax.swing.JButton} {empty} {/add(new JButton())/}"""); } //////////////////////////////////////////////////////////////////////////// @@ -258,13 +254,12 @@ public void test_setLayout() throws Exception { */ @Test public void test_inheritParentLayout() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new GridLayout());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new GridLayout()); + } + }"""); GridLayoutInfo parentLayout = (GridLayoutInfo) panel.getLayout(); // prepare preferences PreferencesRepairer preferencesRepairer; @@ -293,17 +288,17 @@ public void test_inheritParentLayout() throws Exception { preferencesRepairer.restore(); } // check result - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new GridLayout());", - " {", - " JPanel panel = new JPanel();", - " add(panel);", - " panel.setLayout(new GridLayout(1, 0, 0, 0));", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(new GridLayout()); + { + JPanel panel = new JPanel(); + add(panel); + panel.setLayout(new GridLayout(1, 0, 0, 0)); + } + } + }"""); assertNotSame(parentLayout, newPanel.getLayout()); } @@ -312,13 +307,12 @@ public void test_inheritParentLayout() throws Exception { */ @Test public void test_inheritParentLayout_null() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(null);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(null); + } + }"""); AbsoluteLayoutInfo parentLayout = (AbsoluteLayoutInfo) panel.getLayout(); // prepare preferences PreferencesRepairer preferencesRepairer; @@ -347,17 +341,17 @@ public void test_inheritParentLayout_null() throws Exception { preferencesRepairer.restore(); } // check result - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(null);", - " {", - " JPanel panel = new JPanel();", - " add(panel);", - " panel.setLayout(null);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setLayout(null); + { + JPanel panel = new JPanel(); + add(panel); + panel.setLayout(null); + } + } + }"""); assertNotSame(parentLayout, newPanel.getLayout()); } @@ -366,13 +360,12 @@ public void test_inheritParentLayout_null() throws Exception { */ @Test public void test_setDefaultLayout() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); FlowLayoutInfo flowLayout = (FlowLayoutInfo) panel.getLayout(); // prepare preferences PreferencesRepairer preferencesRepairer; @@ -401,17 +394,17 @@ public void test_setDefaultLayout() throws Exception { preferencesRepairer.restore(); } // check result - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " JPanel panel = new JPanel();", - " add(panel);", - " panel.setLayout(new BorderLayout(0, 0));", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + JPanel panel = new JPanel(); + add(panel); + panel.setLayout(new BorderLayout(0, 0)); + } + } + }"""); assertNotSame(flowLayout, newPanel.getLayout()); } @@ -425,18 +418,16 @@ public void test_setDefaultLayout() throws Exception { */ @Test public void test_clipboard() throws Exception { - String[] lines1 = - { - "public class Test extends JPanel {", - " public Test() {", - " {", - " JPanel inner = new JPanel();", - " inner.setLayout(new GridLayout(1, 0));", - " add(inner);", - " }", - " }", - "}"}; - final ContainerInfo panel = parseContainer(lines1); + final ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + JPanel inner = new JPanel(); + inner.setLayout(new GridLayout(1, 0)); + add(inner); + } + } + }"""); panel.refresh(); // prepare memento final JavaInfoMemento memento; @@ -453,23 +444,21 @@ public void run() throws Exception { memento.apply(); } }); - String[] lines = - { - "public class Test extends JPanel {", - " public Test() {", - " {", - " JPanel inner = new JPanel();", - " inner.setLayout(new GridLayout(1, 0));", - " add(inner);", - " }", - " {", - " JPanel inner = new JPanel();", - " add(inner);", - " inner.setLayout(new GridLayout(1, 0));", - " }", - " }", - "}"}; - assertEditor(lines); + assertEditor(""" + public class Test extends JPanel { + public Test() { + { + JPanel inner = new JPanel(); + inner.setLayout(new GridLayout(1, 0)); + add(inner); + } + { + JPanel inner = new JPanel(); + add(inner); + inner.setLayout(new GridLayout(1, 0)); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -482,13 +471,12 @@ public void run() throws Exception { */ @Test public void test_setLayoutMenu_0() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new JButton());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new JButton()); + } + }"""); ContainerInfo button = (ContainerInfo) panel.getChildrenComponents().get(0); // no layout assertFalse(button.hasLayout()); @@ -505,13 +493,12 @@ public void test_setLayoutMenu_0() throws Exception { */ @Test public void test_setLayoutMenu_1() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); assertTrue(panel.hasLayout()); // prepare "Set Layout" menu manager IMenuManager layoutManager = get_SetLayout_MenuManager(panel); @@ -526,25 +513,25 @@ public void test_setLayoutMenu_1() throws Exception { { IAction action = findChildAction(layoutManager, "GridLayout"); action.run(); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new GridLayout(1, 0, 0, 0));", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + setLayout(new GridLayout(1, 0, 0, 0)); + } + }"""); } // set "absolute" layout { IAction action = findChildAction(layoutManager, "Absolute layout"); action.run(); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " setLayout(null);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + setLayout(null); + } + }"""); } } @@ -557,30 +544,29 @@ public void test_setLayoutMenu_2() throws Exception { do_projectDispose(); do_projectCreate(); try { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); assertTrue(panel.hasLayout()); IMenuManager layoutManager = get_SetLayout_MenuManager(panel); // use one of the actions to set new layout { IAction action = findChildAction(layoutManager, "JGoodies FormLayout"); action.run(); - assertEditor( - "import com.jgoodies.forms.layout.FormLayout;", - "import com.jgoodies.forms.layout.ColumnSpec;", - "import com.jgoodies.forms.layout.RowSpec;", - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new FormLayout(new ColumnSpec[] {},", - " new RowSpec[] {}));", - " }", - "}"); + assertEditor(""" + import com.jgoodies.forms.layout.FormLayout; + import com.jgoodies.forms.layout.ColumnSpec; + import com.jgoodies.forms.layout.RowSpec; + // filler filler filler + public class Test extends JPanel { + public Test() { + setLayout(new FormLayout(new ColumnSpec[] {}, + new RowSpec[] {})); + } + }"""); } } finally { do_projectDispose(); @@ -613,29 +599,26 @@ private static void assertChildAction_existsEnabled(IMenuManager layoutManager, */ @Test public void test_hasLayout_placeholder() throws Exception { - setFileContentSrc( - "test/MyContainer.java", - getTestSource( - "// filler filler filler filler filler", - "public class MyContainer extends JPanel {", - " public MyContainer() {", - " throw new IllegalStateException('actual');", - " }", - "}")); + setFileContentSrc("test/MyContainer.java", getTestSource(""" + // filler filler filler filler filler + public class MyContainer extends JPanel { + public MyContainer() { + throw new IllegalStateException("actual"); + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " add(new MyContainer());", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/add(new MyContainer())/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: test.MyContainer} {empty} {/add(new MyContainer())/}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler filler filler + public class Test extends JPanel { + public Test() { + add(new MyContainer()); + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/add(new MyContainer())/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: test.MyContainer} {empty} {/add(new MyContainer())/}"""); panel.refresh(); ContainerInfo placeholder = (ContainerInfo) panel.getChildrenComponents().get(0); // no Layout for placeholder @@ -654,14 +637,13 @@ public void test_hasLayout_placeholder() throws Exception { */ @Test public void test_canSetLayout_enabled() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); panel.refresh(); // has Layout assertTrue(panel.hasLayout()); @@ -678,14 +660,13 @@ public void test_canSetLayout_enabled() throws Exception { @Test public void test_canSetLayout_disabled() throws Exception { prepareMyPanel_disabledSetLayout(); - ContainerInfo panel = - parseContainer( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // has Layout assertTrue(panel.hasLayout()); @@ -702,26 +683,22 @@ public void test_canSetLayout_disabled() throws Exception { * Prepares test.MyPanel class which does not accept new {@link LayoutManager}. */ public static void prepareMyPanel_disabledSetLayout() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "package test;", - "import javax.swing.JPanel;", - "public class MyPanel extends JPanel {", - " public MyPanel() {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " ", - "")); + setFileContentSrc("test/MyPanel.java", getSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + package test; + import javax.swing.JPanel; + public class MyPanel extends JPanel { + public MyPanel() { + } + }""")); + setFileContentSrc("test/MyPanel.wbp-component.xml", """ + + + + + + """); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JComboBoxTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JComboBoxTest.java index 3d83fa612e..0141effd87 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JComboBoxTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JComboBoxTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -35,21 +35,20 @@ public class JComboBoxTest extends SwingModelTest { */ @Test public void test_addItem() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JComboBox combo = new JComboBox();", - " add(combo);", - " combo.addItem('a');", - " combo.addItem('b');", - " combo.setSelectedIndex(1);", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/add(combo)/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: javax.swing.JComboBox} {local-unique: combo} {/new JComboBox()/ /add(combo)/ /combo.addItem('a')/ /combo.addItem('b')/ /combo.setSelectedIndex(1)/}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JComboBox combo = new JComboBox(); + add(combo); + combo.addItem("a"); + combo.addItem("b"); + combo.setSelectedIndex(1); + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/add(combo)/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: javax.swing.JComboBox} {local-unique: combo} {/new JComboBox()/ /add(combo)/ /combo.addItem("a")/ /combo.addItem("b")/ /combo.setSelectedIndex(1)/}"""); panel.refresh(); assertNoErrors(panel); } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JDialogTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JDialogTest.java index f5211408c6..28a3613fd6 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JDialogTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JDialogTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -47,16 +47,15 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_0() throws Exception { - JDialogInfo dialog = - (JDialogInfo) parseContainer( - "public class Test extends JDialog {", - " public Test() {", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JDialog} {this} {}", - " {method: public java.awt.Container javax.swing.JDialog.getContentPane()} {property} {}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}"); + JDialogInfo dialog = (JDialogInfo) parseContainer(""" + public class Test extends JDialog { + public Test() { + } + }"""); + assertHierarchy(""" + {this: javax.swing.JDialog} {this} {} + {method: public java.awt.Container javax.swing.JDialog.getContentPane()} {property} {} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}"""); // refresh() dialog.refresh(); assertNoErrors(dialog); @@ -87,34 +86,34 @@ public void test_0() throws Exception { */ @Test public void test_parseWithout_getContentPane_this() throws Exception { - parseJavaInfo( - "public class Test extends JDialog {", - " public Test() {", - " setModal(true);", - " setLayout(new FlowLayout());", - " {", - " JButton button = new JButton();", - " this.add(button);", - " }", - " }", - "}"); + parseJavaInfo(""" + public class Test extends JDialog { + public Test() { + setModal(true); + setLayout(new FlowLayout()); + { + JButton button = new JButton(); + this.add(button); + } + } + }"""); // rewritten to use getContentPane() - assertEditor( - "public class Test extends JDialog {", - " public Test() {", - " setModal(true);", - " getContentPane().setLayout(new FlowLayout());", - " {", - " JButton button = new JButton();", - " getContentPane().add(button);", - " }", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JDialog} {this} {/setModal(true)/}", - " {method: public java.awt.Container javax.swing.JDialog.getContentPane()} {property} {/getContentPane().setLayout(new FlowLayout())/ /getContentPane().add(button)/}", - " {new: java.awt.FlowLayout} {empty} {/getContentPane().setLayout(new FlowLayout())/}", - " {new: javax.swing.JButton} {local-unique: button} {/new JButton()/ /getContentPane().add(button)/}"); + assertEditor(""" + public class Test extends JDialog { + public Test() { + setModal(true); + getContentPane().setLayout(new FlowLayout()); + { + JButton button = new JButton(); + getContentPane().add(button); + } + } + }"""); + assertHierarchy(""" + {this: javax.swing.JDialog} {this} {/setModal(true)/} + {method: public java.awt.Container javax.swing.JDialog.getContentPane()} {property} {/getContentPane().setLayout(new FlowLayout())/ /getContentPane().add(button)/} + {new: java.awt.FlowLayout} {empty} {/getContentPane().setLayout(new FlowLayout())/} + {new: javax.swing.JButton} {local-unique: button} {/new JButton()/ /getContentPane().add(button)/}"""); } /** @@ -123,34 +122,34 @@ public void test_parseWithout_getContentPane_this() throws Exception { */ @Test public void test_parseWithout_getContentPane_instance() throws Exception { - parseJavaInfo( - "public class Test {", - " public static void main(String[] args) {", - " JDialog dialog = new JDialog();", - " dialog.setLayout(new FlowLayout());", - " {", - " JButton button = new JButton();", - " dialog.add(button);", - " }", - " }", - "}"); + parseJavaInfo(""" + public class Test { + public static void main(String[] args) { + JDialog dialog = new JDialog(); + dialog.setLayout(new FlowLayout()); + { + JButton button = new JButton(); + dialog.add(button); + } + } + }"""); // rewritten to use getContentPane() - assertEditor( - "public class Test {", - " public static void main(String[] args) {", - " JDialog dialog = new JDialog();", - " dialog.getContentPane().setLayout(new FlowLayout());", - " {", - " JButton button = new JButton();", - " dialog.getContentPane().add(button);", - " }", - " }", - "}"); - assertHierarchy( - "{new: javax.swing.JDialog} {local-unique: dialog} {/new JDialog()/ /dialog.getContentPane()/ /dialog.getContentPane()/}", - " {method: public java.awt.Container javax.swing.JDialog.getContentPane()} {property} {/dialog.getContentPane().setLayout(new FlowLayout())/ /dialog.getContentPane().add(button)/}", - " {new: java.awt.FlowLayout} {empty} {/dialog.getContentPane().setLayout(new FlowLayout())/}", - " {new: javax.swing.JButton} {local-unique: button} {/new JButton()/ /dialog.getContentPane().add(button)/}"); + assertEditor(""" + public class Test { + public static void main(String[] args) { + JDialog dialog = new JDialog(); + dialog.getContentPane().setLayout(new FlowLayout()); + { + JButton button = new JButton(); + dialog.getContentPane().add(button); + } + } + }"""); + assertHierarchy(""" + {new: javax.swing.JDialog} {local-unique: dialog} {/new JDialog()/ /dialog.getContentPane()/ /dialog.getContentPane()/} + {method: public java.awt.Container javax.swing.JDialog.getContentPane()} {property} {/dialog.getContentPane().setLayout(new FlowLayout())/ /dialog.getContentPane().add(button)/} + {new: java.awt.FlowLayout} {empty} {/dialog.getContentPane().setLayout(new FlowLayout())/} + {new: javax.swing.JButton} {local-unique: button} {/new JButton()/ /dialog.getContentPane().add(button)/}"""); } /** @@ -159,29 +158,29 @@ public void test_parseWithout_getContentPane_instance() throws Exception { */ @Test public void test_rewrite_setLayout_noCorrectSignature() throws Exception { - parseJavaInfo( - "public class Test extends JDialog {", - " public Test() {", - " setLayout();", - " }", - " private void setLayout() {", - " getContentPane().setLayout(new FlowLayout());", - " }", - "}"); + parseJavaInfo(""" + public class Test extends JDialog { + public Test() { + setLayout(); + } + private void setLayout() { + getContentPane().setLayout(new FlowLayout()); + } + }"""); // no rewrite - assertEditor( - "public class Test extends JDialog {", - " public Test() {", - " setLayout();", - " }", - " private void setLayout() {", - " getContentPane().setLayout(new FlowLayout());", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JDialog} {this} {}", - " {method: public java.awt.Container javax.swing.JDialog.getContentPane()} {property} {/getContentPane().setLayout(new FlowLayout())/}", - " {new: java.awt.FlowLayout} {empty} {/getContentPane().setLayout(new FlowLayout())/}"); + assertEditor(""" + public class Test extends JDialog { + public Test() { + setLayout(); + } + private void setLayout() { + getContentPane().setLayout(new FlowLayout()); + } + }"""); + assertHierarchy(""" + {this: javax.swing.JDialog} {this} {} + {method: public java.awt.Container javax.swing.JDialog.getContentPane()} {property} {/getContentPane().setLayout(new FlowLayout())/} + {new: java.awt.FlowLayout} {empty} {/getContentPane().setLayout(new FlowLayout())/}"""); } /** @@ -191,31 +190,31 @@ public void test_rewrite_setLayout_noCorrectSignature() throws Exception { */ @Test public void test_rewrite_setLayout_ofInnerJPanel() throws Exception { - parseJavaInfo( - "public class Test extends JDialog {", - " private static class Inner extends JPanel {", - " public Inner() {", - " setLayout(new FlowLayout());", - " }", - " }", - " public Test() {", - " }", - "}"); + parseJavaInfo(""" + public class Test extends JDialog { + private static class Inner extends JPanel { + public Inner() { + setLayout(new FlowLayout()); + } + } + public Test() { + } + }"""); // no changes - assertEditor( - "public class Test extends JDialog {", - " private static class Inner extends JPanel {", - " public Inner() {", - " setLayout(new FlowLayout());", - " }", - " }", - " public Test() {", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JDialog} {this} {}", - " {method: public java.awt.Container javax.swing.JDialog.getContentPane()} {property} {}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}"); + assertEditor(""" + public class Test extends JDialog { + private static class Inner extends JPanel { + public Inner() { + setLayout(new FlowLayout()); + } + } + public Test() { + } + }"""); + assertHierarchy(""" + {this: javax.swing.JDialog} {this} {} + {method: public java.awt.Container javax.swing.JDialog.getContentPane()} {property} {} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}"""); } /** @@ -230,10 +229,10 @@ public Test() { } } """); - assertHierarchy( - "{this: javax.swing.JDialog} {this} {}", - " {method: public java.awt.Container javax.swing.JDialog.getContentPane()} {property} {}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}"); + assertHierarchy(""" + {this: javax.swing.JDialog} {this} {} + {method: public java.awt.Container javax.swing.JDialog.getContentPane()} {property} {} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}"""); // refresh() dialog.refresh(); assertNoErrors(dialog); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JInternalFrameTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JInternalFrameTest.java index 1266b65852..0090491b2e 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JInternalFrameTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JInternalFrameTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -46,17 +46,16 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_this() throws Exception { - JInternalFrameInfo frame = - parseJavaInfo( - "// filler filler filler", - "public class Test extends JInternalFrame {", - " public Test() {", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JInternalFrame} {this} {}", - " {method: public java.awt.Container javax.swing.JInternalFrame.getContentPane()} {property} {}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}"); + JInternalFrameInfo frame = parseJavaInfo(""" + // filler filler filler + public class Test extends JInternalFrame { + public Test() { + } + }"""); + assertHierarchy(""" + {this: javax.swing.JInternalFrame} {this} {} + {method: public java.awt.Container javax.swing.JInternalFrame.getContentPane()} {property} {} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}"""); frame.refresh(); assertNoErrors(frame); // check bounds of JInternalFrame and its "contentPane" @@ -77,27 +76,26 @@ public void test_this() throws Exception { @Test public void test_onJDesktopPane() throws Exception { - ContainerInfo panel = - parseJavaInfo( - "public class Test extends JPanel {", - " public Test() {", - " JDesktopPane desktop = new JDesktopPane();", - " add(desktop);", - " {", - " JInternalFrame frame = new JInternalFrame();", - " desktop.add(frame);", - " frame.setBounds(5, 5, 200, 150);", - " }", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/add(desktop)/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: javax.swing.JDesktopPane} {local-unique: desktop} {/new JDesktopPane()/ /add(desktop)/ /desktop.add(frame)/}", - " {implicit-layout: absolute} {implicit-layout} {}", - " {new: javax.swing.JInternalFrame} {local-unique: frame} {/new JInternalFrame()/ /desktop.add(frame)/ /frame.setBounds(5, 5, 200, 150)/}", - " {method: public java.awt.Container javax.swing.JInternalFrame.getContentPane()} {property} {}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}"); + ContainerInfo panel = parseJavaInfo(""" + public class Test extends JPanel { + public Test() { + JDesktopPane desktop = new JDesktopPane(); + add(desktop); + { + JInternalFrame frame = new JInternalFrame(); + desktop.add(frame); + frame.setBounds(5, 5, 200, 150); + } + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/add(desktop)/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: javax.swing.JDesktopPane} {local-unique: desktop} {/new JDesktopPane()/ /add(desktop)/ /desktop.add(frame)/} + {implicit-layout: absolute} {implicit-layout} {} + {new: javax.swing.JInternalFrame} {local-unique: frame} {/new JInternalFrame()/ /desktop.add(frame)/ /frame.setBounds(5, 5, 200, 150)/} + {method: public java.awt.Container javax.swing.JInternalFrame.getContentPane()} {property} {} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}"""); panel.refresh(); JInternalFrameInfo frame = getJavaInfoByName("frame"); // JInternalFrame should be visible diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JLabelTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JLabelTest.java index 45dec78cd1..5ff1e9c392 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JLabelTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JLabelTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -48,13 +48,12 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_displayedMnemonic_property() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new JLabel());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new JLabel()); + } + }"""); ComponentInfo label = panel.getChildrenComponents().get(0); // we have both variants in ComponentDescription { @@ -87,27 +86,26 @@ public void test_displayedMnemonic_property() throws Exception { @Test public void test_displayedMnemonicIndex_location() throws Exception { dontConvertSingleQuotesToDouble(); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JLabel label = new JLabel();", - " label.setDisplayedMnemonic('C');", - " add(label);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JLabel label = new JLabel(); + label.setDisplayedMnemonic('C'); + add(label); + } + }"""); ComponentInfo label = panel.getChildrenComponents().get(0); // set "displayedMnemonicIndex" label.getPropertyByTitle("displayedMnemonicIndex").setValue(1); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " JLabel label = new JLabel();", - " label.setDisplayedMnemonic('C');", - " label.setDisplayedMnemonicIndex(1);", - " add(label);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + JLabel label = new JLabel(); + label.setDisplayedMnemonic('C'); + label.setDisplayedMnemonicIndex(1); + add(label); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -117,16 +115,15 @@ public void test_displayedMnemonicIndex_location() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_labelFor_getText_noInvocation() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " {", - " JLabel label = new JLabel();", - " add(label);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + JLabel label = new JLabel(); + add(label); + } + } + }"""); panel.refresh(); ComponentInfo label = panel.getChildrenComponents().get(0); // check "labelFor" property @@ -141,17 +138,16 @@ public void test_labelFor_getText_noInvocation() throws Exception { @Test public void test_labelFor_getText_hasInvocation() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " private final JLabel label = new JLabel();", - " private final JTextField textField = new JTextField();", - " public Test() {", - " add(label);", - " label.setLabelFor(textField);", - " add(textField);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + private final JLabel label = new JLabel(); + private final JTextField textField = new JTextField(); + public Test() { + add(label); + label.setLabelFor(textField); + add(textField); + } + }"""); panel.refresh(); ComponentInfo label = panel.getChildrenComponents().get(0); // check "labelFor" property diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JLayeredPaneTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JLayeredPaneTest.java index da510c70c3..9047a21460 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JLayeredPaneTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JLayeredPaneTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -44,18 +44,17 @@ public class JLayeredPaneTest extends SwingModelTest { */ @Test public void test_layer_Constraints() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JLayeredPane pane = new JLayeredPane();", - " add(pane);", - " {", - " JButton button = new JButton();", - " pane.add(button, new Integer(10));", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JLayeredPane pane = new JLayeredPane(); + add(pane); + { + JButton button = new JButton(); + pane.add(button, new Integer(10)); + } + } + }"""); panel.refresh(); JLayeredPaneInfo pane = (JLayeredPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = pane.getChildrenComponents().get(0); @@ -68,18 +67,18 @@ public void test_layer_Constraints() throws Exception { assertEquals(10, layerProperty.getValue()); // update "Layer" property layerProperty.setValue(20); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JLayeredPane pane = new JLayeredPane();", - " add(pane);", - " {", - " JButton button = new JButton();", - " pane.setLayer(button, 20);", - " pane.add(button);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JLayeredPane pane = new JLayeredPane(); + add(pane); + { + JButton button = new JButton(); + pane.setLayer(button, 20); + pane.add(button); + } + } + }"""); assertEquals(20, layerProperty.getValue()); } @@ -89,18 +88,17 @@ public void test_layer_Constraints() throws Exception { */ @Test public void test_layer_noConstraints() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JLayeredPane pane = new JLayeredPane();", - " add(pane);", - " {", - " JButton button = new JButton();", - " pane.add(button, BorderLayout.NORTH);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JLayeredPane pane = new JLayeredPane(); + add(pane); + { + JButton button = new JButton(); + pane.add(button, BorderLayout.NORTH); + } + } + }"""); panel.refresh(); JLayeredPaneInfo pane = (JLayeredPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = pane.getChildrenComponents().get(0); @@ -113,18 +111,18 @@ public void test_layer_noConstraints() throws Exception { assertEquals(0, layerProperty.getValue()); // update "Layer" property layerProperty.setValue(20); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JLayeredPane pane = new JLayeredPane();", - " add(pane);", - " {", - " JButton button = new JButton();", - " pane.setLayer(button, 20);", - " pane.add(button, BorderLayout.NORTH);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JLayeredPane pane = new JLayeredPane(); + add(pane); + { + JButton button = new JButton(); + pane.setLayer(button, 20); + pane.add(button, BorderLayout.NORTH); + } + } + }"""); assertEquals(20, layerProperty.getValue()); } @@ -134,19 +132,18 @@ public void test_layer_noConstraints() throws Exception { */ @Test public void test_layer_setLayer_1() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JLayeredPane pane = new JLayeredPane();", - " add(pane);", - " {", - " JButton button = new JButton();", - " pane.add(button);", - " pane.setLayer(button, 10);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JLayeredPane pane = new JLayeredPane(); + add(pane); + { + JButton button = new JButton(); + pane.add(button); + pane.setLayer(button, 10); + } + } + }"""); panel.refresh(); JLayeredPaneInfo pane = (JLayeredPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = pane.getChildrenComponents().get(0); @@ -159,18 +156,18 @@ public void test_layer_setLayer_1() throws Exception { assertEquals(10, layerProperty.getValue()); // update "Layer" property layerProperty.setValue(20); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JLayeredPane pane = new JLayeredPane();", - " add(pane);", - " {", - " JButton button = new JButton();", - " pane.add(button);", - " pane.setLayer(button, 20);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JLayeredPane pane = new JLayeredPane(); + add(pane); + { + JButton button = new JButton(); + pane.add(button); + pane.setLayer(button, 20); + } + } + }"""); assertEquals(20, layerProperty.getValue()); } @@ -180,19 +177,18 @@ public void test_layer_setLayer_1() throws Exception { */ @Test public void test_layer_setLayer_2() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JLayeredPane pane = new JLayeredPane();", - " add(pane);", - " {", - " JButton button = new JButton();", - " pane.add(button);", - " pane.setLayer(button, 10, 5);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JLayeredPane pane = new JLayeredPane(); + add(pane); + { + JButton button = new JButton(); + pane.add(button); + pane.setLayer(button, 10, 5); + } + } + }"""); panel.refresh(); JLayeredPaneInfo pane = (JLayeredPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = pane.getChildrenComponents().get(0); @@ -205,18 +201,18 @@ public void test_layer_setLayer_2() throws Exception { assertEquals(10, layerProperty.getValue()); // update "Layer" property layerProperty.setValue(20); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JLayeredPane pane = new JLayeredPane();", - " add(pane);", - " {", - " JButton button = new JButton();", - " pane.add(button);", - " pane.setLayer(button, 20, 5);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JLayeredPane pane = new JLayeredPane(); + add(pane); + { + JButton button = new JButton(); + pane.add(button); + pane.setLayer(button, 20, 5); + } + } + }"""); assertEquals(20, layerProperty.getValue()); } @@ -226,19 +222,18 @@ public void test_layer_setLayer_2() throws Exception { */ @Test public void test_layer_setLayer_remove() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JLayeredPane pane = new JLayeredPane();", - " add(pane);", - " {", - " JButton button = new JButton();", - " pane.add(button);", - " pane.setLayer(button, 10);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JLayeredPane pane = new JLayeredPane(); + add(pane); + { + JButton button = new JButton(); + pane.add(button); + pane.setLayer(button, 10); + } + } + }"""); panel.refresh(); JLayeredPaneInfo pane = (JLayeredPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = pane.getChildrenComponents().get(0); @@ -251,17 +246,17 @@ public void test_layer_setLayer_remove() throws Exception { assertEquals(10, layerProperty.getValue()); // update "Layer" property layerProperty.setValue(Property.UNKNOWN_VALUE); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JLayeredPane pane = new JLayeredPane();", - " add(pane);", - " {", - " JButton button = new JButton();", - " pane.add(button);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JLayeredPane pane = new JLayeredPane(); + add(pane); + { + JButton button = new JButton(); + pane.add(button); + } + } + }"""); assertEquals(0, layerProperty.getValue()); } @@ -270,29 +265,28 @@ public void test_layer_setLayer_remove() throws Exception { */ @Test public void test_getGraphicalChildren() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JLayeredPane pane = new JLayeredPane();", - " add(pane);", - " {", - " JButton button_1 = new JButton();", - " pane.add(button_1);", - " pane.setLayer(button_1, 5);", - " }", - " {", - " JButton button_2 = new JButton();", - " pane.add(button_2);", - " pane.setLayer(button_2, 10);", - " }", - " {", - " JButton button_3 = new JButton();", - " pane.add(button_3);", - " pane.setLayer(button_3, 10);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JLayeredPane pane = new JLayeredPane(); + add(pane); + { + JButton button_1 = new JButton(); + pane.add(button_1); + pane.setLayer(button_1, 5); + } + { + JButton button_2 = new JButton(); + pane.add(button_2); + pane.setLayer(button_2, 10); + } + { + JButton button_3 = new JButton(); + pane.add(button_3); + pane.setLayer(button_3, 10); + } + } + }"""); panel.refresh(); JLayeredPaneInfo pane = (JLayeredPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button_1 = pane.getChildrenComponents().get(0); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JListTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JListTest.java index 9bbaa67f3d..81baa3ba71 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JListTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JListTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -35,22 +35,22 @@ public class JListTest extends SwingModelTest { //////////////////////////////////////////////////////////////////////////// @Test public void test_parsing() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JList list = new JList();", - " add(list);", - " list.setModel(new AbstractListModel() {", - " String[] values = {'111', '222', '333'};", - " public int getSize() {", - " return values.length;", - " }", - " public Object getElementAt(int i) {", - " return values[i];", - " }", - " });", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JList list = new JList(); + add(list); + list.setModel(new AbstractListModel() { + String[] values = {"111", "222", "333"}; + public int getSize() { + return values.length; + } + public Object getElementAt(int i) { + return values[i]; + } + }); + } + }"""); refresh(); ComponentInfo listInfo = getJavaInfoByName("list"); JList listObject = (JList) listInfo.getObject(); @@ -76,22 +76,22 @@ public void test_parsing() throws Exception { */ @Test public void test_nullModelValues() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JList list = new JList();", - " add(list);", - " list.setModel(new AbstractListModel() {", - " String[] values = null;", - " public int getSize() {", - " return values.length;", - " }", - " public Object getElementAt(int i) {", - " return values[i];", - " }", - " });", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JList list = new JList(); + add(list); + list.setModel(new AbstractListModel() { + String[] values = null; + public int getSize() { + return values.length; + } + public Object getElementAt(int i) { + return values[i]; + } + }); + } + }"""); refresh(); ComponentInfo listInfo = getJavaInfoByName("list"); JList listObject = (JList) listInfo.getObject(); @@ -108,54 +108,54 @@ public void test_nullModelValues() throws Exception { */ @Test public void test_setSelectedIndex() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JList list = new JList();", - " add(list);", - " list.setModel(new AbstractListModel() {", - " String[] values = {'111', '222', '333'};", - " public int getSize() {", - " return values.length;", - " }", - " public Object getElementAt(int i) {", - " return values[i];", - " }", - " });", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JList list = new JList(); + add(list); + list.setModel(new AbstractListModel() { + String[] values = {"111", "222", "333"}; + public int getSize() { + return values.length; + } + public Object getElementAt(int i) { + return values[i]; + } + }); + } + }"""); refresh(); ComponentInfo listInfo = getJavaInfoByName("list"); // listInfo.getPropertyByTitle("selectedIndex").setValue(1); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " JList list = new JList();", - " add(list);", - " list.setModel(new AbstractListModel() {", - " String[] values = {'111', '222', '333'};", - " public int getSize() {", - " return values.length;", - " }", - " public Object getElementAt(int i) {", - " return values[i];", - " }", - " });", - " list.setSelectedIndex(1);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + JList list = new JList(); + add(list); + list.setModel(new AbstractListModel() { + String[] values = {"111", "222", "333"}; + public int getSize() { + return values.length; + } + public Object getElementAt(int i) { + return values[i]; + } + }); + list.setSelectedIndex(1); + } + }"""); } @Test public void test_modelEditor() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JList list = new JList();", - " add(list);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JList list = new JList(); + add(list); + } + }"""); refresh(); // ComponentInfo listInfo = getJavaInfoByName("list"); @@ -164,21 +164,21 @@ public void test_modelEditor() throws Exception { assertEquals(0, ListModelPropertyEditor.getItems(modelProperty).length); // set new items ListModelPropertyEditor.setItems(modelProperty, new String[]{"aaa", "bbb"}); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " JList list = new JList();", - " list.setModel(new AbstractListModel() {", - " String[] values = new String[] {'aaa', 'bbb'};", - " public int getSize() {", - " return values.length;", - " }", - " public Object getElementAt(int index) {", - " return values[index];", - " }", - " });", - " add(list);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + JList list = new JList(); + list.setModel(new AbstractListModel() { + String[] values = new String[] {"aaa", "bbb"}; + public int getSize() { + return values.length; + } + public Object getElementAt(int index) { + return values[index]; + } + }); + add(list); + } + }"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JScrollPaneTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JScrollPaneTest.java index 5ffac6932d..0a04533938 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JScrollPaneTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JScrollPaneTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -49,16 +49,15 @@ public void _test_exit() throws Exception { */ @Test public void test_association_constructor() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JButton button = new JButton();", - " //", - " JScrollPane scroll = new JScrollPane(button);", - " add(scroll);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JButton button = new JButton(); + // + JScrollPane scroll = new JScrollPane(button); + add(scroll); + } + }"""); JScrollPaneInfo scroll = (JScrollPaneInfo) panel.getChildrenComponents().get(0); assertEquals(1, scroll.getChildrenComponents().size()); // check association @@ -80,18 +79,17 @@ public void test_association_constructor() throws Exception { */ @Test public void test_association_setColumnHeaderView() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JScrollPane scroll = new JScrollPane();", - " add(scroll);", - " {", - " JButton button = new JButton();", - " scroll.setColumnHeaderView(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JScrollPane scroll = new JScrollPane(); + add(scroll); + { + JButton button = new JButton(); + scroll.setColumnHeaderView(button); + } + } + }"""); JScrollPaneInfo scroll = (JScrollPaneInfo) panel.getChildrenComponents().get(0); assertEquals(1, scroll.getChildrenComponents().size()); // check association @@ -114,33 +112,33 @@ public void test_association_setColumnHeaderView() throws Exception { */ @Test public void test_getViewport_add() throws Exception { - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JScrollPane scroll = new JScrollPane();", - " add(scroll);", - " {", - " JButton button = new JButton();", - " scroll.getViewport().add(button);", - " }", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/add(scroll)/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: javax.swing.JScrollPane} {local-unique: scroll} {/new JScrollPane()/ /add(scroll)/ /scroll.setViewportView(button)/}", - " {new: javax.swing.JButton} {local-unique: button} {/new JButton()/ /scroll.setViewportView(button)/}"); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JScrollPane scroll = new JScrollPane();", - " add(scroll);", - " {", - " JButton button = new JButton();", - " scroll.setViewportView(button);", - " }", - " }", - "}"); + parseContainer(""" + class Test extends JPanel { + Test() { + JScrollPane scroll = new JScrollPane(); + add(scroll); + { + JButton button = new JButton(); + scroll.getViewport().add(button); + } + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/add(scroll)/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: javax.swing.JScrollPane} {local-unique: scroll} {/new JScrollPane()/ /add(scroll)/ /scroll.setViewportView(button)/} + {new: javax.swing.JButton} {local-unique: button} {/new JButton()/ /scroll.setViewportView(button)/}"""); + assertEditor(""" + class Test extends JPanel { + Test() { + JScrollPane scroll = new JScrollPane(); + add(scroll); + { + JButton button = new JButton(); + scroll.setViewportView(button); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -150,14 +148,13 @@ public void test_getViewport_add() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_CREATE() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JScrollPane scroll = new JScrollPane();", - " add(scroll);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JScrollPane scroll = new JScrollPane(); + add(scroll); + } + }"""); JScrollPaneInfo scroll = (JScrollPaneInfo) panel.getChildrenComponents().get(0); // add component { @@ -165,17 +162,17 @@ public void test_CREATE() throws Exception { scroll.command_CREATE(newComponent, "setRowHeaderView"); assertInstanceOf(InvocationChildAssociation.class, newComponent.getAssociation()); } - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JScrollPane scroll = new JScrollPane();", - " add(scroll);", - " {", - " JButton button = new JButton();", - " scroll.setRowHeaderView(button);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JScrollPane scroll = new JScrollPane(); + add(scroll); + { + JButton button = new JButton(); + scroll.setRowHeaderView(button); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -185,22 +182,21 @@ public void test_CREATE() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_OUT() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JScrollPane scroll = new JScrollPane();", - " add(scroll);", - " {", - " JButton button = new JButton();", - " scroll.setRowHeaderView(button);", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JScrollPane scroll = new JScrollPane(); + add(scroll); + { + JButton button = new JButton(); + scroll.setRowHeaderView(button); + } + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + } + } + }"""); // prepare source JScrollPaneInfo scroll = (JScrollPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = scroll.getChildrenComponents().get(0); @@ -209,53 +205,52 @@ public void test_OUT() throws Exception { FlowLayoutInfo innerLayout = (FlowLayoutInfo) innerPanel.getLayout(); // do move innerLayout.move(button, null); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JScrollPane scroll = new JScrollPane();", - " add(scroll);", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " {", - " JButton button = new JButton();", - " innerPanel.add(button);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JScrollPane scroll = new JScrollPane(); + add(scroll); + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + { + JButton button = new JButton(); + innerPanel.add(button); + } + } + } + }"""); } @Test public void test_MOVE() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JScrollPane scroll = new JScrollPane();", - " add(scroll);", - " {", - " JButton button = new JButton();", - " scroll.setRowHeaderView(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JScrollPane scroll = new JScrollPane(); + add(scroll); + { + JButton button = new JButton(); + scroll.setRowHeaderView(button); + } + } + }"""); // prepare source JScrollPaneInfo scroll = (JScrollPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = scroll.getChildrenComponents().get(0); // do move scroll.command_MOVE(button, "setColumnHeaderView"); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JScrollPane scroll = new JScrollPane();", - " add(scroll);", - " {", - " JButton button = new JButton();", - " scroll.setColumnHeaderView(button);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JScrollPane scroll = new JScrollPane(); + add(scroll); + { + JButton button = new JButton(); + scroll.setColumnHeaderView(button); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -265,41 +260,40 @@ public void test_MOVE() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_ADD() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JScrollPane scroll = new JScrollPane();", - " add(scroll);", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " {", - " JButton button = new JButton();", - " innerPanel.add(button);", - " }", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JScrollPane scroll = new JScrollPane(); + add(scroll); + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + { + JButton button = new JButton(); + innerPanel.add(button); + } + } + } + }"""); JScrollPaneInfo scroll = (JScrollPaneInfo) panel.getChildrenComponents().get(0); ContainerInfo innerPanel = (ContainerInfo) panel.getChildrenComponents().get(1); ComponentInfo button = innerPanel.getChildrenComponents().get(0); // scroll.command_ADD(button, "setRowHeaderView"); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JScrollPane scroll = new JScrollPane();", - " add(scroll);", - " {", - " JButton button = new JButton();", - " scroll.setRowHeaderView(button);", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JScrollPane scroll = new JScrollPane(); + add(scroll); + { + JButton button = new JButton(); + scroll.setRowHeaderView(button); + } + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + } + } + }"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JSliderTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JSliderTest.java index d59f4fb729..76b0f1f913 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JSliderTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JSliderTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -39,16 +39,15 @@ public class JSliderTest extends SwingModelTest { */ @Test public void test_36471() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JSlider slider = new JSlider();", - " slider.setLabelTable(new java.util.Hashtable());", - " slider.setPaintLabels(true);", - " add(slider);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JSlider slider = new JSlider(); + slider.setLabelTable(new java.util.Hashtable()); + slider.setPaintLabels(true); + add(slider); + } + }"""); panel.refresh(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JSpinnerTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JSpinnerTest.java index 0924da25f2..fc923f82ad 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JSpinnerTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JSpinnerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -70,15 +70,14 @@ public static void tearDownAll() { */ @Test public void test_setEditor() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JSpinner spinner = new JSpinner();", - " spinner.setEditor(new JSpinner.NumberEditor(spinner, '#'));", - " add(spinner);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JSpinner spinner = new JSpinner(); + spinner.setEditor(new JSpinner.NumberEditor(spinner, "#")); + add(spinner); + } + }"""); panel.refresh(); assertNoErrors(panel); } @@ -183,15 +182,14 @@ public void test_dateModel() throws Exception { private void assertEditorTextTooltip(String modelSource, String expectedText, String expectedTooltip) throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JSpinner spinner = new JSpinner();", - " spinner.setModel(" + modelSource + ");", - " add(spinner);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JSpinner spinner = new JSpinner(); + spinner.setModel(%s); + add(spinner); + } + }""".formatted(modelSource)); panel.refresh(); ComponentInfo spinner = panel.getChildrenComponents().get(0); Property modelProperty = spinner.getPropertyByTitle("model"); @@ -300,16 +298,15 @@ public Test() { @Test public void test_editor_dateModel() throws Exception { - ContainerInfo spinner = parseContainer( - """ - import java.util.Calendar; - import java.util.Date; - // filler filler filler - public class Test extends JSpinner { - public Test() { - setModel(new SpinnerDateModel(new Date(1757800800000L), new Date(1757714400000L), new Date(1757887200000L), Calendar.DAY_OF_YEAR)); - } - }"""); + ContainerInfo spinner = parseContainer(""" + import java.util.Calendar; + import java.util.Date; + // filler filler filler + public class Test extends JSpinner { + public Test() { + setModel(new SpinnerDateModel(new Date(1757800800000L), new Date(1757714400000L), new Date(1757887200000L), Calendar.DAY_OF_YEAR)); + } + }"""); spinner.refresh(); Property modelProperty = spinner.getPropertyByTitle("model"); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JSplitPaneTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JSplitPaneTest.java index 4127178a91..5455d60bd5 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JSplitPaneTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JSplitPaneTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -51,22 +51,21 @@ public void _test_exit() throws Exception { */ @Test public void test_association_setLeftRight() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JButton button = new JButton();", - " split.setLeftComponent(button);", - " }", - " {", - " JButton button = new JButton();", - " split.setRightComponent(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + { + JButton button = new JButton(); + split.setLeftComponent(button); + } + { + JButton button = new JButton(); + split.setRightComponent(button); + } + } + }"""); panel.refresh(); JSplitPaneInfo split = (JSplitPaneInfo) panel.getChildrenComponents().get(0); // @@ -95,14 +94,13 @@ public void test_association_setLeftRight() throws Exception { */ @Test public void test_association_empty() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + } + }"""); panel.refresh(); JSplitPaneInfo split = (JSplitPaneInfo) panel.getChildrenComponents().get(0); // @@ -115,42 +113,41 @@ public void test_association_empty() throws Exception { */ @Test public void test_association_setDividerLocation() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JButton button_1 = new JButton();", - " split.setLeftComponent(button_1);", - " }", - " {", - " JButton button_2 = new JButton();", - " split.setRightComponent(button_2);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + { + JButton button_1 = new JButton(); + split.setLeftComponent(button_1); + } + { + JButton button_2 = new JButton(); + split.setRightComponent(button_2); + } + } + }"""); panel.refresh(); JSplitPaneInfo split = (JSplitPaneInfo) panel.getChildrenComponents().get(0); // split.getPropertyByTitle("dividerLocation(double)").setValue(0.5); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JButton button_1 = new JButton();", - " split.setLeftComponent(button_1);", - " }", - " {", - " JButton button_2 = new JButton();", - " split.setRightComponent(button_2);", - " }", - " split.setDividerLocation(0.5);", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + { + JButton button_1 = new JButton(); + split.setLeftComponent(button_1); + } + { + JButton button_2 = new JButton(); + split.setRightComponent(button_2); + } + split.setDividerLocation(0.5); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -163,22 +160,21 @@ public void test_association_setDividerLocation() throws Exception { */ @Test public void test_getPositionRectangle_1() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JButton button = new JButton();", - " split.setLeftComponent(button);", - " }", - " {", - " JButton button = new JButton();", - " split.setRightComponent(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + { + JButton button = new JButton(); + split.setLeftComponent(button); + } + { + JButton button = new JButton(); + split.setRightComponent(button); + } + } + }"""); panel.refresh(); JSplitPaneInfo split = (JSplitPaneInfo) panel.getChildrenComponents().get(0); // @@ -201,14 +197,13 @@ public void test_getPositionRectangle_1() throws Exception { */ @Test public void test_getPositionRectangle_2() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, null, null);", - " add(split);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, null, null); + add(split); + } + }"""); panel.refresh(); JSplitPaneInfo split = (JSplitPaneInfo) panel.getChildrenComponents().get(0); // @@ -223,14 +218,13 @@ public void test_getPositionRectangle_2() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_CREATE() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + } + }"""); JSplitPaneInfo split = (JSplitPaneInfo) panel.getChildrenComponents().get(0); // add component { @@ -239,17 +233,17 @@ public void test_CREATE() throws Exception { assertInstanceOf(InvocationChildAssociation.class, newComponent.getAssociation()); } // check source - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JButton button = new JButton();", - " split.setLeftComponent(button);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + { + JButton button = new JButton(); + split.setLeftComponent(button); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -259,22 +253,21 @@ public void test_CREATE() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_OUT() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JButton button = new JButton();", - " split.setLeftComponent(button);", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + { + JButton button = new JButton(); + split.setLeftComponent(button); + } + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + } + } + }"""); // prepare source JSplitPaneInfo split = (JSplitPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = split.getChildrenComponents().get(0); @@ -283,53 +276,52 @@ public void test_OUT() throws Exception { FlowLayoutInfo innerLayout = (FlowLayoutInfo) innerPanel.getLayout(); // do move innerLayout.move(button, null); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " {", - " JButton button = new JButton();", - " innerPanel.add(button);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + { + JButton button = new JButton(); + innerPanel.add(button); + } + } + } + }"""); } @Test public void test_MOVE() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JButton button = new JButton();", - " split.setLeftComponent(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + { + JButton button = new JButton(); + split.setLeftComponent(button); + } + } + }"""); // prepare source JSplitPaneInfo split = (JSplitPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = split.getChildrenComponents().get(0); // do move split.command_MOVE(button, false); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JButton button = new JButton();", - " split.setRightComponent(button);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + { + JButton button = new JButton(); + split.setRightComponent(button); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -339,42 +331,41 @@ public void test_MOVE() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_ADD() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " {", - " JButton button = new JButton();", - " innerPanel.add(button);", - " }", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + { + JButton button = new JButton(); + innerPanel.add(button); + } + } + } + }"""); JSplitPaneInfo split = (JSplitPaneInfo) panel.getChildrenComponents().get(0); ContainerInfo innerPanel = (ContainerInfo) panel.getChildrenComponents().get(1); ComponentInfo button = innerPanel.getChildrenComponents().get(0); // split.command_ADD(button, true); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JButton button = new JButton();", - " split.setLeftComponent(button);", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JSplitPane split = new JSplitPane(); + add(split); + { + JButton button = new JButton(); + split.setLeftComponent(button); + } + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -384,24 +375,23 @@ public void test_ADD() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_clipboard() throws Exception { - final ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JButton button = new JButton('A');", - " split.setLeftComponent(button);", - " }", - " {", - " JButton button = new JButton('B');", - " split.setRightComponent(button);", - " }", - " }", - " }", - "}"); + final ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + { + JSplitPane split = new JSplitPane(); + add(split); + { + JButton button = new JButton("A"); + split.setLeftComponent(button); + } + { + JButton button = new JButton("B"); + split.setRightComponent(button); + } + } + } + }"""); refresh(); // { @@ -413,34 +403,34 @@ public void run(ComponentInfo copy) throws Exception { } }); } - assertEditor( - "class Test extends JPanel {", - " Test() {", - " {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JButton button = new JButton('A');", - " split.setLeftComponent(button);", - " }", - " {", - " JButton button = new JButton('B');", - " split.setRightComponent(button);", - " }", - " }", - " {", - " JSplitPane split = new JSplitPane();", - " add(split);", - " {", - " JButton button = new JButton('A');", - " split.setLeftComponent(button);", - " }", - " {", - " JButton button = new JButton('B');", - " split.setRightComponent(button);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + { + JSplitPane split = new JSplitPane(); + add(split); + { + JButton button = new JButton("A"); + split.setLeftComponent(button); + } + { + JButton button = new JButton("B"); + split.setRightComponent(button); + } + } + { + JSplitPane split = new JSplitPane(); + add(split); + { + JButton button = new JButton("A"); + split.setLeftComponent(button); + } + { + JButton button = new JButton("B"); + split.setRightComponent(button); + } + } + } + }"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTabbedPaneTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTabbedPaneTest.java index 85c5539db0..e45673156e 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTabbedPaneTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTabbedPaneTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -65,17 +65,16 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_association() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " //", - " JButton button = new JButton();", - " tabbed.addTab('New tab', button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + // + JButton button = new JButton(); + tabbed.addTab("New tab", button); + } + }"""); refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); assertEquals(1, tabbed.getChildrenComponents().size()); @@ -113,22 +112,22 @@ public void test_association() throws Exception { */ @Test public void test_association_insert() throws Exception { - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.insertTab('title', null, button, 'tip', 0);", - " }", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/add(tabbed)/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: javax.swing.JTabbedPane} {local-unique: tabbed} {/new JTabbedPane()/ /add(tabbed)/ /tabbed.insertTab('title', null, button, 'tip', 0)/}", - " {new: javax.swing.JButton} {local-unique: button} {/new JButton()/ /tabbed.insertTab('title', null, button, 'tip', 0)/}"); + parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.insertTab("title", null, button, "tip", 0); + } + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/add(tabbed)/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: javax.swing.JTabbedPane} {local-unique: tabbed} {/new JTabbedPane()/ /add(tabbed)/ /tabbed.insertTab("title", null, button, "tip", 0)/} + {new: javax.swing.JButton} {local-unique: button} {/new JButton()/ /tabbed.insertTab("title", null, button, "tip", 0)/}"""); } /** @@ -136,20 +135,19 @@ public void test_association_insert() throws Exception { */ @Test public void test_isHorizontal() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " {", - " JTabbedPane tabbed_1 = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed_1);", - " }", - " {", - " JTabbedPane tabbed_2 = new JTabbedPane(SwingConstants.LEFT);", - " add(tabbed_2);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + { + JTabbedPane tabbed_1 = new JTabbedPane(SwingConstants.TOP); + add(tabbed_1); + } + { + JTabbedPane tabbed_2 = new JTabbedPane(SwingConstants.LEFT); + add(tabbed_2); + } + } + }"""); refresh(); JTabbedPaneInfo tabbed_1 = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); JTabbedPaneInfo tabbed_2 = (JTabbedPaneInfo) panel.getChildrenComponents().get(1); @@ -163,15 +161,14 @@ public void test_isHorizontal() throws Exception { */ @Test public void test_badTab() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " tabbed.addTab('title', null);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + tabbed.addTab("title", null); + } + }"""); refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); assertNoErrors(panel); @@ -184,24 +181,21 @@ public void test_badTab() throws Exception { */ @Test public void test_getTabs_noComponentModels() throws Exception { - setFileContentSrc( - "test/MyTabbedPane.java", - getTestSource( - "public class MyTabbedPane extends JTabbedPane {", - " public MyTabbedPane() {", - " addTab('tab_1', new JButton());", - " }", - "}")); + setFileContentSrc("test/MyTabbedPane.java", getTestSource(""" + public class MyTabbedPane extends JTabbedPane { + public MyTabbedPane() { + addTab("tab_1", new JButton()); + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " MyTabbedPane tabbed = new MyTabbedPane();", - " add(tabbed);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + MyTabbedPane tabbed = new MyTabbedPane(); + add(tabbed); + } + }"""); refresh(); assertNoErrors(panel); // ask tabs @@ -214,18 +208,18 @@ public void test_getTabs_noComponentModels() throws Exception { */ @Test public void test_parse_indexOfComponent() throws Exception { - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('111', button);", - " tabbed.setForegroundAt(tabbed.indexOfComponent(button), Color.RED);", - " }", - " }", - "}"); + parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("111", button); + tabbed.setForegroundAt(tabbed.indexOfComponent(button), Color.RED); + } + } + }"""); refresh(); ComponentInfo button = getJavaInfoByName("button"); // @@ -240,18 +234,18 @@ public void test_parse_indexOfComponent() throws Exception { */ @Test public void test_disable_setModel() throws Exception { - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " tabbed.setModel(null);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('tab', button);", - " }", - " }", - "}"); + parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + tabbed.setModel(null); + { + JButton button = new JButton(); + tabbed.addTab("tab", button); + } + } + }"""); refresh(); assertNoErrors(m_lastParseInfo); } @@ -267,14 +261,13 @@ public void test_disable_setModel() throws Exception { */ @Test public void test_getActiveComponent_null() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + } + }"""); refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); IObjectPresentation presentation = tabbed.getPresentation(); @@ -294,16 +287,15 @@ public void test_getActiveComponent_null() throws Exception { */ @Test public void test_getActiveComponent_set() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " tabbed.addTab('111', new JButton('111'));", - " tabbed.addTab('222', new JButton('222'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + tabbed.addTab("111", new JButton("111")); + tabbed.addTab("222", new JButton("222")); + } + }"""); refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); IObjectPresentation presentation = tabbed.getPresentation(); @@ -334,15 +326,14 @@ public void test_getActiveComponent_set() throws Exception { */ @Test public void test_property_list() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " tabbed.addTab('111', new JButton());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + tabbed.addTab("111", new JButton()); + } + }"""); refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = tabbed.getChildrenComponents().get(0); @@ -377,15 +368,14 @@ public void test_property_list() throws Exception { */ @Test public void test_property_subAssociation() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " tabbed.addTab('111', new JButton());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + tabbed.addTab("111", new JButton()); + } + }"""); refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); // prepare button/property @@ -412,16 +402,15 @@ public void test_property_subAssociation() throws Exception { */ @Test public void test_property_subAt() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " tabbed.addTab('111', new JButton());", - " tabbed.setForegroundAt(0, Color.RED);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + tabbed.addTab("111", new JButton()); + tabbed.setForegroundAt(0, Color.RED); + } + }"""); refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); // @@ -440,14 +429,14 @@ public void test_property_subAt() throws Exception { { // can not remove, ignore "set" property.setValue(Property.UNKNOWN_VALUE); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " tabbed.addTab('111', new JButton());", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + tabbed.addTab("111", new JButton()); + } + }"""); } } @@ -456,18 +445,17 @@ public void test_property_subAt() throws Exception { */ @Test public void test_property_subAtSet() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " //", - " JButton button = new JButton();", - " tabbed.addTab('111', button);", - " tabbed.setEnabledAt(0, false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + // + JButton button = new JButton(); + tabbed.addTab("111", button); + tabbed.setEnabledAt(0, false); + } + }"""); refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); // @@ -479,18 +467,18 @@ public void test_property_subAtSet() throws Exception { // add value { property.setExpression("java.awt.Color.RED", null); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " //", - " JButton button = new JButton();", - " tabbed.addTab('111', button);", - " tabbed.setForegroundAt(0, Color.RED);", - " tabbed.setEnabledAt(0, false);", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + // + JButton button = new JButton(); + tabbed.addTab("111", button); + tabbed.setForegroundAt(0, Color.RED); + tabbed.setEnabledAt(0, false); + } + }"""); } } @@ -501,15 +489,14 @@ public void test_property_subAtSet() throws Exception { */ @Test public void test_property_subAtSetConflict() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " tabbed.addTab('111', new JButton());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + tabbed.addTab("111", new JButton()); + } + }"""); refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); // @@ -521,15 +508,15 @@ public void test_property_subAtSetConflict() throws Exception { // add value { property.setValue("ToolTip"); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " tabbed.addTab('111', new JButton());", - " tabbed.setToolTipTextAt(0, 'ToolTip');", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + tabbed.addTab("111", new JButton()); + tabbed.setToolTipTextAt(0, "ToolTip"); + } + }"""); } } @@ -538,17 +525,16 @@ public void test_property_subAtSetConflict() throws Exception { */ @Test public void test_property_subAtRemove() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " //", - " tabbed.addTab('111', new JButton());", - " tabbed.setEnabledAt(0, false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + // + tabbed.addTab("111", new JButton()); + tabbed.setEnabledAt(0, false); + } + }"""); refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); // @@ -560,15 +546,15 @@ public void test_property_subAtRemove() throws Exception { // add value { property.setValue(Boolean.TRUE); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP);", - " add(tabbed);", - " //", - " tabbed.addTab('111', new JButton());", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(SwingConstants.TOP); + add(tabbed); + // + tabbed.addTab("111", new JButton()); + } + }"""); } } @@ -594,14 +580,13 @@ private Property getTabPropertyByTitle(ComponentInfo component, String title) th //////////////////////////////////////////////////////////////////////////// @Test public void test_CREATE() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + } + }"""); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); // panel.refresh(); @@ -621,17 +606,17 @@ public void test_CREATE() throws Exception { assertInstanceOf(InvocationChildAssociation.class, button.getAssociation()); } // check source - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('New tab', null, button, null);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("New tab", null, button, null); + } + } + }"""); // new component is active assertSame(button, tabbed.getActiveComponent()); } finally { @@ -644,18 +629,17 @@ public void test_CREATE() throws Exception { */ @Test public void test_CREATE_1() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " tabbed.addTab('111', new JButton());", - " tabbed.setEnabledAt(0, false);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + tabbed.addTab("111", new JButton()); + tabbed.setEnabledAt(0, false); + } + } + }"""); refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = tabbed.getChildrenComponents().get(0); @@ -671,21 +655,21 @@ public void test_CREATE_1() throws Exception { } } // check source - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('New tab', null, button, null);", - " }", - " {", - " tabbed.addTab('111', new JButton());", - " tabbed.setEnabledAt(1, false);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("New tab", null, button, null); + } + { + tabbed.addTab("111", new JButton()); + tabbed.setEnabledAt(1, false); + } + } + }"""); // new component is active assertSame(newButton, tabbed.getActiveComponent()); } @@ -695,18 +679,17 @@ public void test_CREATE_1() throws Exception { */ @Test public void test_CREATE_2() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " tabbed.addTab('tab1', new JLabel());", - " tabbed.setEnabledAt(0, false);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + tabbed.addTab("tab1", new JLabel()); + tabbed.setEnabledAt(0, false); + } + } + }"""); refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo label = tabbed.getChildrenComponents().get(0); @@ -719,21 +702,21 @@ public void test_CREATE_2() throws Exception { flowContainer.command_CREATE(newButton, label); } // check source - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('New tab', null, button, null);", - " }", - " {", - " tabbed.addTab('tab1', new JLabel());", - " tabbed.setEnabledAt(1, false);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("New tab", null, button, null); + } + { + tabbed.addTab("tab1", new JLabel()); + tabbed.setEnabledAt(1, false); + } + } + }"""); // new component is active assertSame(newButton, tabbed.getActiveComponent()); } @@ -745,67 +728,65 @@ public void test_CREATE_2() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_DELETE() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('000', button);", - " tabbed.setEnabledAt(0, false);", - " }", - " {", - " JButton button = new JButton();", - " tabbed.addTab('111', button);", - " tabbed.setEnabledAt(1, false);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("000", button); + tabbed.setEnabledAt(0, false); + } + { + JButton button = new JButton(); + tabbed.addTab("111", button); + tabbed.setEnabledAt(1, false); + } + } + }"""); // prepare source JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = tabbed.getChildrenComponents().get(0); // do move button.delete(); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('111', button);", - " tabbed.setEnabledAt(0, false);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("111", button); + tabbed.setEnabledAt(0, false); + } + } + }"""); } @Test public void test_OUT() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('000', button);", - " tabbed.setEnabledAt(0, false);", - " }", - " {", - " JButton button = new JButton();", - " tabbed.addTab('111', button);", - " tabbed.setEnabledAt(1, false);", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("000", button); + tabbed.setEnabledAt(0, false); + } + { + JButton button = new JButton(); + tabbed.addTab("111", button); + tabbed.setEnabledAt(1, false); + } + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + } + } + }"""); // prepare source JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = tabbed.getChildrenComponents().get(0); @@ -814,46 +795,45 @@ public void test_OUT() throws Exception { FlowLayoutInfo innerLayout = (FlowLayoutInfo) innerPanel.getLayout(); // do move innerLayout.move(button, null); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('111', button);", - " tabbed.setEnabledAt(0, false);", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " {", - " JButton button = new JButton();", - " innerPanel.add(button);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("111", button); + tabbed.setEnabledAt(0, false); + } + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + { + JButton button = new JButton(); + innerPanel.add(button); + } + } + } + }"""); } @Test public void test_MOVE_1() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button_1 = new JButton();", - " tabbed.addTab('111', button_1);", - " }", - " {", - " JButton button_2 = new JButton();", - " tabbed.addTab('222', button_2);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button_1 = new JButton(); + tabbed.addTab("111", button_1); + } + { + JButton button_2 = new JButton(); + tabbed.addTab("222", button_2); + } + } + }"""); panel.refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button_1 = tabbed.getChildrenComponents().get(0); @@ -866,43 +846,42 @@ public void test_MOVE_1() throws Exception { } finally { tabbed.endEdit(); } - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button_2 = new JButton();", - " tabbed.addTab('222', button_2);", - " }", - " {", - " JButton button_1 = new JButton();", - " tabbed.addTab('111', button_1);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button_2 = new JButton(); + tabbed.addTab("222", button_2); + } + { + JButton button_1 = new JButton(); + tabbed.addTab("111", button_1); + } + } + }"""); // active tab still should be "111" assertSame(button_1, tabbed.getActiveComponent()); } @Test public void test_MOVE_2() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button_1 = new JButton();", - " tabbed.addTab('111', button_1);", - " }", - " {", - " JButton button_2 = new JButton();", - " tabbed.addTab('222', button_2);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button_1 = new JButton(); + tabbed.addTab("111", button_1); + } + { + JButton button_2 = new JButton(); + tabbed.addTab("222", button_2); + } + } + }"""); panel.refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button_1 = tabbed.getChildrenComponents().get(0); @@ -913,51 +892,50 @@ public void test_MOVE_2() throws Exception { FlowContainer flowContainer = new FlowContainerFactory(tabbed, false).get().get(0); flowContainer.command_MOVE(button_2, button_1); } - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button_2 = new JButton();", - " tabbed.addTab('222', button_2);", - " }", - " {", - " JButton button_1 = new JButton();", - " tabbed.addTab('111', button_1);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button_2 = new JButton(); + tabbed.addTab("222", button_2); + } + { + JButton button_1 = new JButton(); + tabbed.addTab("111", button_1); + } + } + }"""); // active tab still should be "111" assertSame(button_1, tabbed.getActiveComponent()); } @Test public void test_MOVE_atForward() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " //", - " JButton button_0 = new JButton();", - " tabbed.addTab('000', button_0);", - " tabbed.setToolTipTextAt(0, '000');", - " //", - " JButton button_1 = new JButton();", - " tabbed.addTab('111', button_1);", - " tabbed.setToolTipTextAt(1, '111');", - " //", - " JButton button_2 = new JButton();", - " tabbed.addTab('222', button_2);", - " tabbed.setToolTipTextAt(2, '222');", - " //", - " JButton button_3 = new JButton();", - " tabbed.addTab('333', button_3);", - " tabbed.setToolTipTextAt(3, '333');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + // + JButton button_0 = new JButton(); + tabbed.addTab("000", button_0); + tabbed.setToolTipTextAt(0, "000"); + // + JButton button_1 = new JButton(); + tabbed.addTab("111", button_1); + tabbed.setToolTipTextAt(1, "111"); + // + JButton button_2 = new JButton(); + tabbed.addTab("222", button_2); + tabbed.setToolTipTextAt(2, "222"); + // + JButton button_3 = new JButton(); + tabbed.addTab("333", button_3); + tabbed.setToolTipTextAt(3, "333"); + } + }"""); // prepare source JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button_1 = tabbed.getChildrenComponents().get(1); @@ -969,57 +947,56 @@ public void test_MOVE_atForward() throws Exception { } finally { tabbed.endEdit(); } - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " //", - " JButton button_0 = new JButton();", - " tabbed.addTab('000', button_0);", - " tabbed.setToolTipTextAt(0, '000');", - " //", - " JButton button_2 = new JButton();", - " tabbed.addTab('222', button_2);", - " tabbed.setToolTipTextAt(1, '222');", - " //", - " JButton button_1 = new JButton();", - " tabbed.addTab('111', button_1);", - " tabbed.setToolTipTextAt(2, '111');", - " //", - " JButton button_3 = new JButton();", - " tabbed.addTab('333', button_3);", - " tabbed.setToolTipTextAt(3, '333');", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + // + JButton button_0 = new JButton(); + tabbed.addTab("000", button_0); + tabbed.setToolTipTextAt(0, "000"); + // + JButton button_2 = new JButton(); + tabbed.addTab("222", button_2); + tabbed.setToolTipTextAt(1, "222"); + // + JButton button_1 = new JButton(); + tabbed.addTab("111", button_1); + tabbed.setToolTipTextAt(2, "111"); + // + JButton button_3 = new JButton(); + tabbed.addTab("333", button_3); + tabbed.setToolTipTextAt(3, "333"); + } + }"""); } @Test public void test_MOVE_atBackward() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " //", - " JButton button_0 = new JButton();", - " tabbed.addTab('000', button_0);", - " tabbed.setToolTipTextAt(0, '000');", - " //", - " JButton button_1 = new JButton();", - " tabbed.addTab('111', button_1);", - " tabbed.setToolTipTextAt(1, '111');", - " //", - " JButton button_2 = new JButton();", - " tabbed.addTab('222', button_2);", - " tabbed.setToolTipTextAt(2, '222');", - " //", - " JButton button_3 = new JButton();", - " tabbed.addTab('333', button_3);", - " tabbed.setToolTipTextAt(3, '333');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + // + JButton button_0 = new JButton(); + tabbed.addTab("000", button_0); + tabbed.setToolTipTextAt(0, "000"); + // + JButton button_1 = new JButton(); + tabbed.addTab("111", button_1); + tabbed.setToolTipTextAt(1, "111"); + // + JButton button_2 = new JButton(); + tabbed.addTab("222", button_2); + tabbed.setToolTipTextAt(2, "222"); + // + JButton button_3 = new JButton(); + tabbed.addTab("333", button_3); + tabbed.setToolTipTextAt(3, "333"); + } + }"""); // prepare source JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button_1 = tabbed.getChildrenComponents().get(1); @@ -1031,50 +1008,49 @@ public void test_MOVE_atBackward() throws Exception { } finally { tabbed.endEdit(); } - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " //", - " JButton button_0 = new JButton();", - " tabbed.addTab('000', button_0);", - " tabbed.setToolTipTextAt(0, '000');", - " //", - " JButton button_2 = new JButton();", - " tabbed.addTab('222', button_2);", - " tabbed.setToolTipTextAt(1, '222');", - " //", - " JButton button_1 = new JButton();", - " tabbed.addTab('111', button_1);", - " tabbed.setToolTipTextAt(2, '111');", - " //", - " JButton button_3 = new JButton();", - " tabbed.addTab('333', button_3);", - " tabbed.setToolTipTextAt(3, '333');", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + // + JButton button_0 = new JButton(); + tabbed.addTab("000", button_0); + tabbed.setToolTipTextAt(0, "000"); + // + JButton button_2 = new JButton(); + tabbed.addTab("222", button_2); + tabbed.setToolTipTextAt(1, "222"); + // + JButton button_1 = new JButton(); + tabbed.addTab("111", button_1); + tabbed.setToolTipTextAt(2, "111"); + // + JButton button_3 = new JButton(); + tabbed.addTab("333", button_3); + tabbed.setToolTipTextAt(3, "333"); + } + }"""); } @Test public void test_MOVE_atSeveral() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " //", - " JButton button_0 = new JButton();", - " tabbed.addTab('000', button_0);", - " tabbed.setToolTipTextAt(0, '000');", - " //", - " JButton button_1 = new JButton();", - " tabbed.addTab('111', button_1);", - " tabbed.setToolTipTextAt(1, '111');", - " tabbed.setEnabledAt(1, false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + // + JButton button_0 = new JButton(); + tabbed.addTab("000", button_0); + tabbed.setToolTipTextAt(0, "000"); + // + JButton button_1 = new JButton(); + tabbed.addTab("111", button_1); + tabbed.setToolTipTextAt(1, "111"); + tabbed.setEnabledAt(1, false); + } + }"""); // prepare source JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button_0 = tabbed.getChildrenComponents().get(0); @@ -1086,22 +1062,22 @@ public void test_MOVE_atSeveral() throws Exception { } finally { tabbed.endEdit(); } - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " //", - " JButton button_1 = new JButton();", - " tabbed.addTab('111', button_1);", - " tabbed.setToolTipTextAt(0, '111');", - " tabbed.setEnabledAt(0, false);", - " //", - " JButton button_0 = new JButton();", - " tabbed.addTab('000', button_0);", - " tabbed.setToolTipTextAt(1, '000');", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + // + JButton button_1 = new JButton(); + tabbed.addTab("111", button_1); + tabbed.setToolTipTextAt(0, "111"); + tabbed.setEnabledAt(0, false); + // + JButton button_0 = new JButton(); + tabbed.addTab("000", button_0); + tabbed.setToolTipTextAt(1, "000"); + } + }"""); } /** @@ -1109,34 +1085,33 @@ public void test_MOVE_atSeveral() throws Exception { */ @Test public void test_MOVE_beforeAlreadyNext() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('tab', button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("tab", button); + } + } + }"""); panel.refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = tabbed.getChildrenComponents().get(0); // do move tabbed.command_MOVE(button, null); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('tab', button);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("tab", button); + } + } + }"""); } /** @@ -1144,34 +1119,33 @@ public void test_MOVE_beforeAlreadyNext() throws Exception { */ @Test public void test_MOVE_beforeItself() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('tab', button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("tab", button); + } + } + }"""); panel.refresh(); JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button = tabbed.getChildrenComponents().get(0); // do move tabbed.command_MOVE(button, button); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('tab', button);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("tab", button); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1181,27 +1155,26 @@ public void test_MOVE_beforeItself() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_ADD_beforeExisting() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button_0 = new JButton();", - " tabbed.addTab('000', button_0);", - " tabbed.setToolTipTextAt(0, '000');", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " {", - " JButton button = new JButton();", - " innerPanel.add(button);", - " }", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button_0 = new JButton(); + tabbed.addTab("000", button_0); + tabbed.setToolTipTextAt(0, "000"); + } + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + { + JButton button = new JButton(); + innerPanel.add(button); + } + } + } + }"""); panel.refresh(); JTabbedPaneInfo tabbed = getJavaInfoByName("tabbed"); ComponentInfo button_0 = getJavaInfoByName("button_0"); @@ -1209,89 +1182,87 @@ public void test_ADD_beforeExisting() throws Exception { // ComponentInfo button = getJavaInfoByName("button"); tabbed.command_ADD(button, button_0); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('New tab', null, button, null);", - " }", - " {", - " JButton button_0 = new JButton();", - " tabbed.addTab('000', button_0);", - " tabbed.setToolTipTextAt(1, '000');", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("New tab", null, button, null); + } + { + JButton button_0 = new JButton(); + tabbed.addTab("000", button_0); + tabbed.setToolTipTextAt(1, "000"); + } + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + } + } + }"""); assertSame(button, tabbed.getActiveComponent()); } @Test public void test_ADD_first() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " }", - " {", - " JButton button = new JButton();", - " add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + } + { + JButton button = new JButton(); + add(button); + } + } + }"""); panel.refresh(); JTabbedPaneInfo tabbed = getJavaInfoByName("tabbed"); ComponentInfo button = getJavaInfoByName("button"); // tabbed.command_ADD(button, null); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('New tab', null, button, null);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("New tab", null, button, null); + } + } + } + }"""); assertSame(button, tabbed.getActiveComponent()); } @Test public void test_ADD_tree() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button_0 = new JButton();", - " tabbed.addTab('000', button_0);", - " tabbed.setToolTipTextAt(0, '000');", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " {", - " JButton button = new JButton();", - " innerPanel.add(button);", - " }", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button_0 = new JButton(); + tabbed.addTab("000", button_0); + tabbed.setToolTipTextAt(0, "000"); + } + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + { + JButton button = new JButton(); + innerPanel.add(button); + } + } + } + }"""); panel.refresh(); JTabbedPaneInfo tabbed = getJavaInfoByName("tabbed"); ComponentInfo button_0 = getJavaInfoByName("button_0"); @@ -1302,26 +1273,26 @@ public void test_ADD_tree() throws Exception { FlowContainer flowContainer = new FlowContainerFactory(tabbed, false).get().get(0); flowContainer.command_MOVE(button, button_0); } - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button = new JButton();", - " tabbed.addTab('New tab', null, button, null);", - " }", - " {", - " JButton button_0 = new JButton();", - " tabbed.addTab('000', button_0);", - " tabbed.setToolTipTextAt(1, '000');", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button = new JButton(); + tabbed.addTab("New tab", null, button, null); + } + { + JButton button_0 = new JButton(); + tabbed.addTab("000", button_0); + tabbed.setToolTipTextAt(1, "000"); + } + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + } + } + }"""); assertSame(button, tabbed.getActiveComponent()); } @@ -1335,26 +1306,25 @@ public void test_ADD_tree() throws Exception { */ @Test public void test_selecting() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JTabbedPane tabbed = new JTabbedPane();", - " add(tabbed);", - " {", - " JButton button_0 = new JButton();", - " tabbed.addTab('000', button_0);", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " tabbed.add(innerPanel);", - " {", - " JButton button = new JButton();", - " innerPanel.add(button);", - " }", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JTabbedPane tabbed = new JTabbedPane(); + add(tabbed); + { + JButton button_0 = new JButton(); + tabbed.addTab("000", button_0); + } + { + JPanel innerPanel = new JPanel(); + tabbed.add(innerPanel); + { + JButton button = new JButton(); + innerPanel.add(button); + } + } + } + }"""); // JTabbedPaneInfo tabbed = (JTabbedPaneInfo) panel.getChildrenComponents().get(0); ComponentInfo button_0 = tabbed.getChildrenComponents().get(0); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTableTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTableTest.java index 82d4a37e1a..82d938482a 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTableTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTableTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -57,17 +57,16 @@ public void _test_exit() throws Exception { */ @Test public void test_evaluate_innerTableModel() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable(new MyTableModel());", - " add(table);", - " }", - " private class MyTableModel extends DefaultTableModel {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(new MyTableModel()); + add(table); + } + private class MyTableModel extends DefaultTableModel { + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); JTable tableObject = (JTable) tableInfo.getObject(); @@ -80,28 +79,27 @@ public void test_evaluate_innerTableModel() throws Exception { @Test public void test_evaluate_valuesAndColumns() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " new Object[]{", - " '00', '01', '02'", - " },", - " new Object[]{", - " '10', '11', '12'", - " },", - " },", - " new String[]{", - " 'A', 'B', 'C'", - " }", - " ));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + new Object[]{ + "00", "01", "02" + }, + new Object[]{ + "10", "11", "12" + }, + }, + new String[]{ + "A", "B", "C" + } + )); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); JTable tableObject = (JTable) tableInfo.getObject(); @@ -133,26 +131,25 @@ public void test_evaluate_valuesAndColumns() throws Exception { @Test public void test_evaluate_anonymous_noColumnClass() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " new Object[]{", - " '00', '01', '02'", - " },", - " },", - " new String[]{", - " 'A', 'B', 'C'", - " }", - " ) {", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + new Object[]{ + "00", "01", "02" + }, + }, + new String[]{ + "A", "B", "C" + } + ) { + }); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); JTable tableObject = (JTable) tableInfo.getObject(); @@ -179,32 +176,31 @@ public void test_evaluate_anonymous_noColumnClass() throws Exception { @Test public void test_evaluate_anonymous_withColumnClass() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " new Object[]{", - " 'str', Boolean.TRUE, 'obj', Integer.valueOf(5)", - " },", - " },", - " new String[]{", - " 'A', 'B', 'C', 'D'", - " }", - " ) {", - " Class[] columnTypes = new Class[] {", - " String.class, Boolean.class, Object.class, Integer.class", - " };", - " public Class getColumnClass(int columnIndex) {", - " return columnTypes[columnIndex];", - " }", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + new Object[]{ + "str", Boolean.TRUE, "obj", Integer.valueOf(5) + }, + }, + new String[]{ + "A", "B", "C", "D" + } + ) { + Class[] columnTypes = new Class[] { + String.class, Boolean.class, Object.class, Integer.class + }; + public Class getColumnClass(int columnIndex) { + return columnTypes[columnIndex]; + } + }); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); JTable tableObject = (JTable) tableInfo.getObject(); @@ -239,32 +235,31 @@ public void test_evaluate_anonymous_withColumnClass() throws Exception { @Test public void test_evaluate_anonymous_withColumnEditable() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " new Object[]{", - " '0', '1', '2'", - " },", - " },", - " new String[]{", - " 'A', 'B', 'C'", - " }", - " ) {", - " boolean[] columnEditables = new boolean[] {", - " true, true, false", - " };", - " public boolean isCellEditable(int row, int column) {", - " return columnEditables[column];", - " }", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + new Object[]{ + "0", "1", "2" + }, + }, + new String[]{ + "A", "B", "C" + } + ) { + boolean[] columnEditables = new boolean[] { + true, true, false + }; + public boolean isCellEditable(int row, int column) { + return columnEditables[column]; + } + }); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); JTable tableObject = (JTable) tableInfo.getObject(); @@ -291,26 +286,25 @@ public void test_evaluate_anonymous_withColumnEditable() throws Exception { @Test public void test_evaluate_getColumnModel_invocations() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " new Object[]{", - " '0', '1', '2'", - " },", - " },", - " new String[]{", - " 'A', 'B', 'C'", - " }", - " ));", - " table.getColumnModel().getColumn(0).setPreferredWidth(200);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + new Object[]{ + "0", "1", "2" + }, + }, + new String[]{ + "A", "B", "C" + } + )); + table.getColumnModel().getColumn(0).setPreferredWidth(200); + } + }"""); panel.refresh(); assertNoErrors(panel); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); @@ -328,15 +322,14 @@ public void test_evaluate_getColumnModel_invocations() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_editor_getText_noModel() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); // no model, so no text @@ -349,25 +342,24 @@ public void test_editor_getText_noModel() throws Exception { @Test public void test_editor_getText_someModel() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " {'00', '01', '02'},", - " {'10', '11', '12'},", - " },", - " new String[]{", - " 'A', 'B', 'C'", - " }", - " ) {", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + {"00", "01", "02"}, + {"10", "11", "12"}, + }, + new String[]{ + "A", "B", "C" + } + ) { + }); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); // has model, check text @@ -651,24 +643,23 @@ public Class getColumnClass(int columnIndex) { */ @Test public void test_TableModelDescription_insertColumn() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " {'00', '01'},", - " {'10', '11'},", - " },", - " new String[]{", - " 'A', 'B'", - " }", - " ));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + {"00", "01"}, + {"10", "11"}, + }, + new String[]{ + "A", "B" + } + )); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); // prepare TableModelDescription @@ -698,24 +689,23 @@ public void test_TableModelDescription_insertColumn() throws Exception { */ @Test public void test_TableModelDescription_removeColumn() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " {'00', '01', '02'},", - " {'10', '11', '12'},", - " },", - " new String[]{", - " 'A', 'B', 'C'", - " }", - " ));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + {"00", "01", "02"}, + {"10", "11", "12"}, + }, + new String[]{ + "A", "B", "C" + } + )); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); // prepare TableModelDescription @@ -744,24 +734,23 @@ public void test_TableModelDescription_removeColumn() throws Exception { */ @Test public void test_TableModelDescription_setColumnCount() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " {'00', '01'},", - " {'10', '11'},", - " },", - " new String[]{", - " 'A', 'B'", - " }", - " ));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + {"00", "01"}, + {"10", "11"}, + }, + new String[]{ + "A", "B" + } + )); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); // prepare TableModelDescription @@ -807,24 +796,23 @@ public void test_TableModelDescription_setColumnCount() throws Exception { */ @Test public void test_TableModelDescription_moveColumn() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " {'00', '01', '02', '03'},", - " {'10', '11', '12', '13'},", - " },", - " new String[]{", - " 'A', 'B', 'C', 'D'", - " }", - " ));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + {"00", "01", "02", "03"}, + {"10", "11", "12", "13"}, + }, + new String[]{ + "A", "B", "C", "D" + } + )); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); // prepare TableModelDescription @@ -893,24 +881,23 @@ private static void isNewColumn(TableModelDescription modelDescription, int inde */ @Test public void test_TableModelDescription_setColumnType() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " {'00', Boolean.TRUE},", - " {'10', '11'},", - " },", - " new String[]{", - " 'A', 'B'", - " }", - " ));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + {"00", Boolean.TRUE}, + {"10", "11"}, + }, + new String[]{ + "A", "B" + } + )); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); // prepare TableModelDescription @@ -952,24 +939,23 @@ public Class getColumnClass(int columnIndex) { */ @Test public void test_TableModelDescription_insertRow() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " {'00', '01'},", - " {'10', '11'},", - " },", - " new String[]{", - " 'A', 'B'", - " }", - " ));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + {"00", "01"}, + {"10", "11"}, + }, + new String[]{ + "A", "B" + } + )); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); // prepare TableModelDescription @@ -999,25 +985,24 @@ public void test_TableModelDescription_insertRow() throws Exception { */ @Test public void test_TableModelDescription_removeRow() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " {'00', '01'},", - " {'10', '11'},", - " {'20', '21'},", - " },", - " new String[]{", - " 'A', 'B'", - " }", - " ));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + {"00", "01"}, + {"10", "11"}, + {"20", "21"}, + }, + new String[]{ + "A", "B" + } + )); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); // prepare TableModelDescription @@ -1046,24 +1031,23 @@ public void test_TableModelDescription_removeRow() throws Exception { */ @Test public void test_TableModelDescription_setRowCount() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " {'00', '01'},", - " {'10', '11'},", - " },", - " new String[]{", - " 'A', 'B'", - " }", - " ));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + {"00", "01"}, + {"10", "11"}, + }, + new String[]{ + "A", "B" + } + )); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); // prepare TableModelDescription @@ -1108,26 +1092,25 @@ public void test_TableModelDescription_setRowCount() throws Exception { */ @Test public void test_TableModelDescription_moveRow() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.table.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTable table = new JTable();", - " add(table);", - " table.setModel(new DefaultTableModel(", - " new Object[][]{", - " {'00', '01'},", - " {'10', '11'},", - " {'20', '21'},", - " {'30', '31'},", - " },", - " new String[]{", - " 'A', 'B'", - " }", - " ));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.table.*; + public class Test extends JPanel { + public Test() { + JTable table = new JTable(); + add(table); + table.setModel(new DefaultTableModel( + new Object[][]{ + {"00", "01"}, + {"10", "11"}, + {"20", "21"}, + {"30", "31"}, + }, + new String[]{ + "A", "B" + } + )); + } + }"""); panel.refresh(); JTableInfo tableInfo = (JTableInfo) panel.getChildrenComponents().get(0); // prepare TableModelDescription diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTextFieldTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTextFieldTest.java index 5b100eeb61..414facb4c8 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTextFieldTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTextFieldTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -38,16 +38,16 @@ public class JTextFieldTest extends SwingModelTest { */ @Test public void test_exposedDocument() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JTextField textField = new JTextField();", - " add(textField);", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/add(textField)/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: javax.swing.JTextField} {local-unique: textField} {/new JTextField()/ /add(textField)/}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JTextField textField = new JTextField(); + add(textField); + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/add(textField)/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: javax.swing.JTextField} {local-unique: textField} {/new JTextField()/ /add(textField)/}"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JToolBarTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JToolBarTest.java index abdda36f1b..70cec532de 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JToolBarTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JToolBarTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -61,18 +61,17 @@ public class JToolBarTest extends SwingModelTest { */ @Test public void test_association_Component() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " {", - " JButton button = new JButton();", - " bar.add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + { + JButton button = new JButton(); + bar.add(button); + } + } + }"""); assertNoErrors(panel); JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); panel.refresh(); @@ -87,18 +86,17 @@ public void test_association_Component() throws Exception { */ @Test public void test_orientation_horizontal() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " {", - " JButton button = new JButton();", - " bar.add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + { + JButton button = new JButton(); + bar.add(button); + } + } + }"""); JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); panel.refresh(); assertTrue(bar.isHorizontal()); @@ -109,14 +107,13 @@ public void test_orientation_horizontal() throws Exception { */ @Test public void test_orientation_vertical() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar(SwingConstants.VERTICAL);", - " add(bar);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(SwingConstants.VERTICAL); + add(bar); + } + }"""); JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); panel.refresh(); assertFalse(bar.isHorizontal()); @@ -129,14 +126,13 @@ public void test_orientation_vertical() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_CREATE() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + } + }"""); JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); // add component { @@ -144,17 +140,17 @@ public void test_CREATE() throws Exception { bar.command_CREATE(newComponent, null); assertInstanceOf(InvocationChildAssociation.class, newComponent.getAssociation()); } - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " {", - " JButton button = new JButton();", - " bar.add(button);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + { + JButton button = new JButton(); + bar.add(button); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -164,22 +160,21 @@ public void test_CREATE() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_OUT() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " {", - " JButton button = new JButton();", - " bar.add(button);", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + { + JButton button = new JButton(); + bar.add(button); + } + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + } + } + }"""); // prepare source JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); ComponentInfo button = bar.getChildrenComponents().get(0); @@ -188,62 +183,61 @@ public void test_OUT() throws Exception { FlowLayoutInfo innerLayout = (FlowLayoutInfo) innerPanel.getLayout(); // do move innerLayout.move(button, null); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " {", - " JButton button = new JButton();", - " innerPanel.add(button);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + { + JButton button = new JButton(); + innerPanel.add(button); + } + } + } + }"""); } @Test public void test_MOVE() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " {", - " JButton button = new JButton('000');", - " bar.add(button);", - " }", - " {", - " JButton button = new JButton('111');", - " bar.add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + { + JButton button = new JButton("000"); + bar.add(button); + } + { + JButton button = new JButton("111"); + bar.add(button); + } + } + }"""); // prepare source JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); ComponentInfo button_0 = bar.getChildrenComponents().get(0); ComponentInfo button_1 = bar.getChildrenComponents().get(1); // do move bar.command_MOVE(button_1, button_0); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " {", - " JButton button = new JButton('111');", - " bar.add(button);", - " }", - " {", - " JButton button = new JButton('000');", - " bar.add(button);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + { + JButton button = new JButton("111"); + bar.add(button); + } + { + JButton button = new JButton("000"); + bar.add(button); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -253,42 +247,41 @@ public void test_MOVE() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_ADD() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " {", - " JButton button = new JButton();", - " innerPanel.add(button);", - " }", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + { + JButton button = new JButton(); + innerPanel.add(button); + } + } + } + }"""); JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); ContainerInfo innerPanel = (ContainerInfo) panel.getChildrenComponents().get(1); ComponentInfo button = innerPanel.getChildrenComponents().get(0); // bar.command_MOVE(button, null); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " {", - " JButton button = new JButton();", - " bar.add(button);", - " }", - " {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + { + JButton button = new JButton(); + bar.add(button); + } + { + JPanel innerPanel = new JPanel(); + add(innerPanel); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -302,16 +295,15 @@ public void test_ADD() throws Exception { */ @Test public void test_separator_Supports() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " //", - " bar.addSeparator();", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + // + bar.addSeparator(); + } + }"""); JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); JToolBarSeparatorInfo separator = (JToolBarSeparatorInfo) bar.getChildrenComponents().get(0); // check association @@ -396,15 +388,14 @@ public void test_separator_Supports() throws Exception { */ @Test public void test_addSeparator_noBeanProperties() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " bar.addSeparator(new Dimension(100, 50));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JToolBar bar = new JToolBar(); + add(bar); + bar.addSeparator(new Dimension(100, 50)); + } + }"""); JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); ComponentInfo separator = bar.getChildrenComponents().get(0); // @@ -419,14 +410,13 @@ public void test_addSeparator_noBeanProperties() throws Exception { */ @Test public void test_separator_create() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + } + }"""); JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); // create separator JToolBarSeparatorCreationSupport creationSupport = new JToolBarSeparatorCreationSupport(bar); @@ -448,73 +438,71 @@ public void test_separator_create() throws Exception { assertEquals("bar.addSeparator()", association.getSource()); } // check source - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " bar.addSeparator();", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + bar.addSeparator(); + } + }"""); } @Test public void test_separator_move() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " {", - " JButton button = new JButton();", - " bar.add(button);", - " }", - " bar.addSeparator();", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + { + JButton button = new JButton(); + bar.add(button); + } + bar.addSeparator(); + } + }"""); JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); ComponentInfo button = bar.getChildrenComponents().get(0); JToolBarSeparatorInfo separator = (JToolBarSeparatorInfo) bar.getChildrenComponents().get(1); // move separator bar.command_MOVE(separator, button); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " bar.addSeparator();", - " {", - " JButton button = new JButton();", - " bar.add(button);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + bar.addSeparator(); + { + JButton button = new JButton(); + bar.add(button); + } + } + }"""); } @Test public void test_separator_delete() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " bar.addSeparator();", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + bar.addSeparator(); + } + }"""); JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); JToolBarSeparatorInfo separator = (JToolBarSeparatorInfo) bar.getChildrenComponents().get(0); // delete separator assertTrue(separator.canDelete()); separator.delete(); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JToolBar bar = new JToolBar(); + add(bar); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -526,17 +514,15 @@ public void test_separator_delete() throws Exception { * Create {@link CompilationUnit} with external {@link Action}. */ private void createExternalAction() throws Exception { - setFileContentSrc( - "test/ExternalAction.java", - getTestSource( - "public class ExternalAction extends AbstractAction {", - " public ExternalAction() {", - " putValue(NAME, 'My name');", - " putValue(SHORT_DESCRIPTION, 'My short description');", - " }", - " public void actionPerformed(ActionEvent e) {", - " }", - "}")); + setFileContentSrc("test/ExternalAction.java", getTestSource(""" + public class ExternalAction extends AbstractAction { + public ExternalAction() { + putValue(NAME, "My name"); + putValue(SHORT_DESCRIPTION, "My short description"); + } + public void actionPerformed(ActionEvent e) { + } + }""")); waitForAutoBuild(); } @@ -547,18 +533,17 @@ private void createExternalAction() throws Exception { @Test public void test_addAction_parse() throws Exception { createExternalAction(); - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " private ExternalAction action = new ExternalAction();", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " //", - " JButton button = bar.add(action);", - " button.setEnabled(false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + private ExternalAction action = new ExternalAction(); + Test() { + JToolBar bar = new JToolBar(); + add(bar); + // + JButton button = bar.add(action); + button.setEnabled(false); + } + }"""); JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); // we should have ComponentInfo assertEquals(1, bar.getChildrenComponents().size()); @@ -582,30 +567,29 @@ public void test_addAction_parse() throws Exception { @Test public void test_addAction_generate() throws Exception { createExternalAction(); - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " private ExternalAction action = new ExternalAction();", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + private ExternalAction action = new ExternalAction(); + Test() { + JToolBar bar = new JToolBar(); + add(bar); + } + }"""); JToolBarInfo bar = (JToolBarInfo) panel.getChildrenComponents().get(0); ActionInfo action = ActionContainerInfo.getActions(panel).get(0); // add new JButton using ActionInfo ComponentInfo newButton = bar.command_CREATE(action, null); - assertEditor( - "class Test extends JPanel {", - " private ExternalAction action = new ExternalAction();", - " Test() {", - " JToolBar bar = new JToolBar();", - " add(bar);", - " {", - " JButton button = bar.add(action);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + private ExternalAction action = new ExternalAction(); + Test() { + JToolBar bar = new JToolBar(); + add(bar); + { + JButton button = bar.add(action); + } + } + }"""); // ImplicitFactoryCreationSupport { ImplicitFactoryCreationSupport creationSupport = diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTreeTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTreeTest.java index 5aaeade079..e4b4c3f43b 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTreeTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/JTreeTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -21,7 +21,6 @@ import org.eclipse.wb.internal.swing.model.property.editor.models.tree.TreeModelPropertyEditor; import org.eclipse.wb.tests.designer.swing.SwingModelTest; -import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import javax.swing.JTree; @@ -41,28 +40,27 @@ public class JTreeTest extends SwingModelTest { //////////////////////////////////////////////////////////////////////////// @Test public void test_JTree_parsing() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.tree.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTree tree = new JTree();", - " add(tree);", - " tree.setModel(new DefaultTreeModel(", - " new DefaultMutableTreeNode('(root)') {", - " {", - " DefaultMutableTreeNode node1 = new DefaultMutableTreeNode('1');", - " DefaultMutableTreeNode node2 = new DefaultMutableTreeNode('11');", - " node1.add(node2);", - " add(node1);", - " node1 = new DefaultMutableTreeNode('2');", - " node1.add(new DefaultMutableTreeNode('21'));", - " add(node1);", - " }", - " }", - " ));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.tree.*; + public class Test extends JPanel { + public Test() { + JTree tree = new JTree(); + add(tree); + tree.setModel(new DefaultTreeModel( + new DefaultMutableTreeNode("(root)") { + { + DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1"); + DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("11"); + node1.add(node2); + add(node1); + node1 = new DefaultMutableTreeNode("2"); + node1.add(new DefaultMutableTreeNode("21")); + add(node1); + } + } + )); + } + }"""); panel.refresh(); // ComponentInfo treeInfo = panel.getChildrenComponents().get(0); @@ -114,12 +112,12 @@ public void test_JTree_parsing() throws Exception { // tooltip { String tooltip = getPropertyTooltipText(modelEditor, modelProperty); - assertEquals(StringUtils.join(new String[]{ - "(root)", - " 1", - " 11", - " 2", - " 21"}, "\n"), tooltip); + assertEquals(""" + (root) + 1 + 11 + 2 + 21""", tooltip); // position PropertyTooltipProvider provider = modelEditor.getAdapter(PropertyTooltipProvider.class); assertSame(PropertyTooltipProvider.BELOW, provider.getTooltipPosition()); @@ -132,16 +130,15 @@ public void test_JTree_parsing() throws Exception { */ @Test public void test_emptyModel() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.tree.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTree tree = new JTree();", - " add(tree);", - " tree.setModel(null);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.tree.*; + public class Test extends JPanel { + public Test() { + JTree tree = new JTree(); + add(tree); + tree.setModel(null); + } + }"""); panel.refresh(); // ComponentInfo treeInfo = panel.getChildrenComponents().get(0); @@ -172,15 +169,14 @@ public void test_emptyModel() throws Exception { */ @Test public void test_setItems() throws Exception { - ContainerInfo panel = - parseContainer( - "import javax.swing.tree.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTree tree = new JTree();", - " add(tree);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + import javax.swing.tree.*; + public class Test extends JPanel { + public Test() { + JTree tree = new JTree(); + add(tree); + } + }"""); panel.refresh(); // ComponentInfo treeInfo = panel.getChildrenComponents().get(0); @@ -203,28 +199,28 @@ public void test_setItems() throws Exception { modelProperty, 3, rootItem); - assertEditor( - "import javax.swing.tree.*;", - "public class Test extends JPanel {", - " public Test() {", - " JTree tree = new JTree();", - " tree.setModel(new DefaultTreeModel(", - " new DefaultMutableTreeNode('(root)') {", - " {", - " DefaultMutableTreeNode node_1;", - " node_1 = new DefaultMutableTreeNode('aaa');", - " node_1.add(new DefaultMutableTreeNode('1'));", - " node_1.add(new DefaultMutableTreeNode('2'));", - " add(node_1);", - " node_1 = new DefaultMutableTreeNode('bbb');", - " node_1.add(new DefaultMutableTreeNode('3'));", - " add(node_1);", - " }", - " }", - " ));", - " add(tree);", - " }", - "}"); + assertEditor(""" + import javax.swing.tree.*; + public class Test extends JPanel { + public Test() { + JTree tree = new JTree(); + tree.setModel(new DefaultTreeModel( + new DefaultMutableTreeNode("(root)") { + { + DefaultMutableTreeNode node_1; + node_1 = new DefaultMutableTreeNode("aaa"); + node_1.add(new DefaultMutableTreeNode("1")); + node_1.add(new DefaultMutableTreeNode("2")); + add(node_1); + node_1 = new DefaultMutableTreeNode("bbb"); + node_1.add(new DefaultMutableTreeNode("3")); + add(node_1); + } + } + )); + add(tree); + } + }"""); } //////////////////////////////////////////////////////////////////////////// diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/SomeComponentsTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/SomeComponentsTest.java index bb446c5da0..abd2da90f8 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/SomeComponentsTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/SomeComponentsTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -48,18 +48,14 @@ public void _test_exit() throws Exception { */ @Test public void test_JEditorPane() throws Exception { - ContainerInfo panel = - (ContainerInfo) parseSource( - "test", - "Test.java", - getSourceDQ( - "package test;", - "import javax.swing.*;", - "class Test extends JPanel {", - " Test() {", - " add(new JEditorPane());", - " }", - "}")); + ContainerInfo panel = (ContainerInfo) parseSource("test", "Test.java", """ + package test; + import javax.swing.*; + class Test extends JPanel { + Test() { + add(new JEditorPane()); + } + }"""); ComponentInfo editorPane = panel.getChildrenComponents().get(0); // we have both properties, so String variant uses qualified title assertNotNull(editorPane.getPropertyByTitle("page(java.lang.String)")); @@ -74,21 +70,21 @@ public void test_JEditorPane() throws Exception { */ @Test public void test_Canvas_JScrollPane() throws Exception { - parseJavaInfo( - "import java.awt.Canvas;", - "class Test extends JPanel {", - " public Test() {", - " setLayout(new BorderLayout());", - " {", - " JScrollPane scrollPane = new JScrollPane();", - " add(scrollPane);", - " {", - " Canvas canvas = new Canvas();", - " scrollPane.setRowHeaderView(canvas);", - " }", - " }", - " }", - "}"); + parseJavaInfo(""" + import java.awt.Canvas; + class Test extends JPanel { + public Test() { + setLayout(new BorderLayout()); + { + JScrollPane scrollPane = new JScrollPane(); + add(scrollPane); + { + Canvas canvas = new Canvas(); + scrollPane.setRowHeaderView(canvas); + } + } + } + }"""); refresh(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/SwingLiveManagerTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/SwingLiveManagerTest.java index 31ea9f3176..df354abf15 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/SwingLiveManagerTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/SwingLiveManagerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -58,13 +58,12 @@ public void _test_exit() throws Exception { */ @Test public void test_GlobalState() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); panel.refresh(); // initial "active" assertSame(panel, GlobalState.getActiveObject()); @@ -83,13 +82,12 @@ public void test_GlobalState() throws Exception { */ @Test public void test_create() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); panel.refresh(); // ComponentInfo button_1 = createJButton(); @@ -107,32 +105,27 @@ public void test_create() throws Exception { */ @Test public void test_liveImage_forcedSize() throws Exception { - setFileContentSrc( - "test/MyCanvas.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class MyCanvas extends Canvas {", - "}")); - setFileContentSrc( - "test/MyCanvas.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " 100", - " 50", - " ", - "")); + setFileContentSrc("test/MyCanvas.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class MyCanvas extends Canvas { + }""")); + setFileContentSrc("test/MyCanvas.wbp-component.xml", """ + + + + 100 + 50 + + """); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); panel.refresh(); ComponentInfo newComponent = (ComponentInfo) JavaInfoUtils.createJavaInfo( @@ -154,23 +147,20 @@ public void test_liveImage_forcedSize() throws Exception { */ @Test public void test_whenException() throws Exception { - setFileContentSrc( - "test/MyCanvas.java", - getTestSource( - "public class MyCanvas extends Canvas {", - " public void paint(Graphics g) {", - " throw new IllegalStateException('Problem in constructor');", - " }", - "}")); + setFileContentSrc("test/MyCanvas.java", getTestSource(""" + public class MyCanvas extends Canvas { + public void paint(Graphics g) { + throw new IllegalStateException("Problem in constructor"); + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); panel.refresh(); String originalSource = m_lastEditor.getSource(); // ask "live" first time @@ -252,13 +242,12 @@ public void logging(IStatus status, String plugin) { */ @Test public void test_liveBaseline() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); panel.refresh(); // prepare new JButton ComponentInfo newButton = createJavaInfo("javax.swing.JButton"); @@ -268,16 +257,16 @@ public void test_liveBaseline() throws Exception { assertTrue(liveBaseline > 0); // drop JButton ((FlowLayoutInfo) panel.getLayout()).add(newButton, null); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button = new JButton('New button');", - " add(button);", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + JButton button = new JButton("New button"); + add(button); + } + } + }"""); // same baseline as "live" int baseline = newButton.getBaseline(); assertEquals(baseline, liveBaseline); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JMenuBarTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JMenuBarTest.java index 85540a27b1..1146e23ad3 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JMenuBarTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JMenuBarTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -66,26 +66,25 @@ public void _test_exit() throws Exception { */ @Test public void test_parse() throws Exception { - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JMenuItem item_1 = new JMenuItem('Item 1');", - " menu.add(item_1);", - " }", - " {", - " JMenuItem item_2 = new JMenuItem('Item 2');", - " menu.add(item_2);", - " }", - " }", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JMenuItem item_1 = new JMenuItem("Item 1"); + menu.add(item_1); + } + { + JMenuItem item_2 = new JMenuItem("Item 2"); + menu.add(item_2); + } + } + } + }"""); frameInfo.refresh(); // check components tree JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); @@ -99,14 +98,13 @@ public void test_parse() throws Exception { */ @Test public void test_renderEmpty() throws Exception { - ContainerInfo frame = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " }", - "}"); + ContainerInfo frame = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + } + }"""); frame.refresh(); // check JMenuBar_Info JMenuBarInfo menuBar = frame.getChildren(JMenuBarInfo.class).get(0); @@ -118,14 +116,13 @@ public void test_renderEmpty() throws Exception { */ @Test public void test_standaloneJMenuBar() throws Exception { - JMenuBarInfo barInfo = - (JMenuBarInfo) parseContainer(getDoubleQuotes(new String[]{ - "public class Test extends JMenuBar {", - " public Test() {", - " JMenu menu = new JMenu('Menu');", - " add(menu);", - " }", - "}"})); + JMenuBarInfo barInfo = (JMenuBarInfo) parseContainer(""" + public class Test extends JMenuBar { + public Test() { + JMenu menu = new JMenu("Menu"); + add(menu); + } + }"""); barInfo.refresh(); assertInstanceOf(RootAssociation.class, barInfo.getAssociation()); // IMenuInfo @@ -156,20 +153,19 @@ public void test_standaloneJMenuBar() throws Exception { */ @Test public void test_standaloneJMenuBar_2() throws Exception { - JMenuBarInfo barInfo = - (JMenuBarInfo) parseContainer(getDoubleQuotes(new String[]{ - "public class Test extends JMenuBar {", - " public Test() {", - " {", - " JMenu menu = new JMenu('New menu');", - " add(menu);", - " }", - " {", - " JMenu menu = new JMenu('New menu');", - " add(menu);", - " }", - " }", - "}"})); + JMenuBarInfo barInfo = (JMenuBarInfo) parseContainer(""" + public class Test extends JMenuBar { + public Test() { + { + JMenu menu = new JMenu("New menu"); + add(menu); + } + { + JMenu menu = new JMenu("New menu"); + add(menu); + } + } + }"""); barInfo.refresh(); IMenuInfo menuObject = MenuObjectInfoUtils.getMenuInfo(barInfo); List items = menuObject.getItems(); @@ -195,22 +191,21 @@ public void test_standaloneJMenuBar_2() throws Exception { */ @Test public void test_IMenuInfo_access() throws Exception { - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu_1 = new JMenu('Menu 1');", - " menuBar.add(menu_1);", - " }", - " {", - " JMenu menu_2 = new JMenu('Menu 2');", - " menuBar.add(menu_2);", - " }", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu_1 = new JMenu("Menu 1"); + menuBar.add(menu_1); + } + { + JMenu menu_2 = new JMenu("Menu 2"); + menuBar.add(menu_2); + } + } + }"""); frameInfo.refresh(); ContainerInfo contentPaneInfo = (ContainerInfo) frameInfo.getChildrenComponents().get(0); JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); @@ -253,14 +248,13 @@ public void test_IMenuInfo_access() throws Exception { */ @Test public void test_IMenuInfo_CREATE() throws Exception { - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + } + }"""); frameInfo.refresh(); JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); IMenuInfo menuObject = MenuObjectInfoUtils.getMenuInfo(menuBarInfo); @@ -276,17 +270,17 @@ public void test_IMenuInfo_CREATE() throws Exception { JMenuInfo newMenuInfo = (JMenuInfo) createComponent(JMenu.class); assertTrue(policy.validateCreate(newMenuInfo)); policy.commandCreate(newMenuInfo, null); - assertEditor( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('New menu');", - " menuBar.add(menu);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("New menu"); + menuBar.add(menu); + } + } + }"""); } /** @@ -294,14 +288,13 @@ public void test_IMenuInfo_CREATE() throws Exception { */ @Test public void test_IMenuInfo_CREATE_JButton() throws Exception { - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + } + }"""); frameInfo.refresh(); JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); IMenuInfo menuObject = MenuObjectInfoUtils.getMenuInfo(menuBarInfo); @@ -312,17 +305,17 @@ public void test_IMenuInfo_CREATE_JButton() throws Exception { ComponentInfo newButtonInfo = createJButton(); assertTrue(policy.validateCreate(newButtonInfo)); policy.commandCreate(newButtonInfo, null); - assertEditor( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JButton button = new JButton();", - " menuBar.add(button);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JButton button = new JButton(); + menuBar.add(button); + } + } + }"""); // now we have IMenuItemInfo for JButton { List items = menuObject.getItems(); @@ -346,22 +339,21 @@ public void test_IMenuInfo_CREATE_JButton() throws Exception { */ @Test public void test_IMenuInfo_MOVE() throws Exception { - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu_1 = new JMenu('Menu 1');", - " menuBar.add(menu_1);", - " }", - " {", - " JMenu menu_2 = new JMenu('Menu 2');", - " menuBar.add(menu_2);", - " }", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu_1 = new JMenu("Menu 1"); + menuBar.add(menu_1); + } + { + JMenu menu_2 = new JMenu("Menu 2"); + menuBar.add(menu_2); + } + } + }"""); frameInfo.refresh(); // prepare models JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); @@ -372,21 +364,21 @@ public void test_IMenuInfo_MOVE() throws Exception { // move "menu_2" before "menu_1" assertTrue(policy.validateMove(menuInfo_2)); policy.commandMove(menuInfo_2, menuInfo_1); - assertEditor( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu_2 = new JMenu('Menu 2');", - " menuBar.add(menu_2);", - " }", - " {", - " JMenu menu_1 = new JMenu('Menu 1');", - " menuBar.add(menu_1);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu_2 = new JMenu("Menu 2"); + menuBar.add(menu_2); + } + { + JMenu menu_1 = new JMenu("Menu 1"); + menuBar.add(menu_1); + } + } + }"""); } /** @@ -394,27 +386,26 @@ public void test_IMenuInfo_MOVE() throws Exception { */ @Test public void test_IMenuInfo_PASTE() throws Exception { - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu existingMenu = new JMenu('Some menu');", - " menuBar.add(existingMenu);", - " {", - " JMenuItem item_1 = new JMenuItem('Item 1');", - " existingMenu.add(item_1);", - " item_1.setEnabled(false);", - " }", - " {", - " JMenuItem item_2 = new JMenuItem('Item 2');", - " existingMenu.add(item_2);", - " }", - " }", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu existingMenu = new JMenu("Some menu"); + menuBar.add(existingMenu); + { + JMenuItem item_1 = new JMenuItem("Item 1"); + existingMenu.add(item_1); + item_1.setEnabled(false); + } + { + JMenuItem item_2 = new JMenuItem("Item 2"); + existingMenu.add(item_2); + } + } + } + }"""); frameInfo.refresh(); // prepare models JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); @@ -428,39 +419,39 @@ public void test_IMenuInfo_PASTE() throws Exception { assertTrue(policy.validatePaste(mementos)); policy.commandPaste(mementos, null); } - assertEditor( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu existingMenu = new JMenu('Some menu');", - " menuBar.add(existingMenu);", - " {", - " JMenuItem item_1 = new JMenuItem('Item 1');", - " existingMenu.add(item_1);", - " item_1.setEnabled(false);", - " }", - " {", - " JMenuItem item_2 = new JMenuItem('Item 2');", - " existingMenu.add(item_2);", - " }", - " }", - " {", - " JMenu existingMenu = new JMenu('Some menu');", - " menuBar.add(existingMenu);", - " {", - " JMenuItem item_1 = new JMenuItem('Item 1');", - " item_1.setEnabled(false);", - " existingMenu.add(item_1);", - " }", - " {", - " JMenuItem item_2 = new JMenuItem('Item 2');", - " existingMenu.add(item_2);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu existingMenu = new JMenu("Some menu"); + menuBar.add(existingMenu); + { + JMenuItem item_1 = new JMenuItem("Item 1"); + existingMenu.add(item_1); + item_1.setEnabled(false); + } + { + JMenuItem item_2 = new JMenuItem("Item 2"); + existingMenu.add(item_2); + } + } + { + JMenu existingMenu = new JMenu("Some menu"); + menuBar.add(existingMenu); + { + JMenuItem item_1 = new JMenuItem("Item 1"); + item_1.setEnabled(false); + existingMenu.add(item_1); + } + { + JMenuItem item_2 = new JMenuItem("Item 2"); + existingMenu.add(item_2); + } + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -473,27 +464,26 @@ public void test_IMenuInfo_PASTE() throws Exception { */ @Test public void test_CREATE_noChildren() throws Exception { - ContainerInfo frame = - parseContainer( - "// filler filler filler", - "public class Test extends JFrame {", - " public Test() {", - " }", - "}"); + ContainerInfo frame = parseContainer(""" + // filler filler filler + public class Test extends JFrame { + public Test() { + } + }"""); frame.refresh(); // add new JMenuBar_Info JMenuBarInfo menuBar = (JMenuBarInfo) createComponent(JMenuBar.class); menuBar.command_CREATE(frame); - assertEditor( - "// filler filler filler", - "public class Test extends JFrame {", - " public Test() {", - " {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JFrame { + public Test() { + { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + } + } + }"""); } /** @@ -501,27 +491,26 @@ public void test_CREATE_noChildren() throws Exception { */ @Test public void test_CREATE_withStatement() throws Exception { - ContainerInfo frame = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " setEnabled(false);", - " }", - "}"); + ContainerInfo frame = parseContainer(""" + public class Test extends JFrame { + public Test() { + setEnabled(false); + } + }"""); frame.refresh(); // add new JMenuBar_Info JMenuBarInfo menuBar = (JMenuBarInfo) createComponent(JMenuBar.class); menuBar.command_CREATE(frame); - assertEditor( - "public class Test extends JFrame {", - " public Test() {", - " setEnabled(false);", - " {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JFrame { + public Test() { + setEnabled(false); + { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + } + } + }"""); } /** @@ -529,33 +518,32 @@ public void test_CREATE_withStatement() throws Exception { */ @Test public void test_CREATE_withChildren() throws Exception { - ContainerInfo frame = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " {", - " JButton button = new JButton();", - " getContentPane().add(button);", - " }", - " }", - "}"); + ContainerInfo frame = parseContainer(""" + public class Test extends JFrame { + public Test() { + { + JButton button = new JButton(); + getContentPane().add(button); + } + } + }"""); frame.refresh(); // add new JMenuBar_Info JMenuBarInfo menuBar = (JMenuBarInfo) createComponent(JMenuBar.class); menuBar.command_CREATE(frame); - assertEditor( - "public class Test extends JFrame {", - " public Test() {", - " {", - " JButton button = new JButton();", - " getContentPane().add(button);", - " }", - " {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JFrame { + public Test() { + { + JButton button = new JButton(); + getContentPane().add(button); + } + { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + } + } + }"""); } /** @@ -563,54 +551,51 @@ public void test_CREATE_withChildren() throws Exception { */ @Test public void test_CREATE_exposedItem_badReference() throws Exception { - String[] lines = - { - "public class MyFrame extends JFrame {", - " private JMenuBar menuBar;", - " private JMenu menu;", - " private JMenuItem item;", - " public MyFrame() {", - " setJMenuBar(getMainJMenuBar());", - " }", - " public JMenuBar getMainJMenuBar() {", - " if (menuBar == null) {", - " menuBar = new JMenuBar();", - " menuBar.add(getMenu());", - " }", - " return menuBar;", - " }", - " public JMenu getMenu() {", - " if (menu == null) {", - " menu = new JMenu('New SubMenu');", - " menu.add(getItem());", - " }", - " return menu;", - " }", - " public JMenuItem getItem() {", - " if (item == null) {", - " item = new JMenuItem('New Item');", - " }", - " return item;", - " }", - "}"}; - setFileContentSrc("test/MyFrame.java", getTestSource(lines)); + setFileContentSrc("test/MyFrame.java", getTestSource(""" + public class MyFrame extends JFrame { + private JMenuBar menuBar; + private JMenu menu; + private JMenuItem item; + public MyFrame() { + setJMenuBar(getMainJMenuBar()); + } + public JMenuBar getMainJMenuBar() { + if (menuBar == null) { + menuBar = new JMenuBar(); + menuBar.add(getMenu()); + } + return menuBar; + } + public JMenu getMenu() { + if (menu == null) { + menu = new JMenu("New SubMenu"); + menu.add(getItem()); + } + return menu; + } + public JMenuItem getItem() { + if (item == null) { + item = new JMenuItem("New Item"); + } + return item; + } + }""")); waitForAutoBuild(); // parse - ContainerInfo frame = - parseContainer( - "// filler filler filler", - "public class Test extends MyFrame {", - " public Test() {", - " }", - "}"); + ContainerInfo frame = parseContainer(""" + // filler filler filler + public class Test extends MyFrame { + public Test() { + } + }"""); frame.refresh(); - assertHierarchy( - "{this: test.MyFrame} {this} {}", - " {method: public java.awt.Container javax.swing.JFrame.getContentPane()} {property} {}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}", - " {method: public javax.swing.JMenuBar test.MyFrame.getMainJMenuBar()} {property} {}", - " {method: public javax.swing.JMenu test.MyFrame.getMenu()} {property} {}", - " {method: public javax.swing.JMenuItem test.MyFrame.getItem()} {property} {}"); + assertHierarchy(""" + {this: test.MyFrame} {this} {} + {method: public java.awt.Container javax.swing.JFrame.getContentPane()} {property} {} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {} + {method: public javax.swing.JMenuBar test.MyFrame.getMainJMenuBar()} {property} {} + {method: public javax.swing.JMenu test.MyFrame.getMenu()} {property} {} + {method: public javax.swing.JMenuItem test.MyFrame.getItem()} {property} {}"""); // prepare models JMenuBarInfo menuBarInfo = frame.getChildren(JMenuBarInfo.class).get(0); JMenuInfo menuInfo = menuBarInfo.getChildrenMenus().get(0); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JMenuItemTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JMenuItemTest.java index 57b75aded8..a62c79d21c 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JMenuItemTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JMenuItemTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2023 Google, Inc. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -41,22 +41,21 @@ public class JMenuItemTest extends SwingModelTest { */ @Test public void test_0() throws Exception { - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JMenuItem item = new JMenuItem('Item');", - " menu.add(item);", - " }", - " }", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JMenuItem item = new JMenuItem("Item"); + menu.add(item); + } + } + } + }"""); frameInfo.refresh(); // prepare models JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JMenuTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JMenuTest.java index d46ee44fb5..7ffe0e0797 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JMenuTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JMenuTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2025 Google, Inc. and others. + * Copyright (c) 2011, 2026 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -83,17 +83,17 @@ public void _test_exit() throws Exception { */ @Test public void test_renderEmpty() throws Exception { - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " }", - " }", - "}"); + parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + } + } + }"""); refresh(); // check JMenu_Info JMenuInfo menuInfo = getJavaInfoByName("menu"); @@ -107,17 +107,17 @@ public void test_renderEmpty() throws Exception { */ @Test public void test_disposeImages() throws Exception { - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " }", - " }", - "}"); + parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + } + } + }"""); refresh(); // prepare JMenu_Info JMenuInfo menuInfo = getJavaInfoByName("menu"); @@ -138,16 +138,16 @@ public void test_disposeImages() throws Exception { */ @Test public void test_onContainer() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(new BorderLayout());", - " {", - " JMenu menu = new JMenu('Menu');", - " add(menu);", - " }", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(new BorderLayout()); + { + JMenu menu = new JMenu("Menu"); + add(menu); + } + } + }"""); refresh(); JMenuInfo menu = getJavaInfoByName("menu"); // reasonable bounds @@ -160,19 +160,19 @@ public void test_onContainer() throws Exception { */ @Test public void test_deepHierarchy() throws Exception { - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " JMenu menu_1 = new JMenu('A');", - " JMenu menu_2 = new JMenu('B');", - " JMenu menu_3 = new JMenu('C');", - " setJMenuBar(menuBar);", - " menuBar.add(menu_1);", - " menu_1.add(menu_2);", - " menu_2.add(menu_3);", - " }", - "}"); + parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + JMenu menu_1 = new JMenu("A"); + JMenu menu_2 = new JMenu("B"); + JMenu menu_3 = new JMenu("C"); + setJMenuBar(menuBar); + menuBar.add(menu_1); + menu_1.add(menu_2); + menu_2.add(menu_3); + } + }"""); refresh(); // prepare models JMenuInfo menu_1 = getJavaInfoByName("menu_1"); @@ -195,26 +195,25 @@ public void test_deepHierarchy() throws Exception { */ @Test public void test_IMenuItemInfo_IMenuInfo() throws Exception { - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JMenuItem item_1 = new JMenuItem('Item 1');", - " menu.add(item_1);", - " }", - " {", - " JMenuItem item_2 = new JMenuItem('Item 2');", - " menu.add(item_2);", - " }", - " }", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JMenuItem item_1 = new JMenuItem("Item 1"); + menu.add(item_1); + } + { + JMenuItem item_2 = new JMenuItem("Item 2"); + menu.add(item_2); + } + } + } + }"""); frameInfo.refresh(); // prepare models JMenuInfo menuInfo = getJavaInfoByName("menu"); @@ -259,26 +258,25 @@ public void test_IMenuItemInfo_IMenuInfo() throws Exception { */ @Test public void test_IMenuInfo_withSeparator() throws Exception { - ContainerInfo frameInfo = - parseContainer(getDoubleQuotes(new String[]{ - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JMenuItem item_1 = new JMenuItem('Item 1');", - " menu.add(item_1);", - " }", - " {", - " JSeparator separator = new JSeparator();", - " menu.add(separator);", - " }", - " }", - " }", - "}"})); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JMenuItem item_1 = new JMenuItem("Item 1"); + menu.add(item_1); + } + { + JSeparator separator = new JSeparator(); + menu.add(separator); + } + } + } + }"""); frameInfo.refresh(); // prepare models JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); @@ -335,18 +333,17 @@ public void test_IMenuInfo_withSeparator() throws Exception { */ @Test public void test_IMenuInfo_CREATE_noObject() throws Exception { - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " }", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + } + } + }"""); frameInfo.refresh(); // prepare models JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); @@ -372,18 +369,17 @@ public void test_IMenuInfo_CREATE_noObject() throws Exception { */ @Test public void test_IMenuInfo_CREATE() throws Exception { - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " }", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + } + } + }"""); frameInfo.refresh(); // prepare models JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); @@ -396,21 +392,21 @@ public void test_IMenuInfo_CREATE() throws Exception { JMenuItemInfo newItemInfo = (JMenuItemInfo) createComponent(JMenuItem.class); assertTrue(policy.validateCreate(newItemInfo)); policy.commandCreate(newItemInfo, null); - assertEditor( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JMenuItem menuItem = new JMenuItem('New menu item');", - " menu.add(menuItem);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JMenuItem menuItem = new JMenuItem("New menu item"); + menu.add(menuItem); + } + } + } + }"""); } /** @@ -418,17 +414,17 @@ public void test_IMenuInfo_CREATE() throws Exception { */ @Test public void test_IMenuInfo_CREATE_component() throws Exception { - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " }", - " }", - "}"); + parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + } + } + }"""); refresh(); // prepare models JMenuInfo menuInfo = getJavaInfoByName("menu"); @@ -440,21 +436,21 @@ public void test_IMenuInfo_CREATE_component() throws Exception { ComponentInfo newComponent = createJButton(); assertTrue(policy.validateCreate(newComponent)); policy.commandCreate(newComponent, null); - assertEditor( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JButton button = new JButton();", - " menu.add(button);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JButton button = new JButton(); + menu.add(button); + } + } + } + }"""); } /** @@ -462,26 +458,25 @@ public void test_IMenuInfo_CREATE_component() throws Exception { */ @Test public void test_IMenuInfo_MOVE() throws Exception { - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JMenuItem item_1 = new JMenuItem('Item 1');", - " menu.add(item_1);", - " }", - " {", - " JMenuItem item_2 = new JMenuItem('Item 2');", - " menu.add(item_2);", - " }", - " }", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JMenuItem item_1 = new JMenuItem("Item 1"); + menu.add(item_1); + } + { + JMenuItem item_2 = new JMenuItem("Item 2"); + menu.add(item_2); + } + } + } + }"""); frameInfo.refresh(); // prepare models JMenuInfo menuInfo = getJavaInfoByName("menu"); @@ -503,25 +498,25 @@ public void test_IMenuInfo_MOVE() throws Exception { // move "item_2" before "item_1" assertTrue(policy.validateMove(itemInfo_2)); policy.commandMove(itemInfo_2, itemInfo_1); - assertEditor( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JMenuItem item_2 = new JMenuItem('Item 2');", - " menu.add(item_2);", - " }", - " {", - " JMenuItem item_1 = new JMenuItem('Item 1');", - " menu.add(item_1);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JMenuItem item_2 = new JMenuItem("Item 2"); + menu.add(item_2); + } + { + JMenuItem item_1 = new JMenuItem("Item 1"); + menu.add(item_1); + } + } + } + }"""); } /** @@ -529,22 +524,21 @@ public void test_IMenuInfo_MOVE() throws Exception { */ @Test public void test_IMenuInfo_PASTE() throws Exception { - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JMenuItem existingItem = new JMenuItem('Some item');", - " menu.add(existingItem);", - " }", - " }", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JMenuItem existingItem = new JMenuItem("Some item"); + menu.add(existingItem); + } + } + } + }"""); frameInfo.refresh(); // prepare models JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); @@ -559,25 +553,25 @@ public void test_IMenuInfo_PASTE() throws Exception { assertTrue(policy.validatePaste(mementos)); policy.commandPaste(mementos, null); } - assertEditor( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JMenuItem existingItem = new JMenuItem('Some item');", - " menu.add(existingItem);", - " }", - " {", - " JMenuItem existingItem = new JMenuItem('Some item');", - " menu.add(existingItem);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JMenuItem existingItem = new JMenuItem("Some item"); + menu.add(existingItem); + } + { + JMenuItem existingItem = new JMenuItem("Some item"); + menu.add(existingItem); + } + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -589,17 +583,15 @@ public void test_IMenuInfo_PASTE() throws Exception { * Create {@link CompilationUnit} with external {@link Action}. */ private void createExternalAction() throws Exception { - setFileContentSrc( - "test/ExternalAction.java", - getTestSource( - "public class ExternalAction extends AbstractAction {", - " public ExternalAction() {", - " putValue(NAME, 'My name');", - " putValue(SHORT_DESCRIPTION, 'My short description');", - " }", - " public void actionPerformed(ActionEvent e) {", - " }", - "}")); + setFileContentSrc("test/ExternalAction.java", getTestSource(""" + public class ExternalAction extends AbstractAction { + public ExternalAction() { + putValue(NAME, "My name"); + putValue(SHORT_DESCRIPTION, "My short description"); + } + public void actionPerformed(ActionEvent e) { + } + }""")); waitForAutoBuild(); } @@ -609,22 +601,21 @@ private void createExternalAction() throws Exception { @Test public void test_addAction_parse() throws Exception { createExternalAction(); - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " private ExternalAction action = new ExternalAction();", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JMenuItem menuItem = menu.add(action);", - " }", - " }", - " }", - "}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + private ExternalAction action = new ExternalAction(); + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JMenuItem menuItem = menu.add(action); + } + } + } + }"""); frameInfo.refresh(); // prepare models JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); @@ -648,38 +639,36 @@ public void test_addAction_parse() throws Exception { @Test public void test_IMenuInfo_CREATE_existingAction() throws Exception { createExternalAction(); - String[] lines = - { - "public class Test extends JFrame {", - " private ExternalAction action = new ExternalAction();", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " }", - " }", - "}"}; - ContainerInfo frameInfo = parseContainer(lines); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + private ExternalAction action = new ExternalAction(); + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + } + } + }"""); frameInfo.refresh(); // prepare models ActionInfo action = ActionContainerInfo.getActions(frameInfo).get(0); - test_IMenuInfo_CREATE_forAction(frameInfo, action, new String[]{ - "public class Test extends JFrame {", - " private ExternalAction action = new ExternalAction();", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JMenuItem menuItem = menu.add(action);", - " }", - " }", - " }", - "}"}); + test_IMenuInfo_CREATE_forAction(frameInfo, action, """ + public class Test extends JFrame { + private ExternalAction action = new ExternalAction(); + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JMenuItem menuItem = menu.add(action); + } + } + } + }"""); } /** @@ -688,37 +677,35 @@ public void test_IMenuInfo_CREATE_existingAction() throws Exception { @Test public void test_IMenuInfo_CREATE_newAction() throws Exception { createExternalAction(); - String[] lines = - { - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " }", - " }", - "}"}; - ContainerInfo frameInfo = parseContainer(lines); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + } + } + }"""); frameInfo.refresh(); // prepare models ActionInfo action = createJavaInfo("test.ExternalAction"); - test_IMenuInfo_CREATE_forAction(frameInfo, action, new String[]{ - "public class Test extends JFrame {", - " private final ExternalAction externalAction = new ExternalAction();", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JMenuItem menuItem = menu.add(externalAction);", - " }", - " }", - " }", - "}"}); + test_IMenuInfo_CREATE_forAction(frameInfo, action, """ + public class Test extends JFrame { + private final ExternalAction externalAction = new ExternalAction(); + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JMenuItem menuItem = menu.add(externalAction); + } + } + } + }"""); } /** @@ -727,77 +714,72 @@ public void test_IMenuInfo_CREATE_newAction() throws Exception { @Test public void test_IMenuInfo_CREATE_newAction_lazy() throws Exception { createExternalAction(); - String[] lines1 = - { - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu();", - " menuBar.add(menu);", - " }", - " }", - "}"}; - ContainerInfo frameInfo = parseContainer(lines1); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu(); + menuBar.add(menu); + } + } + }"""); frameInfo.refresh(); // prepare models SwingTestUtils.setGenerations( LazyVariableDescription.INSTANCE, LazyStatementGeneratorDescription.INSTANCE); ActionInfo action = createJavaInfo("test.ExternalAction"); - JMenuItemInfo newItem = - test_IMenuInfo_CREATE_forAction0(frameInfo, action, new String[]{ - "public class Test extends JFrame {", - " private ExternalAction externalAction;", - " private JMenuItem menuItem;", - " private JMenu menu;", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " menu = new JMenu();", - " menuBar.add(menu);", - " getMenuItem();", - " }", - " }", - " private ExternalAction getExternalAction() {", - " if (externalAction == null) {", - " externalAction = new ExternalAction();", - " }", - " return externalAction;", - " }", - " private JMenuItem getMenuItem() {", - " if (menuItem == null) {", - " menuItem = menu.add(getExternalAction());", - " }", - " return menuItem;", - " }", - "}"}); + JMenuItemInfo newItem = test_IMenuInfo_CREATE_forAction0(frameInfo, action, """ + public class Test extends JFrame { + private ExternalAction externalAction; + private JMenuItem menuItem; + private JMenu menu; + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + menu = new JMenu(); + menuBar.add(menu); + getMenuItem(); + } + } + private ExternalAction getExternalAction() { + if (externalAction == null) { + externalAction = new ExternalAction(); + } + return externalAction; + } + private JMenuItem getMenuItem() { + if (menuItem == null) { + menuItem = menu.add(getExternalAction()); + } + return menuItem; + } + }"""); // delete "newItem" assertTrue(newItem.canDelete()); newItem.delete(); - String[] lines = - { - "public class Test extends JFrame {", - " private ExternalAction externalAction;", - " private JMenu menu;", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " menu = new JMenu();", - " menuBar.add(menu);", - " }", - " }", - " private ExternalAction getExternalAction() {", - " if (externalAction == null) {", - " externalAction = new ExternalAction();", - " }", - " return externalAction;", - " }", - "}"}; - assertEditor(lines); + assertEditor(""" + public class Test extends JFrame { + private ExternalAction externalAction; + private JMenu menu; + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + menu = new JMenu(); + menuBar.add(menu); + } + } + private ExternalAction getExternalAction() { + if (externalAction == null) { + externalAction = new ExternalAction(); + } + return externalAction; + } + }"""); } /** @@ -806,87 +788,82 @@ public void test_IMenuInfo_CREATE_newAction_lazy() throws Exception { @Test public void test_IMenuInfo_CREATE_newAction_lazy2() throws Exception { createExternalAction(); - String[] lines1 = - { - "public class Test extends JFrame {", - " private JMenu menu;", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " menuBar.add(getMenu());", - " }", - " private JMenu getMenu() {", - " if (menu == null) {", - " menu = new JMenu();", - " }", - " return menu;", - " }", - "}"}; - ContainerInfo frameInfo = parseContainer(lines1); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + private JMenu menu; + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + menuBar.add(getMenu()); + } + private JMenu getMenu() { + if (menu == null) { + menu = new JMenu(); + } + return menu; + } + }"""); frameInfo.refresh(); // prepare models SwingTestUtils.setGenerations( LazyVariableDescription.INSTANCE, LazyStatementGeneratorDescription.INSTANCE); ActionInfo action = createJavaInfo("test.ExternalAction"); - JMenuItemInfo newItem = - test_IMenuInfo_CREATE_forAction0(frameInfo, action, new String[]{ - "public class Test extends JFrame {", - " private JMenu menu;", - " private ExternalAction externalAction;", - " private JMenuItem menuItem;", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " menuBar.add(getMenu());", - " }", - " private JMenu getMenu() {", - " if (menu == null) {", - " menu = new JMenu();", - " getMenuItem();", - " }", - " return menu;", - " }", - " private ExternalAction getExternalAction() {", - " if (externalAction == null) {", - " externalAction = new ExternalAction();", - " }", - " return externalAction;", - " }", - " private JMenuItem getMenuItem() {", - " if (menuItem == null) {", - " menuItem = getMenu().add(getExternalAction());", - " }", - " return menuItem;", - " }", - "}"}); + JMenuItemInfo newItem = test_IMenuInfo_CREATE_forAction0(frameInfo, action, """ + public class Test extends JFrame { + private JMenu menu; + private ExternalAction externalAction; + private JMenuItem menuItem; + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + menuBar.add(getMenu()); + } + private JMenu getMenu() { + if (menu == null) { + menu = new JMenu(); + getMenuItem(); + } + return menu; + } + private ExternalAction getExternalAction() { + if (externalAction == null) { + externalAction = new ExternalAction(); + } + return externalAction; + } + private JMenuItem getMenuItem() { + if (menuItem == null) { + menuItem = getMenu().add(getExternalAction()); + } + return menuItem; + } + }"""); // delete "newItem" assertTrue(newItem.canDelete()); newItem.delete(); - String[] lines = - { - "public class Test extends JFrame {", - " private JMenu menu;", - " private ExternalAction externalAction;", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " menuBar.add(getMenu());", - " }", - " private JMenu getMenu() {", - " if (menu == null) {", - " menu = new JMenu();", - " }", - " return menu;", - " }", - " private ExternalAction getExternalAction() {", - " if (externalAction == null) {", - " externalAction = new ExternalAction();", - " }", - " return externalAction;", - " }", - "}"}; - assertEditor(lines); + assertEditor(""" + public class Test extends JFrame { + private JMenu menu; + private ExternalAction externalAction; + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + menuBar.add(getMenu()); + } + private JMenu getMenu() { + if (menu == null) { + menu = new JMenu(); + } + return menu; + } + private ExternalAction getExternalAction() { + if (externalAction == null) { + externalAction = new ExternalAction(); + } + return externalAction; + } + }"""); } /** @@ -895,40 +872,39 @@ public void test_IMenuInfo_CREATE_newAction_lazy2() throws Exception { @Test public void test_IMenuInfo_CREATE_newAction_lazy3() throws Exception { createExternalAction(); - ContainerInfo frameInfo = - parseContainer( - "public class Test extends JFrame {", - " private JMenu menu;", - " private final ExternalAction externalAction = new ExternalAction();", - " private JMenuItem menuItem;", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " menuBar.add(getMenu());", - " }", - " private JMenu getMenu() {", - " if (menu == null) {", - " menu = new JMenu('Menu');", - " getMenuItem();", - " }", - " return menu;", - " }", - " private JMenuItem getMenuItem() {", - " if (menuItem == null) {", - " menuItem = getMenu().add(externalAction);", - " }", - " return menuItem;", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JFrame} {this} {/setJMenuBar(menuBar)/}", - " {method: public java.awt.Container javax.swing.JFrame.getContentPane()} {property} {}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}", - " {new: javax.swing.JMenuBar} {local-unique: menuBar} {/new JMenuBar()/ /setJMenuBar(menuBar)/ /menuBar.add(getMenu())/}", - " {new: javax.swing.JMenu} {lazy: menu getMenu()} {/new JMenu('Menu')/ /getMenu().add(externalAction)/ /menu/ /menuBar.add(getMenu())/}", - " {implicit-factory} {lazy: menuItem getMenuItem()} {/getMenu().add(externalAction)/ /menuItem/ /getMenuItem()/}", - " {org.eclipse.wb.internal.swing.model.bean.ActionContainerInfo}", - " {new: test.ExternalAction} {field-initializer: externalAction} {/new ExternalAction()/ /getMenu().add(externalAction)/}"); + ContainerInfo frameInfo = parseContainer(""" + public class Test extends JFrame { + private JMenu menu; + private final ExternalAction externalAction = new ExternalAction(); + private JMenuItem menuItem; + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + menuBar.add(getMenu()); + } + private JMenu getMenu() { + if (menu == null) { + menu = new JMenu("Menu"); + getMenuItem(); + } + return menu; + } + private JMenuItem getMenuItem() { + if (menuItem == null) { + menuItem = getMenu().add(externalAction); + } + return menuItem; + } + }"""); + assertHierarchy(""" + {this: javax.swing.JFrame} {this} {/setJMenuBar(menuBar)/} + {method: public java.awt.Container javax.swing.JFrame.getContentPane()} {property} {} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {} + {new: javax.swing.JMenuBar} {local-unique: menuBar} {/new JMenuBar()/ /setJMenuBar(menuBar)/ /menuBar.add(getMenu())/} + {new: javax.swing.JMenu} {lazy: menu getMenu()} {/new JMenu("Menu")/ /getMenu().add(externalAction)/ /menu/ /menuBar.add(getMenu())/} + {implicit-factory} {lazy: menuItem getMenuItem()} {/getMenu().add(externalAction)/ /menuItem/ /getMenuItem()/} + {org.eclipse.wb.internal.swing.model.bean.ActionContainerInfo} + {new: test.ExternalAction} {field-initializer: externalAction} {/new ExternalAction()/ /getMenu().add(externalAction)/}"""); frameInfo.refresh(); // prepare models JMenuItemInfo item; @@ -940,27 +916,27 @@ public void test_IMenuInfo_CREATE_newAction_lazy3() throws Exception { // delete "item" assertTrue(item.canDelete()); item.delete(); - assertEditor( - "public class Test extends JFrame {", - " private JMenu menu;", - " private final ExternalAction externalAction = new ExternalAction();", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " menuBar.add(getMenu());", - " }", - " private JMenu getMenu() {", - " if (menu == null) {", - " menu = new JMenu('Menu');", - " }", - " return menu;", - " }", - "}"); + assertEditor(""" + public class Test extends JFrame { + private JMenu menu; + private final ExternalAction externalAction = new ExternalAction(); + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + menuBar.add(getMenu()); + } + private JMenu getMenu() { + if (menu == null) { + menu = new JMenu("Menu"); + } + return menu; + } + }"""); } private void test_IMenuInfo_CREATE_forAction(ContainerInfo frameInfo, ActionInfo action, - String[] expectedLines) throws Exception { + String expectedLines) throws Exception { JMenuItemInfo itemInfo = test_IMenuInfo_CREATE_forAction0(frameInfo, action, expectedLines); // check new JMenuItem_Info { @@ -976,7 +952,7 @@ private void test_IMenuInfo_CREATE_forAction(ContainerInfo frameInfo, private JMenuItemInfo test_IMenuInfo_CREATE_forAction0(ContainerInfo frameInfo, ActionInfo action, - String[] expectedLines) throws Exception { + String expectedLines) throws Exception { JMenuBarInfo menuBarInfo = frameInfo.getChildren(JMenuBarInfo.class).get(0); JMenuInfo menuInfo = menuBarInfo.getChildrenMenus().get(0); IMenuInfo menuObject = MenuObjectInfoUtils.getMenuInfo(menuInfo); @@ -1001,25 +977,25 @@ private JMenuItemInfo test_IMenuInfo_CREATE_forAction0(ContainerInfo frameInfo, */ @Test public void test_separatorParse_addSeparator() throws Exception { - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " menu.addSeparator();", - " }", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JFrame} {this} {/setJMenuBar(menuBar)/}", - " {method: public java.awt.Container javax.swing.JFrame.getContentPane()} {property} {}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}", - " {new: javax.swing.JMenuBar} {local-unique: menuBar} {/new JMenuBar()/ /setJMenuBar(menuBar)/ /menuBar.add(menu)/}", - " {new: javax.swing.JMenu} {local-unique: menu} {/new JMenu('Menu')/ /menuBar.add(menu)/ /menu.addSeparator()/}", - " {void} {void} {/menu.addSeparator()/}"); + parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + menu.addSeparator(); + } + } + }"""); + assertHierarchy(""" + {this: javax.swing.JFrame} {this} {/setJMenuBar(menuBar)/} + {method: public java.awt.Container javax.swing.JFrame.getContentPane()} {property} {} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {} + {new: javax.swing.JMenuBar} {local-unique: menuBar} {/new JMenuBar()/ /setJMenuBar(menuBar)/ /menuBar.add(menu)/} + {new: javax.swing.JMenu} {local-unique: menu} {/new JMenu("Menu")/ /menuBar.add(menu)/ /menu.addSeparator()/} + {void} {void} {/menu.addSeparator()/}"""); refresh(); // prepare models JMenuInfo menu = getJavaInfoByName("menu"); @@ -1053,28 +1029,28 @@ public void test_separatorParse_addSeparator() throws Exception { */ @Test public void test_separatorParse_newSeparator() throws Exception { - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " {", - " JPopupMenu.Separator separator = new JPopupMenu.Separator();", - " menu.add(separator);", - " }", - " }", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JFrame} {this} {/setJMenuBar(menuBar)/}", - " {method: public java.awt.Container javax.swing.JFrame.getContentPane()} {property} {}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}", - " {new: javax.swing.JMenuBar} {local-unique: menuBar} {/new JMenuBar()/ /setJMenuBar(menuBar)/ /menuBar.add(menu)/}", - " {new: javax.swing.JMenu} {local-unique: menu} {/new JMenu('Menu')/ /menuBar.add(menu)/ /menu.add(separator)/}", - " {new: javax.swing.JPopupMenu$Separator} {local-unique: separator} {/new JPopupMenu.Separator()/ /menu.add(separator)/}"); + parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + { + JPopupMenu.Separator separator = new JPopupMenu.Separator(); + menu.add(separator); + } + } + } + }"""); + assertHierarchy(""" + {this: javax.swing.JFrame} {this} {/setJMenuBar(menuBar)/} + {method: public java.awt.Container javax.swing.JFrame.getContentPane()} {property} {} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {} + {new: javax.swing.JMenuBar} {local-unique: menuBar} {/new JMenuBar()/ /setJMenuBar(menuBar)/ /menuBar.add(menu)/} + {new: javax.swing.JMenu} {local-unique: menu} {/new JMenu("Menu")/ /menuBar.add(menu)/ /menu.add(separator)/} + {new: javax.swing.JPopupMenu$Separator} {local-unique: separator} {/new JPopupMenu.Separator()/ /menu.add(separator)/}"""); refresh(); } @@ -1083,17 +1059,17 @@ public void test_separatorParse_newSeparator() throws Exception { */ @Test public void test_separator_CREATE() throws Exception { - parseContainer( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " }", - " }", - "}"); + parseContainer(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + } + } + }"""); refresh(); // prepare models JMenuInfo menuInfo = getJavaInfoByName("menu"); @@ -1112,18 +1088,18 @@ public void test_separator_CREATE() throws Exception { // do add assertTrue(policy.validateCreate(separator)); policy.commandCreate(separator, null); - assertEditor( - "public class Test extends JFrame {", - " public Test() {", - " JMenuBar menuBar = new JMenuBar();", - " setJMenuBar(menuBar);", - " {", - " JMenu menu = new JMenu('Menu');", - " menuBar.add(menu);", - " menu.addSeparator();", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JFrame { + public Test() { + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + { + JMenu menu = new JMenu("Menu"); + menuBar.add(menu); + menu.addSeparator(); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1137,43 +1113,40 @@ public void test_separator_CREATE() throws Exception { */ @Test public void test_visualInheritance() throws Exception { - createModelType( - "test", - "MyFrame.java", - getTestSource( - "public class MyFrame extends JFrame {", - " private final JMenuBar m_menuBar = new JMenuBar();", - " private final JMenu m_menu = new JMenu();", - " private final JMenuItem m_menuItem = new JMenuItem();", - " public MyFrame() {", - " setJMenuBar(m_menuBar);", - " m_menuBar.add(m_menu);", - " m_menu.add(m_menuItem);", - " }", - " public JMenuBar getMyMenuBar() {", - " return m_menuBar;", - " }", - " public JMenu getMyMenu() {", - " return m_menu;", - " }", - " public JMenuItem getMyMenuItem() {", - " return m_menuItem;", - " }", - "}")); + createModelType("test", "MyFrame.java", getTestSource(""" + public class MyFrame extends JFrame { + private final JMenuBar m_menuBar = new JMenuBar(); + private final JMenu m_menu = new JMenu(); + private final JMenuItem m_menuItem = new JMenuItem(); + public MyFrame() { + setJMenuBar(m_menuBar); + m_menuBar.add(m_menu); + m_menu.add(m_menuItem); + } + public JMenuBar getMyMenuBar() { + return m_menuBar; + } + public JMenu getMyMenu() { + return m_menu; + } + public JMenuItem getMyMenuItem() { + return m_menuItem; + } + }""")); waitForAutoBuild(); // parse - parseContainer( - "// filler filler filler", - "public class Test extends MyFrame {", - " public Test() {", - " }", - "}"); - assertHierarchy( - "{this: test.MyFrame} {this} {}", - " {method: public java.awt.Container javax.swing.JFrame.getContentPane()} {property} {}", - " {implicit-layout: java.awt.BorderLayout} {implicit-layout} {}", - " {method: public javax.swing.JMenuBar test.MyFrame.getMyMenuBar()} {property} {}", - " {method: public javax.swing.JMenu test.MyFrame.getMyMenu()} {property} {}", - " {method: public javax.swing.JMenuItem test.MyFrame.getMyMenuItem()} {property} {}"); + parseContainer(""" + // filler filler filler + public class Test extends MyFrame { + public Test() { + } + }"""); + assertHierarchy(""" + {this: test.MyFrame} {this} {} + {method: public java.awt.Container javax.swing.JFrame.getContentPane()} {property} {} + {implicit-layout: java.awt.BorderLayout} {implicit-layout} {} + {method: public javax.swing.JMenuBar test.MyFrame.getMyMenuBar()} {property} {} + {method: public javax.swing.JMenu test.MyFrame.getMyMenu()} {property} {} + {method: public javax.swing.JMenuItem test.MyFrame.getMyMenuItem()} {property} {}"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JPopupMenuTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JPopupMenuTest.java index 1fc9b0498a..10b6b60815 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JPopupMenuTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/menu/JPopupMenuTest.java @@ -68,24 +68,23 @@ public void _test_exit() throws Exception { */ @Test public void test_parse() throws Exception { - ContainerInfo panelInfo = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(this, popup);", - " {", - " JMenuItem item_1 = new JMenuItem('Item 1');", - " popup.add(item_1);", - " }", - " {", - " JMenuItem item_2 = new JMenuItem('Item 2');", - " popup.add(item_2);", - " }", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); + ContainerInfo panelInfo = parseContainer(""" + public class Test extends JPanel { + public Test() { + JPopupMenu popup = new JPopupMenu(); + addPopup(this, popup); + { + JMenuItem item_1 = new JMenuItem("Item 1"); + popup.add(item_1); + } + { + JMenuItem item_2 = new JMenuItem("Item 2"); + popup.add(item_2); + } + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); panelInfo.refresh(); // prepare JPopupMenu_Info JPopupMenuInfo popupInfo = panelInfo.getChildren(JPopupMenuInfo.class).get(0); @@ -135,16 +134,15 @@ public void test_parse() throws Exception { */ @Test public void test_noItems() throws Exception { - ContainerInfo panelInfo = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(this, popup);", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); + ContainerInfo panelInfo = parseContainer(""" + public class Test extends JPanel { + public Test() { + JPopupMenu popup = new JPopupMenu(); + addPopup(this, popup); + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); panelInfo.refresh(); // do checks JPopupMenuInfo popupInfo = panelInfo.getChildren(JPopupMenuInfo.class).get(0); @@ -163,24 +161,23 @@ public void test_noItems() throws Exception { */ @Test public void test_IMenuInfo_withSeparator() throws Exception { - ContainerInfo panelInfo = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(this, popup);", - " {", - " JMenuItem item_1 = new JMenuItem('Item 1');", - " popup.add(item_1);", - " }", - " {", - " JSeparator separator = new JSeparator();", - " popup.add(separator);", - " }", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); + ContainerInfo panelInfo = parseContainer(""" + public class Test extends JPanel { + public Test() { + JPopupMenu popup = new JPopupMenu(); + addPopup(this, popup); + { + JMenuItem item_1 = new JMenuItem("Item 1"); + popup.add(item_1); + } + { + JSeparator separator = new JSeparator(); + popup.add(separator); + } + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); panelInfo.refresh(); // prepare models JPopupMenuInfo popupInfo = panelInfo.getChildren(JPopupMenuInfo.class).get(0); @@ -231,13 +228,12 @@ public void test_IMenuInfo_withSeparator() throws Exception { */ @Test public void test_CREATE() throws Exception { - ContainerInfo panelInfo = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panelInfo = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); panelInfo.refresh(); // add new JPopupMenu JPopupMenuInfo popupInfo = (JPopupMenuInfo) createComponent(JPopupMenu.class); @@ -246,33 +242,33 @@ public void test_CREATE() throws Exception { JPopupMenuAssociation association = (JPopupMenuAssociation) popupInfo.getAssociation(); assertEquals("addPopup(this, popupMenu)", association.getSource()); } - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " JPopupMenu popupMenu = new JPopupMenu();", - " addPopup(this, popupMenu);", - " }", - " }", - " private static void addPopup(Component component, final JPopupMenu popup) {", - " component.addMouseListener(new MouseAdapter() {", - " public void mousePressed(MouseEvent e) {", - " if (e.isPopupTrigger()) {", - " showMenu(e);", - " }", - " }", - " public void mouseReleased(MouseEvent e) {", - " if (e.isPopupTrigger()) {", - " showMenu(e);", - " }", - " }", - " private void showMenu(MouseEvent e) {", - " popup.show(e.getComponent(), e.getX(), e.getY());", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + JPopupMenu popupMenu = new JPopupMenu(); + addPopup(this, popupMenu); + } + } + private static void addPopup(Component component, final JPopupMenu popup) { + component.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + if (e.isPopupTrigger()) { + showMenu(e); + } + } + public void mouseReleased(MouseEvent e) { + if (e.isPopupTrigger()) { + showMenu(e); + } + } + private void showMenu(MouseEvent e) { + popup.show(e.getComponent(), e.getX(), e.getY()); + } + }); + } + }"""); } /** @@ -280,25 +276,24 @@ public void test_CREATE() throws Exception { */ @Test public void test_MOVE() throws Exception { - ContainerInfo panelInfo = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button_1 = new JButton();", - " add(button_1);", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(button_1, popup);", - " popup.add(new JMenuItem());", - " }", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " }", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); + ContainerInfo panelInfo = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + JButton button_1 = new JButton(); + add(button_1); + JPopupMenu popup = new JPopupMenu(); + addPopup(button_1, popup); + popup.add(new JMenuItem()); + } + { + JButton button_2 = new JButton(); + add(button_2); + } + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); panelInfo.refresh(); // prepare components ComponentInfo buttonInfo_1 = panelInfo.getChildrenComponents().get(0); @@ -306,24 +301,24 @@ public void test_MOVE() throws Exception { JPopupMenuInfo popupInfo = buttonInfo_1.getChildren(JPopupMenuInfo.class).get(0); // move JPopupMenu_Info popupInfo.command_MOVE(buttonInfo_2); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button_1 = new JButton();", - " add(button_1);", - " }", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(button_2, popup);", - " popup.add(new JMenuItem());", - " }", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + { + JButton button_1 = new JButton(); + add(button_1); + } + { + JButton button_2 = new JButton(); + add(button_2); + JPopupMenu popup = new JPopupMenu(); + addPopup(button_2, popup); + popup.add(new JMenuItem()); + } + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); } /** @@ -331,35 +326,34 @@ public void test_MOVE() throws Exception { */ @Test public void test_MOVE_toTheContainer() throws Exception { - ContainerInfo panelInfo = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JPopupMenu popupMenu = new JPopupMenu();", - " addPopup(this, popupMenu);", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); + ContainerInfo panelInfo = parseContainer(""" + public class Test extends JPanel { + public Test() { + JPopupMenu popupMenu = new JPopupMenu(); + addPopup(this, popupMenu); + JPanel innerPanel = new JPanel(); + add(innerPanel); + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); panelInfo.refresh(); // prepare components JPopupMenuInfo popupInfo = getJavaInfoByName("popupMenu"); ComponentInfo innerPanel = getJavaInfoByName("innerPanel"); // move JPopupMenu_Info popupInfo.command_MOVE(innerPanel); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " JPanel innerPanel = new JPanel();", - " add(innerPanel);", - " JPopupMenu popupMenu = new JPopupMenu();", - " addPopup(innerPanel, popupMenu);", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + JPanel innerPanel = new JPanel(); + add(innerPanel); + JPopupMenu popupMenu = new JPopupMenu(); + addPopup(innerPanel, popupMenu); + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); } /** @@ -367,27 +361,26 @@ public void test_MOVE_toTheContainer() throws Exception { */ @Test public void test_PASTE() throws Exception { - ContainerInfo panelInfo = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button_1 = new JButton();", - " add(button_1);", - " {", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(button_1, popup);", - " popup.add(new JMenuItem('Some item'));", - " }", - " }", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " }", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); + ContainerInfo panelInfo = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + JButton button_1 = new JButton(); + add(button_1); + { + JPopupMenu popup = new JPopupMenu(); + addPopup(button_1, popup); + popup.add(new JMenuItem("Some item")); + } + } + { + JButton button_2 = new JButton(); + add(button_2); + } + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); panelInfo.refresh(); // prepare components ComponentInfo buttonInfo_1 = panelInfo.getChildrenComponents().get(0); @@ -400,34 +393,34 @@ public void test_PASTE() throws Exception { popupCopyInfo.command_CREATE(buttonInfo_2); memento.apply(); } - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button_1 = new JButton();", - " add(button_1);", - " {", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(button_1, popup);", - " popup.add(new JMenuItem('Some item'));", - " }", - " }", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " {", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(button_2, popup);", - " {", - " JMenuItem menuItem = new JMenuItem('Some item');", - " popup.add(menuItem);", - " }", - " }", - " }", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + { + JButton button_1 = new JButton(); + add(button_1); + { + JPopupMenu popup = new JPopupMenu(); + addPopup(button_1, popup); + popup.add(new JMenuItem("Some item")); + } + } + { + JButton button_2 = new JButton(); + add(button_2); + { + JPopupMenu popup = new JPopupMenu(); + addPopup(button_2, popup); + { + JMenuItem menuItem = new JMenuItem("Some item"); + popup.add(menuItem); + } + } + } + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); } /** @@ -435,16 +428,15 @@ public void test_PASTE() throws Exception { */ @Test public void test_hasTrackingListener() throws Exception { - ContainerInfo panelInfo = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(this, popup);", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); + ContainerInfo panelInfo = parseContainer(""" + public class Test extends JPanel { + public Test() { + JPopupMenu popup = new JPopupMenu(); + addPopup(this, popup); + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); panelInfo.refresh(); MouseListener[] mouseListeners = panelInfo.getComponent().getMouseListeners(); Assertions.assertThat(mouseListeners).isNotEmpty(); @@ -460,23 +452,23 @@ public void test_hasTrackingListener() throws Exception { */ @Test public void test_separator_addSeparator() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(this, popup);", - " {", - " popup.addSeparator();", - " }", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/addPopup(this, popup)/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: javax.swing.JPopupMenu} {local-unique: popup} {/new JPopupMenu()/ /addPopup(this, popup)/ /popup.addSeparator()/}", - " {void} {void} {/popup.addSeparator()/}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JPopupMenu popup = new JPopupMenu(); + addPopup(this, popup); + { + popup.addSeparator(); + } + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/addPopup(this, popup)/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: javax.swing.JPopupMenu} {local-unique: popup} {/new JPopupMenu()/ /addPopup(this, popup)/ /popup.addSeparator()/} + {void} {void} {/popup.addSeparator()/}"""); JPopupMenuInfo popup = getJavaInfoByName("popup"); JPopupMenuSeparatorInfo separator = popup.getChildren(JPopupMenuSeparatorInfo.class).get(0); // check VoidInvocationVariableSupport @@ -506,24 +498,24 @@ public void test_separator_addSeparator() throws Exception { */ @Test public void test_separator_newSeparator() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(this, popup);", - " {", - " JPopupMenu.Separator separator = new JPopupMenu.Separator();", - " popup.add(separator);", - " }", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/addPopup(this, popup)/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: javax.swing.JPopupMenu} {local-unique: popup} {/new JPopupMenu()/ /addPopup(this, popup)/ /popup.add(separator)/}", - " {new: javax.swing.JPopupMenu$Separator} {local-unique: separator} {/new JPopupMenu.Separator()/ /popup.add(separator)/}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JPopupMenu popup = new JPopupMenu(); + addPopup(this, popup); + { + JPopupMenu.Separator separator = new JPopupMenu.Separator(); + popup.add(separator); + } + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/addPopup(this, popup)/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: javax.swing.JPopupMenu} {local-unique: popup} {/new JPopupMenu()/ /addPopup(this, popup)/ /popup.add(separator)/} + {new: javax.swing.JPopupMenu$Separator} {local-unique: separator} {/new JPopupMenu.Separator()/ /popup.add(separator)/}"""); } /** @@ -531,15 +523,15 @@ public void test_separator_newSeparator() throws Exception { */ @Test public void test_separator_create_addSeparator() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(this, popup);", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JPopupMenu popup = new JPopupMenu(); + addPopup(this, popup); + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); JPopupMenuInfo popup = getJavaInfoByName("popup"); // create separator JPopupMenuSeparatorCreationSupport creationSupport = @@ -562,15 +554,15 @@ public void test_separator_create_addSeparator() throws Exception { assertEquals("popup.addSeparator()", association.getSource()); } // check source - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " JPopupMenu popup = new JPopupMenu();", - " addPopup(this, popup);", - " popup.addSeparator();", - " }", - " private static void addPopup(Component component, JPopupMenu popup) {", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + JPopupMenu popup = new JPopupMenu(); + addPopup(this, popup); + popup.addSeparator(); + } + private static void addPopup(Component component, JPopupMenu popup) { + } + }"""); } } From 3a50b70f3ef55533bec8841cf0f96bacd8ca24a5 Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Sat, 18 Apr 2026 21:39:58 +0200 Subject: [PATCH 2/2] Reactivate ComponentTest.test_zeroSize() This test was disabled with 2f300b9729c1245867a56f24effd41e67ceb2eea because the frame might not be at the expected location. Given that this test is only about the size of the component and not the type, we can use a JPanel instead, which is guaranteed to always be at (0,0). --- .../tests/designer/swing/model/component/ComponentTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/ComponentTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/ComponentTest.java index f6b21a9970..21551eb63c 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/ComponentTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/component/ComponentTest.java @@ -31,7 +31,6 @@ import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.RGB; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.awt.Component; @@ -85,13 +84,11 @@ public Test() { /** * We can not create {@link java.awt.Image} with zero size, so we should check this. */ - @Disabled @Test public void test_zeroSize() throws Exception { ContainerInfo panel = parseContainer(""" - public class Test extends Frame { + public class Test extends JPanel { public Test() { - setUndecorated(true); setSize(0, 0); } }""");