From b4973800b960351c9e823b02f6d1f5e0785e7cf5 Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Mon, 18 May 2026 20:04:49 +0200 Subject: [PATCH] Migrate property tests to text blocks --- .../ConstructorCreationSupportTest.java | 144 +- .../ComponentDescriptionIbmTest.java | 28 +- .../core/model/parser/ExecuteOnParseTest.java | 30 +- .../core/model/parser/SwingParserTest.java | 46 +- .../property/ComponentClassPropertyTest.java | 28 +- .../model/property/EventsPropertyTest.java | 3837 ++++++++--------- .../property/ExposePropertySupportTest.java | 371 +- .../PropertyCategoryProvidersTest.java | 28 +- .../model/property/PropertyManagerTest.java | 28 +- .../core/model/property/PropertyTest.java | 696 ++- .../property/StandardConvertersTest.java | 162 +- .../model/property/TabOrderPropertyTest.java | 76 +- .../property/accessor/AccessorUtilsTest.java | 173 +- .../accessor/ConstructorAccessorTest.java | 146 +- .../accessor/FactoryAccessorTest.java | 104 +- .../property/accessor/FieldAccessorTest.java | 373 +- ...nvocationChildAssociationAccessorTest.java | 126 +- .../MethodInvocationAccessorTest.java | 156 +- .../MethodInvocationArgumentAccessorTest.java | 183 +- .../property/accessor/SetterAccessorTest.java | 365 +- .../SuperConstructorAccessorTest.java | 104 +- .../AbstractTextPropertyEditorTest.java | 14 +- .../BooleanObjectPropertyEditorTest.java | 185 +- .../editor/BooleanPropertyEditorTest.java | 142 +- .../editor/ByteObjectPropertyEditorTest.java | 147 +- .../ConstantSelectionPropertyEditorTest.java | 285 +- .../editor/DatePropertyEditorTest.java | 206 +- .../DisplayExpressionPropertyEditorTest.java | 66 +- .../DoubleObjectPropertyEditorTest.java | 147 +- .../editor/EnumPropertyEditorTest.java | 137 +- .../EnumerationValuesPropertyEditorTest.java | 76 +- .../ExpressionListPropertyEditorTest.java | 19 +- .../editor/InnerClassPropertyEditorTest.java | 361 +- .../InstanceObjectPropertyEditorTest.java | 204 +- .../IntegerArrayPropertyEditorTest.java | 120 +- .../IntegerObjectPropertyEditorTest.java | 147 +- .../editor/IntegerPropertyEditorTest.java | 120 +- .../editor/LocalePropertyEditorTest.java | 49 +- .../editor/LongObjectPropertyEditorTest.java | 147 +- .../editor/ObjectPropertyEditorTest.java | 637 ++- .../editor/ShortObjectPropertyEditorTest.java | 147 +- .../editor/StaticFieldPropertyEditorTest.java | 38 +- .../editor/StringListPropertyEditorTest.java | 69 +- .../editor/StringsAddPropertyTest.java | 142 +- .../editor/StylePropertyEditorLongTest.java | 230 +- .../editor/StylePropertyEditorTest.java | 231 +- .../core/model/util/JavaInfoUtilsTest.java | 26 +- .../core/model/util/MethodOrderTest.java | 184 +- .../model/util/StackContainerSupportTest.java | 20 +- .../tests/designer/swing/SwingModelTest.java | 6 +- 50 files changed, 5483 insertions(+), 6023 deletions(-) diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/creation/ConstructorCreationSupportTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/creation/ConstructorCreationSupportTest.java index bcac2974e2..8980d553d2 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/creation/ConstructorCreationSupportTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/creation/ConstructorCreationSupportTest.java @@ -771,20 +771,20 @@ public void run(ComponentInfo copy) throws Exception { */ @Test public void test_getSource_forCreationId() throws Exception { - setJavaContentSrc("test", "MyButton", new String[]{ - "public class MyButton extends JButton {", - " public MyButton(boolean b) {", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "MyButton", """ + public class MyButton extends JButton { + public MyButton(boolean b) { + } + }""", """ + + + + + + + + + """); String[] lines = {"public class Test extends JPanel {", " public Test() {", " }", "}"}; // parse parseContainer(lines); @@ -809,11 +809,11 @@ public void test_getSource_forCreationId() throws Exception { */ @Test public void test_getSource_forSource() throws Exception { - setJavaContentSrc("test", "MyButton", new String[]{ - "public class MyButton extends JButton {", - " public MyButton(boolean b) {", - " }", - "}"}, null); + setJavaContentSrc("test", "MyButton", """ + public class MyButton extends JButton { + public MyButton(boolean b) { + } + }""", null); String[] lines = {"public class Test extends JPanel {", " public Test() {", " }", "}"}; // parse parseContainer(lines); @@ -827,18 +827,18 @@ public void test_getSource_forSource() throws Exception { @Test public void test_CREATE_noInvocations() throws Exception { - setJavaContentSrc("test", "MyButton", new String[]{ - "public class MyButton extends JButton {", - " public MyButton() {", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "MyButton", """ + public class MyButton extends JButton { + public MyButton() { + } + }""", """ + + + + + + + """); String[] lines1 = {"public class Test extends JPanel {", " public Test() {", " }", "}"}; // parse ContainerInfo panel = parseContainer(lines1); @@ -879,18 +879,18 @@ public void test_CREATE_noInvocations() throws Exception { @Test public void test_CREATE_addInvocations() throws Exception { - setJavaContentSrc("test", "MyButton", new String[]{ - "public class MyButton extends JButton {", - " public MyButton() {", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "MyButton", """ + public class MyButton extends JButton { + public MyButton() { + } + }""", """ + + + + + + + """); String[] lines1 = {"public class Test extends JPanel {", " public Test() {", " }", "}"}; // parse ContainerInfo panel = parseContainer(lines1); @@ -918,19 +918,19 @@ public void test_CREATE_addInvocations() throws Exception { @Test public void test_template_index() throws Exception { - setJavaContentSrc("test", "MyButton", new String[]{ - "public class MyButton extends JButton {", - " public MyButton(String value) {", - " }", - " public void setValue(String value) {", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "MyButton", """ + public class MyButton extends JButton { + public MyButton(String value) { + } + public void setValue(String value) { + } + }""", """ + + + + + + """); String[] lines1 = {"public class Test extends JPanel {", " public Test() {", " }", "}"}; // parse ContainerInfo panel = parseContainer(lines1); @@ -1020,22 +1020,22 @@ public void test_getAssociation_noParent() throws Exception { */ @Test public void test_getAssociation_hasParent() throws Exception { - setJavaContentSrc("test", "MyButton", new String[]{ - "public class MyButton extends JButton {", - " public MyButton(JPanel parent) {", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "MyButton", """ + public class MyButton extends JButton { + public MyButton(JPanel parent) { + } + }""", """ + + + + + + + + + + + """); String[] lines = {"public class Test extends JPanel {", " public Test() {", " }", "}"}; // parse parseContainer(lines); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/description/ComponentDescriptionIbmTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/description/ComponentDescriptionIbmTest.java index 911577c6cd..b43c36332d 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/description/ComponentDescriptionIbmTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/description/ComponentDescriptionIbmTest.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 @@ -108,19 +108,19 @@ public static void tearDownClass() throws Exception { // //////////////////////////////////////////////////////////////////////////// private ContainerInfo createDefaultProjectContents() throws Exception { - setJavaContentSrc("test", "TestPanel", new String[]{ - "public class TestPanel extends JPanel {", - " public TestPanel(){", - " }", - " protected void setTestProperty(int value){", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "TestPanel", """ + public class TestPanel extends JPanel { + public TestPanel(){ + } + protected void setTestProperty(int value){ + } + }""", """ + + + + + + """); return parseContainer( "// filler filler filler", "public class Test extends TestPanel {", diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/parser/ExecuteOnParseTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/parser/ExecuteOnParseTest.java index 453438673c..e9d8e25d50 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/parser/ExecuteOnParseTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/parser/ExecuteOnParseTest.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 @@ -2685,20 +2685,20 @@ public void test_dontVisit_AnonymouseClassDeclaration() throws Exception { */ @Test public void test_createAssociateAndInvokeMethod() throws Exception { - setJavaContentSrc("test", "MyButton", new String[]{ - "public class MyButton extends JButton {", - " public MyButton(Container container) {", - " container.add(this);", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "MyButton", """ + public class MyButton extends JButton { + public MyButton(Container container) { + container.add(this); + } + }""", """ + + + + + + + + """); // parse ContainerInfo panel = parseContainer( diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/parser/SwingParserTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/parser/SwingParserTest.java index 3cc39e5440..9e5b32c7bc 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/parser/SwingParserTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/parser/SwingParserTest.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 @@ -1378,17 +1378,17 @@ public void test_AbstractButton_setModel_null() throws Exception { */ @Test public void test_preferredRoot_singlePreferred() throws Exception { - setJavaContentSrc("test", "MyPanel", new String[]{ - "public class MyPanel extends JPanel {", - " public MyPanel() {", - " }", - "}"}, new String[]{ - "", - "", - " ", - " true", - " ", - ""}); + setJavaContentSrc("test", "MyPanel", """ + public class MyPanel extends JPanel { + public MyPanel() { + } + }""", """ + + + + true + + """); // standard JPanel has bigger hierarchy, so without "parser.preferredRoot" is would be selected parseContainer( "public class Test {", @@ -1411,17 +1411,17 @@ public void test_preferredRoot_singlePreferred() throws Exception { */ @Test public void test_preferredRoot_twoPreferred() throws Exception { - setJavaContentSrc("test", "MyPanel", new String[]{ - "public class MyPanel extends JPanel {", - " public MyPanel() {", - " }", - "}"}, new String[]{ - "", - "", - " ", - " true", - " ", - ""}); + setJavaContentSrc("test", "MyPanel", """ + public class MyPanel extends JPanel { + public MyPanel() { + } + }""", """ + + + + true + + """); parseContainer( "public class Test {", " public static void main(String[] args) {", diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/ComponentClassPropertyTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/ComponentClassPropertyTest.java index ff51e744a6..780ee7236f 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/ComponentClassPropertyTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/ComponentClassPropertyTest.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,25 +39,23 @@ public class ComponentClassPropertyTest extends SwingModelTest { */ @Test public void test_noForNullClass() 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); + } + }"""); assertNull(panel.getLayout().getPropertyByTitle("Class")); } @Test public void test_property() 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() { + } + }"""); // property ComponentClassProperty property = (ComponentClassProperty) panel.getPropertyByTitle("Class"); assertNotNull(property); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/EventsPropertyTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/EventsPropertyTest.java index 606f5dfc00..649fe5b03c 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/EventsPropertyTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/EventsPropertyTest.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 @@ -126,13 +126,12 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_noListeners() 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() { + } + }"""); EventsProperty eventsProperty = (EventsProperty) panel.getPropertyByTitle("Events"); assertFalse(eventsProperty.isModified()); assertSame(Property.UNKNOWN_VALUE, eventsProperty.getValue()); @@ -141,20 +140,19 @@ public void test_noListeners() throws Exception { @Test public void test_hasListener() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyPressed(KeyEvent e) {", - " System.out.println('keyPressed!');", - " }", - " public void keyReleased(KeyEvent e) {", - " System.out.println('keyReleased!');", - " }", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + System.out.println("keyPressed!"); + } + public void keyReleased(KeyEvent e) { + System.out.println("keyReleased!"); + } + }); + } + }"""); EventsProperty eventsProperty = (EventsProperty) panel.getPropertyByTitle("Events"); assertNotNull(eventsProperty); assertTrue(eventsProperty.isModified()); @@ -189,17 +187,16 @@ public void test_hasListener() throws Exception { @Test public void test_listenerInVariable() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " KeyListener listener = new KeyAdapter() {", - " public void keyPressed(KeyEvent e) {", - " }", - " };", - " addKeyListener(listener);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + KeyListener listener = new KeyAdapter() { + public void keyPressed(KeyEvent e) { + } + }; + addKeyListener(listener); + } + }"""); Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); assertNotNull(keyPressedProperty); assertTrue(keyPressedProperty.isModified()); @@ -207,21 +204,20 @@ public void test_listenerInVariable() throws Exception { @Test public void test_listenerInnerType() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " private class KeyHandler extends KeyAdapter {", - " public void keyPressed(KeyEvent e) {", - " System.out.println('keyPressed!');", - " }", - " public void keyReleased(KeyEvent e) {", - " System.out.println('keyReleased!');", - " }", - " }", - " Test() {", - " addKeyListener(new KeyHandler());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + private class KeyHandler extends KeyAdapter { + public void keyPressed(KeyEvent e) { + System.out.println("keyPressed!"); + } + public void keyReleased(KeyEvent e) { + System.out.println("keyReleased!"); + } + } + Test() { + addKeyListener(new KeyHandler()); + } + }"""); EventsProperty eventsProperty = (EventsProperty) panel.getPropertyByTitle("Events"); assertEquals("[key]", getPropertyText(eventsProperty)); // @@ -236,30 +232,31 @@ public void test_listenerInnerType() throws Exception { */ @Test public void test_qualifeidListenerNames() throws Exception { - setFileContentSrc( - "test/Listener_1.java", - getSourceDQ("package test;", "public interface Listener_1 {", " void foo();", "}")); - setFileContentSrc( - "test/Listener_2.java", - getSourceDQ("package test;", "public interface Listener_2 {", " void bar();", "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyListener(Listener_1 listener) {", - " }", - " public void addMyListener(Listener_2 listener) {", - " }", - "}")); + setFileContentSrc("test/Listener_1.java", """ + package test; + public interface Listener_1 { + void foo(); + }"""); + setFileContentSrc("test/Listener_2.java", """ + package test; + public interface Listener_2 { + void bar(); + }"""); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyListener(Listener_1 listener) { + } + public void addMyListener(Listener_2 listener) { + } + }""")); waitForAutoBuild(); // - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // Listener_1.foo() { Property property = getEventsListenerMethod(panel, "my(test.Listener_1)", "foo"); @@ -283,22 +280,21 @@ public void test_qualifeidListenerNames() throws Exception { */ @Test public void test_listenerThis_1() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel implements KeyListener {", - " Test() {", - " addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " System.out.println('keyPressed!');", - " }", - " public void keyReleased(KeyEvent e) {", - " System.out.println('keyReleased!');", - " }", - " public void keyTyped(KeyEvent e) {", - " System.out.println('keyTyped!');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel implements KeyListener { + Test() { + addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + System.out.println("keyPressed!"); + } + public void keyReleased(KeyEvent e) { + System.out.println("keyReleased!"); + } + public void keyTyped(KeyEvent e) { + System.out.println("keyTyped!"); + } + }"""); EventsProperty eventsProperty = (EventsProperty) panel.getPropertyByTitle("Events"); assertEquals("[key]", getPropertyText(eventsProperty)); // @@ -313,32 +309,31 @@ public void test_listenerThis_1() throws Exception { */ @Test public void test_listenerThis_2() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel implements KeyListener {", - " private final JButton m_button = new JButton();", - " Test() {", - " add(m_button);", - " addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " // valid routing IfStatement", - " if (e.getSource() == this) {", - " onThis_keyPressed(e);", - " }", - " }", - " public void keyReleased(KeyEvent e) {", - " if (e.getSource() == m_button) {", - " // do nothing, we need this only to show EventsProperty", - " // that here we have routing to stubs", - " }", - " }", - " public void keyTyped(KeyEvent e) {", - " // no any statement, so no stubs routing, so is handler", - " }", - " private void onThis_keyPressed(KeyEvent e) {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel implements KeyListener { + private final JButton m_button = new JButton(); + Test() { + add(m_button); + addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + // valid routing IfStatement + if (e.getSource() == this) { + onThis_keyPressed(e); + } + } + public void keyReleased(KeyEvent e) { + if (e.getSource() == m_button) { + // do nothing, we need this only to show EventsProperty + // that here we have routing to stubs + } + } + public void keyTyped(KeyEvent e) { + // no any statement, so no stubs routing, so is handler + } + private void onThis_keyPressed(KeyEvent e) { + } + }"""); EventsProperty eventsProperty = (EventsProperty) panel.getPropertyByTitle("Events"); assertEquals("[key]", getPropertyText(eventsProperty)); // @@ -352,34 +347,33 @@ public void test_listenerThis_2() throws Exception { */ @Test public void test_listenerThis_3() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel implements KeyListener {", - " private final JButton m_button = new JButton();", - " Test() {", - " add(m_button);", - " addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " // valid routing IfStatement, single Statement (not Block) as 'then'", - " if (e.getSource() == this)", - " onThis_keyPressed(e);", - " }", - " public void keyReleased(KeyEvent e) {", - " if (e.getSource() == m_button) {", - " // do nothing, we need this only to show EventsProperty", - " // that here we have routing to stubs", - " }", - " }", - " public void keyTyped(KeyEvent e) {", - " if (e.getSource() == m_button) {", - " // do nothing, we need this only to show EventsProperty", - " // that here we have routing to stubs", - " }", - " }", - " private void onThis_keyPressed(KeyEvent e) {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel implements KeyListener { + private final JButton m_button = new JButton(); + Test() { + add(m_button); + addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + // valid routing IfStatement, single Statement (not Block) as "then" + if (e.getSource() == this) + onThis_keyPressed(e); + } + public void keyReleased(KeyEvent e) { + if (e.getSource() == m_button) { + // do nothing, we need this only to show EventsProperty + // that here we have routing to stubs + } + } + public void keyTyped(KeyEvent e) { + if (e.getSource() == m_button) { + // do nothing, we need this only to show EventsProperty + // that here we have routing to stubs + } + } + private void onThis_keyPressed(KeyEvent e) { + } + }"""); EventsProperty eventsProperty = (EventsProperty) panel.getPropertyByTitle("Events"); assertEquals("[key]", getPropertyText(eventsProperty)); // @@ -396,29 +390,28 @@ public void test_listenerThis_3() throws Exception { */ @Test public void test_listenerAndExecutionFlow() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel implements KeyListener {", - " private JButton m_button;", - " Test() {", - " m_button = new JButton();", - " add(m_button);", - " m_button.addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " if (e.getSource() == m_button) {", - " onButton_keyPressed(e);", - " }", - " }", - " public void keyReleased(KeyEvent e) {", - " // no any statement, so no stubs routing, so is handler", - " }", - " public void keyTyped(KeyEvent e) {", - " // no any statement, so no stubs routing, so is handler", - " }", - " private void onButton_keyPressed(KeyEvent e) {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel implements KeyListener { + private JButton m_button; + Test() { + m_button = new JButton(); + add(m_button); + m_button.addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + if (e.getSource() == m_button) { + onButton_keyPressed(e); + } + } + public void keyReleased(KeyEvent e) { + // no any statement, so no stubs routing, so is handler + } + public void keyTyped(KeyEvent e) { + // no any statement, so no stubs routing, so is handler + } + private void onButton_keyPressed(KeyEvent e) { + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); EventsProperty eventsProperty = (EventsProperty) button.getPropertyByTitle("Events"); assertEquals("[key]", getPropertyText(eventsProperty)); @@ -453,62 +446,59 @@ public void accept(SWTBot bot) { @Test public void test_delete_method_noListener() 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() { + } + }"""); // do delete, no GUI expected Property keyReleasedProperty = getEventsListenerMethod(panel, "key", "released"); keyReleasedProperty.setValue(Property.UNKNOWN_VALUE); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); } @Test public void test_delete_method_noMethod() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); // do delete, no GUI expected Property keyReleasedProperty = getEventsListenerMethod(panel, "key", "released"); keyReleasedProperty.setValue(Property.UNKNOWN_VALUE); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); } @Test public void test_delete_method_Cancel() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); final Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); String expectedSource = m_lastEditor.getSource(); // press "Cancel", so don't delete @@ -530,79 +520,76 @@ public void accept(SWTBot bot) { @Test public void test_delete_method() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); // Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); deleteEventPropertyWithGUI(keyPressedProperty); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); } @Test public void test_delete_methodWithStub() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyPressed(KeyEvent e) {", - " do_keyPressed(e);", - " }", - " });", - " }", - " public void do_keyPressed(KeyEvent e) {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + do_keyPressed(e); + } + }); + } + public void do_keyPressed(KeyEvent e) { + } + }"""); // Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); deleteEventPropertyWithGUI(keyPressedProperty); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); } @Test public void test_delete_listener() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyPressed(KeyEvent e) {", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + } + public void keyReleased(KeyEvent e) { + } + }); + } + }"""); // Property keyProperty = getEventsListener(panel, "key"); deleteEventPropertyWithGUI(keyProperty); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); assertEquals(m_lastEditor.getSource(), m_lastEditor.getModelUnit().getSource()); } @@ -613,56 +600,54 @@ public void test_delete_listener() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_deleteInner_method() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new MyKeyListener());", - " }", - " private class MyKeyListener extends KeyAdapter {", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + addKeyListener(new MyKeyListener()); + } + private class MyKeyListener extends KeyAdapter { + public void keyPressed(KeyEvent e) { + } + } + }"""); // prepare property Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); assertTrue(keyPressedProperty.isModified()); // do delete deleteEventPropertyWithGUI(keyPressedProperty); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); } @Test public void test_deleteInner_listener() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new MyKeyListener());", - " }", - " private class MyKeyListener extends KeyAdapter {", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + addKeyListener(new MyKeyListener()); + } + private class MyKeyListener extends KeyAdapter { + public void keyPressed(KeyEvent e) { + } + } + }"""); // prepare property Property keyProperty = getEventsListener(panel, "key"); assertTrue(keyProperty.isModified()); // do delete deleteEventPropertyWithGUI(keyProperty); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); } /** @@ -671,30 +656,29 @@ public void test_deleteInner_listener() throws Exception { */ @Test public void test_deleteInner_componentWithListener() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " add(button);", - " button.addKeyListener(new MyKeyListener());", - " }", - " private class MyKeyListener extends KeyAdapter {", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + add(button); + button.addKeyListener(new MyKeyListener()); + } + private class MyKeyListener extends KeyAdapter { + public void keyPressed(KeyEvent e) { + } + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); // do delete "button" button.delete(); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); } /** @@ -702,36 +686,35 @@ public void test_deleteInner_componentWithListener() throws Exception { */ @Test public void test_deleteComponent_andOtherListeners() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button_1 = new JButton();", - " add(button_1);", - " button_1.addKeyListener(new KeyAdapter() {});", - " }", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " button_2.addKeyListener(new KeyAdapter() {});", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + JButton button_1 = new JButton(); + add(button_1); + button_1.addKeyListener(new KeyAdapter() {}); + } + { + JButton button_2 = new JButton(); + add(button_2); + button_2.addKeyListener(new KeyAdapter() {}); + } + } + }"""); panel.refresh(); ComponentInfo button_1 = panel.getChildrenComponents().get(0); // do delete "button" button_1.delete(); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " button_2.addKeyListener(new KeyAdapter() {});", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + { + JButton button_2 = new JButton(); + add(button_2); + button_2.addKeyListener(new KeyAdapter() {}); + } + } + }"""); } /** @@ -740,137 +723,137 @@ public void test_deleteComponent_andOtherListeners() throws Exception { */ @Test public void test_deleteInner_listener_twoUsages_deleteJavaInfo() throws Exception { - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button = new JButton();", - " add(button);", - " button.addKeyListener(new MyKeyListener());", - " }", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " button_2.addKeyListener(new MyKeyListener());", - " }", - " }", - " private class MyKeyListener extends KeyAdapter {", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - "}"); + parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + JButton button = new JButton(); + add(button); + button.addKeyListener(new MyKeyListener()); + } + { + JButton button_2 = new JButton(); + add(button_2); + button_2.addKeyListener(new MyKeyListener()); + } + } + private class MyKeyListener extends KeyAdapter { + public void keyPressed(KeyEvent e) { + } + } + }"""); JavaInfo button = getJavaInfoByName("button"); // do delete button.delete(); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " button_2.addKeyListener(new MyKeyListener());", - " }", - " }", - " private class MyKeyListener extends KeyAdapter {", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + JButton button_2 = new JButton(); + add(button_2); + button_2.addKeyListener(new MyKeyListener()); + } + } + private class MyKeyListener extends KeyAdapter { + public void keyPressed(KeyEvent e) { + } + } + }"""); } @Test public void test_deleteInner_listener_twoUsages_keepOne() throws Exception { - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button = new JButton();", - " add(button);", - " button.addKeyListener(new MyKeyListener());", - " }", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " button_2.addKeyListener(new MyKeyListener());", - " }", - " }", - " private class MyKeyListener extends KeyAdapter {", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - "}"); + parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + JButton button = new JButton(); + add(button); + button.addKeyListener(new MyKeyListener()); + } + { + JButton button_2 = new JButton(); + add(button_2); + button_2.addKeyListener(new MyKeyListener()); + } + } + private class MyKeyListener extends KeyAdapter { + public void keyPressed(KeyEvent e) { + } + } + }"""); JavaInfo button = getJavaInfoByName("button"); // prepare property Property keyProperty = getEventsListener(button, "key"); assertTrue(keyProperty.isModified()); // do delete deleteInnerListener_twoUsages(keyProperty, "&No"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button = new JButton();", - " add(button);", - " }", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " button_2.addKeyListener(new MyKeyListener());", - " }", - " }", - " private class MyKeyListener extends KeyAdapter {", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + JButton button = new JButton(); + add(button); + } + { + JButton button_2 = new JButton(); + add(button_2); + button_2.addKeyListener(new MyKeyListener()); + } + } + private class MyKeyListener extends KeyAdapter { + public void keyPressed(KeyEvent e) { + } + } + }"""); } @Test public void test_deleteInner_listener_twoUsages_removeAll() throws Exception { - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button = new JButton();", - " add(button);", - " button.addKeyListener(new MyKeyListener());", - " }", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " button_2.addKeyListener(new MyKeyListener());", - " }", - " }", - " private class MyKeyListener extends KeyAdapter {", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - "}"); + parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + JButton button = new JButton(); + add(button); + button.addKeyListener(new MyKeyListener()); + } + { + JButton button_2 = new JButton(); + add(button_2); + button_2.addKeyListener(new MyKeyListener()); + } + } + private class MyKeyListener extends KeyAdapter { + public void keyPressed(KeyEvent e) { + } + } + }"""); JavaInfo button = getJavaInfoByName("button"); // prepare property Property keyProperty = getEventsListener(button, "key"); assertTrue(keyProperty.isModified()); // do delete deleteInnerListener_twoUsages(keyProperty, "&Yes"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button = new JButton();", - " add(button);", - " }", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + JButton button = new JButton(); + add(button); + } + { + JButton button_2 = new JButton(); + add(button_2); + } + } + }"""); } private static void deleteInnerListener_twoUsages(final Property property, @@ -901,42 +884,41 @@ public void accept(SWTBot bot) { */ @Test public void test_deleteThis_listener() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel implements KeyListener {", - " private final JButton m_button = new JButton();", - " Test() {", - " add(m_button);", - " m_button.addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " // valid routing IfStatement", - " if (e.getSource() == m_button) {", - " onButton_keyPressed(e);", - " }", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " public void keyTyped(KeyEvent e) {", - " }", - " private void onButton_keyPressed(KeyEvent e) {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel implements KeyListener { + private final JButton m_button = new JButton(); + Test() { + add(m_button); + m_button.addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + // valid routing IfStatement + if (e.getSource() == m_button) { + onButton_keyPressed(e); + } + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } + private void onButton_keyPressed(KeyEvent e) { + } + }"""); panel.refresh(); // delete "button" ComponentInfo button = panel.getChildrenComponents().get(0); button.delete(); - assertEditor( - "class Test extends JPanel implements KeyListener {", - " Test() {", - " }", - " public void keyPressed(KeyEvent e) {", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " public void keyTyped(KeyEvent e) {", - " }", - "}"); + assertEditor(""" + class Test extends JPanel implements KeyListener { + Test() { + } + public void keyPressed(KeyEvent e) { + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -949,37 +931,36 @@ public void test_deleteThis_listener() throws Exception { */ @Test public void test_delete_method_interfaceWithDirectStub() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel implements KeyListener {", - " Test() {", - " addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " onThis_keyPressed(e);", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " public void keyTyped(KeyEvent e) {", - " }", - " private void onThis_keyPressed(KeyEvent e) {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel implements KeyListener { + Test() { + addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + onThis_keyPressed(e); + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } + private void onThis_keyPressed(KeyEvent e) { + } + }"""); // do delete, no GUI expected Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); keyPressedProperty.setValue(Property.UNKNOWN_VALUE); - assertEditor( - "class Test extends JPanel implements KeyListener {", - " Test() {", - " addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " public void keyTyped(KeyEvent e) {", - " }", - "}"); + assertEditor(""" + class Test extends JPanel implements KeyListener { + Test() { + addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } + }"""); } /** @@ -987,39 +968,38 @@ public void test_delete_method_interfaceWithDirectStub() throws Exception { */ @Test public void test_delete_method_interfaceWithConditionalStub_block() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel implements KeyListener {", - " Test() {", - " addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " if (e.getSource() == this) {", - " onThis_keyPressed(e);", - " }", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " public void keyTyped(KeyEvent e) {", - " }", - " private void onThis_keyPressed(KeyEvent e) {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel implements KeyListener { + Test() { + addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + if (e.getSource() == this) { + onThis_keyPressed(e); + } + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } + private void onThis_keyPressed(KeyEvent e) { + } + }"""); // do delete, no GUI expected Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); keyPressedProperty.setValue(Property.UNKNOWN_VALUE); - assertEditor( - "class Test extends JPanel implements KeyListener {", - " Test() {", - " addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " public void keyTyped(KeyEvent e) {", - " }", - "}"); + assertEditor(""" + class Test extends JPanel implements KeyListener { + Test() { + addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } + }"""); } /** @@ -1027,38 +1007,37 @@ public void test_delete_method_interfaceWithConditionalStub_block() throws Excep */ @Test public void test_delete_method_interfaceWithConditionalStub_flat() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel implements KeyListener {", - " Test() {", - " addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " if (e.getSource() == this)", - " onThis_keyPressed(e);", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " public void keyTyped(KeyEvent e) {", - " }", - " private void onThis_keyPressed(KeyEvent e) {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel implements KeyListener { + Test() { + addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + if (e.getSource() == this) + onThis_keyPressed(e); + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } + private void onThis_keyPressed(KeyEvent e) { + } + }"""); // do delete, no GUI expected Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); keyPressedProperty.setValue(Property.UNKNOWN_VALUE); - assertEditor( - "class Test extends JPanel implements KeyListener {", - " Test() {", - " addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " public void keyTyped(KeyEvent e) {", - " }", - "}"); + assertEditor(""" + class Test extends JPanel implements KeyListener { + Test() { + addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } + }"""); } /** @@ -1067,44 +1046,43 @@ public void test_delete_method_interfaceWithConditionalStub_flat() throws Except */ @Test public void test_delete_method_interfaceWithConditionalStub_plusOtherPlace() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel implements KeyListener {", - " Test() {", - " addKeyListener(this);", - " // not in listener, so ignored", - " onThis_keyPressed(null);", - " }", - " public void keyPressed(KeyEvent e) {", - " if (e.getSource() == this)", - " onThis_keyPressed(e);", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " public void keyTyped(KeyEvent e) {", - " }", - " private void onThis_keyPressed(KeyEvent e) {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel implements KeyListener { + Test() { + addKeyListener(this); + // not in listener, so ignored + onThis_keyPressed(null); + } + public void keyPressed(KeyEvent e) { + if (e.getSource() == this) + onThis_keyPressed(e); + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } + private void onThis_keyPressed(KeyEvent e) { + } + }"""); // do delete, no GUI expected Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); keyPressedProperty.setValue(Property.UNKNOWN_VALUE); - assertEditor( - "class Test extends JPanel implements KeyListener {", - " Test() {", - " addKeyListener(this);", - " // not in listener, so ignored", - " onThis_keyPressed(null);", - " }", - " public void keyPressed(KeyEvent e) {", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " public void keyTyped(KeyEvent e) {", - " }", - " private void onThis_keyPressed(KeyEvent e) {", - " }", - "}"); + assertEditor(""" + class Test extends JPanel implements KeyListener { + Test() { + addKeyListener(this); + // not in listener, so ignored + onThis_keyPressed(null); + } + public void keyPressed(KeyEvent e) { + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } + private void onThis_keyPressed(KeyEvent e) { + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1114,38 +1092,36 @@ public void test_delete_method_interfaceWithConditionalStub_plusOtherPlace() thr //////////////////////////////////////////////////////////////////////////// @Test public void test_ensureListenerMethod_addListenerMethod() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + }); + } + }"""); // Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); } @Test public void test_ensureListenerMethod_addListener() 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() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_ANONYMOUS); @@ -1153,73 +1129,72 @@ public void test_ensureListenerMethod_addListener() throws Exception { { Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); } // add one more method { Property keyPressedProperty = getEventsListenerMethod(panel, "key", "released"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " @Override", - " public void keyReleased(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + } + @Override + public void keyReleased(KeyEvent e) { + } + }); + } + }"""); } } @Test public void test_addListener_deleteListener() 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() { + } + }"""); Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); // ensure listener { ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); } // delete listener { deleteEventPropertyWithGUI(keyPressedProperty); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); } } @@ -1230,13 +1205,12 @@ public void test_addListener_deleteListener() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_ensureListenerMethod_inner_badPosition() 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() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INNER_CLASS); @@ -1252,13 +1226,12 @@ public void test_ensureListenerMethod_inner_badPosition() throws Exception { @Test public void test_ensureListenerMethod_inner_firstInType() 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() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INNER_CLASS); @@ -1266,29 +1239,28 @@ public void test_ensureListenerMethod_inner_firstInType() throws Exception { // ensure listener Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " private class ThisKeyListener extends KeyAdapter {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - " public Test() {", - " addKeyListener(new ThisKeyListener());", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + private class ThisKeyListener extends KeyAdapter { + @Override + public void keyPressed(KeyEvent e) { + } + } + public Test() { + addKeyListener(new ThisKeyListener()); + } + }"""); } @Test public void test_ensureListenerMethod_inner_lastInType() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "class Test extends JPanel {", - " Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + class Test extends JPanel { + Test() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INNER_CLASS); @@ -1296,29 +1268,28 @@ public void test_ensureListenerMethod_inner_lastInType() throws Exception { // ensure listener Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new ThisKeyListener());", - " }", - " private class ThisKeyListener extends KeyAdapter {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler + class Test extends JPanel { + Test() { + addKeyListener(new ThisKeyListener()); + } + private class ThisKeyListener extends KeyAdapter { + @Override + public void keyPressed(KeyEvent e) { + } + } + }"""); } @Test public void test_ensureListenerMethod_inner_beforeExistingListener() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " }", - " private class ThisMouseListener extends MouseAdapter {}", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + } + private class ThisMouseListener extends MouseAdapter {} + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INNER_CLASS); @@ -1326,29 +1297,28 @@ public void test_ensureListenerMethod_inner_beforeExistingListener() throws Exce // ensure listener Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new ThisKeyListener());", - " }", - " private class ThisKeyListener extends KeyAdapter {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - " private class ThisMouseListener extends MouseAdapter {}", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + addKeyListener(new ThisKeyListener()); + } + private class ThisKeyListener extends KeyAdapter { + @Override + public void keyPressed(KeyEvent e) { + } + } + private class ThisMouseListener extends MouseAdapter {} + }"""); } @Test public void test_ensureListenerMethod_inner_beforeNotExistingListener() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "class Test extends JPanel {", - " Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + class Test extends JPanel { + Test() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INNER_CLASS); @@ -1356,29 +1326,28 @@ public void test_ensureListenerMethod_inner_beforeNotExistingListener() throws E // ensure listener Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "class Test extends JPanel {", - " private class ThisKeyListener extends KeyAdapter {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - " Test() {", - " addKeyListener(new ThisKeyListener());", - " }", - "}"); + assertEditor(""" + // filler filler filler + class Test extends JPanel { + private class ThisKeyListener extends KeyAdapter { + @Override + public void keyPressed(KeyEvent e) { + } + } + Test() { + addKeyListener(new ThisKeyListener()); + } + }"""); } @Test public void test_ensureListenerMethod_inner_afterExistingListener() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " private class ThisMouseListener extends MouseAdapter {}", - " Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + private class ThisMouseListener extends MouseAdapter {} + Test() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INNER_CLASS); @@ -1386,30 +1355,29 @@ public void test_ensureListenerMethod_inner_afterExistingListener() throws Excep // ensure listener Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "class Test extends JPanel {", - " private class ThisMouseListener extends MouseAdapter {}", - " private class ThisKeyListener extends KeyAdapter {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - " Test() {", - " addKeyListener(new ThisKeyListener());", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + private class ThisMouseListener extends MouseAdapter {} + private class ThisKeyListener extends KeyAdapter { + @Override + public void keyPressed(KeyEvent e) { + } + } + Test() { + addKeyListener(new ThisKeyListener()); + } + }"""); } @Test public void test_ensureListenerMethod_inner_noAdapter() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JButton button = new JButton();", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JButton button = new JButton(); + add(button); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); @@ -1418,29 +1386,28 @@ public void test_ensureListenerMethod_inner_noAdapter() throws Exception { // ensure listener Property keyPressedProperty = getEventsListenerMethod(button, "action", "performed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "class Test extends JPanel {", - " private class ButtonActionListener implements ActionListener {", - " public void actionPerformed(ActionEvent e) {", - " }", - " }", - " Test() {", - " JButton button = new JButton();", - " button.addActionListener(new ButtonActionListener());", - " add(button);", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + private class ButtonActionListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + } + } + Test() { + JButton button = new JButton(); + button.addActionListener(new ButtonActionListener()); + add(button); + } + }"""); } @Test public void test_ensureListenerMethod_inner_exposedVariable() throws Exception { - ContainerInfo frame = - parseContainer( - "// filler filler filler", - "class Test extends JFrame {", - " Test() {", - " }", - "}"); + ContainerInfo frame = parseContainer(""" + // filler filler filler + class Test extends JFrame { + Test() { + } + }"""); ContainerInfo contentPane = (ContainerInfo) frame.getChildrenComponents().get(0); // set preferences IPreferenceStore preferences = frame.getDescription().getToolkit().getPreferences(); @@ -1449,29 +1416,28 @@ public void test_ensureListenerMethod_inner_exposedVariable() throws Exception { // ensure listener Property keyPressedProperty = getEventsListenerMethod(contentPane, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "class Test extends JFrame {", - " private class ThisContentPaneKeyListener extends KeyAdapter {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - " Test() {", - " getContentPane().addKeyListener(new ThisContentPaneKeyListener());", - " }", - "}"); + assertEditor(""" + // filler filler filler + class Test extends JFrame { + private class ThisContentPaneKeyListener extends KeyAdapter { + @Override + public void keyPressed(KeyEvent e) { + } + } + Test() { + getContentPane().addKeyListener(new ThisContentPaneKeyListener()); + } + }"""); } @Test public void test_ensureListenerMethod_inner_nameTemplate() 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() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INNER_CLASS); @@ -1480,18 +1446,18 @@ public void test_ensureListenerMethod_inner_nameTemplate() throws Exception { // ensure listener Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " private class KeyListener_this extends KeyAdapter {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - " public Test() {", - " addKeyListener(new KeyListener_this());", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + private class KeyListener_this extends KeyAdapter { + @Override + public void keyPressed(KeyEvent e) { + } + } + public Test() { + addKeyListener(new KeyListener_this()); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1505,32 +1471,31 @@ public void test_ensureListenerMethod_inner_nameTemplate() throws Exception { */ @Test public void test_ensureListenerMethod_interface_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() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INTERFACE); // ensure listener Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel implements KeyListener {", - " public Test() {", - " addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " public void keyTyped(KeyEvent e) {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel implements KeyListener { + public Test() { + addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } + }"""); } /** @@ -1539,13 +1504,12 @@ public void test_ensureListenerMethod_interface_1() throws Exception { */ @Test public void test_ensureStubMethod_interface_2() 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() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INTERFACE); @@ -1553,24 +1517,24 @@ public void test_ensureStubMethod_interface_2() throws Exception { // ensure listener Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureStubMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel implements KeyListener {", - " public Test() {", - " addKeyListener(this);", - " }", - " public void keyPressed(KeyEvent e) {", - " if (e.getSource() == this) {", - " do_this_keyPressed(e);", - " }", - " }", - " public void keyReleased(KeyEvent e) {", - " }", - " public void keyTyped(KeyEvent e) {", - " }", - " protected void do_this_keyPressed(KeyEvent e) {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel implements KeyListener { + public Test() { + addKeyListener(this); + } + public void keyPressed(KeyEvent e) { + if (e.getSource() == this) { + do_this_keyPressed(e); + } + } + public void keyReleased(KeyEvent e) { + } + public void keyTyped(KeyEvent e) { + } + protected void do_this_keyPressed(KeyEvent e) { + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1580,13 +1544,12 @@ public void test_ensureStubMethod_interface_2() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_openStubMethod() 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() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CREATE_STUB, true); @@ -1605,20 +1568,20 @@ public void test_openStubMethod() throws Exception { // verify verify(pageSite).openSourcePosition(openSourcePosition.capture()); verifyNoMoreInteractions(pageSite); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " do_this_keyPressed(e);", - " }", - " });", - " }", - " protected void do_this_keyPressed(KeyEvent e) {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + do_this_keyPressed(e); + } + }); + } + protected void do_this_keyPressed(KeyEvent e) { + } + }"""); // check captured position { assertTrue(openSourcePosition.getValue() != 0); @@ -1649,15 +1612,14 @@ public void test_openStubMethod() throws Exception { */ @Test public void test_openStubMethod_whenInnerClass() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " private class MyListener extends KeyAdapter {", - " }", - " public Test() {", - " addKeyListener(new MyListener());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + private class MyListener extends KeyAdapter { + } + public Test() { + addKeyListener(new MyListener()); + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CREATE_STUB, true); @@ -1665,17 +1627,17 @@ public void test_openStubMethod_whenInnerClass() throws Exception { DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "openStubMethod()"); - assertEditor( - "public class Test extends JPanel {", - " private class MyListener extends KeyAdapter {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - " public Test() {", - " addKeyListener(new MyListener());", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private class MyListener extends KeyAdapter { + @Override + public void keyPressed(KeyEvent e) { + } + } + public Test() { + addKeyListener(new MyListener()); + } + }"""); } /** @@ -1683,28 +1645,27 @@ public void test_openStubMethod_whenInnerClass() throws Exception { */ @Test public void test_openStubMethod_noStub() 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() { + } + }"""); // DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "openStubMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); } /** @@ -1712,29 +1673,28 @@ public void test_openStubMethod_noStub() throws Exception { */ @Test public void test_ensureStubMethod_noStub() 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() { + } + }"""); // DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); MethodDeclaration listenerMethod = (MethodDeclaration) ReflectionUtils.invokeMethod(keyPressedProperty, "ensureStubMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); assertEquals("keyPressed", listenerMethod.getName().getIdentifier()); } @@ -1743,16 +1703,15 @@ public void test_ensureStubMethod_noStub() throws Exception { */ @Test public void test_openStubMethod_noStub2() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CREATE_STUB, true); @@ -1760,26 +1719,25 @@ public void test_openStubMethod_noStub2() throws Exception { DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "openStubMethod()"); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); } @Test public void test_openStubMethod_static() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test {", - " public static void main(String [] args) {", - " JPanel panel = new JPanel();", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test { + public static void main(String [] args) { + JPanel panel = new JPanel(); + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CREATE_STUB, true); @@ -1787,20 +1745,20 @@ public void test_openStubMethod_static() throws Exception { DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "openStubMethod()"); - assertEditor( - "class Test {", - " public static void main(String [] args) {", - " JPanel panel = new JPanel();", - " panel.addKeyListener(new KeyAdapter() {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " do_panel_keyPressed(e);", - " }", - " });", - " }", - " protected static void do_panel_keyPressed(KeyEvent e) {", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String [] args) { + JPanel panel = new JPanel(); + panel.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + do_panel_keyPressed(e); + } + }); + } + protected static void do_panel_keyPressed(KeyEvent e) { + } + }"""); } /** @@ -1809,30 +1767,29 @@ public void test_openStubMethod_static() throws Exception { */ @Test public void test_openStubMethod_whenLocalClass() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " class MyListener extends KeyAdapter {", - " }", - " addKeyListener(new MyListener());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + class MyListener extends KeyAdapter { + } + addKeyListener(new MyListener()); + } + }"""); // DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "openStubMethod()"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " class MyListener extends KeyAdapter {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " }", - " addKeyListener(new MyListener());", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + class MyListener extends KeyAdapter { + @Override + public void keyPressed(KeyEvent e) { + } + } + addKeyListener(new MyListener()); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1847,13 +1804,12 @@ public void test_openStubMethod_whenLocalClass() throws Exception { */ @Test public void test_openStubListenerMethod_valid() 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() { + } + }"""); // set mock for DesignPageSite DesignPageSite pageSite; { @@ -1868,17 +1824,17 @@ public void test_openStubListenerMethod_valid() throws Exception { // test results verify(pageSite).openSourcePosition(ArgumentMatchers.anyInt()); verifyNoMoreInteractions(pageSite); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " addKeyListener(new KeyAdapter() {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); } /** @@ -1888,16 +1844,16 @@ public void test_openStubListenerMethod_valid() throws Exception { */ @Test public void test_openStubListenerMethod_openSource() throws Exception { - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button = new JButton();", - " add(button);", - " }", - " }", - "}"); + parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + JButton button = new JButton(); + add(button); + } + } + }"""); ComponentInfo button = getJavaInfoByName("button"); // set mock for DesignPageSite IDesignPageSite pageSite; @@ -1917,16 +1873,16 @@ public void test_openStubListenerMethod_openSource() throws Exception { assertEquals( button.getCreationSupport().getNode().getStartPosition(), openSourcePosition.getValue().intValue()); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " JButton button = new JButton();", - " add(button);", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + JButton button = new JButton(); + add(button); + } + } + }"""); } /** @@ -1937,13 +1893,12 @@ public void test_openStubListenerMethod_openSource() throws Exception { @Test public void test_openStubListenerMethod_sendBroadcast() throws Exception { String name = "wbp:broadcast with parameters"; - 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() { + } + }"""); DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); // final AtomicReference broSpec = new AtomicReference<>(); @@ -1959,12 +1914,12 @@ public void invoke(JavaInfo javaInfo, String spec) throws Exception { waitEventLoop(0); // test results assertEquals(name, broSpec.get()); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); } /** @@ -1974,13 +1929,12 @@ public void invoke(JavaInfo javaInfo, String spec) throws Exception { */ @Test public void test_openStubListenerMethod_invalid() 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() { + } + }"""); // set mock for DesignPageSite IDesignPageSite pageSite; { @@ -1993,12 +1947,12 @@ public void test_openStubListenerMethod_invalid() throws Exception { eventsProperty.openStubMethod("no-such-listener/no-matter-what-method"); // test results verifyNoInteractions(pageSite); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2011,47 +1965,42 @@ public void test_openStubListenerMethod_invalid() throws Exception { */ @Test public void test_ensureListenerMethod_customListener() throws Exception { - setFileContentSrc( - "test/MyListener.java", - getSourceDQ( - "package test;", - "public interface MyListener {", - " void click(Object widget, int x, int y);", - " int offset();", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "// filler filler filler", - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyListener.java", """ + package test; + public interface MyListener { + void click(Object widget, int x, int y); + int offset(); + }"""); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + // filler filler filler + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); // - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // Property clickProperty = getEventsListenerMethod(panel, "my", "click"); ReflectionUtils.invokeMethod(clickProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " addMyListener(new MyListener() {", - " public void click(Object widget, int x, int y) {", - " }", - " public int offset() {", - " return 0;", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + addMyListener(new MyListener() { + public void click(Object widget, int x, int y) { + } + public int offset() { + return 0; + } + }); + } + }"""); } /** @@ -2059,39 +2008,34 @@ public void test_ensureListenerMethod_customListener() throws Exception { */ @Test public void test_ensureListenerMethod_listenerInConstructor() throws Exception { - setFileContentSrc( - "test/MyButton.java", - getTestSource( - "public class MyButton extends JButton {", - " public MyButton(String text, FocusListener listener) {", - " }", - "}")); - setFileContentSrc( - "test/MyButton.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - "")); + setFileContentSrc("test/MyButton.java", getTestSource(""" + public class MyButton extends JButton { + public MyButton(String text, FocusListener listener) { + } + }""")); + setFileContentSrc("test/MyButton.wbp-component.xml", """ + + + + + + + + + + + """); waitForAutoBuild(); // - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton('text', new FocusAdapter() {", - " public void focusGained(FocusEvent e) {}", - " });", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton("text", new FocusAdapter() { + public void focusGained(FocusEvent e) {} + }); + add(button); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // Property focusGainedProperty = getEventsListenerMethod(button, "focus", "gained"); @@ -2105,40 +2049,35 @@ public void test_ensureListenerMethod_listenerInConstructor() throws Exception { */ @Test public void test_listenerInConstructor_inVariable() throws Exception { - setFileContentSrc( - "test/MyButton.java", - getTestSource( - "public class MyButton extends JButton {", - " public MyButton(String text, FocusListener listener) {", - " }", - "}")); - setFileContentSrc( - "test/MyButton.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - "")); + setFileContentSrc("test/MyButton.java", getTestSource(""" + public class MyButton extends JButton { + public MyButton(String text, FocusListener listener) { + } + }""")); + setFileContentSrc("test/MyButton.wbp-component.xml", """ + + + + + + + + + + + """); waitForAutoBuild(); // - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " FocusListener listener = new FocusAdapter() {", - " public void focusGained(FocusEvent e0) {}", - " };", - " MyButton button = new MyButton('text', listener);", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + FocusListener listener = new FocusAdapter() { + public void focusGained(FocusEvent e0) {} + }; + MyButton button = new MyButton("text", listener); + add(button); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // String expectedSource = m_lastEditor.getSource(); @@ -2153,30 +2092,29 @@ public void test_listenerInConstructor_inVariable() throws Exception { @Test public void test_ensureListenerMethod_final() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + }); + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_FINAL_PARAMETERS, true); // ensure listener Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); ReflectionUtils.invokeMethod(keyPressedProperty, "ensureListenerMethod()"); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " @Override", - " public void keyPressed(final KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(final KeyEvent e) { + } + }); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2189,22 +2127,21 @@ public void test_ensureListenerMethod_final() throws Exception { */ @Test public void test_decorateIcon() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " {", - " JButton button_1 = new JButton();", - " add(button_1);", - " button_1.addKeyListener(new KeyAdapter() {", - " });", - " }", - " {", - " JButton button_2 = new JButton();", - " add(button_2);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + { + JButton button_1 = new JButton(); + add(button_1); + button_1.addKeyListener(new KeyAdapter() { + }); + } + { + JButton button_2 = new JButton(); + add(button_2); + } + } + }"""); ComponentInfo button_1 = panel.getChildrenComponents().get(0); ComponentInfo button_2 = panel.getChildrenComponents().get(1); // be default decoration enabled @@ -2231,16 +2168,15 @@ public void test_decorateIcon() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_ListenerMethodPropertyEditor_doubleClick() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyReleased(KeyEvent e) {", - " }", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + public void keyReleased(KeyEvent e) { + } + }); + } + }"""); DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); // Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); @@ -2251,18 +2187,18 @@ public void test_ListenerMethodPropertyEditor_doubleClick() throws Exception { { PropertyEditor keyPressedEditor = keyPressedProperty.getEditor(); keyPressedEditor.doubleClick(keyPressedProperty); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyReleased(KeyEvent e) {", - " }", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + public void keyReleased(KeyEvent e) { + } + @Override + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); } } @@ -2272,14 +2208,13 @@ public void test_ListenerMethodPropertyEditor_doubleClick() throws Exception { */ @Test public void test_ListenerMethodPropertyEditor_activate() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + }); + } + }"""); DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); // Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); @@ -2288,16 +2223,16 @@ public void test_ListenerMethodPropertyEditor_activate() throws Exception { { PropertyEditor keyPressedEditor = keyPressedProperty.getEditor(); keyPressedEditor.activate(null, keyPressedProperty, null); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); } } @@ -2311,22 +2246,19 @@ public void test_ListenerMethodPropertyEditor_activate() throws Exception { */ @Test public void test_addXHandler() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyCoolHandler(KeyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyCoolHandler(KeyListener listener) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); EventsProperty eventsProperty = (EventsProperty) panel.getPropertyByTitle("Events"); Property myCoolProperty = getPropertyByTitle(getSubProperties(eventsProperty), "myCool"); assertNotNull(myCoolProperty); @@ -2337,28 +2269,23 @@ public void test_addXHandler() throws Exception { */ @Test public void test_listenerAsClass() throws Exception { - setFileContentSrc( - "test/MyListener.java", - getTestSource( - "public abstract class MyListener implements java.util.EventListener {", - " public abstract void handle(KeyEvent event);", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyListener.java", getTestSource(""" + public abstract class MyListener implements java.util.EventListener { + public abstract void handle(KeyEvent event); + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // check that "my" listener exists and has only "handle" method { Property listener = getEventsListener(panel, "my"); @@ -2369,16 +2296,16 @@ public void test_listenerAsClass() throws Exception { } // open "my.handle" listener method ensureListenerMethod(panel, "my", "handle"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " addMyListener(new MyListener() {", - " public void handle(KeyEvent event) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + addMyListener(new MyListener() { + public void handle(KeyEvent event) { + } + }); + } + }"""); } /** @@ -2386,45 +2313,40 @@ public void test_listenerAsClass() throws Exception { */ @Test public void test_listenerAsClass_innerType() throws Exception { - setFileContentSrc( - "test/MyListener.java", - getTestSource( - "public abstract class MyListener implements java.util.EventListener {", - " public abstract void handle(KeyEvent event);", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyListener.java", getTestSource(""" + public abstract class MyListener implements java.util.EventListener { + public abstract void handle(KeyEvent event); + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INNER_CLASS); preferences.setValue(P_INNER_POSITION, V_INNER_FIRST); // open "my.handle" listener method ensureListenerMethod(panel, "my", "handle"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " private class ThisMyListener extends MyListener {", - " public void handle(KeyEvent event) {", - " }", - " }", - " public Test() {", - " addMyListener(new ThisMyListener());", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + private class ThisMyListener extends MyListener { + public void handle(KeyEvent event) { + } + } + public Test() { + addMyListener(new ThisMyListener()); + } + }"""); } /** @@ -2433,31 +2355,26 @@ public void test_listenerAsClass_innerType() throws Exception { */ @Test public void test_listenerAsClass_useDeclaredNonAbstractMethods() throws Exception { - setFileContentSrc( - "test/MyListener.java", - getTestSource( - "public abstract class MyListener implements java.util.EventListener {", - " public void handle(KeyEvent event) {", - " }", - " public void handle2(KeyEvent event) {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyListener.java", getTestSource(""" + public abstract class MyListener implements java.util.EventListener { + public void handle(KeyEvent event) { + } + public void handle2(KeyEvent event) { + } + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // check that "my" listener exists and has only "handle" method { Property listener = getEventsListener(panel, "my"); @@ -2469,16 +2386,16 @@ public void test_listenerAsClass_useDeclaredNonAbstractMethods() throws Exceptio } // open "my.handle" listener method ensureListenerMethod(panel, "my", "handle"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " addMyListener(new MyListener() {", - " public void handle(KeyEvent event) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + addMyListener(new MyListener() { + public void handle(KeyEvent event) { + } + }); + } + }"""); } /** @@ -2486,37 +2403,30 @@ public void test_listenerAsClass_useDeclaredNonAbstractMethods() throws Exceptio */ @Test public void test_listenerAsClass_implementGenericInterface() throws Exception { - setFileContentSrc( - "test/MyInterface.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public interface MyInterface {", - " void handle(E event);", - "}")); - setFileContentSrc( - "test/MyListener.java", - getTestSource( - "public abstract class MyListener implements MyInterface {", - " public void handle(KeyEvent event) {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyInterface.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public interface MyInterface { + void handle(E event); + }""")); + setFileContentSrc("test/MyListener.java", getTestSource(""" + public abstract class MyListener implements MyInterface { + public void handle(KeyEvent event) { + } + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // check that "my" listener exists and has only "handle" method { Property listener = getEventsListener(panel, "my"); @@ -2532,28 +2442,23 @@ public void test_listenerAsClass_implementGenericInterface() throws Exception { */ @Test public void test_listenerWithGeneric() throws Exception { - setFileContentSrc( - "test/MyListener.java", - getTestSource( - "public abstract class MyListener {", - " public abstract void handle(E event);", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyListener.java", getTestSource(""" + public abstract class MyListener { + public abstract void handle(E event); + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // check that "my" listener exists and has only "handle" method { Property listener = getEventsListener(panel, "my"); @@ -2564,16 +2469,16 @@ public void test_listenerWithGeneric() throws Exception { } // open "my.handle" listener method ensureListenerMethod(panel, "my", "handle"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " addMyListener(new MyListener() {", - " public void handle(KeyEvent event) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + addMyListener(new MyListener() { + public void handle(KeyEvent event) { + } + }); + } + }"""); } /** @@ -2581,45 +2486,40 @@ public void test_listenerWithGeneric() throws Exception { */ @Test public void test_listenerWithGeneric_innerType() throws Exception { - setFileContentSrc( - "test/MyListener.java", - getTestSource( - "public abstract class MyListener {", - " public abstract void handle(E event);", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyListener.java", getTestSource(""" + public abstract class MyListener { + public abstract void handle(E event); + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INNER_CLASS); preferences.setValue(P_INNER_POSITION, V_INNER_FIRST); // open "my.handle" listener method ensureListenerMethod(panel, "my", "handle"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " private class ThisMyListener extends MyListener {", - " public void handle(KeyEvent event) {", - " }", - " }", - " public Test() {", - " addMyListener(new ThisMyListener());", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + private class ThisMyListener extends MyListener { + public void handle(KeyEvent event) { + } + } + public Test() { + addMyListener(new ThisMyListener()); + } + }"""); } /** @@ -2629,36 +2529,29 @@ public void test_listenerWithGeneric_innerType() throws Exception { */ @Test public void test_listenerWithGeneric_parameterizedEvent() throws Exception { - setFileContentSrc( - "test/MyEvent.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public abstract class MyEvent {", - " public E value;", - "}")); - setFileContentSrc( - "test/MyListener.java", - getTestSource( - "public abstract class MyListener {", - " public abstract void handle(MyEvent event);", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyEvent.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public abstract class MyEvent { + public E value; + }""")); + setFileContentSrc("test/MyListener.java", getTestSource(""" + public abstract class MyListener { + public abstract void handle(MyEvent event); + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // check that "my" listener exists and has only "handle" method { Property listener = getEventsListener(panel, "my"); @@ -2669,16 +2562,16 @@ public void test_listenerWithGeneric_parameterizedEvent() throws Exception { } // open "my.handle" listener method ensureListenerMethod(panel, "my", "handle"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " addMyListener(new MyListener() {", - " public void handle(MyEvent event) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + addMyListener(new MyListener() { + public void handle(MyEvent event) { + } + }); + } + }"""); } /** @@ -2687,47 +2580,39 @@ public void test_listenerWithGeneric_parameterizedEvent() throws Exception { */ @Test public void test_listenerWithGeneric_parameterizedEvent_actualInType() throws Exception { - setFileContentSrc( - "test/MyEvent.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public abstract class MyEvent {", - " public E value;", - "}")); - setFileContentSrc( - "test/MyListener.java", - getTestSource( - "public abstract class MyListener {", - " public abstract void handle(MyEvent event);", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel2.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "// filler filler filler", - "public class MyPanel2 extends MyPanel {", - "}")); + setFileContentSrc("test/MyEvent.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public abstract class MyEvent { + public E value; + }""")); + setFileContentSrc("test/MyListener.java", getTestSource(""" + public abstract class MyListener { + public abstract void handle(MyEvent event); + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); + setFileContentSrc("test/MyPanel2.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + // filler filler filler + public class MyPanel2 extends MyPanel { + }""")); waitForAutoBuild(); // parse - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " MyPanel2 inner = new MyPanel2();", - " add(inner);", - " }", - " }", - "}"); + parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + MyPanel2 inner = new MyPanel2(); + add(inner); + } + } + }"""); ContainerInfo inner = getJavaInfoByName("inner"); // check that "my" listener exists and has only "handle" method { @@ -2739,20 +2624,20 @@ public void test_listenerWithGeneric_parameterizedEvent_actualInType() throws Ex } // open "my.handle" listener method ensureListenerMethod(inner, "my", "handle"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " MyPanel2 inner = new MyPanel2();", - " inner.addMyListener(new MyListener() {", - " public void handle(MyEvent event) {", - " }", - " });", - " add(inner);", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + MyPanel2 inner = new MyPanel2(); + inner.addMyListener(new MyListener() { + public void handle(MyEvent event) { + } + }); + add(inner); + } + } + }"""); } /** @@ -2761,84 +2646,70 @@ public void test_listenerWithGeneric_parameterizedEvent_actualInType() throws Ex */ @Test public void test_listenerWithGeneric_parameterizedEvent_actualInSuperclass() throws Exception { - setFileContentSrc( - "test/MyEvent.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public abstract class MyEvent {", - " public E value;", - "}")); - setFileContentSrc( - "test/MyListener.java", - getTestSource( - "// filler filler filler filler filler", - "public abstract class MyListener {", - " public abstract void handle(MyEvent event);", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "// filler filler filler filler filler", - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel2.java", - getTestSource( - "// filler filler filler filler filler", - "public class MyPanel2 extends MyPanel {", - "}")); - setFileContentSrc( - "test/MyPanel3.java", - getTestSource( - "// filler filler filler filler filler", - "public class MyPanel3 extends MyPanel2 {", - "}")); - setFileContentSrc( - "test/MyPanel4.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class MyPanel4 extends MyPanel3 {", - "}")); - setFileContentSrc( - "test/MyPanel5.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class MyPanel5 extends MyPanel4 {", - "}")); + setFileContentSrc("test/MyEvent.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public abstract class MyEvent { + public E value; + }""")); + setFileContentSrc("test/MyListener.java", getTestSource(""" + // filler filler filler filler filler + public abstract class MyListener { + public abstract void handle(MyEvent event); + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + // filler filler filler filler filler + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); + setFileContentSrc("test/MyPanel2.java", getTestSource(""" + // filler filler filler filler filler + public class MyPanel2 extends MyPanel { + }""")); + setFileContentSrc("test/MyPanel3.java", getTestSource(""" + // filler filler filler filler filler + public class MyPanel3 extends MyPanel2 { + }""")); + setFileContentSrc("test/MyPanel4.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class MyPanel4 extends MyPanel3 { + }""")); + setFileContentSrc("test/MyPanel5.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class MyPanel5 extends MyPanel4 { + }""")); waitForAutoBuild(); // parse - parseContainer( - "// filler filler filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " MyPanel5 inner = new MyPanel5();", - " add(inner);", - " }", - " }", - "}"); + parseContainer(""" + // filler filler filler filler filler + public class Test extends JPanel { + public Test() { + { + MyPanel5 inner = new MyPanel5(); + add(inner); + } + } + }"""); ContainerInfo inner = getJavaInfoByName("inner"); // open "my.handle" listener method ensureListenerMethod(inner, "my", "handle"); - assertEditor( - "// filler filler filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " MyPanel5 inner = new MyPanel5();", - " inner.addMyListener(new MyListener() {", - " public void handle(MyEvent event) {", - " }", - " });", - " add(inner);", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler filler filler + public class Test extends JPanel { + public Test() { + { + MyPanel5 inner = new MyPanel5(); + inner.addMyListener(new MyListener() { + public void handle(MyEvent event) { + } + }); + add(inner); + } + } + }"""); } /** @@ -2846,39 +2717,33 @@ public void test_listenerWithGeneric_parameterizedEvent_actualInSuperclass() thr */ @Test public void test_listenerWithGeneric_parameterizedEvent_noTypeArgument() throws Exception { - setFileContentSrc( - "test/MyEvent.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public abstract class MyEvent {", - " public E value;", - "}")); - setFileContentSrc( - "test/MyListener.java", - getTestSource( - "public abstract class MyListener {", - " public abstract void handle(MyEvent event);", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyEvent.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public abstract class MyEvent { + public E value; + }""")); + setFileContentSrc("test/MyListener.java", getTestSource(""" + public abstract class MyListener { + public abstract void handle(MyEvent event); + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); // parse - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " MyPanel inner = new MyPanel();", - " add(inner);", - " }", - " }", - "}"); + parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + MyPanel inner = new MyPanel(); + add(inner); + } + } + }"""); ContainerInfo inner = getJavaInfoByName("inner"); // check that "my" listener exists and has only "handle" method { @@ -2890,20 +2755,20 @@ public void test_listenerWithGeneric_parameterizedEvent_noTypeArgument() throws } // open "my.handle" listener method ensureListenerMethod(inner, "my", "handle"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " {", - " MyPanel inner = new MyPanel();", - " inner.addMyListener(new MyListener() {", - " public void handle(MyEvent event) {", - " }", - " });", - " add(inner);", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + { + MyPanel inner = new MyPanel(); + inner.addMyListener(new MyListener() { + public void handle(MyEvent event) { + } + }); + add(inner); + } + } + }"""); } /** @@ -2912,29 +2777,25 @@ public void test_listenerWithGeneric_parameterizedEvent_noTypeArgument() throws */ @Test public void test_listenerWithGeneric_pureTypeVariable() throws Exception { - setFileContentSrc( - "test/MyListener.java", - getTestSource( - "public abstract class MyListener {", - " public abstract void handle(E object);", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyListener.java", getTestSource(""" + public abstract class MyListener { + public abstract void handle(E object); + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); // parse - parseContainer( - "// filler filler filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " MyPanel myPanel = new MyPanel();", - " add(myPanel);", - " }", - "}"); + parseContainer(""" + // filler filler filler filler filler + public class Test extends JPanel { + public Test() { + MyPanel myPanel = new MyPanel(); + add(myPanel); + } + }"""); ContainerInfo myPanel = getJavaInfoByName("myPanel"); // check that "my" listener exists and has only "handle" method { @@ -2946,18 +2807,18 @@ public void test_listenerWithGeneric_pureTypeVariable() throws Exception { } // open "my.handle" listener method ensureListenerMethod(myPanel, "my", "handle"); - assertEditor( - "// filler filler filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " MyPanel myPanel = new MyPanel();", - " myPanel.addMyListener(new MyListener() {", - " public void handle(T object) {", - " }", - " });", - " add(myPanel);", - " }", - "}"); + assertEditor(""" + // filler filler filler filler filler + public class Test extends JPanel { + public Test() { + MyPanel myPanel = new MyPanel(); + myPanel.addMyListener(new MyListener() { + public void handle(T object) { + } + }); + add(myPanel); + } + }"""); } /** @@ -2965,22 +2826,19 @@ public void test_listenerWithGeneric_pureTypeVariable() throws Exception { */ @Test public void test_addListener_justSuchName() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addListener(KeyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addListener(KeyListener listener) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // there is "addListener" property { Property listenerProperty = getEventsListener(panel, "addListener"); @@ -2990,17 +2848,17 @@ public void test_addListener_justSuchName() throws Exception { { Property pressedProperty = getEventsListenerMethod(panel, "addListener", "keyPressed"); ReflectionUtils.invokeMethod(pressedProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " addListener(new KeyAdapter() {", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + addListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); } } @@ -3009,55 +2867,48 @@ public void test_addListener_justSuchName() throws Exception { */ @Test public void test_addMyListenerAdapter() throws Exception { - setFileContentSrc( - "test/MyListener.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public interface MyListener {", - " void down();", - " void up();", - "}")); - setFileContentSrc( - "test/MyListenerAdapter.java", - getTestSource( - "public class MyListenerAdapter implements MyListener {", - " public void down() {", - " }", - " public void up() {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyListener.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public interface MyListener { + void down(); + void up(); + }""")); + setFileContentSrc("test/MyListenerAdapter.java", getTestSource(""" + public class MyListenerAdapter implements MyListener { + public void down() { + } + public void up() { + } + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // open listener, adapter should be used { Property pressedProperty = getEventsListenerMethod(panel, "my", "down"); ReflectionUtils.invokeMethod(pressedProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " addMyListener(new MyListenerAdapter() {", - " @Override", - " public void down() {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + addMyListener(new MyListenerAdapter() { + @Override + public void down() { + } + }); + } + }"""); } } @@ -3066,65 +2917,54 @@ public void test_addMyListenerAdapter() throws Exception { */ @Test public void test_addAdapterInheritance() throws Exception { - setFileContentSrc( - "test/SuperListener.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public interface SuperListener {", - " void foo(int fooValue);", - "}")); - setFileContentSrc( - "test/SubListener.java", - getTestSource( - "public interface SubListener extends SuperListener {", - " void bar(int barValue);", - "}")); - setFileContentSrc( - "test/SuperListenerAdapter.java", - getTestSource( - "public class SuperListenerAdapter implements SuperListener {", - " public void foo(int fooValue) {", - " }", - "}")); - setFileContentSrc( - "test/SubListenerAdapter.java", - getTestSource( - "public class SubListenerAdapter extends SuperListenerAdapter implements SuperListener {", - " public void bar(int barValue) {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void addSubListener(SubListener listener) {", - " }", - "}")); + setFileContentSrc("test/SuperListener.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public interface SuperListener { + void foo(int fooValue); + }""")); + setFileContentSrc("test/SubListener.java", getTestSource(""" + public interface SubListener extends SuperListener { + void bar(int barValue); + }""")); + setFileContentSrc("test/SuperListenerAdapter.java", getTestSource(""" + public class SuperListenerAdapter implements SuperListener { + public void foo(int fooValue) { + } + }""")); + setFileContentSrc("test/SubListenerAdapter.java", getTestSource(""" + public class SubListenerAdapter extends SuperListenerAdapter implements SuperListener { + public void bar(int barValue) { + } + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void addSubListener(SubListener listener) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // open listener, adapter should be used { Property pressedProperty = getEventsListenerMethod(panel, "sub", "foo"); ReflectionUtils.invokeMethod(pressedProperty, "ensureListenerMethod()"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " addSubListener(new SubListenerAdapter() {", - " @Override", - " public void foo(int fooValue) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + addSubListener(new SubListenerAdapter() { + @Override + public void foo(int fooValue) { + } + }); + } + }"""); } } @@ -3140,29 +2980,28 @@ public void test_addAdapterInheritance() throws Exception { @Test public void test_listenerAsInnerTypeOfComponent_anonymous() throws Exception { prepare_listenerAsInnerTypeOfComponent(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // open listener { Property pressedProperty = getEventsListenerMethod(panel, "my", "handle"); ReflectionUtils.invokeMethod(pressedProperty, "ensureListenerMethod()"); - assertEditor( - "import test.MyPanel.MyListener;", - "import test.MyPanel.MyEvent;", - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " addMyListener(new MyListener() {", - " public void handle(MyEvent event) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + import test.MyPanel.MyListener; + import test.MyPanel.MyEvent; + // filler filler filler + public class Test extends MyPanel { + public Test() { + addMyListener(new MyListener() { + public void handle(MyEvent event) { + } + }); + } + }"""); } } @@ -3173,13 +3012,12 @@ public void test_listenerAsInnerTypeOfComponent_anonymous() throws Exception { @Test public void test_listenerAsInnerTypeOfComponent_inner() throws Exception { prepare_listenerAsInnerTypeOfComponent(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INNER_CLASS); @@ -3188,19 +3026,19 @@ public void test_listenerAsInnerTypeOfComponent_inner() throws Exception { { Property pressedProperty = getEventsListenerMethod(panel, "my", "handle"); ReflectionUtils.invokeMethod(pressedProperty, "ensureListenerMethod()"); - assertEditor( - "import test.MyPanel.MyListener;", - "import test.MyPanel.MyEvent;", - "// filler filler filler", - "public class Test extends MyPanel {", - " private class ThisMyListener implements MyListener {", - " public void handle(MyEvent event) {", - " }", - " }", - " public Test() {", - " addMyListener(new ThisMyListener());", - " }", - "}"); + assertEditor(""" + import test.MyPanel.MyListener; + import test.MyPanel.MyEvent; + // filler filler filler + public class Test extends MyPanel { + private class ThisMyListener implements MyListener { + public void handle(MyEvent event) { + } + } + public Test() { + addMyListener(new ThisMyListener()); + } + }"""); } } @@ -3211,13 +3049,12 @@ public void test_listenerAsInnerTypeOfComponent_inner() throws Exception { @Test public void test_listenerAsInnerTypeOfComponent_innerAdapter() throws Exception { prepare_listenerAsInnerTypeOfComponent_withAdapter(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INNER_CLASS); @@ -3226,19 +3063,19 @@ public void test_listenerAsInnerTypeOfComponent_innerAdapter() throws Exception { Property pressedProperty = getEventsListenerMethod(panel, "my", "handle"); ReflectionUtils.invokeMethod(pressedProperty, "ensureListenerMethod()"); - assertEditor( - "import test.MyPanel.MyAdapter;", - "import test.MyPanel.MyEvent;", - "// filler filler filler", - "public class Test extends MyPanel {", - " private class ThisMyListener extends MyAdapter {", - " public void handle(MyEvent event) {", - " }", - " }", - " public Test() {", - " addMyListener(new ThisMyListener());", - " }", - "}"); + assertEditor(""" + import test.MyPanel.MyAdapter; + import test.MyPanel.MyEvent; + // filler filler filler + public class Test extends MyPanel { + private class ThisMyListener extends MyAdapter { + public void handle(MyEvent event) { + } + } + public Test() { + addMyListener(new ThisMyListener()); + } + }"""); } } @@ -3249,13 +3086,12 @@ public void test_listenerAsInnerTypeOfComponent_innerAdapter() throws Exception @Test public void test_listenerAsInnerTypeOfComponent_interface() throws Exception { prepare_listenerAsInnerTypeOfComponent(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // set preferences IPreferenceStore preferences = panel.getDescription().getToolkit().getPreferences(); preferences.setValue(P_CODE_TYPE, V_CODE_INTERFACE); @@ -3263,53 +3099,49 @@ public void test_listenerAsInnerTypeOfComponent_interface() throws Exception { { Property pressedProperty = getEventsListenerMethod(panel, "my", "handle"); ReflectionUtils.invokeMethod(pressedProperty, "ensureListenerMethod()"); - assertEditor( - "import test.MyPanel.MyListener;", - "import test.MyPanel.MyEvent;", - "// filler filler filler", - "public class Test extends MyPanel implements MyListener {", - " public Test() {", - " addMyListener(this);", - " }", - " public void handle(MyEvent event) {", - " }", - "}"); + assertEditor(""" + import test.MyPanel.MyListener; + import test.MyPanel.MyEvent; + // filler filler filler + public class Test extends MyPanel implements MyListener { + public Test() { + addMyListener(this); + } + public void handle(MyEvent event) { + } + }"""); } } private void prepare_listenerAsInnerTypeOfComponent() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public class MyEvent {", - " }", - " public interface MyListener {", - " void handle(MyEvent event);", - " }", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public class MyEvent { + } + public interface MyListener { + void handle(MyEvent event); + } + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); } private void prepare_listenerAsInnerTypeOfComponent_withAdapter() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public class MyEvent {", - " }", - " public interface MyListener {", - " void handle(MyEvent event);", - " }", - " public class MyAdapter implements MyListener {", - " public void handle(MyEvent event) {", - " }", - " }", - " public void addMyListener(MyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public class MyEvent { + } + public interface MyListener { + void handle(MyEvent event); + } + public class MyAdapter implements MyListener { + public void handle(MyEvent event) { + } + } + public void addMyListener(MyListener listener) { + } + }""")); waitForAutoBuild(); } @@ -3320,16 +3152,15 @@ private void prepare_listenerAsInnerTypeOfComponent_withAdapter() throws Excepti //////////////////////////////////////////////////////////////////////////// @Test public void test_understand() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " this.addKeyListener(new KeyAdapter() {", - " public void keyReleased(KeyEvent e) {", - " }", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + this.addKeyListener(new KeyAdapter() { + public void keyReleased(KeyEvent e) { + } + }); + } + }"""); DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); // prepare properties Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); @@ -3340,13 +3171,12 @@ public void test_understand() throws Exception { @Test public void test_understandLambda() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " this.addMouseWheelListener((event) -> {});", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + this.addMouseWheelListener((event) -> {}); + } + }"""); DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); // prepare properties Property propertyChangeProperty = getEventsListenerMethod(panel, "mouseWheel", "moved"); @@ -3355,13 +3185,12 @@ public void test_understandLambda() throws Exception { @Test public void test_understandLambda_noBlock() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " this.addMouseWheelListener((event) -> System.out.println(event));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + this.addMouseWheelListener((event) -> System.out.println(event)); + } + }"""); DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); // prepare properties Property propertyChangeProperty = getEventsListenerMethod(panel, "mouseWheel", "moved"); @@ -3370,13 +3199,12 @@ public void test_understandLambda_noBlock() throws Exception { @Test public void test_understandLambda_doubleColon() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " this.addMouseWheelListener(System.out::println);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + this.addMouseWheelListener(System.out::println); + } + }"""); DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); // prepare properties Property propertyChangeProperty = getEventsListenerMethod(panel, "mouseWheel", "moved"); @@ -3385,21 +3213,20 @@ public void test_understandLambda_doubleColon() throws Exception { @Test public void test_understandLambda_factory() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " this.addMouseWheelListener(mouseWheelMovedAdapter((event) -> {}));", - " }", - " static MouseWheelListener mouseWheelMovedAdapter(java.util.function.Consumer c) {", - " return new MouseAdapter() {", - " @Override", - " public void mouseWheelMoved(MouseWheelEvent e) {", - " c.accept(e);", - " }", - " };", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + this.addMouseWheelListener(mouseWheelMovedAdapter((event) -> {})); + } + static MouseWheelListener mouseWheelMovedAdapter(java.util.function.Consumer c) { + return new MouseAdapter() { + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + c.accept(e); + } + }; + } + }"""); DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); // prepare properties Property propertyChangeProperty = getEventsListenerMethod(panel, "mouseWheel", "moved"); @@ -3408,16 +3235,15 @@ public void test_understandLambda_factory() throws Exception { @Test public void test_contextMenu() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyReleased(KeyEvent e) {", - " }", - " });", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + public void keyReleased(KeyEvent e) { + } + }); + } + }"""); DesignPageSite.Helper.setSite(panel, DesignPageSite.EMPTY); // prepare properties Property keyPressedProperty = getEventsListenerMethod(panel, "key", "pressed"); @@ -3452,18 +3278,18 @@ public void test_contextMenu() throws Exception { assertNotNull(keyPressedAction); // run, new handler should be added keyPressedAction.run(); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " addKeyListener(new KeyAdapter() {", - " public void keyReleased(KeyEvent e) {", - " }", - " @Override", - " public void keyPressed(KeyEvent e) {", - " }", - " });", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + addKeyListener(new KeyAdapter() { + public void keyReleased(KeyEvent e) { + } + @Override + public void keyPressed(KeyEvent e) { + } + }); + } + }"""); } // check for images { @@ -3481,23 +3307,20 @@ public void test_contextMenu() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_deprecatedListenerMethod() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " @Deprecated", - " public void addMyListener(KeyListener listener) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + @Deprecated + public void addMyListener(KeyListener listener) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); Property listener = getEventsListener(panel, "my"); assertNotNull(listener); assertSame(PropertyCategory.ADVANCED, listener.getCategory()); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/ExposePropertySupportTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/ExposePropertySupportTest.java index 39bbc6830a..43b3c99be7 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/ExposePropertySupportTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/ExposePropertySupportTest.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 @@ -59,14 +59,13 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_validOrInvalidProperty() 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() { + } + }"""); // { IAction action = getExposeAction(panel, "Class"); @@ -85,14 +84,13 @@ public void test_validOrInvalidProperty() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_validate() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " }", - " private int getFoo() {return 0;}", - " private void setBar(boolean bar) {}", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + } + private int getFoo() {return 0;} + private void setBar(boolean bar) {} + }"""); IAction action = getExposeAction(panel, "enabled"); // invalid identifier { @@ -127,26 +125,25 @@ private static String call_validate(IAction action, String exposedName) throws E */ @Test public void test_getPreviewSource_primitive() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " add(button);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + add(button); + } + }"""); ComponentInfo button = getJavaInfoByName("button"); // - assertEquals( - getSourceDQ( - "...", - " public float getButtonAlignmentX() {", - " return button.getAlignmentX();", - " }", - " public void setButtonAlignmentX(float alignmentX) {", - " button.setAlignmentX(alignmentX);", - " }", - "..."), - call_getPreview(button, "alignmentX", "buttonAlignmentX", true)); + assertEquals(""" + ... + public float getButtonAlignmentX() { + return button.getAlignmentX(); + } + public void setButtonAlignmentX(float alignmentX) { + button.setAlignmentX(alignmentX); + } + ... + """, call_getPreview(button, "alignmentX", "buttonAlignmentX", true)); } /** @@ -154,27 +151,26 @@ public void test_getPreviewSource_primitive() throws Exception { */ @Test public void test_getPreviewSource_parameter() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " private int alignmentX;", - " public Test() {", - " JButton button = new JButton();", - " add(button);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + private int alignmentX; + public Test() { + JButton button = new JButton(); + add(button); + } + }"""); ComponentInfo button = getJavaInfoByName("button"); // - assertEquals( - getSourceDQ( - "...", - " public float getButtonAlignmentX() {", - " return button.getAlignmentX();", - " }", - " public void setButtonAlignmentX(float alignmentX_1) {", - " button.setAlignmentX(alignmentX_1);", - " }", - "..."), - call_getPreview(button, "alignmentX", "buttonAlignmentX", true)); + assertEquals(""" + ... + public float getButtonAlignmentX() { + return button.getAlignmentX(); + } + public void setButtonAlignmentX(float alignmentX_1) { + button.setAlignmentX(alignmentX_1); + } + ... + """, call_getPreview(button, "alignmentX", "buttonAlignmentX", true)); } /** @@ -182,26 +178,25 @@ public void test_getPreviewSource_parameter() throws Exception { */ @Test public void test_getPreviewSource_qualified() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " add(button);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + add(button); + } + }"""); ComponentInfo button = getJavaInfoByName("button"); // - assertEquals( - getSourceDQ( - "...", - " public String getButtonName() {", - " return button.getName();", - " }", - " public void setButtonName(String name) {", - " button.setName(name);", - " }", - "..."), - call_getPreview(button, "name", "buttonName", true)); + assertEquals(""" + ... + public String getButtonName() { + return button.getName(); + } + public void setButtonName(String name) { + button.setName(name); + } + ... + """, call_getPreview(button, "name", "buttonName", true)); } /** @@ -209,38 +204,35 @@ public void test_getPreviewSource_qualified() throws Exception { */ @Test public void test_getPreviewSource_qualifiedArray() throws Exception { - setFileContentSrc( - "test/MyButton.java", - getTestSource( - "public class MyButton extends JButton {", - " public String[] getItems() {", - " return null;", - " }", - " public void setItems(String[] items) {", - " }", - "}")); + setFileContentSrc("test/MyButton.java", getTestSource(""" + public class MyButton extends JButton { + public String[] getItems() { + return null; + } + public void setItems(String[] items) { + } + }""")); waitForAutoBuild(); // parse - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + } + }"""); ComponentInfo button = getJavaInfoByName("button"); // check preview - assertEquals( - getSourceDQ( - "...", - " public String[] getButtonItems() {", - " return button.getItems();", - " }", - " public void setButtonItems(String[] items) {", - " button.setItems(items);", - " }", - "..."), - call_getPreview(button, "items", "buttonItems", true)); + assertEquals(""" + ... + public String[] getButtonItems() { + return button.getItems(); + } + public void setButtonItems(String[] items) { + button.setItems(items); + } + ... + """, call_getPreview(button, "items", "buttonItems", true)); } /** @@ -248,26 +240,25 @@ public void test_getPreviewSource_qualifiedArray() throws Exception { */ @Test public void test_getPreviewSource_protected() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " add(button);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + add(button); + } + }"""); ComponentInfo button = getJavaInfoByName("button"); // - assertEquals( - getSourceDQ( - "...", - " protected String getButtonName() {", - " return button.getName();", - " }", - " protected void setButtonName(String name) {", - " button.setName(name);", - " }", - "..."), - call_getPreview(button, "name", "buttonName", false)); + assertEquals(""" + ... + protected String getButtonName() { + return button.getName(); + } + protected void setButtonName(String name) { + button.setName(name); + } + ... + """, call_getPreview(button, "name", "buttonName", false)); } private static String call_getPreview(JavaInfo component, @@ -309,30 +300,30 @@ private static String call_getPreview(JavaInfo component, */ @Test public void test_expose_String() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " add(button);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + add(button); + } + }"""); ComponentInfo button = getJavaInfoByName("button"); // call_expose(button, "name", "buttonName", true); - assertEditor( - "public class Test extends JPanel {", - " private JButton button;", - " public Test() {", - " button = new JButton();", - " add(button);", - " }", - " public String getButtonName() {", - " return button.getName();", - " }", - " public void setButtonName(String name) {", - " button.setName(name);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private JButton button; + public Test() { + button = new JButton(); + add(button); + } + public String getButtonName() { + return button.getName(); + } + public void setButtonName(String name) { + button.setName(name); + } + }"""); } /** @@ -340,42 +331,40 @@ public void test_expose_String() throws Exception { */ @Test public void test_expose_StringArray() throws Exception { - setFileContentSrc( - "test/MyButton.java", - getTestSource( - "public class MyButton extends JButton {", - " public String[] getItems() {", - " return null;", - " }", - " public void setItems(String[] items) {", - " }", - "}")); + setFileContentSrc("test/MyButton.java", getTestSource(""" + public class MyButton extends JButton { + public String[] getItems() { + return null; + } + public void setItems(String[] items) { + } + }""")); waitForAutoBuild(); // parse - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + } + }"""); ComponentInfo button = getJavaInfoByName("button"); // call_expose(button, "items", "buttonItems", true); - assertEditor( - "public class Test extends JPanel {", - " private MyButton button;", - " public Test() {", - " button = new MyButton();", - " add(button);", - " }", - " public String[] getButtonItems() {", - " return button.getItems();", - " }", - " public void setButtonItems(String[] items) {", - " button.setItems(items);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private MyButton button; + public Test() { + button = new MyButton(); + add(button); + } + public String[] getButtonItems() { + return button.getItems(); + } + public void setButtonItems(String[] items) { + button.setItems(items); + } + }"""); } private static void call_expose(JavaInfo component, @@ -395,13 +384,13 @@ private static void call_expose(JavaInfo component, //////////////////////////////////////////////////////////////////////////// @Test public void test_animateDialog() throws Exception { - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " add(button);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + add(button); + } + }"""); ComponentInfo button = getJavaInfoByName("button"); assertNotNull(button); // prepare action @@ -442,20 +431,20 @@ public void accept(SWTBot bot) { okButton.click(); } }); - assertEditor( - "public class Test extends JPanel {", - " private JButton button;", - " public Test() {", - " button = new JButton();", - " add(button);", - " }", - " public String getMyText() {", - " return button.getText();", - " }", - " public void setMyText(String text) {", - " button.setText(text);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private JButton button; + public Test() { + button = new JButton(); + add(button); + } + public String getMyText() { + return button.getText(); + } + public void setMyText(String text) { + button.setText(text); + } + }"""); } //////////////////////////////////////////////////////////////////////////// diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/PropertyCategoryProvidersTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/PropertyCategoryProvidersTest.java index bb43d782c8..393c89031d 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/PropertyCategoryProvidersTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/PropertyCategoryProvidersTest.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 @@ -70,13 +70,12 @@ public void test_fromProperty() throws Exception { @Test public void test_forcedByUser() throws Exception { PropertyCategoryProvider provider = PropertyCategoryProviders.forcedByUser(); - 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() { + } + }"""); Property property = panel.getPropertyByTitle("background"); // no forced initially assertSame(null, provider.getCategory(property)); @@ -152,13 +151,12 @@ public PropertyCategory getCategory(Property property) { @Test public void test_def() throws Exception { PropertyCategoryProvider provider = PropertyCategoryProviders.def(); - 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() { + } + }"""); Property property = panel.getPropertyByTitle("background"); // NORMAL initially assertSame(PropertyCategory.NORMAL, provider.getCategory(property)); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/PropertyManagerTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/PropertyManagerTest.java index b2a904fcc5..cb5aee7c97 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/PropertyManagerTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/PropertyManagerTest.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 @@ -66,13 +66,12 @@ public void test_unknownProperty() throws Exception { */ @Test public void test_GenericProperty() 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() { + } + }"""); Property property = panel.getPropertyByTitle("background"); // "normal" initially assertSame(null, PropertyManager.getCategoryForced(property)); @@ -104,13 +103,12 @@ private void checkCategory(Property property, PropertyCategory category) { */ @Test public void test_GenericProperty2() 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() { + } + }"""); Property property = panel.getPropertyByTitle("background"); // "preferred" from previous test assertSame(PropertyCategory.PREFERRED, PropertyManager.getCategory(property)); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/PropertyTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/PropertyTest.java index b2194a7066..2e0154dc2c 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/PropertyTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/PropertyTest.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 @@ -82,13 +82,12 @@ public void test_unknown() throws Exception { */ @Test public void test_JavaProperty_getJavaInfo() 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() { + } + }"""); JavaProperty property = (JavaProperty) panel.getPropertyByTitle("enabled"); // assertSame(panel, property.getObjectInfo()); @@ -101,13 +100,12 @@ public void test_JavaProperty_getJavaInfo() throws Exception { */ @Test public void test_JavaProperty_getTitle() 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() { + } + }"""); JavaProperty property = (JavaProperty) panel.getPropertyByTitle("enabled"); // default title assertEquals("enabled", property.getTitle()); @@ -127,17 +125,16 @@ public void test_JavaProperty_getTitle() throws Exception { */ @Test public void test_GenericPropertyComposite() throws Exception { - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " JButton button_1 = new JButton('111');", - " add(button_1);", - " //", - " JButton button_2 = new JButton('222');", - " add(button_2);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + JButton button_1 = new JButton("111"); + add(button_1); + // + JButton button_2 = new JButton("222"); + add(button_2); + } + }"""); ComponentInfo button_1 = panel.getChildrenComponents().get(0); ComponentInfo button_2 = panel.getChildrenComponents().get(1); // "icon" property @@ -189,16 +186,16 @@ public void test_GenericPropertyComposite() throws Exception { compositeProperty.setValue("333"); assertEquals("333", compositeProperty.getValue()); assertEquals("\"333\"", m_lastEditor.getSource(compositeProperty.getExpression())); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JButton button_1 = new JButton('333');", - " add(button_1);", - " //", - " JButton button_2 = new JButton('333');", - " add(button_2);", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JButton button_1 = new JButton("333"); + add(button_1); + // + JButton button_2 = new JButton("333"); + add(button_2); + } + }"""); } // setExpression() { @@ -206,16 +203,16 @@ public void test_GenericPropertyComposite() throws Exception { compositeProperty.setExpression(StringConverter.INSTANCE.toJavaSource(panel, value), value); assertEquals("444", compositeProperty.getValue()); assertEquals("\"444\"", m_lastEditor.getSource(compositeProperty.getExpression())); - assertEditor( - "class Test extends JPanel {", - " Test() {", - " JButton button_1 = new JButton('444');", - " add(button_1);", - " //", - " JButton button_2 = new JButton('444');", - " add(button_2);", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + JButton button_1 = new JButton("444"); + add(button_1); + // + JButton button_2 = new JButton("444"); + add(button_2); + } + }"""); } } } @@ -314,13 +311,12 @@ public Class getType() { */ @Test public void test_GenericPropertyImpl_copyConstructor() 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() { + } + }"""); // prepare "enabled" property GenericPropertyImpl enabledProperty = (GenericPropertyImpl) panel.getPropertyByTitle("enabled"); assertNotNull(enabledProperty); @@ -345,13 +341,12 @@ public void test_GenericPropertyImpl_copyConstructor() throws Exception { */ @Test public void test_GenericPropertyImpl_copyConstructor2() 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() { + } + }"""); // prepare "enabled" property GenericPropertyImpl enabledProperty = (GenericPropertyImpl) panel.getPropertyByTitle("enabled"); assertNotNull(enabledProperty); @@ -376,14 +371,13 @@ public void test_GenericPropertyImpl_copyConstructor2() throws Exception { */ @Test public void test_GenericPropertyImpl_copyConstructor_copyType() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " add(new JButton('a'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + add(new JButton("a")); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // prepare property GenericPropertyImpl textProperty = @@ -407,13 +401,12 @@ public void test_GenericPropertyImpl_copyConstructor_copyType() throws Exception */ @Test public void test_GenericPropertyImpl_setValue_getValue_withoutRefresh() 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(); panel.startEdit(); // use "name" property @@ -441,13 +434,12 @@ public void test_GenericPropertyImpl_setValue_getValue_withoutRefresh() throws E */ @Test public void test_GenericPropertyImpl_setValueUNKNOWN_getValue_withRefresh() 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(); // use "name" property GenericProperty property = (GenericProperty) panel.getPropertyByTitle("name"); @@ -474,25 +466,24 @@ public void test_GenericPropertyImpl_setValueUNKNOWN_getValue_withRefresh() thro */ @Test public void test_GenericPropertyImpl_setExpression() 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(); // use "toolTipText" property GenericProperty property = (GenericProperty) panel.getPropertyByTitle("toolTipText"); // set expression property.setExpression("\"name: \" + %this%.getName()", Property.UNKNOWN_VALUE); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " setToolTipText('name: ' + getName());", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + setToolTipText("name: " + getName()); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -507,13 +498,12 @@ public void test_GenericPropertyImpl_setExpression() throws Exception { */ @Test public void test_GenericProperty_valueValidation_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() { + } + }"""); Property enabledProperty = panel.getPropertyByTitle("enabled"); // add listener that prevents "enabled" modification panel.addBroadcastListener(new GenericPropertySetValue() { @@ -525,12 +515,12 @@ public void invoke(GenericPropertyImpl property, Object[] value, boolean[] shoul }); // try to set value enabledProperty.setValue(Boolean.FALSE); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); } /** @@ -540,13 +530,12 @@ public void invoke(GenericPropertyImpl property, Object[] value, boolean[] shoul */ @Test public void test_GenericProperty_valueValidation_2() 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() { + } + }"""); Property enabledProperty = panel.getPropertyByTitle("enabled"); // add listener that on "enabled" modification modifies also "visible" panel.addBroadcastListener(new GenericPropertySetValue() { @@ -560,14 +549,14 @@ public void invoke(GenericPropertyImpl property, Object[] value, boolean[] shoul }); // try to set value enabledProperty.setValue(Boolean.FALSE); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(false);", - " setVisible(false);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + setEnabled(false); + setVisible(false); + } + }"""); } /** @@ -577,13 +566,12 @@ public void invoke(GenericPropertyImpl property, Object[] value, boolean[] shoul */ @Test public void test_GenericProperty_expressionValidation_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() { + } + }"""); final GenericProperty enabledProperty = (GenericProperty) panel.getPropertyByTitle("enabled"); final GenericProperty visibleProperty = (GenericProperty) panel.getPropertyByTitle("visible"); // add listener that prevents "enabled" modification @@ -598,21 +586,21 @@ public void setPropertyExpression(GenericPropertyImpl property, }); // try to set value for "enabled", ignored enabledProperty.setExpression("false", Property.UNKNOWN_VALUE); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); // set value for "visible", works visibleProperty.setExpression("false", Property.UNKNOWN_VALUE); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " setVisible(false);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + setVisible(false); + } + }"""); } /** @@ -620,13 +608,12 @@ public void setPropertyExpression(GenericPropertyImpl property, */ @Test public void test_GenericProperty_propertyValueWasSet() 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() { + } + }"""); final GenericProperty enabledProperty = (GenericProperty) panel.getPropertyByTitle("enabled"); final AtomicBoolean wasFired = new AtomicBoolean(); // add listener @@ -642,34 +629,34 @@ public void propertyValueWasSet(GenericPropertyImpl property) throws Exception { wasFired.set(false); enabledProperty.setValue(false); assertTrue(wasFired.get()); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(false);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + setEnabled(false); + } + }"""); // set value for "enabled" to "true" wasFired.set(false); enabledProperty.setValue(true); assertTrue(wasFired.get()); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); // set value for "enabled" to "false" wasFired.set(false); enabledProperty.setExpression("false", Property.UNKNOWN_VALUE); assertTrue(wasFired.get()); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(false);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + setEnabled(false); + } + }"""); } /** @@ -678,13 +665,12 @@ public void propertyValueWasSet(GenericPropertyImpl property) throws Exception { */ @Test public void test_GenericProperty_getValue_expressionListener() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(true);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setEnabled(true); + } + }"""); panel.refresh(); final GenericProperty enabledProperty = (GenericProperty) panel.getPropertyByTitle("enabled"); // initially normal, boolean value @@ -710,13 +696,12 @@ public void invoke(GenericPropertyImpl property, Expression expression, Object[] */ @Test public void test_GenericProperty_getValue_unconditionaListener_String() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(true);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setEnabled(true); + } + }"""); panel.refresh(); final GenericProperty enabledProperty = (GenericProperty) panel.getPropertyByTitle("enabled"); // initially normal, boolean value @@ -742,13 +727,12 @@ public void invoke(GenericPropertyImpl property, Object[] value) throws Exceptio */ @Test public void test_GenericProperty_getValue_unconditionaListener_null() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(true);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setEnabled(true); + } + }"""); panel.refresh(); final GenericProperty enabledProperty = (GenericProperty) panel.getPropertyByTitle("enabled"); // initially normal, boolean value @@ -772,46 +756,41 @@ public void invoke(GenericPropertyImpl property, Object[] value) throws Exceptio */ @Test public void test_defaultPropertyValue_ignoreAccessor() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public int getFoo() {", - " return 5;", - " }", - " public void setFoo(int foo) {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " ", - "")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public int getFoo() { + return 5; + } + public void setFoo(int foo) { + } + }""")); + setFileContentSrc("test/MyPanel.wbp-component.xml", """ + + + + + + """); waitForAutoBuild(); // - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); Property property = panel.getPropertyByTitle("foo"); assertEquals(2, property.getValue()); // set new value (ignoring that it is default value of accessor) property.setValue(5); assertEquals(5, property.getValue()); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(5);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(5); + } + }"""); } /** @@ -821,35 +800,30 @@ public void test_defaultPropertyValue_ignoreAccessor() throws Exception { */ @Test public void test_defaultPropertyValue_noDefaultValue_forConstructor() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public int foo;", - " public MyPanel(int foo) {", - " this.foo = foo;", - " }", - "}")); - setFileContentSrc( - "test/MyPanel.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " ", - " ", - " ", - "")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public int foo; + public MyPanel(int foo) { + this.foo = foo; + } + }""")); + setFileContentSrc("test/MyPanel.wbp-component.xml", """ + + + + + + + + """); waitForAutoBuild(); // - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " super(2);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + super(2); + } + }"""); Property property = panel.getPropertyByTitle("foo"); assertEquals(2, property.getValue()); // set same value @@ -864,22 +838,19 @@ public void test_defaultPropertyValue_noDefaultValue_forConstructor() throws Exc */ @Test public void test_defaultPropertyValue_noDefaultValue() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setFoo(int foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setFoo(int foo) { + } + }""")); waitForAutoBuild(); // - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); assertSame(Property.UNKNOWN_VALUE, panel.getPropertyByTitle("foo").getValue()); } @@ -888,13 +859,12 @@ public void test_defaultPropertyValue_noDefaultValue() throws Exception { */ @Test public void test_GenericProperty_getType() 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() { + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("enabled"); assertSame(boolean.class, property.getType()); } @@ -906,14 +876,13 @@ public void test_GenericProperty_getType() throws Exception { */ @Test public void test_GenericProperty_getType_forConstructor_subProperty() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " add(new JButton('a'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + add(new JButton("a")); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // GenericProperty property = @@ -932,20 +901,16 @@ public void test_GenericProperty_getType_forConstructor_subProperty() throws Exc */ @Test public void test_setterAccessor() throws Exception { - JavaInfo panel = - parseSource( - "test", - "Test.java", - getSourceDQ( - "package test;", - "import java.awt.*;", - "import javax.swing.*;", - "class Test {", - " public static void main(String args[]) {", - " JPanel panel = new JPanel();", - " panel.setEnabled(false);", - " }", - "}")); + JavaInfo panel = parseSource("test", "Test.java", """ + package test; + import java.awt.*; + import javax.swing.*; + class Test { + public static void main(String args[]) { + JPanel panel = new JPanel(); + panel.setEnabled(false); + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("enabled"); assertNotNull(property); assertSame(panel, property.getJavaInfo()); @@ -1060,16 +1025,16 @@ private static void check_setterAccessor(JavaInfo panel, AstEditor editor = panel.getEditor(); assertAST(editor); // - String[] innerLines = setSource != null ? new String[]{" " + setSource} : null; - String expectedSource = - getSource3(new String[]{ - "package test;", - "import java.awt.*;", - "import javax.swing.*;", - "class Test {", - " public static void main(String args[]) {", - " JPanel panel = new JPanel();"}, innerLines, new String[]{" }", "}"}); - assertEquals(expectedSource, editor.getSource()); + String innerLines = setSource != null ? "\n " + setSource : ""; + assertEquals(""" + package test; + import java.awt.*; + import javax.swing.*; + class Test { + public static void main(String args[]) { + JPanel panel = new JPanel();%s + } + }""".formatted(innerLines), editor.getSource()); assertRelatedNodes(panel, relatedNodes); // check property assertEquals(modified, property.isModified()); @@ -1085,20 +1050,16 @@ private static void check_setterAccessor(JavaInfo panel, */ @Test public void test_constructorAccessor_1() throws Exception { - JavaInfo button = - parseSource( - "test", - "Test.java", - getSourceDQ( - "package test;", - "import java.awt.*;", - "import javax.swing.*;", - "class Test {", - " public static void main(String args[]) {", - " JButton button = new JButton();", - " button.setText('abc');", - " }", - "}")); + JavaInfo button = parseSource("test", "Test.java", """ + package test; + import java.awt.*; + import javax.swing.*; + class Test { + public static void main(String args[]) { + JButton button = new JButton(); + button.setText("abc"); + } + }"""); GenericProperty property = (GenericProperty) button.getPropertyByTitle("text"); assertNotNull(property); // initial checks @@ -1117,28 +1078,26 @@ public void test_constructorAccessor_1() throws Exception { // set value, should be changed using setText() { property.setValue("12345"); - check_constructorAccessor(button, new String[]{ - " JButton button = new JButton();", - " button.setText(\"12345\");"}, new String[]{ - "new JButton()", - "button.setText(\"12345\")"}); + check_constructorAccessor( + button, + new String[]{"JButton button = new JButton();", "button.setText(\"12345\");"}, + new String[]{"new JButton()", "button.setText(\"12345\")"}); } // remove value, setText() should be removed { property.setValue(Property.UNKNOWN_VALUE); check_constructorAccessor( button, - new String[]{" JButton button = new JButton();"}, + new String[]{"JButton button = new JButton();"}, new String[]{"new JButton()"}); } // set value, setText() should be added { property.setValue("12345"); - check_constructorAccessor(button, new String[]{ - " JButton button = new JButton();", - " button.setText(\"12345\");"}, new String[]{ - "new JButton()", - "button.setText(\"12345\")"}); + check_constructorAccessor( + button, + new String[]{"JButton button = new JButton();", "button.setText(\"12345\");"}, + new String[]{"new JButton()", "button.setText(\"12345\")"}); } } @@ -1147,19 +1106,15 @@ public void test_constructorAccessor_1() throws Exception { */ @Test public void test_constructorAccessor_2() throws Exception { - JavaInfo button = - parseSource( - "test", - "Test.java", - getSourceDQ( - "package test;", - "import java.awt.*;", - "import javax.swing.*;", - "class Test {", - " public static void main(String args[]) {", - " JButton button = new JButton('abc');", - " }", - "}")); + JavaInfo button = parseSource("test", "Test.java", """ + package test; + import java.awt.*; + import javax.swing.*; + class Test { + public static void main(String args[]) { + JButton button = new JButton("abc"); + } + }"""); GenericProperty property = (GenericProperty) button.getPropertyByTitle("text"); assertNotNull(property); // check accessors @@ -1182,7 +1137,7 @@ public void test_constructorAccessor_2() throws Exception { property.setValue("12345"); check_constructorAccessor( button, - new String[]{" JButton button = new JButton(\"12345\");"}, + new String[]{"JButton button = new JButton(\"12345\");"}, new String[]{"new JButton(\"12345\")"}); } // reset to default @@ -1191,7 +1146,7 @@ public void test_constructorAccessor_2() throws Exception { property.setValue(Property.UNKNOWN_VALUE); check_constructorAccessor( button, - new String[]{" JButton button = new JButton((String) null);"}, + new String[]{"JButton button = new JButton((String) null);"}, new String[]{"new JButton((String) null)"}); } } @@ -1199,18 +1154,20 @@ public void test_constructorAccessor_2() throws Exception { private static void check_constructorAccessor(JavaInfo button, String[] lines, String[] relatedNodes) throws Exception { - String[] lines_prefix = - new String[]{ - "package test;", - "import java.awt.*;", - "import javax.swing.*;", - "class Test {", - " public static void main(String args[]) {"}; - String[] lines_suffix = new String[]{" }", "}"}; - // AstEditor editor = button.getEditor(); assertAST(editor); - assertEquals(getSource3(lines_prefix, lines, lines_suffix), editor.getSource()); + StringBuilder innerLines = new StringBuilder(); + for (String line : lines) { + innerLines.append("\n ").append(line); + } + assertEquals(""" + package test; + import java.awt.*; + import javax.swing.*; + class Test { + public static void main(String args[]) {%s + } + }""".formatted(innerLines), editor.getSource()); assertRelatedNodes(button, relatedNodes); } @@ -1225,24 +1182,21 @@ private static void check_constructorAccessor(JavaInfo button, */ @Test public void test_StandardBeanPropertiesRule_twoSettersWithSameName() throws Exception { - setFileContentSrc( - "test/MyButton.java", - getTestSource( - "public class MyButton extends JButton {", - " public void setFoo(String text) {", - " }", - " public void setFoo(String[] text) {", - " }", - "}")); + setFileContentSrc("test/MyButton.java", getTestSource(""" + public class MyButton extends JButton { + public void setFoo(String text) { + } + public void setFoo(String[] text) { + } + }""")); waitForAutoBuild(); // - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new MyButton());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new MyButton()); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // assertNotNull(button.getPropertyByTitle("foo(java.lang.String)")); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/StandardConvertersTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/StandardConvertersTest.java index 64cbdc679d..b04f4b7478 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/StandardConvertersTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/StandardConvertersTest.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 @@ -102,33 +102,30 @@ public void test_property_String() throws Exception { */ private void check_converter(String typeName, Object value, String expectedSource) throws Exception { - setFileContentSrc( - "test/Base.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Base extends JPanel {", - " public void setValue(" + typeName + " value) {", - " }", - "}")); + setFileContentSrc("test/Base.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Base extends JPanel { + public void setValue(%s value) { + } + }""".formatted(typeName))); waitForAutoBuild(); // - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public final class Test extends Base {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public final class Test extends Base { + public Test() { + } + }"""); Property property = panel.getPropertyByTitle("value"); property.setValue(value); - assertEditor( - "// filler filler filler", - "public final class Test extends Base {", - " public Test() {", - " setValue(" + expectedSource + ");", - " }", - "}"); + assertEditor(""" + // filler filler filler + public final class Test extends Base { + public Test() { + setValue(%s); + } + }""".formatted(expectedSource)); } //////////////////////////////////////////////////////////////////////////// @@ -284,13 +281,12 @@ public void test_BooleanObjectConverter_null() throws Exception { @Test public void test_BooleanObjectConverter_forJava5() 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() { + } + }"""); ExpressionConverter converter = BooleanObjectConverter.INSTANCE; assertEquals("(Boolean) null", converter.toJavaSource(panel, null)); assertEquals("false", converter.toJavaSource(panel, false)); @@ -318,13 +314,12 @@ public void test_ByteObjectConverter_null() throws Exception { @Test public void test_ByteObjectConverter_forJava5() 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() { + } + }"""); ExpressionConverter converter = ByteObjectConverter.INSTANCE; assertEquals("(byte) 1", converter.toJavaSource(panel, Byte.valueOf((byte) 1))); assertEquals("(byte) -1", converter.toJavaSource(panel, Byte.valueOf((byte) -1))); @@ -334,13 +329,12 @@ public void test_ByteObjectConverter_forJava5() throws Exception { @Test public void test_ByteObjectConverter_forJava5_disableBoxing() throws Exception { m_javaProject.setOption(JavaCore.COMPILER_PB_AUTOBOXING, "error"); - 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() { + } + }"""); ExpressionConverter converter = ByteObjectConverter.INSTANCE; assertEquals("Byte.valueOf((byte) 1)", converter.toJavaSource(panel, Byte.valueOf((byte) 1))); assertEquals("Byte.valueOf((byte) -1)", converter.toJavaSource(panel, Byte.valueOf((byte) -1))); @@ -359,13 +353,12 @@ public void test_ShortObjectConverter_null() throws Exception { @Test public void test_ShortObjectConverter_forJava5() 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() { + } + }"""); ExpressionConverter converter = ShortObjectConverter.INSTANCE; assertEquals("(short) 1", converter.toJavaSource(panel, Short.valueOf((short) 1))); assertEquals("(short) -1", converter.toJavaSource(panel, Short.valueOf((short) -1))); @@ -393,13 +386,12 @@ public void test_IntegerObjectConverter_null() throws Exception { @Test public void test_IntegerObjectConverter_forJava5() 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() { + } + }"""); ExpressionConverter converter = IntegerObjectConverter.INSTANCE; assertEquals("1", converter.toJavaSource(panel, Integer.valueOf(1))); assertEquals("-1", converter.toJavaSource(panel, Integer.valueOf(-1))); @@ -429,13 +421,12 @@ public void test_LongObjectConverter_null() throws Exception { @Test public void test_LongObjectConverter_forJava5_disableBoxing() throws Exception { m_javaProject.setOption(JavaCore.COMPILER_PB_AUTOBOXING, "error"); - 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() { + } + }"""); ExpressionConverter converter = LongObjectConverter.INSTANCE; assertEquals("Long.valueOf(1L)", converter.toJavaSource(panel, Long.valueOf(1))); assertEquals("Long.valueOf(-1L)", converter.toJavaSource(panel, Long.valueOf(-1))); @@ -464,13 +455,12 @@ public void test_DoubleObjectConverter_null() throws Exception { @Test public void test_DoubleObjectConverter_forJava5() 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() { + } + }"""); ExpressionConverter converter = DoubleObjectConverter.INSTANCE; assertEquals("1.2", converter.toJavaSource(panel, Double.valueOf(1.2))); assertEquals("-1.2", converter.toJavaSource(panel, Double.valueOf(-1.2))); @@ -480,13 +470,12 @@ public void test_DoubleObjectConverter_forJava5() throws Exception { @Test public void test_DoubleObjectConverter_forJava5_disableBoxing() throws Exception { m_javaProject.setOption(JavaCore.COMPILER_PB_AUTOBOXING, "error"); - 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() { + } + }"""); ExpressionConverter converter = DoubleObjectConverter.INSTANCE; assertEquals("Double.valueOf(1.2)", converter.toJavaSource(panel, Double.valueOf(1.2))); assertEquals("Double.valueOf(-1.2)", converter.toJavaSource(panel, Double.valueOf(-1.2))); @@ -517,13 +506,12 @@ public void test_StringConverter() throws Exception { @Test public void test_StringConverter_hasFile_withCharset() throws Exception { ExpressionConverter converter = StringConverter.INSTANCE; - 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() { + } + }"""); IFile file = (IFile) panel.getEditor().getModelUnit().getUnderlyingResource(); String value = "\u0410\u0411\u0412"; // ISO-8859-1, encoded diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/TabOrderPropertyTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/TabOrderPropertyTest.java index d465fa72ba..3d5b4082a2 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/TabOrderPropertyTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/TabOrderPropertyTest.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 @@ -50,13 +50,12 @@ public class TabOrderPropertyTest extends SwingModelTest { //////////////////////////////////////////////////////////////////////////// @Test public void test_common() 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); + } + }"""); TestTabOrderProperty property = new TestTabOrderProperty(panel, null, null, null, null); assertEquals("tab order", property.getTitle()); assertFalse(property.isModified()); @@ -64,13 +63,12 @@ public void test_common() throws Exception { @Test public void test_tooltip() 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); + } + }"""); // create property without tooltip TestTabOrderProperty property = new TestTabOrderProperty(panel, null, null, null, null); // @@ -90,16 +88,15 @@ public void test_tooltip() throws Exception { @Test public void test_noValue() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " add(button);", - " JLabel label = new JLabel();", - " add(label);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + add(button); + JLabel label = new JLabel(); + add(label); + } + }"""); panel.refresh(); // assertEquals(2, panel.getChildrenComponents().size()); @@ -128,21 +125,20 @@ public void test_noValue() throws Exception { @Test public void test_value() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JButton button = new JButton();", - " add(button);", - " JComboBox combo = new JComboBox();", - " add(combo);", - " JLabel label = new JLabel();", - " add(label);", - " setTabOrder(new JComponent[]{label, button});", - " }", - " public void setTabOrder(JComponent []orders) {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JButton button = new JButton(); + add(button); + JComboBox combo = new JComboBox(); + add(combo); + JLabel label = new JLabel(); + add(label); + setTabOrder(new JComponent[]{label, button}); + } + public void setTabOrder(JComponent []orders) { + } + }"""); panel.refresh(); // assertEquals(3, panel.getChildrenComponents().size()); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/AccessorUtilsTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/AccessorUtilsTest.java index ca96a91577..f17075dfd5 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/AccessorUtilsTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/AccessorUtilsTest.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 @@ -43,41 +43,37 @@ public class AccessorUtilsTest extends SwingModelTest { // //////////////////////////////////////////////////////////////////////////// private Class getAccessObjectClass() throws Exception { - setFileContentSrc( - "test/AccessObject.java", - getSourceDQ( - "package test;", - "public class AccessObject {", - " public int publicField;", - " protected int protectedField;", - " public void publicMethod() {", - " }", - " protected void protectedMethod() {", - " }", - "}")); + setFileContentSrc("test/AccessObject.java", """ + package test; + public class AccessObject { + public int publicField; + protected int protectedField; + public void publicMethod() { + } + protected void protectedMethod() { + } + }"""); waitForAutoBuild(); return m_lastLoader.loadClass("test.AccessObject"); } private Class getTooltipObjectClass() throws Exception { - setFileContentSrc( - "test/TooltipObject.java", - getSourceDQ( - "package test;", - "public class TooltipObject {", - " /**", - " * Some javadoc for field.", - " */", - " public int javadocField;", - " public int emptyField;", - " /**", - " * Some javadoc for method.", - " */", - " public void javadocMethod() {", - " }", - " public void emptyMethod() {", - " }", - "}")); + setFileContentSrc("test/TooltipObject.java", """ + package test; + public class TooltipObject { + /** + * Some javadoc for field. + */ + public int javadocField; + public int emptyField; + /** + * Some javadoc for method. + */ + public void javadocMethod() { + } + public void emptyMethod() { + } + }"""); waitForAutoBuild(); return m_lastLoader.loadClass("test.TooltipObject"); } @@ -92,12 +88,12 @@ private Class getTooltipObjectClass() throws Exception { */ @Test public void test_IAccessibleExpressionAccessor_forMethod_public() throws Exception { - parseContainer( - "// filler filler filler", - "public final class Test extends JPanel {", - " public Test() {", - " }", - "}"); + parseContainer(""" + // filler filler filler + public final class Test extends JPanel { + public Test() { + } + }"""); // check IAccessibleExpressionAccessor Method method = ReflectionUtils.getMethod(getAccessObjectClass(), "publicMethod"); IAccessibleExpressionAccessor accessor = @@ -114,13 +110,12 @@ public void test_IAccessibleExpressionAccessor_forMethod_public() throws Excepti @Test public void test_IAccessibleExpressionAccessor_forMethod_protected() throws Exception { // parse - 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()); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // check IAccessibleExpressionAccessor Method method = ReflectionUtils.getMethod(getAccessObjectClass(), "protectedMethod"); @@ -140,12 +135,12 @@ public void test_IAccessibleExpressionAccessor_forMethod_protected() throws Exce */ @Test public void test_IAccessibleExpressionAccessor_forField_public() throws Exception { - parseContainer( - "// filler filler filler", - "public final class Test extends JPanel {", - " public Test() {", - " }", - "}"); + parseContainer(""" + // filler filler filler + public final class Test extends JPanel { + public Test() { + } + }"""); // check IAccessibleExpressionAccessor Field field = ReflectionUtils.getFieldByName(getAccessObjectClass(), "publicField"); IAccessibleExpressionAccessor accessor = @@ -162,13 +157,12 @@ public void test_IAccessibleExpressionAccessor_forField_public() throws Exceptio @Test public void test_IAccessibleExpressionAccessor_forField_protected() throws Exception { // prepare JavaInfo - 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()); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // check IAccessibleExpressionAccessor Field field = ReflectionUtils.getFieldByName(getAccessObjectClass(), "protectedField"); @@ -188,13 +182,12 @@ public void test_IAccessibleExpressionAccessor_forField_protected() throws Excep */ @Test public void test_getExposableExpressionAccessor() 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() { + } + }"""); { Property property = panel.getPropertyByTitle("Class"); IExposableExpressionAccessor accessor = @@ -221,13 +214,12 @@ public void test_getExposableExpressionAccessor() throws Exception { */ @Test public void test_PropertyTooltipProvider_forMethod_noJavadoc() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public final class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public final class Test extends JPanel { + public Test() { + } + }"""); Property property = panel.getPropertyByTitle("enabled"); // check PropertyTooltipProvider Method method = ReflectionUtils.getMethod(getTooltipObjectClass(), "emptyMethod"); @@ -241,13 +233,12 @@ public void test_PropertyTooltipProvider_forMethod_noJavadoc() throws Exception */ @Test public void test_PropertyTooltipProvider_forMethod_withJavadoc() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public final class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public final class Test extends JPanel { + public Test() { + } + }"""); Property property = panel.getPropertyByTitle("enabled"); // check PropertyTooltipProvider Method method = ReflectionUtils.getMethod(getTooltipObjectClass(), "javadocMethod"); @@ -266,13 +257,12 @@ public void test_PropertyTooltipProvider_forMethod_withJavadoc() throws Exceptio */ @Test public void test_PropertyTooltipProvider_forField_noJavadoc() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public final class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public final class Test extends JPanel { + public Test() { + } + }"""); Property property = panel.getPropertyByTitle("enabled"); // check PropertyTooltipProvider Field method = ReflectionUtils.getFieldByName(getTooltipObjectClass(), "emptyField"); @@ -286,13 +276,12 @@ public void test_PropertyTooltipProvider_forField_noJavadoc() throws Exception { */ @Test public void test_PropertyTooltipProvider_forField_withJavadoc() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public final class Test extends JPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public final class Test extends JPanel { + public Test() { + } + }"""); Property property = panel.getPropertyByTitle("enabled"); // check PropertyTooltipProvider Field method = ReflectionUtils.getFieldByName(getTooltipObjectClass(), "javadocField"); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/ConstructorAccessorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/ConstructorAccessorTest.java index c1a646f591..9a1cead793 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/ConstructorAccessorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/ConstructorAccessorTest.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 @@ -41,13 +41,12 @@ public class ConstructorAccessorTest extends SwingModelTest { //////////////////////////////////////////////////////////////////////////// @Test public void test_0() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new JButton('text'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new JButton("text")); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); GenericProperty property = (GenericProperty) button.getPropertyByTitle("text"); ConstructorAccessor accessor = @@ -64,25 +63,24 @@ public void test_0() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_setExpression_newValue() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new JButton('text'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new JButton("text")); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); GenericProperty property = (GenericProperty) button.getPropertyByTitle("text"); ConstructorAccessor accessor = (ConstructorAccessor) getGenericPropertyAccessors(property).get(1); // check assertTrue(accessor.setExpression(button, "\"new text\"")); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " add(new JButton('new text'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + add(new JButton("new text")); + } + }"""); } /** @@ -90,25 +88,24 @@ public void test_setExpression_newValue() throws Exception { */ @Test public void test_setExpression_nullValue() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new JButton('text'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new JButton("text")); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); GenericProperty property = (GenericProperty) button.getPropertyByTitle("text"); ConstructorAccessor accessor = (ConstructorAccessor) getGenericPropertyAccessors(property).get(1); // set "null", default value is used assertTrue(accessor.setExpression(button, null)); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " add(new JButton((String) null));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + add(new JButton((String) null)); + } + }"""); } /** @@ -116,24 +113,23 @@ public void test_setExpression_nullValue() throws Exception { */ @Test public void test_setExpression_nullValue_noDefault() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new JButton('text'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new JButton("text")); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // create accessor ConstructorAccessor accessor = new ConstructorAccessor(0, null); // set "null", but no default value, so ignored assertFalse(accessor.setExpression(button, null)); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " add(new JButton('text'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + add(new JButton("text")); + } + }"""); } /** @@ -141,26 +137,24 @@ public void test_setExpression_nullValue_noDefault() throws Exception { */ @Test public void test_setExpression_replaceComponent() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public MyPanel(JButton button) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public MyPanel(JButton button) { + } + }""")); waitForAutoBuild(); // parse - parseContainer( - "public class Test extends JPanel {", - " private final JButton button_1 = new JButton();", - " private final JButton button_2 = new JButton();", - " private final MyPanel myPanel = new MyPanel(button_1);", - " public Test() {", - " add(button_1);", - " add(button_2);", - " add(myPanel);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + private final JButton button_1 = new JButton(); + private final JButton button_2 = new JButton(); + private final MyPanel myPanel = new MyPanel(button_1); + public Test() { + add(button_1); + add(button_2); + add(myPanel); + } + }"""); ContainerInfo myPanel = getJavaInfoByName("myPanel"); ComponentInfo button_1 = getJavaInfoByName("button_1"); ComponentInfo button_2 = getJavaInfoByName("button_2"); @@ -182,16 +176,16 @@ public void test_setExpression_replaceComponent() throws Exception { String source = TemplateUtils.format("{0}", button_2); setterAccessor.setExpression(myPanel, source); } - assertEditor( - "public class Test extends JPanel {", - " private final JButton button_1 = new JButton();", - " private final JButton button_2 = new JButton();", - " private final MyPanel myPanel = new MyPanel(button_2);", - " public Test() {", - " add(button_1);", - " add(button_2);", - " add(myPanel);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private final JButton button_1 = new JButton(); + private final JButton button_2 = new JButton(); + private final MyPanel myPanel = new MyPanel(button_2); + public Test() { + add(button_1); + add(button_2); + add(myPanel); + } + }"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/FactoryAccessorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/FactoryAccessorTest.java index d6a4589964..443c5718b0 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/FactoryAccessorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/FactoryAccessorTest.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,14 +39,12 @@ public class FactoryAccessorTest extends SwingModelTest { public void setUp() throws Exception { super.setUp(); if (m_testProject != null) { - setFileContentSrc( - "test/StaticFactory.java", - getTestSource( - "public final class StaticFactory {", - " public static JButton createButton(String text) {", - " return new JButton(text);", - " }", - "}")); + setFileContentSrc("test/StaticFactory.java", getTestSource(""" + public final class StaticFactory { + public static JButton createButton(String text) { + return new JButton(text); + } + }""")); waitForAutoBuild(); } } @@ -58,13 +56,12 @@ public void setUp() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_0() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(StaticFactory.createButton('text'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(StaticFactory.createButton("text")); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); GenericProperty property = (GenericProperty) button.getPropertyByTitle("text"); FactoryAccessor accessor = (FactoryAccessor) getGenericPropertyAccessors(property).get(1); @@ -79,24 +76,23 @@ public void test_0() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_setExpression_newValue() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(StaticFactory.createButton('text'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(StaticFactory.createButton("text")); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); GenericProperty property = (GenericProperty) button.getPropertyByTitle("text"); FactoryAccessor accessor = (FactoryAccessor) getGenericPropertyAccessors(property).get(1); // check assertTrue(accessor.setExpression(button, "\"new text\"")); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " add(StaticFactory.createButton('new text'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + add(StaticFactory.createButton("new text")); + } + }"""); } /** @@ -104,24 +100,23 @@ public void test_setExpression_newValue() throws Exception { */ @Test public void test_setExpression_nullValue() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(StaticFactory.createButton('text'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(StaticFactory.createButton("text")); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); GenericProperty property = (GenericProperty) button.getPropertyByTitle("text"); FactoryAccessor accessor = (FactoryAccessor) getGenericPropertyAccessors(property).get(1); // set "null", default value is used assertTrue(accessor.setExpression(button, null)); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " add(StaticFactory.createButton((String) null));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + add(StaticFactory.createButton((String) null)); + } + }"""); } /** @@ -129,23 +124,22 @@ public void test_setExpression_nullValue() throws Exception { */ @Test public void test_setExpression_nullValue_noDefault() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(StaticFactory.createButton('text'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(StaticFactory.createButton("text")); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // create accessor FactoryAccessor accessor = new FactoryAccessor(0, null); // set "null", but no default value, so ignored assertFalse(accessor.setExpression(button, null)); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " add(StaticFactory.createButton('text'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + add(StaticFactory.createButton("text")); + } + }"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/FieldAccessorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/FieldAccessorTest.java index 9cf95e42ea..5f83dc2a68 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/FieldAccessorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/FieldAccessorTest.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 @@ -27,6 +27,7 @@ import org.eclipse.jdt.core.dom.Assignment; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.util.List; @@ -57,15 +58,14 @@ public void _test_exit() throws Exception { @Test public void test_fieldAccessor() throws Exception { defineMyButton(); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " button.hgap = 1;", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + button.hgap = 1; + add(button); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); GenericProperty property = (GenericProperty) button.getPropertyByTitle("hgap"); // check getValue() @@ -75,41 +75,41 @@ public void test_fieldAccessor() throws Exception { property.setValue(3); assertEquals(3, property.getValue()); assertNotNull(property.getExpression()); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " button.hgap = 3;", - " add(button);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + button.hgap = 3; + add(button); + } + }"""); } // remove property { property.setValue(Property.UNKNOWN_VALUE); assertEquals(0, property.getValue()); assertNull(property.getExpression()); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + } + }"""); } // add property { property.setValue(2); assertEquals(2, property.getValue()); assertNotNull(property.getExpression()); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " button.hgap = 2;", - " add(button);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + button.hgap = 2; + add(button); + } + }"""); } } @@ -123,27 +123,24 @@ public void test_fieldAccessor() throws Exception { */ @Test public void test_0() throws Exception { - setFileContentSrc( - "test/MyComponent.java", - getTestSource( - "public class MyComponent extends JComponent {", - " /**", - " * my documentation", - " */", - " public int field_1 = 1;", - " public double field_2 = 2.0;", - " public MyComponent() {", - " }", - "}")); + setFileContentSrc("test/MyComponent.java", getTestSource(""" + public class MyComponent extends JComponent { + /** + * my documentation + */ + public int field_1 = 1; + public double field_2 = 2.0; + public MyComponent() { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new MyComponent());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new MyComponent()); + } + }"""); ComponentInfo myComponent = panel.getChildrenComponents().get(0); // field_1 { @@ -205,24 +202,21 @@ public void test_0() throws Exception { */ @Test public void test_defaultValue() throws Exception { - setFileContentSrc( - "test/MyButton.java", - getTestSource( - "public class MyButton extends JButton {", - " public String foo;", - " public MyButton(String s) {", - " foo = s;", - " }", - "}")); + setFileContentSrc("test/MyButton.java", getTestSource(""" + public class MyButton extends JButton { + public String foo; + public MyButton(String s) { + foo = s; + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new MyButton('A'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new MyButton("A")); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); Property constructorTextProperty = PropertyUtils.getByPath(button, "Constructor/s"); @@ -232,12 +226,12 @@ public void test_defaultValue() throws Exception { assertEquals("A", fooProperty.getValue()); // set new value in constructor constructorTextProperty.setValue("B"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " add(new MyButton('B'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + add(new MyButton("B")); + } + }"""); assertEquals("B", constructorTextProperty.getValue()); assertEquals("B", fooProperty.getValue()); } @@ -248,25 +242,22 @@ public void test_defaultValue() throws Exception { */ @Test public void test_defaultValue_whenReplacedWithPlaceholder() throws Exception { - setFileContentSrc( - "test/MyButton.java", - getTestSource( - "public class MyButton extends JButton {", - " public String foo;", - " public MyButton() {", - " throw new IllegalStateException();", - " }", - "}")); + setFileContentSrc("test/MyButton.java", getTestSource(""" + public class MyButton extends JButton { + public String foo; + public MyButton() { + throw new IllegalStateException(); + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + } + }"""); panel.refresh(); // ComponentInfo button = getJavaInfoByName("button"); @@ -285,15 +276,14 @@ public void test_defaultValue_whenReplacedWithPlaceholder() throws Exception { @Test public void test_separateAssignment() throws Exception { defineMyButton(); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " button.hgap = 5;", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + button.hgap = 5; + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); GenericProperty property = (GenericProperty) button.getPropertyByTitle("hgap"); @@ -310,14 +300,14 @@ public void test_separateAssignment() throws Exception { // just assignment value should be changed, still same Assignment should be used Assignment newAssignment = (Assignment) property.getExpression().getParent(); assertEquals("button.hgap = 6", m_lastEditor.getSource(newAssignment)); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " button.hgap = 6;", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + button.hgap = 6; + } + }"""); assertSame(oldAssignment, newAssignment); } @@ -327,15 +317,14 @@ public void test_separateAssignment() throws Exception { @Test public void test_sequence_parse() throws Exception { defineMyButton(); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " button.hgap = button.vgap = 5;", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + button.hgap = button.vgap = 5; + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); panel.refresh(); // check that hgap/vgap have value "5" @@ -352,30 +341,29 @@ public void test_sequence_parse() throws Exception { @Test public void test_sequence_modifyLast() throws Exception { defineMyButton(); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " button.hgap = button.vgap = 5;", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + button.hgap = button.vgap = 5; + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // Property vgapProperty = button.getPropertyByTitle("vgap"); assertEquals(5, vgapProperty.getValue()); // vgapProperty.setValue(10); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " button.hgap = 5;", - " button.vgap = 10;", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + button.hgap = 5; + button.vgap = 10; + } + }"""); assertEquals(10, vgapProperty.getValue()); } @@ -385,56 +373,56 @@ public void test_sequence_modifyLast() throws Exception { @Test public void test_sequence_modifyFirst() throws Exception { defineMyButton(); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " button.hgap = button.vgap = 5;", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + button.hgap = button.vgap = 5; + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // Property hgapProperty = button.getPropertyByTitle("hgap"); assertEquals(5, hgapProperty.getValue()); // hgapProperty.setValue(10); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " button.hgap = 10;", - " button.vgap = 5;", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + button.hgap = 10; + button.vgap = 5; + } + }"""); assertEquals(10, hgapProperty.getValue()); } /** * Test for {@link FieldAccessor} with sequence of assignments to "this" fields. */ - /*public void test_fieldAccessor_sequenceThis() throws Exception { - setFileContentSrc("test/MyPanel.java", getTestSource( - "public class MyPanel extends JPanel {", - " public int hgap;", - " public int vgap;", - "}")); - waitForAutoBuild(); - // - ContainerInfo panel = - parseTestSource(new String[]{ - "public class Test extends MyPanel {", - " public Test() {", - " hgap = vgap = 5;", - " }", - "}"}); - panel.refresh(); - // check that hgap/vgap have value "5" - assertEquals(5, ReflectionUtils.getFieldInt(panel, "hgap")); - assertEquals(5, ReflectionUtils.getFieldInt(panel, "vgap")); - }*/ + @Test + @Disabled + public void test_fieldAccessor_sequenceThis() throws Exception { + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public int hgap; + public int vgap; + }""")); + waitForAutoBuild(); + // + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + hgap = vgap = 5; + } + }"""); + panel.refresh(); + // check that hgap/vgap have value "5" + assertEquals(5, ReflectionUtils.getFieldInt(panel.getObject(), "hgap")); + assertEquals(5, ReflectionUtils.getFieldInt(panel.getObject(), "vgap")); + } //////////////////////////////////////////////////////////////////////////// // // IAccessibleExpressionAccessor @@ -445,24 +433,21 @@ public void test_sequence_modifyFirst() throws Exception { */ @Test public void test_IAccessibleExpressionAccessor() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class MyPanel extends JPanel {", - " public int foo;", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class MyPanel extends JPanel { + public int foo; + }""")); waitForAutoBuild(); // parse // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("foo"); FieldAccessor accessor = (FieldAccessor) getGenericPropertyAccessors(property).get(0); // check that IAccessibleExpressionAccessor is available @@ -483,13 +468,11 @@ public void test_IAccessibleExpressionAccessor() throws Exception { * Defines MyButton class. */ private void defineMyButton() throws Exception { - setFileContentSrc( - "test/MyButton.java", - getTestSource( - "public class MyButton extends JButton {", - " public int hgap;", - " public int vgap;", - "}")); + setFileContentSrc("test/MyButton.java", getTestSource(""" + public class MyButton extends JButton { + public int hgap; + public int vgap; + }""")); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/InvocationChildAssociationAccessorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/InvocationChildAssociationAccessorTest.java index 6cf496f0ce..9be0ac42ca 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/InvocationChildAssociationAccessorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/InvocationChildAssociationAccessorTest.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,26 +38,22 @@ public class InvocationChildAssociationAccessorTest extends SwingModelTest { public void setUp() throws Exception { super.setUp(); if (m_testProject != null) { - setFileContentSrc( - "test/MyContainer.java", - getTestSource( - "public class MyContainer extends JPanel {", - " public void addChild(String text, Component component) {", - " add(component);", - " }", - "}")); - setFileContentSrc( - "test/MyContainer.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - "")); + setFileContentSrc("test/MyContainer.java", getTestSource(""" + public class MyContainer extends JPanel { + public void addChild(String text, Component component) { + add(component); + } + }""")); + setFileContentSrc("test/MyContainer.wbp-component.xml", """ + + + + + + + + + """); waitForAutoBuild(); } } @@ -69,13 +65,12 @@ public void setUp() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_0() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyContainer {", - " public Test() {", - " addChild('text', new JButton());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyContainer { + public Test() { + addChild("text", new JButton()); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); InvocationChildAssociationAccessor accessor = new InvocationChildAssociationAccessor(0, "\"\""); // check @@ -89,23 +84,22 @@ public void test_0() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_setExpression_newValue() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyContainer {", - " public Test() {", - " addChild('text', new JButton());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyContainer { + public Test() { + addChild("text", new JButton()); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); InvocationChildAssociationAccessor accessor = new InvocationChildAssociationAccessor(0, "\"\""); // check assertTrue(accessor.setExpression(button, "\"new text\"")); - assertEditor( - "public class Test extends MyContainer {", - " public Test() {", - " addChild('new text', new JButton());", - " }", - "}"); + assertEditor(""" + public class Test extends MyContainer { + public Test() { + addChild("new text", new JButton()); + } + }"""); } /** @@ -113,23 +107,22 @@ public void test_setExpression_newValue() throws Exception { */ @Test public void test_setExpression_nullValue() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyContainer {", - " public Test() {", - " addChild('text', new JButton());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyContainer { + public Test() { + addChild("text", new JButton()); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); InvocationChildAssociationAccessor accessor = new InvocationChildAssociationAccessor(0, "\"\""); // set "null", default value is used assertTrue(accessor.setExpression(button, null)); - assertEditor( - "public class Test extends MyContainer {", - " public Test() {", - " addChild('', new JButton());", - " }", - "}"); + assertEditor(""" + public class Test extends MyContainer { + public Test() { + addChild("", new JButton()); + } + }"""); } /** @@ -137,22 +130,21 @@ public void test_setExpression_nullValue() throws Exception { */ @Test public void test_setExpression_nullValue_noDefault() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyContainer {", - " public Test() {", - " addChild('text', new JButton());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyContainer { + public Test() { + addChild("text", new JButton()); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); InvocationChildAssociationAccessor accessor = new InvocationChildAssociationAccessor(0, null); // set "null", but no default value, so ignored assertFalse(accessor.setExpression(button, null)); - assertEditor( - "public class Test extends MyContainer {", - " public Test() {", - " addChild('text', new JButton());", - " }", - "}"); + assertEditor(""" + public class Test extends MyContainer { + public Test() { + addChild("text", new JButton()); + } + }"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/MethodInvocationAccessorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/MethodInvocationAccessorTest.java index 8b764812b5..4a69d4e389 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/MethodInvocationAccessorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/MethodInvocationAccessorTest.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 @@ -41,26 +41,22 @@ public class MethodInvocationAccessorTest extends SwingModelTest { public void setUp() throws Exception { super.setUp(); // prepare MyPanel - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setText(String text, boolean html) {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - "")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setText(String text, boolean html) { + } + }""")); + setFileContentSrc("test/MyPanel.wbp-component.xml", """ + + + + + + + + + + """); waitForAutoBuild(); } @@ -71,13 +67,12 @@ public void setUp() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_access() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("text"); MethodInvocationAccessor accessor = (MethodInvocationAccessor) getGenericPropertyAccessors(property).get(0); @@ -98,13 +93,12 @@ public void test_access() throws Exception { */ @Test public void test_getExpression_noInvocation() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("text"); MethodInvocationAccessor accessor = (MethodInvocationAccessor) getGenericPropertyAccessors(property).get(0); @@ -118,13 +112,12 @@ public void test_getExpression_noInvocation() throws Exception { */ @Test public void test_getExpression_hasInvocation() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " setText('text', false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + setText("text", false); + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("text"); MethodInvocationAccessor accessor = (MethodInvocationAccessor) getGenericPropertyAccessors(property).get(0); @@ -143,25 +136,24 @@ public void test_getExpression_hasInvocation() throws Exception { */ @Test public void test_setExpression_addNew() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("text"); MethodInvocationAccessor accessor = (MethodInvocationAccessor) getGenericPropertyAccessors(property).get(0); // do check accessor.setExpression(panel, "\"new text\", true"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setText('new text', true);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setText("new text", true); + } + }"""); } /** @@ -169,25 +161,24 @@ public void test_setExpression_addNew() throws Exception { */ @Test public void test_setExpression_removeExisting() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setText('text', false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setText("text", false); + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("text"); MethodInvocationAccessor accessor = (MethodInvocationAccessor) getGenericPropertyAccessors(property).get(0); // do check accessor.setExpression(panel, null); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -195,23 +186,22 @@ public void test_setExpression_removeExisting() throws Exception { */ @Test public void test_setExpression_replaceExisting() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " setText('text', false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + setText("text", false); + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("text"); MethodInvocationAccessor accessor = (MethodInvocationAccessor) getGenericPropertyAccessors(property).get(0); // do check accessor.setExpression(panel, "\"new text\", true"); - assertEditor( - "public class Test extends MyPanel {", - " public Test() {", - " setText('new text', true);", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel { + public Test() { + setText("new text", true); + } + }"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/MethodInvocationArgumentAccessorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/MethodInvocationArgumentAccessorTest.java index 7ce2416e9f..ba76219695 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/MethodInvocationArgumentAccessorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/MethodInvocationArgumentAccessorTest.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 @@ -42,26 +42,22 @@ public class MethodInvocationArgumentAccessorTest extends SwingModelTest { public void setUp() throws Exception { super.setUp(); // prepare MyPanel - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setText(String text, boolean html) {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - "")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setText(String text, boolean html) { + } + }""")); + setFileContentSrc("test/MyPanel.wbp-component.xml", """ + + + + + + + + + + """); waitForAutoBuild(); } @@ -72,13 +68,12 @@ public void setUp() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_access() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); ExpressionAccessor accessor = getTestAccessor(panel, -1); // no adapters assertNull(accessor.getAdapter(null)); @@ -96,13 +91,12 @@ public void test_access() throws Exception { */ @Test public void test_getExpression_noInvocation() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); ExpressionAccessor accessor = getTestAccessor(panel, -1); // do check assertNull(accessor.getExpression(panel)); @@ -113,13 +107,12 @@ public void test_getExpression_noInvocation() throws Exception { */ @Test public void test_getExpression_hasInvocation() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " setText(null, false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + setText(null, false); + } + }"""); ExpressionAccessor accessor = getTestAccessor(panel, 1); // do check assertEquals("false", m_lastEditor.getSource(accessor.getExpression(panel))); @@ -135,22 +128,21 @@ public void test_getExpression_hasInvocation() throws Exception { */ @Test public void test_setExpression_replaceExisting() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " setText(null, false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + setText(null, false); + } + }"""); ExpressionAccessor accessor = getTestAccessor(panel, 1); // do check accessor.setExpression(panel, "true"); - assertEditor( - "public class Test extends MyPanel {", - " public Test() {", - " setText(null, true);", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel { + public Test() { + setText(null, true); + } + }"""); } /** @@ -160,23 +152,22 @@ public void test_setExpression_replaceExisting() throws Exception { */ @Test public void test_setExpression_removeExisting_1() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setText('foo', false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setText("foo", false); + } + }"""); ExpressionAccessor accessor = getTestAccessor(panel, 0); // do check accessor.setExpression(panel, "(String) null"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -186,23 +177,22 @@ public void test_setExpression_removeExisting_1() throws Exception { */ @Test public void test_setExpression_removeExisting_2() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setText('foo', false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setText("foo", false); + } + }"""); ExpressionAccessor accessor = getTestAccessor(panel, 0); // do check accessor.setExpression(panel, null); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -210,23 +200,22 @@ public void test_setExpression_removeExisting_2() throws Exception { */ @Test public void test_setExpression_addNew() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); ExpressionAccessor accessor = getTestAccessor(panel, 1); // do check accessor.setExpression(panel, "true"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setText((String) null, true);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setText((String) null, true); + } + }"""); } //////////////////////////////////////////////////////////////////////////// diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/SetterAccessorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/SetterAccessorTest.java index 978c5a53ef..e2145f6b35 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/SetterAccessorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/SetterAccessorTest.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 @@ -63,13 +63,12 @@ public void _test_exit() throws Exception { */ @Test public void test_getGetter() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setEnabled(false); + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("enabled"); SetterAccessor accessor = (SetterAccessor) getGenericPropertyAccessors(property).get(0); // check @@ -103,13 +102,12 @@ public void test_setGetter() throws Exception { */ @Test public void test_IAccessibleExpressionAccessor() 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() { + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("enabled"); SetterAccessor accessor = (SetterAccessor) getGenericPropertyAccessors(property).get(0); // check that IAccessibleExpressionAccessor is available @@ -126,13 +124,12 @@ public void test_IAccessibleExpressionAccessor() throws Exception { */ @Test public void test_PropertyTooltipProvider() 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() { + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("enabled"); SetterAccessor accessor = (SetterAccessor) getGenericPropertyAccessors(property).get(0); // ignore arbitrary adapter @@ -155,25 +152,24 @@ public void test_PropertyTooltipProvider() throws Exception { */ @Test public void test_setExpression_remove() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + setEnabled(false); + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("enabled"); SetterAccessor accessor = (SetterAccessor) getGenericPropertyAccessors(property).get(0); // check assertFalse(((BooleanLiteral) accessor.getExpression(panel)).booleanValue()); accessor.setExpression(panel, null); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); } /** @@ -181,24 +177,23 @@ public void test_setExpression_remove() throws Exception { */ @Test public void test_setExpression_sameSource() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setEnabled(false); + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("enabled"); ExpressionAccessor setterAccessor = getGenericPropertyAccessors(property).get(0); // check assertFalse(((BooleanLiteral) setterAccessor.getExpression(panel)).booleanValue()); setterAccessor.setExpression(panel, "false"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(false);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setEnabled(false); + } + }"""); } /** @@ -206,24 +201,23 @@ public void test_setExpression_sameSource() throws Exception { */ @Test public void test_setExpression_newSource() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(true);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setEnabled(true); + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("enabled"); ExpressionAccessor setterAccessor = getGenericPropertyAccessors(property).get(0); // check assertTrue(((BooleanLiteral) setterAccessor.getExpression(panel)).booleanValue()); setterAccessor.setExpression(panel, "false"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(false);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + setEnabled(false); + } + }"""); } /** @@ -231,25 +225,24 @@ public void test_setExpression_newSource() throws Exception { */ @Test public void test_setExpression_newInvocation() 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() { + } + }"""); GenericProperty property = (GenericProperty) panel.getPropertyByTitle("enabled"); ExpressionAccessor setterAccessor = getGenericPropertyAccessors(property).get(0); // check assertNull(setterAccessor.getExpression(panel)); setterAccessor.setExpression(panel, "false"); - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " setEnabled(false);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + setEnabled(false); + } + }"""); } /** @@ -257,26 +250,23 @@ public void test_setExpression_newInvocation() throws Exception { */ @Test public void test_setExpression_replaceComponent() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setFoo(String o) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setFoo(String o) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " private final JButton button_1 = new JButton();", - " private final JButton button_2 = new JButton();", - " public Test() {", - " setFoo(button_1.getName());", - " add(button_1);", - " add(button_2);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + private final JButton button_1 = new JButton(); + private final JButton button_2 = new JButton(); + public Test() { + setFoo(button_1.getName()); + add(button_1); + add(button_2); + } + }"""); ComponentInfo button_1 = getJavaInfoByName("button_1"); ComponentInfo button_2 = getJavaInfoByName("button_2"); // prepare ExpressionAccessor @@ -296,16 +286,16 @@ public void test_setExpression_replaceComponent() throws Exception { String source = TemplateUtils.format("{0}.getName()", button_2); setterAccessor.setExpression(panel, source); } - assertEditor( - "public class Test extends MyPanel {", - " private final JButton button_1 = new JButton();", - " private final JButton button_2 = new JButton();", - " public Test() {", - " setFoo(button_2.getName());", - " add(button_1);", - " add(button_2);", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel { + private final JButton button_1 = new JButton(); + private final JButton button_2 = new JButton(); + public Test() { + setFoo(button_2.getName()); + add(button_1); + add(button_2); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -318,13 +308,12 @@ public void test_setExpression_replaceComponent() throws Exception { */ @Test public void test_exposable() 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() { + } + }"""); // "enabled" { GenericProperty property = (GenericProperty) panel.getPropertyByTitle("enabled"); @@ -356,23 +345,20 @@ public void test_exposable() throws Exception { */ @Test public void test_defaultValue() throws Exception { - setFileContentSrc( - "test/MyButton.java", - getTestSource( - "public class MyButton extends JButton {", - " public MyButton(String s) {", - " setText(s);", - " }", - "}")); + setFileContentSrc("test/MyButton.java", getTestSource(""" + public class MyButton extends JButton { + public MyButton(String s) { + setText(s); + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new MyButton('A'));", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new MyButton("A")); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); Property constructorTextProperty = PropertyUtils.getByPath(button, "Constructor/s"); @@ -382,12 +368,12 @@ public void test_defaultValue() throws Exception { assertEquals("A", textProperty.getValue()); // set new value in constructor constructorTextProperty.setValue("B"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " add(new MyButton('B'));", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + add(new MyButton("B")); + } + }"""); assertEquals("B", constructorTextProperty.getValue()); assertEquals("B", textProperty.getValue()); } @@ -398,29 +384,24 @@ public void test_defaultValue() throws Exception { */ @Test public void test_noDefaultValue() throws Exception { - setFileContentSrc( - "test/MyComponent.java", - getTestSource( - "public class MyComponent extends JComponent {", - " public MyComponent() {", - " }", - "}")); - setFileContentSrc( - "test/MyComponent.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - "")); + setFileContentSrc("test/MyComponent.java", getTestSource(""" + public class MyComponent extends JComponent { + public MyComponent() { + } + }""")); + setFileContentSrc("test/MyComponent.wbp-component.xml", """ + + + + """); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " add(new MyComponent());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + add(new MyComponent()); + } + }"""); ComponentInfo myComponent = panel.getChildrenComponents().get(0); // "panel" has default value for "enabled" { @@ -448,34 +429,29 @@ public void test_noDefaultValue() throws Exception { */ @Test public void test_noDefaultValuesForThis() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JComponent {", - " public int getFoo() {", - " return 555;", - " }", - " public void setFoo(int foo) {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " true", - " ", - "")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JComponent { + public int getFoo() { + return 555; + } + public void setFoo(int foo) { + } + }""")); + setFileContentSrc("test/MyPanel.wbp-component.xml", """ + + + + true + + """); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // we disabled default values, so "foo" has no default value assertSame(Property.UNKNOWN_VALUE, panel.getPropertyByTitle("foo").getValue()); } @@ -486,25 +462,22 @@ public void test_noDefaultValuesForThis() throws Exception { */ @Test public void test_exceptionInDefaultValue() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public int getFoo() {", - " throw new Error();", - " }", - " public void setFoo(int foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public int getFoo() { + throw new Error(); + } + public void setFoo(int foo) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // we throw exception in getFoo(), so "foo" has no default value assertSame(Property.UNKNOWN_VALUE, panel.getPropertyByTitle("foo").getValue()); } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/SuperConstructorAccessorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/SuperConstructorAccessorTest.java index 338a3fe500..5a5ed1db78 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/SuperConstructorAccessorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/accessor/SuperConstructorAccessorTest.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 @@ -40,14 +40,12 @@ public class SuperConstructorAccessorTest extends SwingModelTest { @BeforeEach public void setUp() throws Exception { super.setUp(); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public MyPanel(boolean enabled) {", - " setEnabled(enabled);", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public MyPanel(boolean enabled) { + setEnabled(enabled); + } + }""")); waitForAutoBuild(); } @@ -58,13 +56,12 @@ public void setUp() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_0() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " super(false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + super(false); + } + }"""); // check SuperConstructorAccessor accessor = getAccessor(panel, null); assertSame(Property.UNKNOWN_VALUE, accessor.getDefaultValue(panel)); @@ -78,22 +75,21 @@ public void test_0() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_setExpression_newValue() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " super(false);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + super(false); + } + }"""); // check SuperConstructorAccessor accessor = getAccessor(panel, null); assertTrue(accessor.setExpression(panel, "true")); - assertEditor( - "public class Test extends MyPanel {", - " public Test() {", - " super(true);", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel { + public Test() { + super(true); + } + }"""); } /** @@ -101,22 +97,21 @@ public void test_setExpression_newValue() throws Exception { */ @Test public void test_setExpression_nullValue_noDefault() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " super(true);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + super(true); + } + }"""); // check SuperConstructorAccessor accessor = getAccessor(panel, null); assertFalse(accessor.setExpression(panel, null)); - assertEditor( - "public class Test extends MyPanel {", - " public Test() {", - " super(true);", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel { + public Test() { + super(true); + } + }"""); } /** @@ -124,22 +119,21 @@ public void test_setExpression_nullValue_noDefault() throws Exception { */ @Test public void test_setExpression_nullValue_withDefault() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " super(true);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + super(true); + } + }"""); // check SuperConstructorAccessor accessor = getAccessor(panel, "new java.lang.String().equals(null)"); assertTrue(accessor.setExpression(panel, null)); - assertEditor( - "public class Test extends MyPanel {", - " public Test() {", - " super(new String().equals(null));", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel { + public Test() { + super(new String().equals(null)); + } + }"""); } //////////////////////////////////////////////////////////////////////////// diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/AbstractTextPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/AbstractTextPropertyEditorTest.java index 0e7a6b4c26..f8cf1c6ec8 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/AbstractTextPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/AbstractTextPropertyEditorTest.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 @@ -108,12 +108,12 @@ protected static void assertContainsOnly(Object editor, String fieldName, List T createEditor(Class clazz, diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/BooleanObjectPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/BooleanObjectPropertyEditorTest.java index 10787b2f7f..2c5e3f6ca9 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/BooleanObjectPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/BooleanObjectPropertyEditorTest.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 @@ -48,44 +48,43 @@ public void _test_exit() throws Exception { @Test public void test_doubleClick() throws Exception { prepareBooleanPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // prepare property Property property = panel.getPropertyByTitle("foo"); BooleanObjectPropertyEditor editor = (BooleanObjectPropertyEditor) property.getEditor(); // unknown -> true editor.doubleClick(property); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(true);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(true); + } + }"""); // true -> false editor.doubleClick(property); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(false);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(false); + } + }"""); // false -> true editor.doubleClick(property); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(true);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(true); + } + }"""); } /** @@ -94,27 +93,26 @@ public void test_doubleClick() throws Exception { @Test public void test_doubleClick_fromNull() throws Exception { prepareBooleanPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(null);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(null); + } + }"""); panel.refresh(); // prepare property Property property = panel.getPropertyByTitle("foo"); BooleanObjectPropertyEditor editor = (BooleanObjectPropertyEditor) property.getEditor(); // null -> true editor.doubleClick(property); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(true);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(true); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -128,14 +126,13 @@ public void test_doubleClick_fromNull() throws Exception { @Test public void test_activate_usingKeyboard() throws Exception { prepareBooleanPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(true);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(true); + } + }"""); panel.refresh(); // prepare property Property property = panel.getPropertyByTitle("foo"); @@ -143,13 +140,13 @@ public void test_activate_usingKeyboard() throws Exception { // true -> false boolean activated = editor.activate(null, property, null); assertFalse(activated); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(false);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(false); + } + }"""); } /** @@ -158,14 +155,13 @@ public void test_activate_usingKeyboard() throws Exception { @Test public void test_activate_clickOnCheckBox() throws Exception { prepareBooleanPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(true);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(true); + } + }"""); panel.refresh(); // prepare property Property property = panel.getPropertyByTitle("foo"); @@ -173,13 +169,13 @@ public void test_activate_clickOnCheckBox() throws Exception { // true -> false boolean activated = editor.activate(null, property, new Point(10, 0)); assertFalse(activated); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(false);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(false); + } + }"""); } /** @@ -188,14 +184,13 @@ public void test_activate_clickOnCheckBox() throws Exception { @Test public void test_activate_justClickToSelect() throws Exception { prepareBooleanPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(true);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(true); + } + }"""); panel.refresh(); // prepare property Property property = panel.getPropertyByTitle("foo"); @@ -203,13 +198,13 @@ public void test_activate_justClickToSelect() throws Exception { // true -> false boolean activated = editor.activate(null, property, new Point(100, 0)); assertFalse(activated); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(true);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(true); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -218,13 +213,11 @@ public void test_activate_justClickToSelect() throws Exception { // //////////////////////////////////////////////////////////////////////////// private void prepareBooleanPanel() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setFoo(Boolean foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setFoo(Boolean foo) { + } + }""")); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/BooleanPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/BooleanPropertyEditorTest.java index 4556004bd8..a113831c84 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/BooleanPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/BooleanPropertyEditorTest.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 @@ -47,35 +47,34 @@ public void _test_exit() throws Exception { @Test public void test_doubleClick() throws Exception { prepareBooleanPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // prepare property Property property = panel.getPropertyByTitle("foo"); BooleanPropertyEditor editor = (BooleanPropertyEditor) property.getEditor(); // unknown -> true editor.doubleClick(property); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(true);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(true); + } + }"""); // true -> false editor.doubleClick(property); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(false);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(false); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -89,14 +88,13 @@ public void test_doubleClick() throws Exception { @Test public void test_activate_usingKeyboard() throws Exception { prepareBooleanPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(true);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(true); + } + }"""); panel.refresh(); // prepare property Property property = panel.getPropertyByTitle("foo"); @@ -104,13 +102,13 @@ public void test_activate_usingKeyboard() throws Exception { // true -> false boolean activated = editor.activate(null, property, null); assertFalse(activated); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(false);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(false); + } + }"""); } /** @@ -119,14 +117,13 @@ public void test_activate_usingKeyboard() throws Exception { @Test public void test_activate_clickOnCheckBox() throws Exception { prepareBooleanPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(true);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(true); + } + }"""); panel.refresh(); // prepare property Property property = panel.getPropertyByTitle("foo"); @@ -134,13 +131,13 @@ public void test_activate_clickOnCheckBox() throws Exception { // true -> false boolean activated = editor.activate(null, property, new Point(10, 0)); assertFalse(activated); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(false);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(false); + } + }"""); } /** @@ -149,14 +146,13 @@ public void test_activate_clickOnCheckBox() throws Exception { @Test public void test_activate_justClickToSelect() throws Exception { prepareBooleanPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(true);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(true); + } + }"""); panel.refresh(); // prepare property Property property = panel.getPropertyByTitle("foo"); @@ -164,13 +160,13 @@ public void test_activate_justClickToSelect() throws Exception { // true -> false boolean activated = editor.activate(null, property, new Point(100, 0)); assertFalse(activated); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(true);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(true); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -179,13 +175,11 @@ public void test_activate_justClickToSelect() throws Exception { // //////////////////////////////////////////////////////////////////////////// private void prepareBooleanPanel() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setFoo(boolean foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setFoo(boolean foo) { + } + }""")); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ByteObjectPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ByteObjectPropertyEditorTest.java index 56ad06576b..ae81d56a81 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ByteObjectPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ByteObjectPropertyEditorTest.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 @@ -76,24 +76,23 @@ public void test_getEditorText() throws Exception { @Test public void test_setEditorText_value() throws Exception { prepareBytePanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, "123"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo((byte) 123);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo((byte) 123); + } + }"""); } /** @@ -102,24 +101,23 @@ public void test_setEditorText_value() throws Exception { @Test public void test_setEditorText_null() throws Exception { prepareBytePanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, "null"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo((Byte) null);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo((Byte) null); + } + }"""); } /** @@ -128,24 +126,23 @@ public void test_setEditorText_null() throws Exception { @Test public void test_setEditorText_removeValue_emptyString() throws Exception { prepareBytePanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo((byte) 123);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo((byte) 123); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, ""); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -154,24 +151,23 @@ public void test_setEditorText_removeValue_emptyString() throws Exception { @Test public void test_setEditorText_removeValue_whitespaceString() throws Exception { prepareBytePanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo((byte) 123);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo((byte) 123); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, " "); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -180,13 +176,12 @@ public void test_setEditorText_removeValue_whitespaceString() throws Exception { @Test public void test_setEditorText_invalidValue() throws Exception { prepareBytePanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // final Property property = panel.getPropertyByTitle("foo"); @@ -202,22 +197,20 @@ public void accept(SWTBot bot) { shell.button("OK").click(); } }); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } private void prepareBytePanel() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setFoo(Byte foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setFoo(Byte foo) { + } + }""")); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ConstantSelectionPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ConstantSelectionPropertyEditorTest.java index ef576714d8..8176f90959 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ConstantSelectionPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ConstantSelectionPropertyEditorTest.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 @@ -56,49 +56,43 @@ public void setUp() throws Exception { // prepare test Shell m_shell = new Shell(); // prepare JDT elements - setFileContentSrc( - "test/PrefConstants.java", - getTestSource( - "public interface PrefConstants {", - " String ID_1 = 'id 1';", - " int ID_2 = 2;", - " int ID_3 = 3;", - " String ID_4 = 'id 4';", - "}")); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public MyPanel() {", - " }", - " public void setStringId(String id) {", - " }", - " public void setStringId2(String id) {", - " }", - " public void setIntId(int id) {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " java.lang.String", - " ", - " ", - " ", - " ", - " java.lang.String", - " ", - " ", - " ", - " ", - " int", - " ", - " ", - "")); + setFileContentSrc("test/PrefConstants.java", getTestSource(""" + public interface PrefConstants { + String ID_1 = "id 1"; + int ID_2 = 2; + int ID_3 = 3; + String ID_4 = "id 4"; + }""")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public MyPanel() { + } + public void setStringId(String id) { + } + public void setStringId2(String id) { + } + public void setIntId(int id) { + } + }""")); + setFileContentSrc("test/MyPanel.wbp-component.xml", """ + + + + + java.lang.String + + + + + java.lang.String + + + + + int + + + """); waitForAutoBuild(); } @@ -228,12 +222,12 @@ private List getLocalTypes() throws Exception { */ @Test public void test_utils_noValue() throws Exception { - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); assertNull(getField()); assertNull(getType()); assertNull(getText()); @@ -245,12 +239,12 @@ public void test_utils_noValue() throws Exception { */ @Test public void test_utils_notQualifiedName() throws Exception { - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " setStringId('constant');", - " }", - "}"); + parseContainer(""" + public class Test extends MyPanel { + public Test() { + setStringId("constant"); + } + }"""); assertNull(getField()); assertNull(getType()); assertNull(getText()); @@ -262,12 +256,12 @@ public void test_utils_notQualifiedName() throws Exception { */ @Test public void test_utils_qualifiedName() throws Exception { - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " setStringId(PrefConstants.ID_1);", - " }", - "}"); + parseContainer(""" + public class Test extends MyPanel { + public Test() { + setStringId(PrefConstants.ID_1); + } + }"""); { IField field = getField(); assertEquals("ID_1", field.getElementName()); @@ -290,12 +284,12 @@ public void test_utils_qualifiedName() throws Exception { IField field = constantsType.getField("ID_4"); assertTrue(field.exists()); setField(field); - assertEditor( - "public class Test extends MyPanel {", - " public Test() {", - " setStringId(PrefConstants.ID_4);", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel { + public Test() { + setStringId(PrefConstants.ID_4); + } + }"""); } // after setField() we should understand Expression assertEquals("ID_4", getText()); @@ -306,12 +300,12 @@ public void test_utils_qualifiedName() throws Exception { */ @Test public void test_utils_simpleName_interface() throws Exception { - parseContainer( - "public class Test extends MyPanel implements PrefConstants {", - " public Test() {", - " setStringId(ID_1);", - " }", - "}"); + parseContainer(""" + public class Test extends MyPanel implements PrefConstants { + public Test() { + setStringId(ID_1); + } + }"""); { IField field = getField(); assertEquals("ID_1", field.getElementName()); @@ -334,12 +328,12 @@ public void test_utils_simpleName_interface() throws Exception { IField field = constantsType.getField("ID_4"); assertTrue(field.exists()); setField(field); - assertEditor( - "public class Test extends MyPanel implements PrefConstants {", - " public Test() {", - " setStringId(ID_4);", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel implements PrefConstants { + public Test() { + setStringId(ID_4); + } + }"""); } // after setField() we should understand Expression assertEquals("ID_4", getText()); @@ -350,25 +344,25 @@ public void test_utils_simpleName_interface() throws Exception { */ @Test public void test_setField_local() throws Exception { - parseContainer( - "public class Test extends MyPanel {", - " public static final String LOCAL_ID = 'value';", - " public Test() {", - " }", - "}"); + parseContainer(""" + public class Test extends MyPanel { + public static final String LOCAL_ID = "value"; + public Test() { + } + }"""); // set new IField { IType constantsType = m_testProject.getJavaProject().findType("test.Test"); IField field = constantsType.getField("LOCAL_ID"); assertTrue(field.exists()); setField(field); - assertEditor( - "public class Test extends MyPanel {", - " public static final String LOCAL_ID = 'value';", - " public Test() {", - " setStringId(LOCAL_ID);", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel { + public static final String LOCAL_ID = "value"; + public Test() { + setStringId(LOCAL_ID); + } + }"""); } // after setField() we should understand Expression assertEquals("LOCAL_ID", getText()); @@ -379,16 +373,16 @@ public void test_setField_local() throws Exception { */ @Test public void test_utils_simpleName_field() throws Exception { - parseContainer( - "public class Test extends MyPanel {", - " public static final String LOCAL_ID = 'value';", - " public static final String LOCAL_ID2 = 'value2';", - " private static final String LOCAL_ID3 = 'value3';", - " public static final int INT_VALUE = 0;", - " public Test() {", - " setStringId(LOCAL_ID);", - " }", - "}"); + parseContainer(""" + public class Test extends MyPanel { + public static final String LOCAL_ID = "value"; + public static final String LOCAL_ID2 = "value2"; + private static final String LOCAL_ID3 = "value3"; + public static final int INT_VALUE = 0; + public Test() { + setStringId(LOCAL_ID); + } + }"""); { IField field = getField(); assertEquals("LOCAL_ID", field.getElementName()); @@ -412,13 +406,13 @@ public void test_utils_simpleName_field() throws Exception { */ @Test public void test_utils_simpleName_variable() throws Exception { - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " String id = 'value';", - " setStringId(id);", - " }", - "}"); + parseContainer(""" + public class Test extends MyPanel { + public Test() { + String id = "value"; + setStringId(id); + } + }"""); assertNull(getField()); assertNull(getType()); assertNull(getText()); @@ -429,14 +423,14 @@ public void test_utils_simpleName_variable() throws Exception { */ @Test public void test_getUsedTypes() throws Exception { - parseContainer( - "public class Test extends MyPanel {", - " public static final String LOCAL_ID = 'value';", - " public Test() {", - " setStringId(PrefConstants.ID_1);", - " setStringId2(LOCAL_ID);", - " }", - "}"); + parseContainer(""" + public class Test extends MyPanel { + public static final String LOCAL_ID = "value"; + public Test() { + setStringId(PrefConstants.ID_1); + setStringId2(LOCAL_ID); + } + }"""); Set types = getUsedTypes(); // convert IType's into their names Set typeNames = new HashSet<>(); @@ -453,11 +447,11 @@ public void test_getUsedTypes() throws Exception { */ @Test public void test_getLocalTypes_0() throws Exception { - parseContainer( - "public class Test extends MyPanel implements PrefConstants {", - " public Test() {", - " }", - "}"); + parseContainer(""" + public class Test extends MyPanel implements PrefConstants { + public Test() { + } + }"""); List types = getLocalTypes(); // convert IType's into their names Set typeNames = new HashSet<>(); @@ -475,17 +469,19 @@ public void test_getLocalTypes_0() throws Exception { @Test public void test_getLocalTypes_1() throws Exception { // declare interface without valid (String) constants - setFileContentSrc( - "test/BadConstants.java", - getSourceDQ("package test;", "public interface BadConstants {", " int ID = 0;", "}")); + setFileContentSrc("test/BadConstants.java", """ + package test; + public interface BadConstants { + int ID = 0; + }"""); waitForAutoBuild(); // parse - parseContainer( - "public class Test extends MyPanel implements PrefConstants, BadConstants {", - " public static final String LOCAL_ID = 'value';", - " public Test() {", - " }", - "}"); + parseContainer(""" + public class Test extends MyPanel implements PrefConstants, BadConstants { + public static final String LOCAL_ID = "value"; + public Test() { + } + }"""); List types = getLocalTypes(); // convert IType's into their names Set typeNames = new HashSet<>(); @@ -506,13 +502,12 @@ public void test_getLocalTypes_1() throws Exception { */ @Test public void test_combo_items() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " setStringId(PrefConstants.ID_1);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + setStringId(PrefConstants.ID_1); + } + }"""); Property property = panel.getPropertyByTitle("stringId"); // addComboPropertyItems(property); @@ -530,12 +525,12 @@ public void test_combo_items() throws Exception { // set new item { setComboPropertyValue(property, 1); - assertEditor( - "public class Test extends MyPanel {", - " public Test() {", - " setStringId(PrefConstants.ID_4);", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel { + public Test() { + setStringId(PrefConstants.ID_4); + } + }"""); } } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/DatePropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/DatePropertyEditorTest.java index 2e63595304..d61df638d1 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/DatePropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/DatePropertyEditorTest.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 @@ -64,14 +64,13 @@ public void test_configure() throws Exception { @Test public void test_setValue_default() throws Exception { configureContents(false); - ContainerInfo container = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " DateComponent component = new DateComponent();", - " add(component);", - " }", - "}"); + ContainerInfo container = parseContainer(""" + public class Test extends JPanel { + public Test() { + DateComponent component = new DateComponent(); + add(component); + } + }"""); ComponentInfo componentInfo = container.getChildrenComponents().get(0); // check property Property dateProperty = componentInfo.getPropertyByTitle("date"); @@ -85,28 +84,27 @@ public void test_setValue_default() throws Exception { dateProperty.setValue(rightNow); // check source assertEquals(new SimpleDateFormat().format(rightNow), dateEditor.getText(dateProperty)); - assertEditor( - "import java.util.Date;", - "public class Test extends JPanel {", - " public Test() {", - " DateComponent component = new DateComponent();", - " component.setDate(new Date(" + Long.valueOf(currentTimeMillis).toString() + "L));", - " add(component);", - " }", - "}"); + assertEditor(""" + import java.util.Date; + public class Test extends JPanel { + public Test() { + DateComponent component = new DateComponent(); + component.setDate(new Date(%dL)); + add(component); + } + }""".formatted(currentTimeMillis)); } @Test public void test_setValue_custom() throws Exception { configureContents(true); - ContainerInfo container = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " DateComponent component = new DateComponent();", - " add(component);", - " }", - "}"); + ContainerInfo container = parseContainer(""" + public class Test extends JPanel { + public Test() { + DateComponent component = new DateComponent(); + add(component); + } + }"""); ComponentInfo componentInfo = container.getChildrenComponents().get(0); // check property Property dateProperty = componentInfo.getPropertyByTitle("date"); @@ -120,34 +118,31 @@ public void test_setValue_custom() throws Exception { dateProperty.setValue(currentDate); // check source assertEquals(currentDateStr, dateEditor.getText(dateProperty)); - assertEditor( - "import java.text.SimpleDateFormat;", - "import java.text.ParsePosition;", - "public class Test extends JPanel {", - " public Test() {", - " DateComponent component = new DateComponent();", - " component.setDate(new SimpleDateFormat('dd.MM.yyyy').parse('" - + currentDateStr - + "', new ParsePosition(0)));", - " add(component);", - " }", - "}"); + assertEditor(""" + import java.text.SimpleDateFormat; + import java.text.ParsePosition; + public class Test extends JPanel { + public Test() { + DateComponent component = new DateComponent(); + component.setDate(new SimpleDateFormat("dd.MM.yyyy").parse("%s", new ParsePosition(0))); + add(component); + } + }""".formatted(currentDateStr)); } @Test public void test_setText_default() throws Exception { configureContents(false); long currentTimeMillis = System.currentTimeMillis(); - ContainerInfo container = - parseContainer( - "import java.util.Date;", - "public class Test extends JPanel {", - " public Test() {", - " DateComponent component = new DateComponent();", - " component.setDate(new Date(" + Long.valueOf(currentTimeMillis).toString() + "L));", - " add(component);", - " }", - "}"); + ContainerInfo container = parseContainer(""" + import java.util.Date; + public class Test extends JPanel { + public Test() { + DateComponent component = new DateComponent(); + component.setDate(new Date(%dL)); + add(component); + } + }""".formatted(currentTimeMillis)); ComponentInfo componentInfo = container.getChildrenComponents().get(0); // check property Property dateProperty = componentInfo.getPropertyByTitle("date"); @@ -168,30 +163,29 @@ public void test_setText_default() throws Exception { // check source assertEquals(newDateStr, dateEditor.getText(dateProperty)); assertEquals(newDate, dateProperty.getValue()); - assertEditor( - "import java.util.Date;", - "public class Test extends JPanel {", - " public Test() {", - " DateComponent component = new DateComponent();", - " component.setDate(new Date(0L));", - " add(component);", - " }", - "}"); + assertEditor(""" + import java.util.Date; + public class Test extends JPanel { + public Test() { + DateComponent component = new DateComponent(); + component.setDate(new Date(0L)); + add(component); + } + }"""); } @Test public void test_setText_custom() throws Exception { configureContents(true); - ContainerInfo container = - parseContainer( - "import java.util.Date;", - "public class Test extends JPanel {", - " public Test() {", - " DateComponent component = new DateComponent();", - " component.setDate(new Date());", - " add(component);", - " }", - "}"); + ContainerInfo container = parseContainer(""" + import java.util.Date; + public class Test extends JPanel { + public Test() { + DateComponent component = new DateComponent(); + component.setDate(new Date()); + add(component); + } + }"""); ComponentInfo componentInfo = container.getChildrenComponents().get(0); // check property Property dateProperty = componentInfo.getPropertyByTitle("date"); @@ -211,19 +205,17 @@ public void test_setText_custom() throws Exception { // check source assertEquals(newDateStr, dateEditor.getText(dateProperty)); assertEquals(newDate, dateProperty.getValue()); - assertEditor( - "import java.util.Date;", - "import java.text.SimpleDateFormat;", - "import java.text.ParsePosition;", - "public class Test extends JPanel {", - " public Test() {", - " DateComponent component = new DateComponent();", - " component.setDate(new SimpleDateFormat('dd.MM.yyyy').parse('" - + newDateStr - + "', new ParsePosition(0)));", - " add(component);", - " }", - "}"); + assertEditor(""" + import java.util.Date; + import java.text.SimpleDateFormat; + import java.text.ParsePosition; + public class Test extends JPanel { + public Test() { + DateComponent component = new DateComponent(); + component.setDate(new SimpleDateFormat("dd.MM.yyyy").parse("%s", new ParsePosition(0))); + add(component); + } + }""".formatted(newDateStr)); } //////////////////////////////////////////////////////////////////////////// @@ -249,36 +241,30 @@ private Map getEditorParameters() { } private void configureContents(boolean custom) throws Exception { - setJavaContentSrc( - "test", - "DateComponent", - new String[]{ - "public class DateComponent extends JComponent {", - " public DateComponent(){", - " }", - " public void setDate(java.util.Date value){", - " }", - "}"}, - custom - ? new String[]{ - "", - "", - " ", - " ", - " import javax.swing.JTextField; import java.text.SimpleDateFormat;", - " (new SimpleDateFormat(\"dd.MM.yyyy\")).format(value)", - " (new SimpleDateFormat(\"dd.MM.yyyy\")).parse(value)", - " new java.text.SimpleDateFormat(\"dd.MM.yyyy\").parse(\"%value%\", new java.text.ParsePosition(0))", - " ", - " ", - ""} - : new String[]{ - "", - "", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "DateComponent", """ + public class DateComponent extends JComponent { + public DateComponent(){ + } + public void setDate(java.util.Date value){ + } + }""", custom ? """ + + + + + import javax.swing.JTextField; import java.text.SimpleDateFormat; + (new SimpleDateFormat(\"dd.MM.yyyy\")).format(value) + (new SimpleDateFormat(\"dd.MM.yyyy\")).parse(value) + new java.text.SimpleDateFormat(\"dd.MM.yyyy\").parse(\"%value%\", new java.text.ParsePosition(0)) + + + """ : """ + + + + + + """); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/DisplayExpressionPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/DisplayExpressionPropertyEditorTest.java index 34da6ad0b0..959aaf5087 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/DisplayExpressionPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/DisplayExpressionPropertyEditorTest.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 @@ -34,13 +34,12 @@ public class DisplayExpressionPropertyEditorTest extends SwingModelTest { public void test_noExpression() throws Exception { createMyPanel(); // parse - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // prepare "myFoo" property Property fooProperty = panel.getPropertyByTitle("myFoo"); @@ -54,13 +53,12 @@ public void test_noExpression() throws Exception { public void test_hasExpression() throws Exception { createMyPanel(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " foo(1 + 2);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + foo(1 + 2); + } + }"""); panel.refresh(); // prepare "myFoo" property Property fooProperty = panel.getPropertyByTitle("myFoo"); @@ -71,27 +69,23 @@ public void test_hasExpression() throws Exception { } private void createMyPanel() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void foo(int value) {", - " }", - "}")); - setFileContentSrc( - "test/MyPanel.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - "")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void foo(int value) { + } + }""")); + setFileContentSrc("test/MyPanel.wbp-component.xml", """ + + + + + + + + + + + """); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/DoubleObjectPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/DoubleObjectPropertyEditorTest.java index 092b377c96..ff75e0a7fe 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/DoubleObjectPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/DoubleObjectPropertyEditorTest.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 @@ -76,24 +76,23 @@ public void test_getEditorText() throws Exception { @Test public void test_setEditorText_value() throws Exception { prepareDoublePanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, "12.3"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(12.3);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(12.3); + } + }"""); } /** @@ -102,24 +101,23 @@ public void test_setEditorText_value() throws Exception { @Test public void test_setEditorText_null() throws Exception { prepareDoublePanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, "null"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo((Double) null);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo((Double) null); + } + }"""); } /** @@ -128,24 +126,23 @@ public void test_setEditorText_null() throws Exception { @Test public void test_setEditorText_removeValue_emptyString() throws Exception { prepareDoublePanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(12.3);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(12.3); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, ""); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -154,24 +151,23 @@ public void test_setEditorText_removeValue_emptyString() throws Exception { @Test public void test_setEditorText_removeValue_whitespaceString() throws Exception { prepareDoublePanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(12.3);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(12.3); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, " "); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -180,13 +176,12 @@ public void test_setEditorText_removeValue_whitespaceString() throws Exception { @Test public void test_setEditorText_invalidValue() throws Exception { prepareDoublePanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // final Property property = panel.getPropertyByTitle("foo"); @@ -202,22 +197,20 @@ public void accept(SWTBot bot) { shell.button("OK").click(); } }); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } private void prepareDoublePanel() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setFoo(Double foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setFoo(Double foo) { + } + }""")); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/EnumPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/EnumPropertyEditorTest.java index 31414d1f0c..6078101c05 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/EnumPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/EnumPropertyEditorTest.java @@ -50,13 +50,12 @@ public void _test_exit() throws Exception { @Test public void test_externalEnum() throws Exception { prepare_Foo_MyPanel(); - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(Foo.B);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + setFoo(Foo.B); + } + }"""); // prepare property GenericProperty property = (GenericProperty) panel.getPropertyByTitle("foo"); EnumPropertyEditor editor = (EnumPropertyEditor) property.getEditor(); @@ -85,13 +84,12 @@ public void test_externalEnum() throws Exception { @Test public void test_getText_noValue() throws Exception { prepare_Foo_MyPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); // prepare property GenericProperty property = (GenericProperty) panel.getPropertyByTitle("foo"); EnumPropertyEditor editor = (EnumPropertyEditor) property.getEditor(); @@ -106,23 +104,22 @@ public void test_getText_noValue() throws Exception { @Test public void test_setText() throws Exception { prepare_Foo_MyPanel(); - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(Foo.B);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + setFoo(Foo.B); + } + }"""); // prepare property GenericProperty property = (GenericProperty) panel.getPropertyByTitle("foo"); // set value setPropertyText(property, "C"); - assertEditor( - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(Foo.C);", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel { + public Test() { + setFoo(Foo.C); + } + }"""); } /** @@ -131,23 +128,20 @@ public void test_setText() throws Exception { @Test public void test_innerEnum() throws Exception { prepare_Foo(); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public enum Foo {A, B, C}", - " public void setFoo(Foo foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public enum Foo {A, B, C} + public void setFoo(Foo foo) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(Foo.B);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + setFoo(Foo.B); + } + }"""); // prepare property GenericProperty property = (GenericProperty) panel.getPropertyByTitle("foo"); EnumPropertyEditor editor = (EnumPropertyEditor) property.getEditor(); @@ -168,25 +162,22 @@ public void test_innerEnum() throws Exception { @Test public void test_constructorParameter_enum() throws Exception { prepare_Foo(); - setFileContentSrc( - "test/MyButton.java", - getTestSource( - "public class MyButton extends JButton {", - " public MyButton(Foo foo) {", - " }", - "}")); + setFileContentSrc("test/MyButton.java", getTestSource(""" + public class MyButton extends JButton { + public MyButton(Foo foo) { + } + }""")); waitForAutoBuild(); // - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " {", - " MyButton button = new MyButton(Foo.B);", - " add(button);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + MyButton button = new MyButton(Foo.B); + add(button); + } + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // prepare property GenericProperty property = (GenericProperty) PropertyUtils.getByPath(button, "Constructor/foo"); @@ -215,25 +206,21 @@ public void test_constructorParameter_enum() throws Exception { */ private void prepare_Foo_MyPanel() throws Exception { prepare_Foo(); - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setFoo(Foo foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setFoo(Foo foo) { + } + }""")); waitForAutoBuild(); } private void prepare_Foo() throws Exception { - setFileContentSrc( - "test/Foo.java", - getSourceDQ( - "package test;", - "// filler filler filler", - "// filler filler filler", - "public enum Foo {", - " A, B, C", - "}")); + setFileContentSrc("test/Foo.java", """ + package test; + // filler filler filler + // filler filler filler + public enum Foo { + A, B, C + }"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/EnumerationValuesPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/EnumerationValuesPropertyEditorTest.java index b1dfeef743..27696eafc2 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/EnumerationValuesPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/EnumerationValuesPropertyEditorTest.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 @@ -116,13 +116,13 @@ public void test_0() throws Exception { assertEquals(null, ((IClipboardSourceProvider) editor).getClipboardSource(property)); // set value property.setValue(1); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setValue(1);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setValue(1); + } + }"""); // check new state assertEquals("a", getPropertyText(property)); assertEquals("1", ((IClipboardSourceProvider) editor).getClipboardSource(property)); @@ -137,42 +137,38 @@ public void test_0() throws Exception { * Prepares "MyPanel" class and its "MyPanelBeanInfo". */ private void prepareMyPanel(String attributeValue) throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setValue(Object value) {", - " }", - "}")); - String[] lines = - { - "import java.beans.*;", - "public class MyPanelBeanInfo extends SimpleBeanInfo {", - " private PropertyDescriptor[] m_descriptors;", - " public MyPanelBeanInfo() {", - " try {", - " m_descriptors = new PropertyDescriptor[1];", - " m_descriptors[0] = new PropertyDescriptor('value', MyPanel.class, null, 'setValue');", - " m_descriptors[0].setValue('enumerationValues', " + attributeValue + ");", - " } catch (Throwable e) {", - " }", - " }", - " public PropertyDescriptor[] getPropertyDescriptors() {", - " return m_descriptors;", - " }", - "}"}; - setFileContentSrc("test/MyPanelBeanInfo.java", getTestSource(lines)); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setValue(Object value) { + } + }""")); + setFileContentSrc("test/MyPanelBeanInfo.java", getTestSource(""" + import java.beans.*; + public class MyPanelBeanInfo extends SimpleBeanInfo { + private PropertyDescriptor[] m_descriptors; + public MyPanelBeanInfo() { + try { + m_descriptors = new PropertyDescriptor[1]; + m_descriptors[0] = new PropertyDescriptor("value", MyPanel.class, null, "setValue"); + m_descriptors[0].setValue("enumerationValues", %s); + } catch (Throwable e) { + } + } + public PropertyDescriptor[] getPropertyDescriptors() { + return m_descriptors; + } + } + """.formatted(attributeValue))); waitForAutoBuild(); } private GenericProperty getValueProperty() throws Exception { - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // prepare property GenericProperty property = (GenericProperty) panel.getPropertyByTitle("value"); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ExpressionListPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ExpressionListPropertyEditorTest.java index 964271e0a5..69720921e9 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ExpressionListPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ExpressionListPropertyEditorTest.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 @@ -204,15 +204,14 @@ private Map getEditorParameters() { // HashMap params = new HashMap<>(); params.put( - "functions", - getSourceDQ( - "def valueType(c) {", - " if (value == null) {", - " return false; ", - " } else { ", - " return isType(value.getClass(),c); ", - " } ", - "};")); + "functions", """ + def valueType(c) { + if (value == null) { + return false; + } else { + return isType(value.getClass(),c); + } + };"""); params.put( "expressions", Lists.newArrayList("new java.lang.Integer()", "new java.lang.String()", "null")); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/InnerClassPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/InnerClassPropertyEditorTest.java index 23a2a39af9..c4c7cd11fe 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/InnerClassPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/InnerClassPropertyEditorTest.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 @@ -61,14 +61,13 @@ public void test_generateInner() throws Exception { declareProviderProperty_inner(); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // final Property property = button.getPropertyByTitle("labelProvider"); @@ -78,19 +77,19 @@ public void test_generateInner() throws Exception { // add new provider { propertyEditor.activate(null, property, null); - assertEditor( - "public class Test extends JPanel {", - " private class LabelProvider implements ILabelProvider {", - " public String getText(Object o) {", - " return null;", - " }", - " }", - " public Test() {", - " MyButton button = new MyButton();", - " button.setLabelProvider(new LabelProvider());", - " add(button);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private class LabelProvider implements ILabelProvider { + public String getText(Object o) { + return null; + } + } + public Test() { + MyButton button = new MyButton(); + button.setLabelProvider(new LabelProvider()); + add(button); + } + }"""); assertEquals("test.Test.LabelProvider", getPropertyText(property)); } // kick "doubleClick", assert that expected position opened @@ -111,25 +110,23 @@ public void test_generateInner() throws Exception { public void test_openExternalClass() throws Exception { declareButtonAndProvider(); declareProviderProperty_inner(); - setFileContentSrc( - "test/ExternalLabelProvider.java", - getTestSource( - "public class ExternalLabelProvider implements ILabelProvider {", - " public ExternalLabelProvider(long level) {", - " }", - " public String getText(Object o) {", - " return null;", - " }", - "}")); + setFileContentSrc("test/ExternalLabelProvider.java", getTestSource(""" + public class ExternalLabelProvider implements ILabelProvider { + public ExternalLabelProvider(long level) { + } + public String getText(Object o) { + return null; + } + }""")); waitForAutoBuild(); // parse - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + } + }"""); ComponentInfo button = getJavaInfoByName("button"); // final Property property = button.getPropertyByTitle("labelProvider"); @@ -150,14 +147,14 @@ public void accept(SWTBot bot) { } }); // check source - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " button.setLabelProvider(new ExternalLabelProvider(0L));", - " add(button);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + button.setLabelProvider(new ExternalLabelProvider(0L)); + add(button); + } + }"""); assertEquals("test.ExternalLabelProvider", getPropertyText(property)); } } @@ -170,25 +167,23 @@ public void accept(SWTBot bot) { public void test_openExternalClass_abstract() throws Exception { declareButtonAndProvider(); declareProviderProperty_inner(); - setFileContentSrc( - "test/AbstractLabelProvider.java", - getTestSource( - "public abstract class AbstractLabelProvider implements ILabelProvider {", - " public AbstractLabelProvider(long level) {", - " }", - " public String getText(Object o) {", - " return null;", - " }", - "}")); + setFileContentSrc("test/AbstractLabelProvider.java", getTestSource(""" + public abstract class AbstractLabelProvider implements ILabelProvider { + public AbstractLabelProvider(long level) { + } + public String getText(Object o) { + return null; + } + }""")); waitForAutoBuild(); // parse - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + } + }"""); ComponentInfo button = getJavaInfoByName("button"); // final Property property = button.getPropertyByTitle("labelProvider"); @@ -219,35 +214,32 @@ public void accept(SWTBot bot) { @Test public void test_generateAnonymous() throws Exception { declareButtonAndProvider(); - setFileContentSrc( - "test/MyButton.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " anonymous", - " test.ILabelProvider", - " ", - " ", - " ", - "")); + setFileContentSrc("test/MyButton.wbp-component.xml", """ + + + + + anonymous + test.ILabelProvider + + + + """); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // final Property property = button.getPropertyByTitle("labelProvider"); @@ -257,18 +249,18 @@ public void test_generateAnonymous() throws Exception { // add new provider { propertyEditor.activate(null, property, null); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " button.setLabelProvider(new ILabelProvider() {", - " public String getText(Object o) {", - " return null;", - " }", - " });", - " add(button);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + button.setLabelProvider(new ILabelProvider() { + public String getText(Object o) { + return null; + } + }); + add(button); + } + }"""); assertEquals("", getPropertyText(property)); } } @@ -279,45 +271,40 @@ public void test_generateAnonymous() throws Exception { @Test public void test_templateExpression() throws Exception { declareButtonAndProvider(); - setFileContentSrc( - "test/AbstractLabelProvider.java", - getTestSource( - "public abstract class AbstractLabelProvider implements ILabelProvider {", - " public AbstractLabelProvider(JLabel label) {", - " }", - "}")); - setFileContentSrc( - "test/MyButton.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " anonymous", - " test.ILabelProvider", - " ", - " ", - " ", - "")); + setFileContentSrc("test/AbstractLabelProvider.java", getTestSource(""" + public abstract class AbstractLabelProvider implements ILabelProvider { + public AbstractLabelProvider(JLabel label) { + } + }""")); + setFileContentSrc("test/MyButton.wbp-component.xml", """ + + + + + anonymous + test.ILabelProvider + + + + """); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " JLabel myLabel = new JLabel();", - " add(myLabel);", - " //", - " MyButton button = new MyButton();", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + JLabel myLabel = new JLabel(); + add(myLabel); + // + MyButton button = new MyButton(); + add(button); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(1); // prepare property final Property property = button.getPropertyByTitle("labelProvider"); @@ -327,21 +314,21 @@ public void test_templateExpression() throws Exception { // add new provider { propertyEditor.activate(null, property, null); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " JLabel myLabel = new JLabel();", - " add(myLabel);", - " //", - " MyButton button = new MyButton();", - " button.setLabelProvider(new AbstractLabelProvider(myLabel) {", - " public String getText(Object o) {", - " return null;", - " }", - " });", - " add(button);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + JLabel myLabel = new JLabel(); + add(myLabel); + // + MyButton button = new MyButton(); + button.setLabelProvider(new AbstractLabelProvider(myLabel) { + public String getText(Object o) { + return null; + } + }); + add(button); + } + }"""); assertEquals("", getPropertyText(property)); } } @@ -352,43 +339,37 @@ public void test_templateExpression() throws Exception { // //////////////////////////////////////////////////////////////////////////// private void declareButtonAndProvider() throws Exception { - setFileContentSrc( - "test/ILabelProvider.java", - getTestSource( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public interface ILabelProvider {", - " String getText(Object o);", - "}")); - setFileContentSrc( - "test/MyButton.java", - getTestSource( - "public class MyButton extends JButton {", - " public void setLabelProvider(ILabelProvider provider) {", - " }", - "}")); + setFileContentSrc("test/ILabelProvider.java", getTestSource(""" + // filler filler filler filler filler + // filler filler filler filler filler + public interface ILabelProvider { + String getText(Object o); + }""")); + setFileContentSrc("test/MyButton.java", getTestSource(""" + public class MyButton extends JButton { + public void setLabelProvider(ILabelProvider provider) { + } + }""")); } private void declareProviderProperty_inner() throws Exception { - setFileContentSrc( - "test/MyButton.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " inner", - " LabelProvider", - " test.ILabelProvider", - " ", - " ", - " ", - "")); + setFileContentSrc("test/MyButton.wbp-component.xml", """ + + + + + inner + LabelProvider + test.ILabelProvider + + + + """); } } \ No newline at end of file diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/InstanceObjectPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/InstanceObjectPropertyEditorTest.java index 839c7c6031..48e151e1db 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/InstanceObjectPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/InstanceObjectPropertyEditorTest.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,12 +57,12 @@ public void _test_exit() throws Exception { */ @Test public void test_configure() throws Exception { - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); Map parameters = getEditorParameters(); { // full configuration @@ -94,13 +94,12 @@ public void test_configure() throws Exception { @Test public void test_parse_noValue() throws Exception { configureContents(); - ContainerInfo container = - parseContainer( - "// filler filler filler", - "public class Test extends TestPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo container = parseContainer(""" + // filler filler filler + public class Test extends TestPanel { + public Test() { + } + }"""); // property Property property = container.getPropertyByTitle("property"); assertNotNull(property); @@ -118,13 +117,12 @@ public void test_parse_noValue() throws Exception { @Test public void test_parse_withValue() throws Exception { configureContents(); - ContainerInfo container = - parseContainer( - "public class Test extends TestPanel {", - " public Test() {", - " setProperty(new JButton());", - " }", - "}"); + ContainerInfo container = parseContainer(""" + public class Test extends TestPanel { + public Test() { + setProperty(new JButton()); + } + }"""); // property instance info Assertions.assertThat(container.getChildrenComponents()).hasSize(1); ComponentInfo childInfo = container.getChildrenComponents().get(0); @@ -149,13 +147,12 @@ public void test_parse_withValue() throws Exception { @Test public void test_dialog() throws Exception { configureContents(); - ContainerInfo container = - parseContainer( - "// filler filler filler", - "public class Test extends TestPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo container = parseContainer(""" + // filler filler filler + public class Test extends TestPanel { + public Test() { + } + }"""); // property instance info Assertions.assertThat(container.getChildrenComponents()).hasSize(0); // property @@ -176,13 +173,13 @@ public void accept(SWTBot bot) { } }); // check source - assertEditor( - "// filler filler filler", - "public class Test extends TestPanel {", - " public Test() {", - " setProperty(new JButton('New button'));", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends TestPanel { + public Test() { + setProperty(new JButton("New button")); + } + }"""); assertEquals("javax.swing.JButton", getPropertyText(property)); Assertions.assertThat(container.getChildrenComponents()).hasSize(1); assertSame(container.getChildrenComponents().get(0), editor.getInstanceInfo(property)); @@ -196,13 +193,12 @@ public void accept(SWTBot bot) { @Test public void test_doubleClick() throws Exception { configureContents(); - ContainerInfo container = - parseContainer( - "// filler filler filler", - "public class Test extends TestPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo container = parseContainer(""" + // filler filler filler + public class Test extends TestPanel { + public Test() { + } + }"""); // property instance info Assertions.assertThat(container.getChildrenComponents()).hasSize(0); // property @@ -211,16 +207,16 @@ public void test_doubleClick() throws Exception { InstanceObjectPropertyEditor editor = (InstanceObjectPropertyEditor) property.getEditor(); // kick "doubleClick" editor.doubleClick(property); - assertEditor( - "// filler filler filler", - "public class Test extends TestPanel {", - " public Test() {", - " setProperty(", - " new AbstractButton() {", - " }", - " );", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends TestPanel { + public Test() { + setProperty( + new AbstractButton() { + } + ); + } + }"""); assertEquals("", getPropertyText(property)); Assertions.assertThat(container.getChildrenComponents()).isEmpty(); } @@ -231,14 +227,13 @@ public void test_doubleClick() throws Exception { @Test public void test_restore_default() throws Exception { configureContents(); - ContainerInfo container = - parseContainer( - "// filler filler filler", - "public class Test extends TestPanel {", - " public Test() {", - " setProperty(new JButton());", - " }", - "}"); + ContainerInfo container = parseContainer(""" + // filler filler filler + public class Test extends TestPanel { + public Test() { + setProperty(new JButton()); + } + }"""); // property instance info Assertions.assertThat(container.getChildrenComponents()).hasSize(1); // property @@ -252,12 +247,12 @@ public void test_restore_default() throws Exception { // set to default property.setValue(Property.UNKNOWN_VALUE); // check source - assertEditor( - "// filler filler filler", - "public class Test extends TestPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends TestPanel { + public Test() { + } + }"""); Assertions.assertThat(container.getChildrenComponents()).isEmpty(); } @@ -267,13 +262,12 @@ public void test_restore_default() throws Exception { @Test public void test_sub_properties() throws Exception { configureContents(); - ContainerInfo container = - parseContainer( - "public class Test extends TestPanel {", - " public Test() {", - " setProperty(new JButton());", - " }", - "}"); + ContainerInfo container = parseContainer(""" + public class Test extends TestPanel { + public Test() { + setProperty(new JButton()); + } + }"""); // property Property property = container.getPropertyByTitle("property"); //editor @@ -284,14 +278,14 @@ public void test_sub_properties() throws Exception { assertSame(subProperty, instanceInfo.getPropertyByTitle("text")); subProperty.setValue("value"); // check source - assertEditor( - "public class Test extends TestPanel {", - " public Test() {", - " JButton button = new JButton();", - " button.setText('value');", - " setProperty(button);", - " }", - "}"); + assertEditor(""" + public class Test extends TestPanel { + public Test() { + JButton button = new JButton(); + button.setText("value"); + setProperty(button); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -321,30 +315,30 @@ protected InstanceObjectPropertyEditor createEditor(Map paramete } private void configureContents() throws Exception { - setJavaContentSrc("test", "TestPanel", new String[]{ - "public class TestPanel extends JPanel {", - " public TestPanel(){", - " }", - " public void setProperty(AbstractButton value){", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " javax.swing.AbstractButton", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "TestPanel", """ + public class TestPanel extends JPanel { + public TestPanel(){ + } + public void setProperty(AbstractButton value){ + } + }""", """ + + + + + + + + + + javax.swing.AbstractButton + + + + """); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/IntegerArrayPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/IntegerArrayPropertyEditorTest.java index 56ebc7dd15..b62ee18054 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/IntegerArrayPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/IntegerArrayPropertyEditorTest.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 @@ -72,24 +72,23 @@ public void test_getEditorText() throws Exception { @Test public void test_setEditorText_setValue() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, "1 2 3"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(new int[] {1, 2, 3});", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(new int[] {1, 2, 3}); + } + }"""); } /** @@ -98,24 +97,23 @@ public void test_setEditorText_setValue() throws Exception { @Test public void test_setEditorText_removeValue_emptyString() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(1, 2, 3);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(1, 2, 3); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, ""); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -124,24 +122,23 @@ public void test_setEditorText_removeValue_emptyString() throws Exception { @Test public void test_setEditorText_removeValue_whitespaceString() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(1, 2, 3);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(1, 2, 3); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, " "); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -150,13 +147,12 @@ public void test_setEditorText_removeValue_whitespaceString() throws Exception { @Test public void test_setEditorText_invalidValue() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // final Property property = panel.getPropertyByTitle("foo"); @@ -172,22 +168,20 @@ public void accept(SWTBot bot) { shell.button("OK").click(); } }); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } private void prepareIntegerPanel() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setFoo(int... foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setFoo(int... foo) { + } + }""")); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/IntegerObjectPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/IntegerObjectPropertyEditorTest.java index 433d6c3023..6fda92e2df 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/IntegerObjectPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/IntegerObjectPropertyEditorTest.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 @@ -76,24 +76,23 @@ public void test_getEditorText() throws Exception { @Test public void test_setEditorText_value() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, "123"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(123);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(123); + } + }"""); } /** @@ -102,24 +101,23 @@ public void test_setEditorText_value() throws Exception { @Test public void test_setEditorText_null() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, "null"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo((Integer) null);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo((Integer) null); + } + }"""); } /** @@ -128,24 +126,23 @@ public void test_setEditorText_null() throws Exception { @Test public void test_setEditorText_removeValue_emptyString() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(123);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(123); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, ""); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -154,24 +151,23 @@ public void test_setEditorText_removeValue_emptyString() throws Exception { @Test public void test_setEditorText_removeValue_whitespaceString() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(123);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(123); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, " "); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -180,13 +176,12 @@ public void test_setEditorText_removeValue_whitespaceString() throws Exception { @Test public void test_setEditorText_invalidValue() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // final Property property = panel.getPropertyByTitle("foo"); @@ -202,22 +197,20 @@ public void accept(SWTBot bot) { shell.button("OK").click(); } }); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } private void prepareIntegerPanel() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setFoo(Integer foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setFoo(Integer foo) { + } + }""")); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/IntegerPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/IntegerPropertyEditorTest.java index f8fe373553..916fe4a926 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/IntegerPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/IntegerPropertyEditorTest.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 @@ -72,24 +72,23 @@ public void test_getEditorText() throws Exception { @Test public void test_setEditorText_setValue() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, "123"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(123);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(123); + } + }"""); } /** @@ -98,24 +97,23 @@ public void test_setEditorText_setValue() throws Exception { @Test public void test_setEditorText_removeValue_emptyString() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(123);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(123); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, ""); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -124,24 +122,23 @@ public void test_setEditorText_removeValue_emptyString() throws Exception { @Test public void test_setEditorText_removeValue_whitespaceString() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(123);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(123); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, " "); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -150,13 +147,12 @@ public void test_setEditorText_removeValue_whitespaceString() throws Exception { @Test public void test_setEditorText_invalidValue() throws Exception { prepareIntegerPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // final Property property = panel.getPropertyByTitle("foo"); @@ -172,22 +168,20 @@ public void accept(SWTBot bot) { shell.button("OK").click(); } }); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } private void prepareIntegerPanel() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setFoo(int foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setFoo(int foo) { + } + }""")); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/LocalePropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/LocalePropertyEditorTest.java index f68d777afc..d3d192b622 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/LocalePropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/LocalePropertyEditorTest.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,24 +35,21 @@ public class LocalePropertyEditorTest extends SwingModelTest { //////////////////////////////////////////////////////////////////////////// @Test public void test_setText() throws Exception { - setFileContentSrc( - "test/MyButton.java", - getTestSource( - "import java.util.Locale;", - "public class MyButton extends JButton {", - " public void setFoo(Locale locale) {", - " }", - "}")); + setFileContentSrc("test/MyButton.java", getTestSource(""" + import java.util.Locale; + public class MyButton extends JButton { + public void setFoo(Locale locale) { + } + }""")); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + add(button); + } + }"""); ComponentInfo button = panel.getChildrenComponents().get(0); // Property property = button.getPropertyByTitle("foo"); @@ -61,15 +58,15 @@ public void test_setText() throws Exception { assertEquals(null, getPropertyText(property)); // set value property.setValue(Locale.GERMAN); - assertEditor( - "import java.util.Locale;", - "public class Test extends JPanel {", - " public Test() {", - " MyButton button = new MyButton();", - " button.setFoo(Locale.GERMAN);", - " add(button);", - " }", - "}"); + assertEditor(""" + import java.util.Locale; + public class Test extends JPanel { + public Test() { + MyButton button = new MyButton(); + button.setFoo(Locale.GERMAN); + add(button); + } + }"""); assertEquals(Locale.GERMAN.getDisplayName(), getPropertyText(property)); } } \ No newline at end of file diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/LongObjectPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/LongObjectPropertyEditorTest.java index 3a3da8e669..e49c8b3b4c 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/LongObjectPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/LongObjectPropertyEditorTest.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 @@ -76,24 +76,23 @@ public void test_getEditorText() throws Exception { @Test public void test_setEditorText_value() throws Exception { prepareLongPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, "123"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(123L);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(123L); + } + }"""); } /** @@ -102,24 +101,23 @@ public void test_setEditorText_value() throws Exception { @Test public void test_setEditorText_null() throws Exception { prepareLongPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, "null"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo((Long) null);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo((Long) null); + } + }"""); } /** @@ -128,24 +126,23 @@ public void test_setEditorText_null() throws Exception { @Test public void test_setEditorText_removeValue_emptyString() throws Exception { prepareLongPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(123L);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(123L); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, ""); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -154,24 +151,23 @@ public void test_setEditorText_removeValue_emptyString() throws Exception { @Test public void test_setEditorText_removeValue_whitespaceString() throws Exception { prepareLongPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo(123L);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo(123L); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, " "); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -180,13 +176,12 @@ public void test_setEditorText_removeValue_whitespaceString() throws Exception { @Test public void test_setEditorText_invalidValue() throws Exception { prepareLongPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // final Property property = panel.getPropertyByTitle("foo"); @@ -202,22 +197,20 @@ public void accept(SWTBot bot) { shell.button("OK").click(); } }); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } private void prepareLongPanel() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setFoo(Long foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setFoo(Long foo) { + } + }""")); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ObjectPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ObjectPropertyEditorTest.java index 6631b1d3ca..9a59663079 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ObjectPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ObjectPropertyEditorTest.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,44 +66,43 @@ public void _test_exit() throws Exception { */ @Test public void test_nonVisualBean() throws Exception { - setJavaContentSrc("test", "MyObject", new String[]{ - "public class MyObject {", - " // filler filler filler filler filler", - "}"}, null); - setJavaContentSrc("test", "MyComponent", new String[]{ - "public class MyComponent extends JLabel {", - " public void setValue(MyObject object) {", - " }", - "}"}, null); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " private final MyComponent component = new MyComponent();", - " /**", - " * @wbp.nonvisual location=0,0", - " */", - " private final MyObject object_1 = new MyObject();", - " /**", - " * @wbp.nonvisual location=0,0", - " */", - " private final Object object_2 = new Object();", - " public Test() {", - " add(component);", - " }", - "}"); + setJavaContentSrc("test", "MyObject", """ + public class MyObject { + // filler filler filler filler filler + }""", null); + setJavaContentSrc("test", "MyComponent", """ + public class MyComponent extends JLabel { + public void setValue(MyObject object) { + } + }""", null); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + private final MyComponent component = new MyComponent(); + /** + * @wbp.nonvisual location=0,0 + */ + private final MyObject object_1 = new MyObject(); + /** + * @wbp.nonvisual location=0,0 + */ + private final Object object_2 = new Object(); + public Test() { + add(component); + } + }"""); panel.refresh(); // no "Object" properties for standard Swing components { assertNull(panel.getPropertyByTitle("dropTarget")); } // hierarchy - assertHierarchy( - "{this: javax.swing.JPanel} {this} {/add(component)/}", - " {implicit-layout: java.awt.FlowLayout} {implicit-layout} {}", - " {new: test.MyComponent} {field-initializer: component} {/new MyComponent()/ /add(component)/}", - " {NonVisualBeans}", - " {new: test.MyObject} {field-initializer: object_1} {/new MyObject()/}", - " {new: java.lang.Object} {field-initializer: object_2} {/new Object()/}"); + assertHierarchy(""" + {this: javax.swing.JPanel} {this} {/add(component)/} + {implicit-layout: java.awt.FlowLayout} {implicit-layout} {} + {new: test.MyComponent} {field-initializer: component} {/new MyComponent()/ /add(component)/} + {NonVisualBeans} + {new: test.MyObject} {field-initializer: object_1} {/new MyObject()/} + {new: java.lang.Object} {field-initializer: object_2} {/new Object()/}"""); ComponentInfo component = panel.getChildrenComponents().get(0); // prepare property final Property property = component.getPropertyByTitle("value"); @@ -154,22 +153,22 @@ public void accept(SWTBot bot) { } }); // check - assertEditor( - "public class Test extends JPanel {", - " private final MyComponent component = new MyComponent();", - " /**", - " * @wbp.nonvisual location=0,0", - " */", - " private final MyObject object_1 = new MyObject();", - " /**", - " * @wbp.nonvisual location=0,0", - " */", - " private final Object object_2 = new Object();", - " public Test() {", - " component.setValue(object_1);", - " add(component);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private final MyComponent component = new MyComponent(); + /** + * @wbp.nonvisual location=0,0 + */ + private final MyObject object_1 = new MyObject(); + /** + * @wbp.nonvisual location=0,0 + */ + private final Object object_2 = new Object(); + public Test() { + component.setValue(object_1); + add(component); + } + }"""); assertNoErrors(panel); assertEquals("object_1", getPropertyText(property)); } @@ -179,23 +178,22 @@ public void accept(SWTBot bot) { */ @Test public void test_subclassOfComponent() throws Exception { - setJavaContentSrc("test", "MyComponent", new String[]{ - "public class MyComponent extends JLabel {", - " public void setButton(JButton button) {", - " }", - "}"}, null); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " private final MyComponent component = new MyComponent();", - " private final JButton button = new JButton();", - " private final JTextField textField = new JTextField();", - " public Test() {", - " add(component);", - " add(button);", - " add(textField);", - " }", - "}"); + setJavaContentSrc("test", "MyComponent", """ + public class MyComponent extends JLabel { + public void setButton(JButton button) { + } + }""", null); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + private final MyComponent component = new MyComponent(); + private final JButton button = new JButton(); + private final JTextField textField = new JTextField(); + public Test() { + add(component); + add(button); + add(textField); + } + }"""); panel.refresh(); ComponentInfo component = panel.getChildrenComponents().get(0); // prepare property @@ -231,18 +229,18 @@ public void accept(SWTBot bot) { } }); // check - assertEditor( - "public class Test extends JPanel {", - " private final MyComponent component = new MyComponent();", - " private final JButton button = new JButton();", - " private final JTextField textField = new JTextField();", - " public Test() {", - " component.setButton(button);", - " add(component);", - " add(button);", - " add(textField);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private final MyComponent component = new MyComponent(); + private final JButton button = new JButton(); + private final JTextField textField = new JTextField(); + public Test() { + component.setButton(button); + add(component); + add(button); + add(textField); + } + }"""); assertNoErrors(panel); assertEquals("button", getPropertyText(property)); } @@ -252,24 +250,23 @@ public void accept(SWTBot bot) { */ @Test public void test_initialSelection() throws Exception { - setJavaContentSrc("test", "MyComponent", new String[]{ - "public class MyComponent extends JLabel {", - " public void setButton(JButton button) {", - " }", - "}"}, null); - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " private final MyComponent component = new MyComponent();", - " private final JButton button_1 = new JButton();", - " private final JButton button_2 = new JButton();", - " public Test() {", - " component.setButton(button_2);", - " add(component);", - " add(button_1);", - " add(button_2);", - " }", - "}"); + setJavaContentSrc("test", "MyComponent", """ + public class MyComponent extends JLabel { + public void setButton(JButton button) { + } + }""", null); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + private final MyComponent component = new MyComponent(); + private final JButton button_1 = new JButton(); + private final JButton button_2 = new JButton(); + public Test() { + component.setButton(button_2); + add(component); + add(button_1); + add(button_2); + } + }"""); panel.refresh(); ComponentInfo component = getJavaInfoByName("component"); // prepare property @@ -307,16 +304,15 @@ public void accept(SWTBot bot) { */ @Test public void test_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 @@ -338,17 +334,16 @@ public void test_getText_noInvocation() throws Exception { */ @Test public void test_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 @@ -367,14 +362,13 @@ public void test_getText_hasInvocation() throws Exception { */ @Test public void test_withAbsoluteLayout() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " setLayout(null);", - " add(new JLabel());", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + setLayout(null); + add(new JLabel()); + } + }"""); panel.refresh(); ComponentInfo label = panel.getChildrenComponents().get(0); // prepare property @@ -401,40 +395,39 @@ public void accept(SWTBot bot) { */ @Test public void test_setComponent_labelBefore() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " {", - " JLabel label = new JLabel();", - " add(label);", - " }", - " {", - " JTextField textField = new JTextField();", - " add(textField);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + JLabel label = new JLabel(); + add(label); + } + { + JTextField textField = new JTextField(); + add(textField); + } + } + }"""); ComponentInfo label = panel.getChildrenComponents().get(0); ComponentInfo textField = panel.getChildrenComponents().get(1); // set "labelFor" property Property labelForProperty = label.getPropertyByTitle("labelFor"); setComponent(labelForProperty, textField); - assertEditor( - "public class Test extends JPanel {", - " private JLabel label;", - " public Test() {", - " {", - " label = new JLabel();", - " add(label);", - " }", - " {", - " JTextField textField = new JTextField();", - " label.setLabelFor(textField);", - " add(textField);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private JLabel label; + public Test() { + { + label = new JLabel(); + add(label); + } + { + JTextField textField = new JTextField(); + label.setLabelFor(textField); + add(textField); + } + } + }"""); } /** @@ -442,40 +435,39 @@ public void test_setComponent_labelBefore() throws Exception { */ @Test public void test_setComponent_labelAfter() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " public Test() {", - " {", - " JTextField textField = new JTextField();", - " add(textField);", - " }", - " {", - " JLabel label = new JLabel();", - " add(label);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + { + JTextField textField = new JTextField(); + add(textField); + } + { + JLabel label = new JLabel(); + add(label); + } + } + }"""); ComponentInfo textField = panel.getChildrenComponents().get(0); ComponentInfo label = panel.getChildrenComponents().get(1); // set "labelFor" property Property labelForProperty = label.getPropertyByTitle("labelFor"); setComponent(labelForProperty, textField); - assertEditor( - "public class Test extends JPanel {", - " private JTextField textField;", - " public Test() {", - " {", - " textField = new JTextField();", - " add(textField);", - " }", - " {", - " JLabel label = new JLabel();", - " label.setLabelFor(textField);", - " add(label);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private JTextField textField; + public Test() { + { + textField = new JTextField(); + add(textField); + } + { + JLabel label = new JLabel(); + label.setLabelFor(textField); + add(label); + } + } + }"""); } /** @@ -484,55 +476,54 @@ public void test_setComponent_labelAfter() throws Exception { */ @Test public void test_setComponent_lazy() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " private JLabel m_label;", - " private JTextField m_textField;", - " public Test() {", - " add(getLabel());", - " add(getTextField());", - " }", - " private JLabel getLabel() {", - " if (m_label == null) {", - " m_label = new JLabel();", - " }", - " return m_label;", - " }", - " private JTextField getTextField() {", - " if (m_textField == null) {", - " m_textField = new JTextField();", - " }", - " return m_textField;", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + private JLabel m_label; + private JTextField m_textField; + public Test() { + add(getLabel()); + add(getTextField()); + } + private JLabel getLabel() { + if (m_label == null) { + m_label = new JLabel(); + } + return m_label; + } + private JTextField getTextField() { + if (m_textField == null) { + m_textField = new JTextField(); + } + return m_textField; + } + }"""); ComponentInfo label = panel.getChildrenComponents().get(0); ComponentInfo textField = panel.getChildrenComponents().get(1); // set "labelFor" property Property labelForProperty = label.getPropertyByTitle("labelFor"); setComponent(labelForProperty, textField); - assertEditor( - "public class Test extends JPanel {", - " private JLabel m_label;", - " private JTextField m_textField;", - " public Test() {", - " add(getLabel());", - " add(getTextField());", - " }", - " private JLabel getLabel() {", - " if (m_label == null) {", - " m_label = new JLabel();", - " m_label.setLabelFor(getTextField());", - " }", - " return m_label;", - " }", - " private JTextField getTextField() {", - " if (m_textField == null) {", - " m_textField = new JTextField();", - " }", - " return m_textField;", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private JLabel m_label; + private JTextField m_textField; + public Test() { + add(getLabel()); + add(getTextField()); + } + private JLabel getLabel() { + if (m_label == null) { + m_label = new JLabel(); + m_label.setLabelFor(getTextField()); + } + return m_label; + } + private JTextField getTextField() { + if (m_textField == null) { + m_textField = new JTextField(); + } + return m_textField; + } + }"""); } /** @@ -540,50 +531,49 @@ public void test_setComponent_lazy() throws Exception { */ @Test public void test_setComponent_newComponent() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " private JLabel label;", - " public Test() {", - " {", - " label = new JLabel();", - " add(label);", - " }", - " {", - " JTextField textField_1 = new JTextField();", - " label.setLabelFor(textField_1);", - " add(textField_1);", - " }", - " {", - " JTextField textField_2 = new JTextField();", - " add(textField_2);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + private JLabel label; + public Test() { + { + label = new JLabel(); + add(label); + } + { + JTextField textField_1 = new JTextField(); + label.setLabelFor(textField_1); + add(textField_1); + } + { + JTextField textField_2 = new JTextField(); + add(textField_2); + } + } + }"""); ComponentInfo label = panel.getChildrenComponents().get(0); ComponentInfo textField_2 = panel.getChildrenComponents().get(2); // set "labelFor" property Property labelForProperty = label.getPropertyByTitle("labelFor"); setComponent(labelForProperty, textField_2); - assertEditor( - "public class Test extends JPanel {", - " private JLabel label;", - " public Test() {", - " {", - " label = new JLabel();", - " add(label);", - " }", - " {", - " JTextField textField_1 = new JTextField();", - " add(textField_1);", - " }", - " {", - " JTextField textField_2 = new JTextField();", - " label.setLabelFor(textField_2);", - " add(textField_2);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private JLabel label; + public Test() { + { + label = new JLabel(); + add(label); + } + { + JTextField textField_1 = new JTextField(); + add(textField_1); + } + { + JTextField textField_2 = new JTextField(); + label.setLabelFor(textField_2); + add(textField_2); + } + } + }"""); } /** @@ -591,40 +581,39 @@ public void test_setComponent_newComponent() throws Exception { */ @Test public void test_setComponent_noComponent() throws Exception { - ContainerInfo panel = - parseContainer( - "public class Test extends JPanel {", - " private JLabel label;", - " public Test() {", - " {", - " label = new JLabel();", - " add(label);", - " }", - " {", - " JTextField textField_1 = new JTextField();", - " label.setLabelFor(textField_1);", - " add(textField_1);", - " }", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + private JLabel label; + public Test() { + { + label = new JLabel(); + add(label); + } + { + JTextField textField_1 = new JTextField(); + label.setLabelFor(textField_1); + add(textField_1); + } + } + }"""); ComponentInfo label = panel.getChildrenComponents().get(0); // set "labelFor" property Property labelForProperty = label.getPropertyByTitle("labelFor"); setComponent(labelForProperty, null); - assertEditor( - "public class Test extends JPanel {", - " private JLabel label;", - " public Test() {", - " {", - " label = new JLabel();", - " add(label);", - " }", - " {", - " JTextField textField_1 = new JTextField();", - " add(textField_1);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private JLabel label; + public Test() { + { + label = new JLabel(); + add(label); + } + { + JTextField textField_1 = new JTextField(); + add(textField_1); + } + } + }"""); } /** @@ -632,26 +621,24 @@ public void test_setComponent_noComponent() throws Exception { */ @Test public void test_setComponent_constructor() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public MyPanel(JButton button) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public MyPanel(JButton button) { + } + }""")); waitForAutoBuild(); // parse - parseContainer( - "public class Test extends JPanel {", - " private final JButton button_1 = new JButton();", - " private final JButton button_2 = new JButton();", - " private final MyPanel myPanel = new MyPanel(button_1);", - " public Test() {", - " add(button_1);", - " add(button_2);", - " add(myPanel);", - " }", - "}"); + parseContainer(""" + public class Test extends JPanel { + private final JButton button_1 = new JButton(); + private final JButton button_2 = new JButton(); + private final MyPanel myPanel = new MyPanel(button_1); + public Test() { + add(button_1); + add(button_2); + add(myPanel); + } + }"""); refresh(); ContainerInfo myPanel = getJavaInfoByName("myPanel"); ComponentInfo button_2 = getJavaInfoByName("button_2"); @@ -663,17 +650,17 @@ public void test_setComponent_constructor() throws Exception { assertEquals("button_1", getPropertyText(property)); // set "button_2" setComponent(property, button_2); - assertEditor( - "public class Test extends JPanel {", - " private final JButton button_1 = new JButton();", - " private final JButton button_2 = new JButton();", - " private final MyPanel myPanel = new MyPanel(button_2);", - " public Test() {", - " add(button_1);", - " add(button_2);", - " add(myPanel);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + private final JButton button_1 = new JButton(); + private final JButton button_2 = new JButton(); + private final MyPanel myPanel = new MyPanel(button_2); + public Test() { + add(button_1); + add(button_2); + add(myPanel); + } + }"""); } private static void setComponent(Property property, JavaInfo component) throws Exception { diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ShortObjectPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ShortObjectPropertyEditorTest.java index ef587e2080..6aac097a27 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ShortObjectPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/ShortObjectPropertyEditorTest.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 @@ -76,24 +76,23 @@ public void test_getEditorText() throws Exception { @Test public void test_setEditorText_value() throws Exception { prepareShortPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, "123"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo((short) 123);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo((short) 123); + } + }"""); } /** @@ -102,24 +101,23 @@ public void test_setEditorText_value() throws Exception { @Test public void test_setEditorText_null() throws Exception { prepareShortPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, "null"); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo((Short) null);", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo((Short) null); + } + }"""); } /** @@ -128,24 +126,23 @@ public void test_setEditorText_null() throws Exception { @Test public void test_setEditorText_removeValue_emptyString() throws Exception { prepareShortPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo((short) 123);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo((short) 123); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, ""); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -154,24 +151,23 @@ public void test_setEditorText_removeValue_emptyString() throws Exception { @Test public void test_setEditorText_removeValue_whitespaceString() throws Exception { prepareShortPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " setFoo((short) 123);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + setFoo((short) 123); + } + }"""); panel.refresh(); // Property property = panel.getPropertyByTitle("foo"); setTextEditorText(property, " "); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } /** @@ -180,13 +176,12 @@ public void test_setEditorText_removeValue_whitespaceString() throws Exception { @Test public void test_setEditorText_invalidValue() throws Exception { prepareShortPanel(); - ContainerInfo panel = - parseContainer( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); panel.refresh(); // final Property property = panel.getPropertyByTitle("foo"); @@ -202,22 +197,20 @@ public void accept(SWTBot bot) { shell.button("OK").click(); } }); - assertEditor( - "// filler filler filler", - "public class Test extends MyPanel {", - " public Test() {", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends MyPanel { + public Test() { + } + }"""); } private void prepareShortPanel() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void setFoo(Short foo) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void setFoo(Short foo) { + } + }""")); waitForAutoBuild(); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StaticFieldPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StaticFieldPropertyEditorTest.java index 0927eaa568..3478ea5a09 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StaticFieldPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StaticFieldPropertyEditorTest.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 @@ -147,12 +147,12 @@ public void test_configure_5() throws Exception { */ @Test public void test_configure_6() throws Exception { - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); // create StaticFieldPropertyEditor StaticFieldPropertyEditor editor = new StaticFieldPropertyEditor(); editor.configure(m_lastState, Map.of( @@ -175,12 +175,12 @@ public void test_configure_6() throws Exception { */ @Test public void test_configure_7() throws Exception { - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); // create StaticFieldPropertyEditor StaticFieldPropertyEditor editor = new StaticFieldPropertyEditor(); editor.configure(m_lastState, Map.of( @@ -203,12 +203,12 @@ public void test_configure_7() throws Exception { */ @Test public void test_configure_8() throws Exception { - parseContainer( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " }", - "}"); + parseContainer(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + } + }"""); // create StaticFieldPropertyEditor try { StaticFieldPropertyEditor editor = new StaticFieldPropertyEditor(); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StringListPropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StringListPropertyEditorTest.java index 1e663b04f7..610b4b720f 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StringListPropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StringListPropertyEditorTest.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 @@ -157,35 +157,34 @@ public void setValue(Object value) throws Exception { @Test public void test_defaultValue() throws Exception { // create contents - setJavaContentSrc("test", "MyButton", new String[]{ - "import javax.swing.JButton;", - "class MyButton extends JButton {", - " public void setSelect(java.lang.String value) {", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " false", - " default", - " string", - " value", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "MyButton", """ + import javax.swing.JButton; + class MyButton extends JButton { + public void setSelect(java.lang.String value) { + } + }""", """ + + + + + false + default + string + value + + + + """); waitForAutoBuild(); // - ContainerInfo panel = - parseContainer( - "class Test extends JPanel {", - " Test() {", - " MyButton button = new MyButton();", - " button.setSelect('string');", - " add(button);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + class Test extends JPanel { + Test() { + MyButton button = new MyButton(); + button.setSelect("string"); + add(button); + } + }"""); panel.refresh(); ComponentInfo button = panel.getChildrenComponents().get(0); Property property = button.getPropertyByTitle("select"); @@ -197,13 +196,13 @@ public void test_defaultValue() throws Exception { setComboPropertyValue(property, 0); assertEquals(property.getValue(), "default"); // check source - assertEditor( - "class Test extends JPanel {", - " Test() {", - " MyButton button = new MyButton();", - " add(button);", - " }", - "}"); + assertEditor(""" + class Test extends JPanel { + Test() { + MyButton button = new MyButton(); + add(button); + } + }"""); } //////////////////////////////////////////////////////////////////////////// diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StringsAddPropertyTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StringsAddPropertyTest.java index d4dd5eca2d..5ba6631052 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StringsAddPropertyTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StringsAddPropertyTest.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 @@ -34,30 +34,27 @@ public class StringsAddPropertyTest extends SwingModelTest { @Test public void test_0() throws Exception { createMyPanel(); - setFileContentSrc( - "test/MyPanel.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " addItem", - " ", - "")); + setFileContentSrc("test/MyPanel.wbp-component.xml", """ + + + + + + + + + addItem + + """); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " addItem('aaa');", - " addItem('bbb');", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + addItem("aaa"); + addItem("bbb"); + } + }"""); panel.refresh(); // prepare "items" property Property itemsProperty = panel.getPropertyByTitle("items"); @@ -71,14 +68,14 @@ public void test_0() throws Exception { // set new items { itemsProperty.setValue(new String[]{"000", "111", "222"}); - assertEditor( - "public class Test extends MyPanel {", - " public Test() {", - " addItem('000');", - " addItem('111');", - " addItem('222');", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel { + public Test() { + addItem("000"); + addItem("111"); + addItem("222"); + } + }"""); assertEquals("[000,111,222]", getPropertyText(itemsProperty)); assertTrue(itemsProperty.isModified()); assertArrayEquals(new String[] { "000", "111", "222" }, (String[]) itemsProperty.getValue()); @@ -88,33 +85,30 @@ public void test_0() throws Exception { @Test public void test_removeMethods() throws Exception { createMyPanel(); - setFileContentSrc( - "test/MyPanel.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " addItem", - " clear() insertItem(java.lang.String,int)", - " ", - "")); + setFileContentSrc("test/MyPanel.wbp-component.xml", """ + + + + + + + + + addItem + clear() insertItem(java.lang.String,int) + + """); waitForAutoBuild(); // parse - ContainerInfo panel = - parseContainer( - "public class Test extends MyPanel {", - " public Test() {", - " clear();", - " addItem('aaa');", - " addItem('bbb');", - " insertItem('ccc', 1);", - " }", - "}"); + ContainerInfo panel = parseContainer(""" + public class Test extends MyPanel { + public Test() { + clear(); + addItem("aaa"); + addItem("bbb"); + insertItem("ccc", 1); + } + }"""); panel.refresh(); // prepare "items" property Property itemsProperty = panel.getPropertyByTitle("items"); @@ -128,14 +122,14 @@ public void test_removeMethods() throws Exception { // set new items { itemsProperty.setValue(new String[]{"000", "111", "222"}); - assertEditor( - "public class Test extends MyPanel {", - " public Test() {", - " addItem('000');", - " addItem('111');", - " addItem('222');", - " }", - "}"); + assertEditor(""" + public class Test extends MyPanel { + public Test() { + addItem("000"); + addItem("111"); + addItem("222"); + } + }"""); assertEquals("[000,111,222]", getPropertyText(itemsProperty)); assertTrue(itemsProperty.isModified()); assertArrayEquals(new String[] { "000", "111", "222" }, (String[]) itemsProperty.getValue()); @@ -143,16 +137,14 @@ public void test_removeMethods() throws Exception { } private void createMyPanel() throws Exception { - setFileContentSrc( - "test/MyPanel.java", - getTestSource( - "public class MyPanel extends JPanel {", - " public void clear() {", - " }", - " public void addItem(String item) {", - " }", - " public void insertItem(String item, int index) {", - " }", - "}")); + setFileContentSrc("test/MyPanel.java", getTestSource(""" + public class MyPanel extends JPanel { + public void clear() { + } + public void addItem(String item) { + } + public void insertItem(String item, int index) { + } + }""")); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StylePropertyEditorLongTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StylePropertyEditorLongTest.java index b838998e21..4fc2c00456 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StylePropertyEditorLongTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StylePropertyEditorLongTest.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 @@ -59,31 +59,27 @@ public class StylePropertyEditorLongTest extends SwingModelTest { @Override protected void configureNewProject() throws Exception { super.configureNewProject(); - setFileContentSrc( - "test/StylePanel.java", - getTestSource( - "public class StylePanel extends JPanel {", - " public StylePanel(long style) {", - " }", - "}")); - setFileContentSrc( - "test/SWT.java", - getTestSource( - "public interface SWT {", - " long NONE = 0;", - " long B0 = 1 << 0;", - " long B1 = 1 << 1;", - " long B2 = 1 << 2;", - " long B3 = 1 << 3;", - " // mix", - " long B0_B1 = B0 | B1;", - " long B0_B2 = B0 | B2;", - " //", - " long R1 = 1 << 4;", - " long R2 = 1 << 5;", - " long R3 = 1 << 6;", - " long R4 = 1 << 7;", - "}")); + setFileContentSrc("test/StylePanel.java", getTestSource(""" + public class StylePanel extends JPanel { + public StylePanel(long style) { + } + }""")); + setFileContentSrc("test/SWT.java", getTestSource(""" + public interface SWT { + long NONE = 0; + long B0 = 1 << 0; + long B1 = 1 << 1; + long B2 = 1 << 2; + long B3 = 1 << 3; + // mix + long B0_B1 = B0 | B1; + long B0_B2 = B0 | B2; + // + long R1 = 1 << 4; + long R2 = 1 << 5; + long R3 = 1 << 6; + long R4 = 1 << 7; + }""")); forgetCreatedResources(); } @@ -240,39 +236,35 @@ public void test_Select_2() throws Exception { @Test public void test_Select_for_methodProperty() throws Exception { - setFileContentSrc( - "test/TestComposite.java", - getTestSource( - "public class TestComposite extends JPanel {", - " private long m_format;", - " public long getFormat() {", - " return m_format;", - " }", - " public void setFormat(long format) {", - " m_format = format;", - " }", - "}")); - setFileContentSrc( - "test/TestComposite.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " test.SWT", - " type NONE NONE R1 R2", - " ", - " ", - "")); + setFileContentSrc("test/TestComposite.java", getTestSource(""" + public class TestComposite extends JPanel { + private long m_format; + public long getFormat() { + return m_format; + } + public void setFormat(long format) { + m_format = format; + } + }""")); + setFileContentSrc("test/TestComposite.wbp-component.xml", """ + + + + + test.SWT + type NONE NONE R1 R2 + + + """); waitForAutoBuild(); // parse - parseStyleProperties0("format", new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " TestComposite composite = new TestComposite();", - " add(composite);", - " }", - "}"}); + parseStyleProperties0("format", """ + public class Test extends JPanel { + public Test() { + TestComposite composite = new TestComposite(); + add(composite); + } + }"""); Assertions.assertThat(m_properties).hasSize(1); Property alignProperty = m_properties[0]; // initially no style @@ -281,37 +273,37 @@ public void test_Select_for_methodProperty() throws Exception { alignProperty.setValue("R1"); assertEquals("R1", alignProperty.getValue()); assertEditorText("[R1]"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " TestComposite composite = new TestComposite();", - " composite.setFormat(SWT.R1);", - " add(composite);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + TestComposite composite = new TestComposite(); + composite.setFormat(SWT.R1); + add(composite); + } + }"""); // := R2 alignProperty.setValue("R2"); assertEquals("R2", alignProperty.getValue()); assertEditorText("[R2]"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " TestComposite composite = new TestComposite();", - " composite.setFormat(SWT.R2);", - " add(composite);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + TestComposite composite = new TestComposite(); + composite.setFormat(SWT.R2); + add(composite); + } + }"""); // := NONE alignProperty.setValue("NONE"); assertEquals("NONE", alignProperty.getValue()); assertEditorText("[]"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " TestComposite composite = new TestComposite();", - " add(composite);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + TestComposite composite = new TestComposite(); + add(composite); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -584,13 +576,13 @@ private void assertEditorText(String text) throws Exception { } private void assertStyleSource(String styleSource) { - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " add(new TestComposite(" + styleSource + "));", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + add(new TestComposite(%s)); + } + }""".formatted(styleSource)); } private void parseStyleProperties(String... styleLines) throws Exception { @@ -598,13 +590,11 @@ private void parseStyleProperties(String... styleLines) throws Exception { } private void parseStyleProperties(String styleSource, String[] styleLines0) throws Exception { - setFileContentSrc( - "test/TestComposite.java", - getTestSource( - "public class TestComposite extends JPanel {", - " public TestComposite(long style) {", - " }", - "}")); + setFileContentSrc("test/TestComposite.java", getTestSource(""" + public class TestComposite extends JPanel { + public TestComposite(long style) { + } + }""")); // convert: name|value into "parameter" line String[] styleLines = new String[styleLines0.length]; for (int i = 0; i < styleLines0.length; i++) { @@ -612,40 +602,36 @@ private void parseStyleProperties(String styleSource, String[] styleLines0) thro int index = line.indexOf('|'); String name = line.substring(0, index); String value = line.substring(index + 1); - styleLines[i] = MessageFormat.format("{1}", name, value); + styleLines[i] = MessageFormat.format("{1}", name, value); } // prepare description - String[] lines; - lines = - new String[]{ - "", - "", - " ", - " ", - " ", - " ", - " test.SWT"}; - lines = CodeUtils.join(lines, styleLines); - lines = - CodeUtils.join(lines, new String[]{ - " ", - " ", - " ", - " ", - ""}); - setFileContentSrc("test/TestComposite.wbp-component.xml", getSource(lines)); + setFileContentSrc("test/TestComposite.wbp-component.xml", getSource(""" + + + + + + + test.SWT + %s + + + + + + """.formatted(String.join("\n", styleLines)))); waitForAutoBuild(); // parse - parseStyleProperties0("Constructor/style", new String[]{ - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " add(new TestComposite(" + styleSource + "));", - " }", - "}"}); + parseStyleProperties0("Constructor/style", """ + // filler filler filler + public class Test extends JPanel { + public Test() { + add(new TestComposite(%s)); + } + }""".formatted(styleSource)); } - private void parseStyleProperties0(String propertyPath, String[] lines) throws Exception { + private void parseStyleProperties0(String propertyPath, String lines) throws Exception { ContainerInfo panel = parseContainer(lines); panel.refresh(); // prepare "style" property diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StylePropertyEditorTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StylePropertyEditorTest.java index e87bd7ef82..15d2101ac1 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StylePropertyEditorTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/property/editor/StylePropertyEditorTest.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 @@ -20,7 +20,6 @@ import org.eclipse.wb.internal.core.model.property.editor.StringComboPropertyEditor; import org.eclipse.wb.internal.core.model.property.editor.style.StylePropertyEditor; import org.eclipse.wb.internal.core.model.util.PropertyUtils; -import org.eclipse.wb.internal.core.utils.jdt.core.CodeUtils; import org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils; import org.eclipse.wb.internal.core.utils.state.EditorWarning; import org.eclipse.wb.internal.swing.model.component.ComponentInfo; @@ -58,31 +57,27 @@ public class StylePropertyEditorTest extends SwingModelTest { @Override protected void configureNewProject() throws Exception { super.configureNewProject(); - setFileContentSrc( - "test/StylePanel.java", - getTestSource( - "public class StylePanel extends JPanel {", - " public StylePanel(int style) {", - " }", - "}")); - setFileContentSrc( - "test/SWT.java", - getTestSource( - "public interface SWT {", - " int NONE = 0;", - " int B0 = 1 << 0;", - " int B1 = 1 << 1;", - " int B2 = 1 << 2;", - " int B3 = 1 << 3;", - " // mix", - " int B0_B1 = B0 | B1;", - " int B0_B2 = B0 | B2;", - " //", - " int R1 = 1 << 4;", - " int R2 = 1 << 5;", - " int R3 = 1 << 6;", - " int R4 = 1 << 7;", - "}")); + setFileContentSrc("test/StylePanel.java", getTestSource(""" + public class StylePanel extends JPanel { + public StylePanel(int style) { + } + }""")); + setFileContentSrc("test/SWT.java", getTestSource(""" + public interface SWT { + int NONE = 0; + int B0 = 1 << 0; + int B1 = 1 << 1; + int B2 = 1 << 2; + int B3 = 1 << 3; + // mix + int B0_B1 = B0 | B1; + int B0_B2 = B0 | B2; + // + int R1 = 1 << 4; + int R2 = 1 << 5; + int R3 = 1 << 6; + int R4 = 1 << 7; + }""")); forgetCreatedResources(); } @@ -228,39 +223,35 @@ public void test_Select_2() throws Exception { @Test public void test_Select_for_methodProperty() throws Exception { - setFileContentSrc( - "test/TestComposite.java", - getTestSource( - "public class TestComposite extends JPanel {", - " private int m_format;", - " public int getFormat() {", - " return m_format;", - " }", - " public void setFormat(int format) {", - " m_format = format;", - " }", - "}")); - setFileContentSrc( - "test/TestComposite.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " test.SWT", - " type NONE NONE R1 R2", - " ", - " ", - "")); + setFileContentSrc("test/TestComposite.java", getTestSource(""" + public class TestComposite extends JPanel { + private int m_format; + public int getFormat() { + return m_format; + } + public void setFormat(int format) { + m_format = format; + } + }""")); + setFileContentSrc("test/TestComposite.wbp-component.xml", """ + + + + + test.SWT + type NONE NONE R1 R2 + + + """); waitForAutoBuild(); // parse - parseStyleProperties0("format", new String[]{ - "public class Test extends JPanel {", - " public Test() {", - " TestComposite composite = new TestComposite();", - " add(composite);", - " }", - "}"}); + parseStyleProperties0("format", """ + public class Test extends JPanel { + public Test() { + TestComposite composite = new TestComposite(); + add(composite); + } + }"""); Assertions.assertThat(m_properties).hasSize(1); Property alignProperty = m_properties[0]; // initially no style @@ -269,37 +260,37 @@ public void test_Select_for_methodProperty() throws Exception { alignProperty.setValue("R1"); assertEquals("R1", alignProperty.getValue()); assertEditorText("[R1]"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " TestComposite composite = new TestComposite();", - " composite.setFormat(SWT.R1);", - " add(composite);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + TestComposite composite = new TestComposite(); + composite.setFormat(SWT.R1); + add(composite); + } + }"""); // := R2 alignProperty.setValue("R2"); assertEquals("R2", alignProperty.getValue()); assertEditorText("[R2]"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " TestComposite composite = new TestComposite();", - " composite.setFormat(SWT.R2);", - " add(composite);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + TestComposite composite = new TestComposite(); + composite.setFormat(SWT.R2); + add(composite); + } + }"""); // := NONE alignProperty.setValue("NONE"); assertEquals("NONE", alignProperty.getValue()); assertEditorText("[]"); - assertEditor( - "public class Test extends JPanel {", - " public Test() {", - " TestComposite composite = new TestComposite();", - " add(composite);", - " }", - "}"); + assertEditor(""" + public class Test extends JPanel { + public Test() { + TestComposite composite = new TestComposite(); + add(composite); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -572,13 +563,13 @@ private void assertEditorText(String text) throws Exception { } private void assertStyleSource(String styleSource) { - assertEditor( - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " add(new TestComposite(" + styleSource + "));", - " }", - "}"); + assertEditor(""" + // filler filler filler + public class Test extends JPanel { + public Test() { + add(new TestComposite(%s)); + } + }""".formatted(styleSource)); } private void parseStyleProperties(String... styleLines) throws Exception { @@ -586,13 +577,11 @@ private void parseStyleProperties(String... styleLines) throws Exception { } private void parseStyleProperties(String styleSource, String[] styleLines0) throws Exception { - setFileContentSrc( - "test/TestComposite.java", - getTestSource( - "public class TestComposite extends JPanel {", - " public TestComposite(int style) {", - " }", - "}")); + setFileContentSrc("test/TestComposite.java", getTestSource(""" + public class TestComposite extends JPanel { + public TestComposite(int style) { + } + }""")); // convert: name|value into "parameter" line String[] styleLines = new String[styleLines0.length]; for (int i = 0; i < styleLines0.length; i++) { @@ -600,40 +589,36 @@ private void parseStyleProperties(String styleSource, String[] styleLines0) thro int index = line.indexOf('|'); String name = line.substring(0, index); String value = line.substring(index + 1); - styleLines[i] = MessageFormat.format("{1}", name, value); + styleLines[i] = MessageFormat.format("{1}", name, value); } // prepare description - String[] lines; - lines = - new String[]{ - "", - "", - " ", - " ", - " ", - " ", - " test.SWT"}; - lines = CodeUtils.join(lines, styleLines); - lines = - CodeUtils.join(lines, new String[]{ - " ", - " ", - " ", - " ", - ""}); - setFileContentSrc("test/TestComposite.wbp-component.xml", getSource(lines)); + setFileContentSrc("test/TestComposite.wbp-component.xml", getSource(""" + + + + + + + test.SWT + %s + + + + + + """.formatted(String.join("\n", styleLines)))); waitForAutoBuild(); // parse - parseStyleProperties0("Constructor/style", new String[]{ - "// filler filler filler", - "public class Test extends JPanel {", - " public Test() {", - " add(new TestComposite(" + styleSource + "));", - " }", - "}"}); + parseStyleProperties0("Constructor/style", """ + // filler filler filler + public class Test extends JPanel { + public Test() { + add(new TestComposite(%s)); + } + }""".formatted(styleSource)); } - private void parseStyleProperties0(String propertyPath, String[] lines) throws Exception { + private void parseStyleProperties0(String propertyPath, String lines) throws Exception { ContainerInfo panel = parseContainer(lines); panel.refresh(); // prepare "style" property diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/util/JavaInfoUtilsTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/util/JavaInfoUtilsTest.java index acea53c078..749bdc225e 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/util/JavaInfoUtilsTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/util/JavaInfoUtilsTest.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 @@ -481,18 +481,18 @@ public void test_setParameter() throws Exception { @Test public void test_getParameters() throws Exception { - setJavaContentSrc("test", "MyPanel", new String[]{ - "public class MyPanel extends JPanel {", - " public MyPanel() {", - " }", - "}"}, new String[]{ - "", - "", - " ", - " value_1", - " 1000", - " ", - ""}); + setJavaContentSrc("test", "MyPanel", """ + public class MyPanel extends JPanel { + public MyPanel() { + } + }""", """ + + + + value_1 + 1000 + + """); waitForAutoBuild(); // parse ContainerInfo panel = diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/util/MethodOrderTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/util/MethodOrderTest.java index 3f9c5186cb..7e536701e4 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/util/MethodOrderTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/util/MethodOrderTest.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 @@ -1780,60 +1780,60 @@ public void test_afterChildren_addChild() throws Exception { private void configureProject_afterChildren() throws Exception { { // ItemPanel1 - setJavaContentSrc("test", "ItemPanel1", new String[]{ - "public class ItemPanel1 extends JPanel {", - " public ItemPanel1(JPanel parent){", - " parent.add(this);", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "ItemPanel1", """ + public class ItemPanel1 extends JPanel { + public ItemPanel1(JPanel parent){ + parent.add(this); + } + }""", """ + + + + + + + + + + + """); } { // ItemPanel2 - setJavaContentSrc("test", "ItemPanel2", new String[]{ - "public class ItemPanel2 extends JPanel {", - " public ItemPanel2(JPanel parent){", - " parent.add(this);", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "ItemPanel2", """ + public class ItemPanel2 extends JPanel { + public ItemPanel2(JPanel parent){ + parent.add(this); + } + }""", """ + + + + + + + + + + + """); } { // ContainerPanel - setJavaContentSrc("test", "ContainerPanel", new String[]{ - "public class ContainerPanel extends JPanel {", - " public void setProperty_1(int value){", - " }", - " public void setProperty_2(int value){", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "ContainerPanel", """ + public class ContainerPanel extends JPanel { + public void setProperty_1(int value){ + } + public void setProperty_2(int value){ + } + }""", """ + + + + + + + """); } } @@ -2063,55 +2063,55 @@ public void test_afterParentChildren_invocationBlockLast() throws Exception { private void configureProject_afterParentChildren() throws Exception { { // ItemPanel - setJavaContentSrc("test", "ItemPanel", new String[]{ - "public class ItemPanel extends JPanel {", - " public ItemPanel(JPanel parent){", - " parent.add(this);", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "ItemPanel", """ + public class ItemPanel extends JPanel { + public ItemPanel(JPanel parent){ + parent.add(this); + } + }""", """ + + + + + + + + + + + """); } { // PropertyItem - setJavaContentSrc("test", "PropertyItem", new String[]{ - "public class PropertyItem extends Component {", - " public PropertyItem(){", - " }", - " public void setValue(int value){", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "PropertyItem", """ + public class PropertyItem extends Component { + public PropertyItem(){ + } + public void setValue(int value){ + } + }""", """ + + + + + + """); } { // ContainerPanel - setJavaContentSrc("test", "ContainerPanel", new String[]{ - "public class ContainerPanel extends JPanel {", - " public void setProperty(test.PropertyItem value){", - " }", - "}"}, new String[]{ - "", - "", - " ", - " ", - " ", - " ", - " ", - ""}); + setJavaContentSrc("test", "ContainerPanel", """ + public class ContainerPanel extends JPanel { + public void setProperty(test.PropertyItem value){ + } + }""", """ + + + + + + + + """); } waitForAutoBuild(); } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/util/StackContainerSupportTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/util/StackContainerSupportTest.java index cec0406e26..70753b3454 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/util/StackContainerSupportTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/util/StackContainerSupportTest.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 @@ -547,15 +547,15 @@ public void test_moveChild_toOuter() throws Exception { // //////////////////////////////////////////////////////////////////////////// private void prepareCardPanel() throws Exception { - setJavaContentSrc("test", "CardPanel", new String[]{ - "public class CardPanel extends JPanel {", - " public CardPanel() {", - " }", - "}"}, new String[]{ - "", - "", - " ", - ""}); + setJavaContentSrc("test", "CardPanel", """ + public class CardPanel extends JPanel { + public CardPanel() { + } + }""", """ + + + + """.formatted(CardPanel_Info.class.getName())); } public static class CardPanel_Info extends ContainerInfo { diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/SwingModelTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/SwingModelTest.java index 781161a7ac..6f37df268c 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/SwingModelTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/SwingModelTest.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 @@ -107,8 +107,8 @@ public String getTestSource(String... lines) { */ public final void setJavaContentSrc(String packageName, String className, - String[] source, - String[] meta) throws Exception { + String source, + String meta) throws Exception { setFileContentSrc(packageName, className + ".java", getTestSource(source)); if (meta != null) { setFileContentSrc(packageName, className + ".wbp-component.xml", getSource(meta));