diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/ManagerUtilsTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/ManagerUtilsTest.java index 77efcd2cc..278ebca9f 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/ManagerUtilsTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/ManagerUtilsTest.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 @@ -144,12 +144,11 @@ public void test_ensure_ResourceManager() throws Exception { } private void parseShell() throws Exception { - shell = - parseComposite( - "// filler filler filler", - "public class Test extends Shell {", - " public Test() {", - " }", - "}"); + shell = parseComposite(""" + // filler filler filler + public class Test extends Shell { + public Test() { + } + }"""); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/ClipboardTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/ClipboardTest.java index 4b53f46f0..8e7a177ac 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/ClipboardTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/ClipboardTest.java @@ -141,17 +141,16 @@ private void check_propertiesPaste(String invocationCode) throws Exception { private void check_propertiesPaste(String invocationCode_1, String invocationCode_2) throws Exception { m_waitForAutoBuild = true; - final CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.BORDER | SWT.CHECK);", - " button." + invocationCode_1 + ";", - " }", - " }", - "}"); + final CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.BORDER | SWT.CHECK); + button.%s; + } + } + }""".formatted(invocationCode_1)); final RowLayoutInfo rowLayout = (RowLayoutInfo) shell.getLayout(); shell.refresh(); // create memento for "button" @@ -167,20 +166,20 @@ private void check_propertiesPaste(String invocationCode_1, String invocationCod rowLayout.command_CREATE(button, null); memento.apply(); }); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.BORDER | SWT.CHECK);", - " button." + invocationCode_1 + ";", - " }", - " {", - " Button button = new Button(this, SWT.BORDER | SWT.CHECK);", - " button." + invocationCode_2 + ";", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.BORDER | SWT.CHECK); + button.%s; + } + { + Button button = new Button(this, SWT.BORDER | SWT.CHECK); + button.%s; + } + } + }""".formatted(invocationCode_1, invocationCode_2)); } } @@ -194,16 +193,15 @@ private void check_propertiesPaste(String invocationCode_1, String invocationCod */ @Test public void test_liveImageSize() throws Exception { - final CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 20, 200, 100);", - " }", - " }", - "}"); + final CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 20, 200, 100); + } + } + }"""); final AbsoluteLayoutInfo absoluteLayout = (AbsoluteLayoutInfo) shell.getLayout(); shell.refresh(); // create memento for "control" @@ -251,16 +249,15 @@ public void test_liveImageSize() throws Exception { */ @Test public void test_asserts() throws Exception { - final CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 20, 200, 100);", - " }", - " }", - "}"); + final CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 20, 200, 100); + } + } + }"""); final AbsoluteLayoutInfo absoluteLayout = (AbsoluteLayoutInfo) shell.getLayout(); shell.refresh(); // create memento for "control" @@ -296,7 +293,7 @@ public void test_asserts() throws Exception { /** * Does copy/paste for first child of parsed {@link CompositeInfo} with {@link RowLayoutInfo}. */ - private void layouts_doCopy(String[] sourceLines, String[] targetLines) throws Exception { + private void layouts_doCopy(String sourceLines, String targetLines) throws Exception { final CompositeInfo shell = parseComposite(sourceLines); final RowLayoutInfo rowLayout = (RowLayoutInfo) shell.getLayout(); shell.refresh(); @@ -311,502 +308,476 @@ private void layouts_doCopy(String[] sourceLines, String[] targetLines) throws E @Test public void test_factoryStatic() throws Exception { - setFileContentSrc( - "test/StaticFactory.java", - getTestSource( - "public final class StaticFactory {", - " public static Button createButton(Composite parent, String text) {", - " Button button = new Button(parent, SWT.NONE);", - " button.setText(text);", - " return button;", - " }", - "}")); + setFileContentSrc("test/StaticFactory.java", getTestSource(""" + public final class StaticFactory { + public static Button createButton(Composite parent, String text) { + Button button = new Button(parent, SWT.NONE); + button.setText(text); + return button; + } + }""")); waitForAutoBuild(); // - String[] sourceLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = StaticFactory.createButton(this, \"button\");", - " }", - " }", - "}"}; - String[] targetLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = StaticFactory.createButton(this, \"button\");", - " }", - " {", - " Button button = StaticFactory.createButton(this, \"button\");", - " }", - " }", - "}"}; + String sourceLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = StaticFactory.createButton(this, "button"); + } + } + }"""; + String targetLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = StaticFactory.createButton(this, "button"); + } + { + Button button = StaticFactory.createButton(this, "button"); + } + } + }"""; layouts_doCopy(sourceLines, targetLines); } @Test public void test_viewer_1() throws Exception { - String[] sourceLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " TableViewer viewer = new TableViewer(this, SWT.BORDER);", - " viewer.setUseHashlookup(true);", - " viewer.getTable().setHeaderVisible(true);", - " }", - " }", - "}"}; - String[] targetLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " TableViewer viewer = new TableViewer(this, SWT.BORDER);", - " viewer.setUseHashlookup(true);", - " viewer.getTable().setHeaderVisible(true);", - " }", - " {", - " TableViewer viewer = new TableViewer(this, SWT.BORDER);", - " viewer.setUseHashlookup(true);", - " Table table = viewer.getTable();", - " table.setHeaderVisible(true);", - " }", - " }", - "}"}; + String sourceLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + TableViewer viewer = new TableViewer(this, SWT.BORDER); + viewer.setUseHashlookup(true); + viewer.getTable().setHeaderVisible(true); + } + } + }"""; + String targetLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + TableViewer viewer = new TableViewer(this, SWT.BORDER); + viewer.setUseHashlookup(true); + viewer.getTable().setHeaderVisible(true); + } + { + TableViewer viewer = new TableViewer(this, SWT.BORDER); + viewer.setUseHashlookup(true); + Table table = viewer.getTable(); + table.setHeaderVisible(true); + } + } + }"""; layouts_doCopy(sourceLines, targetLines); } @Test public void test_exposedSubComponent() throws Exception { - setFileContentSrc( - "test/MyComposite.java", - getTestSource( - "public class MyComposite extends Composite {", - " private Button m_button;", - " public MyComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new RowLayout());", - " m_button = new Button(this, SWT.NONE);", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + setFileContentSrc("test/MyComposite.java", getTestSource(""" + public class MyComposite extends Composite { + private Button m_button; + public MyComposite(Composite parent, int style) { + super(parent, style); + setLayout(new RowLayout()); + m_button = new Button(this, SWT.NONE); + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); // do copy/paste - String[] sourceLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " myComposite.getButton().setText(\"button\");", - " }", - " }", - "}"}; - String[] targetLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " myComposite.getButton().setText(\"button\");", - " }", - " {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " myComposite.getButton().setText(\"button\");", - " }", - " }", - "}"}; + String sourceLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + myComposite.getButton().setText("button"); + } + } + }"""; + String targetLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + myComposite.getButton().setText("button"); + } + { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + myComposite.getButton().setText("button"); + } + } + }"""; layouts_doCopy(sourceLines, targetLines); } @Test public void test_viewer_2() throws Exception { - String[] sourceLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Table table = new Table(this, SWT.BORDER);", - " table.setHeaderVisible(true);", - " TableViewer viewer = new TableViewer(table);", - " viewer.setUseHashlookup(true);", - " }", - " }", - "}"}; - String[] targetLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Table table = new Table(this, SWT.BORDER);", - " table.setHeaderVisible(true);", - " TableViewer viewer = new TableViewer(table);", - " viewer.setUseHashlookup(true);", - " }", - " {", - " Table table = new Table(this, SWT.BORDER);", - " table.setHeaderVisible(true);", - " TableViewer viewer = new TableViewer(table);", - " viewer.setUseHashlookup(true);", - " }", - " }", - "}"}; + String sourceLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Table table = new Table(this, SWT.BORDER); + table.setHeaderVisible(true); + TableViewer viewer = new TableViewer(table); + viewer.setUseHashlookup(true); + } + } + }"""; + String targetLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Table table = new Table(this, SWT.BORDER); + table.setHeaderVisible(true); + TableViewer viewer = new TableViewer(table); + viewer.setUseHashlookup(true); + } + { + Table table = new Table(this, SWT.BORDER); + table.setHeaderVisible(true); + TableViewer viewer = new TableViewer(table); + viewer.setUseHashlookup(true); + } + } + }"""; layouts_doCopy(sourceLines, targetLines); } @Test public void test_Table() throws Exception { - String[] sourceLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Table table = new Table(this, SWT.BORDER);", - " {", - " TableColumn tableColumn = new TableColumn(table, SWT.NONE);", - " tableColumn.setWidth(100);", - " tableColumn.setText(\"AAA\");", - " }", - " {", - " TableColumn tableColumn = new TableColumn(table, SWT.NONE);", - " tableColumn.setWidth(100);", - " tableColumn.setText(\"BBB\");", - " }", - " }", - " }", - "}"}; - String[] targetLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Table table = new Table(this, SWT.BORDER);", - " {", - " TableColumn tableColumn = new TableColumn(table, SWT.NONE);", - " tableColumn.setWidth(100);", - " tableColumn.setText(\"AAA\");", - " }", - " {", - " TableColumn tableColumn = new TableColumn(table, SWT.NONE);", - " tableColumn.setWidth(100);", - " tableColumn.setText(\"BBB\");", - " }", - " }", - " {", - " Table table = new Table(this, SWT.BORDER);", - " {", - " TableColumn tableColumn = new TableColumn(table, SWT.NONE);", - " tableColumn.setWidth(100);", - " tableColumn.setText(\"AAA\");", - " }", - " {", - " TableColumn tableColumn = new TableColumn(table, SWT.NONE);", - " tableColumn.setWidth(100);", - " tableColumn.setText(\"BBB\");", - " }", - " }", - " }", - "}"}; + String sourceLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Table table = new Table(this, SWT.BORDER); + { + TableColumn tableColumn = new TableColumn(table, SWT.NONE); + tableColumn.setWidth(100); + tableColumn.setText("AAA"); + } + { + TableColumn tableColumn = new TableColumn(table, SWT.NONE); + tableColumn.setWidth(100); + tableColumn.setText("BBB"); + } + } + } + }"""; + String targetLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Table table = new Table(this, SWT.BORDER); + { + TableColumn tableColumn = new TableColumn(table, SWT.NONE); + tableColumn.setWidth(100); + tableColumn.setText("AAA"); + } + { + TableColumn tableColumn = new TableColumn(table, SWT.NONE); + tableColumn.setWidth(100); + tableColumn.setText("BBB"); + } + } + { + Table table = new Table(this, SWT.BORDER); + { + TableColumn tableColumn = new TableColumn(table, SWT.NONE); + tableColumn.setWidth(100); + tableColumn.setText("AAA"); + } + { + TableColumn tableColumn = new TableColumn(table, SWT.NONE); + tableColumn.setWidth(100); + tableColumn.setText("BBB"); + } + } + } + }"""; layouts_doCopy(sourceLines, targetLines); } @Test public void test_layouts_AbsoluteLayout_implicit() throws Exception { - String[] sourceLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " }", - " }", - "}"}; - String[] targetLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " }", - " }", - "}"}; + String sourceLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + } + } + }"""; + String targetLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + } + { + Composite composite = new Composite(this, SWT.NONE); + } + } + }"""; layouts_doCopy(sourceLines, targetLines); } @Test public void test_layouts_AbsoluteLayout_null() throws Exception { - String[] sourceLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(null);", - " }", - " }", - "}"}; - String[] targetLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(null);", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(null);", - " }", - " }", - "}"}; + String sourceLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(null); + } + } + }"""; + String targetLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(null); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(null); + } + } + }"""; layouts_doCopy(sourceLines, targetLines); } @Test public void test_layouts_AbsoluteLayout_withComponent() throws Exception { - String[] sourceLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " button.setText(\"button\");", - " button.setBounds(10, 20, 200, 100);", - " }", - " }", - " }", - "}"}; - String[] targetLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " button.setText(\"button\");", - " button.setBounds(10, 20, 200, 100);", - " }", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " button.setText(\"button\");", - " button.setBounds(10, 20, 200, 100);", - " }", - " }", - " }", - "}"}; + String sourceLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + { + Button button = new Button(composite, SWT.CHECK); + button.setText("button"); + button.setBounds(10, 20, 200, 100); + } + } + } + }"""; + String targetLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + { + Button button = new Button(composite, SWT.CHECK); + button.setText("button"); + button.setBounds(10, 20, 200, 100); + } + } + { + Composite composite = new Composite(this, SWT.NONE); + { + Button button = new Button(composite, SWT.CHECK); + button.setText("button"); + button.setBounds(10, 20, 200, 100); + } + } + } + }"""; layouts_doCopy(sourceLines, targetLines); } @Test public void test_layouts_FillLayout() throws Exception { - String[] sourceLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new FillLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " }", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " button.setText(\"second button\");", - " }", - " }", - " }", - "}"}; - String[] targetLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new FillLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " }", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " button.setText(\"second button\");", - " }", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new FillLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " }", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " button.setText(\"second button\");", - " }", - " }", - " }", - "}"}; + String sourceLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new FillLayout()); + { + Button button = new Button(composite, SWT.NONE); + } + { + Button button = new Button(composite, SWT.CHECK); + button.setText("second button"); + } + } + } + }"""; + String targetLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new FillLayout()); + { + Button button = new Button(composite, SWT.NONE); + } + { + Button button = new Button(composite, SWT.CHECK); + button.setText("second button"); + } + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new FillLayout()); + { + Button button = new Button(composite, SWT.NONE); + } + { + Button button = new Button(composite, SWT.CHECK); + button.setText("second button"); + } + } + } + }"""; layouts_doCopy(sourceLines, targetLines); } @Test public void test_layouts_RowLayout() throws Exception { - String[] sourceLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setLayoutData(new RowData(100, 200));", - " }", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " }", - " {", - " Button button = new Button(composite, SWT.RADIO);", - " RowData rowData = new RowData();", - " rowData.width = 100;", - " button.setLayoutData(rowData);", - " }", - " }", - " }", - "}"}; - String[] targetLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setLayoutData(new RowData(100, 200));", - " }", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " }", - " {", - " Button button = new Button(composite, SWT.RADIO);", - " RowData rowData = new RowData();", - " rowData.width = 100;", - " button.setLayoutData(rowData);", - " }", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setLayoutData(new RowData(100, 200));", - " }", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " }", - " {", - " Button button = new Button(composite, SWT.RADIO);", - " button.setLayoutData(new RowData(100, SWT.DEFAULT));", - " }", - " }", - " }", - "}"}; + String sourceLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new RowLayout()); + { + Button button = new Button(composite, SWT.NONE); + button.setLayoutData(new RowData(100, 200)); + } + { + Button button = new Button(composite, SWT.CHECK); + } + { + Button button = new Button(composite, SWT.RADIO); + RowData rowData = new RowData(); + rowData.width = 100; + button.setLayoutData(rowData); + } + } + } + }"""; + String targetLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new RowLayout()); + { + Button button = new Button(composite, SWT.NONE); + button.setLayoutData(new RowData(100, 200)); + } + { + Button button = new Button(composite, SWT.CHECK); + } + { + Button button = new Button(composite, SWT.RADIO); + RowData rowData = new RowData(); + rowData.width = 100; + button.setLayoutData(rowData); + } + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new RowLayout()); + { + Button button = new Button(composite, SWT.NONE); + button.setLayoutData(new RowData(100, 200)); + } + { + Button button = new Button(composite, SWT.CHECK); + } + { + Button button = new Button(composite, SWT.RADIO); + button.setLayoutData(new RowData(100, SWT.DEFAULT)); + } + } + } + }"""; layouts_doCopy(sourceLines, targetLines); } @Test public void test_layouts_GridLayout() throws Exception { - String[] sourceLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(composite, SWT.NONE);", - " GridData gridData = new GridData();", - " gridData.horizontalAlignment = GridData.FILL;", - " button.setLayoutData(gridData);", - " }", - " new Label(composite, SWT.NONE);", - " new Label(composite, SWT.NONE);", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " }", - " }", - " }", - "}"}; - String[] targetLines = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(composite, SWT.NONE);", - " GridData gridData = new GridData();", - " gridData.horizontalAlignment = GridData.FILL;", - " button.setLayoutData(gridData);", - " }", - " new Label(composite, SWT.NONE);", - " new Label(composite, SWT.NONE);", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " }", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));", - " }", - " new Label(composite, SWT.NONE);", - " new Label(composite, SWT.NONE);", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " }", - " }", - " }", - "}"}; + String sourceLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + { + Button button = new Button(composite, SWT.NONE); + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + button.setLayoutData(gridData); + } + new Label(composite, SWT.NONE); + new Label(composite, SWT.NONE); + { + Button button = new Button(composite, SWT.CHECK); + } + } + } + }"""; + String targetLines = """ + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + { + Button button = new Button(composite, SWT.NONE); + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + button.setLayoutData(gridData); + } + new Label(composite, SWT.NONE); + new Label(composite, SWT.NONE); + { + Button button = new Button(composite, SWT.CHECK); + } + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + { + Button button = new Button(composite, SWT.NONE); + button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); + } + new Label(composite, SWT.NONE); + new Label(composite, SWT.NONE); + { + Button button = new Button(composite, SWT.CHECK); + } + } + } + }"""; layouts_doCopy(sourceLines, targetLines); } } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/jface/ViewerTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/jface/ViewerTest.java index ea17612c0..bb819ccf0 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/jface/ViewerTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/jface/ViewerTest.java @@ -77,14 +77,13 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_normalNoControl_hasExpression() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + } + }"""); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); VariableSupport variableSupport = table.getVariableSupport(); NodeTarget nodeTarget = getNodeStatementTarget(shell, false, 1); @@ -98,77 +97,74 @@ public void test_normalNoControl_hasExpression() throws Exception { @Test public void test_normalNoControl_getReferenceExpression_viewerAsTarget() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + } + }"""); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); VariableSupport variableSupport = table.getVariableSupport(); NodeTarget nodeTarget = getNodeStatementTarget(shell, false, 1); // ask for expression, so materialize assertEquals("table", variableSupport.getReferenceExpression(nodeTarget)); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " Table table = tableViewer.getTable();", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + Table table = tableViewer.getTable(); + } + }"""); } @Test public void test_normalNoControl_getReferenceExpression_blockAsTarget() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + } + }"""); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); VariableSupport variableSupport = table.getVariableSupport(); NodeTarget nodeTarget = getNodeBlockTarget(shell, false); // ask for expression, so materialize assertEquals("table", variableSupport.getReferenceExpression(nodeTarget)); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " Table table = tableViewer.getTable();", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + Table table = tableViewer.getTable(); + } + }"""); } @Test public void test_normalNoControl_getAccessExpression_blockAsTarget() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + } + }"""); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); VariableSupport variableSupport = table.getVariableSupport(); NodeTarget nodeTarget = getNodeBlockTarget(shell, false); // ask for expression, so materialize assertEquals("table.", variableSupport.getAccessExpression(nodeTarget)); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " Table table = tableViewer.getTable();", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + Table table = tableViewer.getTable(); + } + }"""); } /** @@ -176,14 +172,14 @@ public void test_normalNoControl_getAccessExpression_blockAsTarget() throws Exce */ @Test public void test_parseAnonymous_standalone() throws Exception { - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER) {", - " };", - " }", - "}"); + parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER) { + }; + } + }"""); refresh(); assertNoErrors(m_lastParseInfo); } @@ -193,15 +189,15 @@ public void test_parseAnonymous_standalone() throws Exception { */ @Test public void test_parseAnonymous_wrapper() throws Exception { - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " Table table = new Table(this, SWT.BORDER);", - " TableViewer tableViewer = new TableViewer(table) {", - " };", - " }", - "}"); + parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + Table table = new Table(this, SWT.BORDER); + TableViewer tableViewer = new TableViewer(table) { + }; + } + }"""); refresh(); assertNoErrors(m_lastParseInfo); } @@ -211,14 +207,13 @@ public void test_parseAnonymous_wrapper() throws Exception { */ @Test public void test_exposeViewer() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + } + }"""); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); ViewerInfo viewer = (ViewerInfo) table.getChildrenJava().get(0); // check for expose action @@ -233,51 +228,49 @@ public void test_exposeViewer() throws Exception { viewer, "getTableViewer", "public"); - assertEditor( - "class Test extends Shell {", - " private TableViewer tableViewer;", - " public Test() {", - " setLayout(new FillLayout());", - " tableViewer = new TableViewer(this, SWT.BORDER);", - " }", - " public TableViewer getTableViewer() {", - " return tableViewer;", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + private TableViewer tableViewer; + public Test() { + setLayout(new FillLayout()); + tableViewer = new TableViewer(this, SWT.BORDER); + } + public TableViewer getTableViewer() { + return tableViewer; + } + }"""); } @Test public void test_exposedViewer() throws Exception { - setFileContentSrc( - "test/MyComposite.java", - getTestSource( - "public class MyComposite extends Composite {", - " private TableViewer m_viewer;", - " public MyComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new FillLayout());", - " m_viewer = new TableViewer(this, SWT.BORDER);", - " }", - " public TableViewer getViewer() {", - " return m_viewer;", - " }", - "}")); + setFileContentSrc("test/MyComposite.java", getTestSource(""" + public class MyComposite extends Composite { + private TableViewer m_viewer; + public MyComposite(Composite parent, int style) { + super(parent, style); + setLayout(new FillLayout()); + m_viewer = new TableViewer(this, SWT.BORDER); + } + public TableViewer getViewer() { + return m_viewer; + } + }""")); waitForAutoBuild(); // parse - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " MyComposite composite = new MyComposite(this, SWT.NONE);", - " }", - "}"); - assertHierarchy( - "{this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new FillLayout())/ /new MyComposite(this, SWT.NONE)/}", - " {new: org.eclipse.swt.layout.FillLayout} {empty} {/setLayout(new FillLayout())/}", - " {new: test.MyComposite} {local-unique: composite} {/new MyComposite(this, SWT.NONE)/}", - " {implicit-layout: org.eclipse.swt.layout.FillLayout} {implicit-layout} {}", - " {viewer: public org.eclipse.swt.widgets.Table org.eclipse.jface.viewers.TableViewer.getTable()} {viewer} {}", - " {method: public org.eclipse.jface.viewers.TableViewer test.MyComposite.getViewer()} {property} {}"); + parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + MyComposite composite = new MyComposite(this, SWT.NONE); + } + }"""); + assertHierarchy(""" + {this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new FillLayout())/ /new MyComposite(this, SWT.NONE)/} + {new: org.eclipse.swt.layout.FillLayout} {empty} {/setLayout(new FillLayout())/} + {new: test.MyComposite} {local-unique: composite} {/new MyComposite(this, SWT.NONE)/} + {implicit-layout: org.eclipse.swt.layout.FillLayout} {implicit-layout} {} + {viewer: public org.eclipse.swt.widgets.Table org.eclipse.jface.viewers.TableViewer.getTable()} {viewer} {} + {method: public org.eclipse.jface.viewers.TableViewer test.MyComposite.getViewer()} {property} {}"""); } //////////////////////////////////////////////////////////////////////////// @@ -287,15 +280,14 @@ public void test_exposedViewer() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_parseNormalNoControl() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " tableViewer.setUseHashlookup(true);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + tableViewer.setUseHashlookup(true); + } + }"""); assertEquals(2, shell.getChildrenJava().size()); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); // check viewer @@ -338,37 +330,36 @@ public void test_parseNormalNoControl() throws Exception { { assertTrue(table.canDelete()); table.delete(); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + } + }"""); } } @Test public void test_normalNoControl_materialize() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + } + }"""); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); // materialize Table table.addMethodInvocation("setHeaderVisible(boolean)", "true"); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " Table table = tableViewer.getTable();", - " table.setHeaderVisible(true);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + Table table = tableViewer.getTable(); + table.setHeaderVisible(true); + } + }"""); // check supports assertInstanceOf(WrapperMethodControlCreationSupport.class, table.getCreationSupport()); assertInstanceOf(LocalUniqueVariableSupport.class, table.getVariableSupport()); @@ -381,179 +372,174 @@ public void test_normalNoControl_materialize() throws Exception { @Test public void test_normalNoControl_move() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " Composite composite = new Composite(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + Composite composite = new Composite(this, SWT.NONE); + } + }"""); FillLayoutInfo fillLayout = (FillLayoutInfo) shell.getLayout(); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); // do move fillLayout.command_MOVE(table, null); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " Composite composite = new Composite(this, SWT.NONE);", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + Composite composite = new Composite(this, SWT.NONE); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + } + }"""); } @Test public void test_normalNoControl_reparent() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " //", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " //", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + // + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + // + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new RowLayout()); + } + }"""); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); // prepare composite CompositeInfo composite = (CompositeInfo) shell.getChildrenControls().get(1); RowLayoutInfo rowLayout = (RowLayoutInfo) composite.getLayout(); // do reparent rowLayout.command_MOVE(table, null); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " //", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " //", - " TableViewer tableViewer = new TableViewer(composite, SWT.BORDER);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + // + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new RowLayout()); + // + TableViewer tableViewer = new TableViewer(composite, SWT.BORDER); + } + }"""); } @Test public void test_normalWithControl_reparent() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " //", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " Table table = tableViewer.getTable();", - " //", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + // + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + Table table = tableViewer.getTable(); + // + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new RowLayout()); + } + }"""); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); // prepare composite CompositeInfo composite = (CompositeInfo) shell.getChildrenControls().get(1); RowLayoutInfo rowLayout = (RowLayoutInfo) composite.getLayout(); // do reparent rowLayout.command_MOVE(table, null); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " //", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " //", - " TableViewer tableViewer = new TableViewer(composite, SWT.BORDER);", - " Table table = tableViewer.getTable();", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + // + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new RowLayout()); + // + TableViewer tableViewer = new TableViewer(composite, SWT.BORDER); + Table table = tableViewer.getTable(); + } + }"""); } @Test public void test_materialized_move() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " {", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION);", - " Table table = tableViewer.getTable();", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + } + { + TableViewer tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION); + Table table = tableViewer.getTable(); + } + } + }"""); ControlInfo button = shell.getChildrenControls().get(0); ControlInfo table = shell.getChildrenControls().get(1); RowLayoutInfo rowLayout = (RowLayoutInfo) shell.getLayout(); // do move rowLayout.command_MOVE(table, button); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION);", - " Table table = tableViewer.getTable();", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + TableViewer tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION); + Table table = tableViewer.getTable(); + } + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } @Test public void test_newCreated_move() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); ControlInfo button = shell.getChildrenControls().get(0); RowLayoutInfo rowLayout = (RowLayoutInfo) shell.getLayout(); // do create ViewerInfo viewer = createTableViewer(m_lastEditor); ControlInfo table = (ControlInfo) viewer.getWrapper().getWrappedInfo(); rowLayout.command_CREATE(table, null); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " {", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION);", - " Table table = tableViewer.getTable();", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + } + { + TableViewer tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION); + Table table = tableViewer.getTable(); + } + } + }"""); // do move rowLayout.command_MOVE(table, button); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION);", - " Table table = tableViewer.getTable();", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + TableViewer tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION); + Table table = tableViewer.getTable(); + } + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -563,23 +549,23 @@ public void test_newCreated_move() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_parseAroundTable() throws Exception { - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " {", - " Table table = new Table(this, SWT.BORDER);", - " TableViewer viewer = new TableViewer(table);", - " viewer.getTable().setEnabled(false);", - " }", - " }", - "}"); + parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + { + Table table = new Table(this, SWT.BORDER); + TableViewer viewer = new TableViewer(table); + viewer.getTable().setEnabled(false); + } + } + }"""); // hierarchy - assertHierarchy( - "{this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new FillLayout())/ /new Table(this, SWT.BORDER)/}", - " {new: org.eclipse.swt.layout.FillLayout} {empty} {/setLayout(new FillLayout())/}", - " {new: org.eclipse.swt.widgets.Table} {local-unique: table} {/new Table(this, SWT.BORDER)/ /new TableViewer(table)/ /viewer.getTable().setEnabled(false)/}", - " {new: org.eclipse.jface.viewers.TableViewer} {local-unique: viewer} {/new TableViewer(table)/ /viewer.getTable()/}"); + assertHierarchy(""" + {this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new FillLayout())/ /new Table(this, SWT.BORDER)/} + {new: org.eclipse.swt.layout.FillLayout} {empty} {/setLayout(new FillLayout())/} + {new: org.eclipse.swt.widgets.Table} {local-unique: table} {/new Table(this, SWT.BORDER)/ /new TableViewer(table)/ /viewer.getTable().setEnabled(false)/} + {new: org.eclipse.jface.viewers.TableViewer} {local-unique: viewer} {/new TableViewer(table)/ /viewer.getTable()/}"""); TableInfo table = getJavaInfoByName("table"); ViewerInfo viewer = getJavaInfoByName("viewer"); assertSame(table, viewer.getParent()); @@ -596,14 +582,13 @@ public void test_parseAroundTable() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_property_useHashlookup() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + } + }"""); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); ViewerInfo viewer = (ViewerInfo) table.getChildrenJava().get(0); Property property = viewer.getPropertyByTitle("useHashlookup"); @@ -611,35 +596,34 @@ public void test_property_useHashlookup() throws Exception { assertEquals(Boolean.FALSE, property.getValue()); // set "true" - add invocation property.setValue(Boolean.TRUE); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " tableViewer.setUseHashlookup(true);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + tableViewer.setUseHashlookup(true); + } + }"""); // set "false" - remove invocation property.setValue(Boolean.FALSE); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + } + }"""); } @Test public void test_property_style() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + } + }"""); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); ViewerInfo viewer = (ViewerInfo) table.getChildrenJava().get(0); // @@ -649,14 +633,13 @@ public void test_property_style() throws Exception { @Test public void test_contentProvider() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + } + }"""); TableInfo table = (TableInfo) shell.getChildrenControls().get(0); ViewerInfo viewer = (ViewerInfo) table.getChildrenJava().get(0); // @@ -667,23 +650,23 @@ public void test_contentProvider() throws Exception { // add new provider { propertyEditor.activate(null, property, null); - assertEditor( - "class Test extends Shell {", - " private static class ContentProvider implements IStructuredContentProvider {", - " public Object[] getElements(Object inputElement) {", - " return new Object[0];", - " }", - " public void dispose() {", - " }", - " public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {", - " }", - " }", - " public Test() {", - " setLayout(new FillLayout());", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER);", - " tableViewer.setContentProvider(new ContentProvider());", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + private static class ContentProvider implements IStructuredContentProvider { + public Object[] getElements(Object inputElement) { + return new Object[0]; + } + public void dispose() { + } + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + } + public Test() { + setLayout(new FillLayout()); + TableViewer tableViewer = new TableViewer(this, SWT.BORDER); + tableViewer.setContentProvider(new ContentProvider()); + } + }"""); assertEquals("test.Test.ContentProvider", getPropertyText(property)); } // just kick "doubleClick", no result tested @@ -723,12 +706,12 @@ public void accept(SWTBot bot) { @Test public void test_noRootComposite() throws Exception { Throwable e = assertThrows(Throwable.class, () -> { - parseComposite( - "public class Test {", - " public Test(Composite parent) {", - " TableViewer tableViewer = new TableViewer(parent, SWT.BORDER);", - " }", - "}"); + parseComposite(""" + public class Test { + public Test(Composite parent) { + TableViewer tableViewer = new TableViewer(parent, SWT.BORDER); + } + }"""); }); Throwable rootCause = DesignerExceptionUtils.getRootCause(e); Assertions.assertThat(rootCause).isExactlyInstanceOf(NoEntryPointError.class); @@ -741,12 +724,12 @@ public void test_noRootComposite() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_CREATE_liveImage() throws Exception { - parseComposite( - "// filler filler filler", - "class Test extends Shell {", - " public Test() {", - " }", - "}"); + parseComposite(""" + // filler filler filler + class Test extends Shell { + public Test() { + } + }"""); // prepare viewer and table ViewerInfo viewer = createTableViewer(m_lastEditor); TableInfo table = (TableInfo) viewer.getWrapper().getWrappedInfo(); @@ -761,62 +744,54 @@ public void test_CREATE_liveImage() throws Exception { */ @Test public void test_CREATE_liveImage_forcedSize() throws Exception { - setFileContentSrc( - "test/MyTable.java", - getTestSource( - "public class MyTable extends Table {", - " public MyTable(Composite parent, int style) {", - " super(parent, style);", - " }", - " protected void checkSubclass () {", - " }", - "}")); - setFileContentSrc( - "test/MyTableViewer.java", - getTestSource( - "public class MyTableViewer extends TableViewer {", - " public MyTableViewer(Composite parent) {", - " super(new MyTable(parent, SWT.NO_SCROLL));", - " }", - " public MyTable getMyTable() {", - " return (MyTable) getTable();", - " }", - "}")); - setFileContentSrc( - "test/MyTable.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " 200", - " 150", - " ", - "")); - setFileContentSrc( - "test/MyTableViewer.wbp-component.xml", - getSourceDQ( - "", - "", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " getMyTable", - " ", - "")); + setFileContentSrc("test/MyTable.java", getTestSource(""" + public class MyTable extends Table { + public MyTable(Composite parent, int style) { + super(parent, style); + } + protected void checkSubclass () { + } + }""")); + setFileContentSrc("test/MyTableViewer.java", getTestSource(""" + public class MyTableViewer extends TableViewer { + public MyTableViewer(Composite parent) { + super(new MyTable(parent, SWT.NO_SCROLL)); + } + public MyTable getMyTable() { + return (MyTable) getTable(); + } + }""")); + setFileContentSrc("test/MyTable.wbp-component.xml", """ + + + + 200 + 150 + + """); + setFileContentSrc("test/MyTableViewer.wbp-component.xml", """ + + + + + + + + + + + + getMyTable + + """); waitForAutoBuild(); // parse - parseComposite( - "// filler filler filler", - "class Test extends Shell {", - " public Test() {", - " }", - "}"); + parseComposite(""" + // filler filler filler + class Test extends Shell { + public Test() { + } + }"""); // prepare viewer and table ViewerInfo viewer = createViewer(m_lastEditor, "test.MyTableViewer"); TableInfo table = (TableInfo) viewer.getWrapper().getWrappedInfo(); @@ -832,13 +807,12 @@ public void test_CREATE_liveImage_forcedSize() throws Exception { @Test public void test_CREATE() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + } + }"""); FillLayoutInfo fillLayout = (FillLayoutInfo) shell.getLayout(); // prepare Viewer ViewerInfo viewer = createTableViewer(m_lastEditor); @@ -858,16 +832,16 @@ public void test_CREATE() throws Exception { } // create fillLayout.command_CREATE(table, null); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " {", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION);", - " Table table = tableViewer.getTable();", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + { + TableViewer tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION); + Table table = tableViewer.getTable(); + } + } + }"""); // check table { assertSame(shell, table.getParent()); @@ -916,13 +890,12 @@ public void test_CREATE() throws Exception { */ @Test public void test_CREATE_useFieldVariable() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + } + }"""); FillLayoutInfo fillLayout = (FillLayoutInfo) shell.getLayout(); // prepare Viewer and Table ViewerInfo viewer = createTableViewer(m_lastEditor); @@ -931,18 +904,18 @@ public void test_CREATE_useFieldVariable() throws Exception { GenerationSettings settings = viewer.getDescription().getToolkit().getGenerationSettings(); settings.setVariable(FieldUniqueVariableDescription.INSTANCE); fillLayout.command_CREATE(table, null); - assertEditor( - "class Test extends Shell {", - " private Table table;", - " private TableViewer tableViewer;", - " public Test() {", - " setLayout(new FillLayout());", - " {", - " tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION);", - " table = tableViewer.getTable();", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + private Table table; + private TableViewer tableViewer; + public Test() { + setLayout(new FillLayout()); + { + tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION); + table = tableViewer.getTable(); + } + } + }"""); } /** diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/AbsoluteLayoutOrderingTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/AbsoluteLayoutOrderingTest.java index aa8f3c3fe..3815a6bfa 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/AbsoluteLayoutOrderingTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/AbsoluteLayoutOrderingTest.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 @@ -51,16 +51,15 @@ public void _test_exit() throws Exception { */ @Test public void test_enablement() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " Button button = new Button(this, SWT.NONE);", - " Text text = new Text(this, SWT.NONE);", - " Table table = new Table(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + Button button = new Button(this, SWT.NONE); + Text text = new Text(this, SWT.NONE); + Table table = new Table(this, SWT.NONE); + } + }"""); ControlInfo button = shell.getChildrenControls().get(0); ControlInfo text = shell.getChildrenControls().get(1); ControlInfo table = shell.getChildrenControls().get(2); @@ -95,121 +94,117 @@ public void test_enablement() throws Exception { @Test public void test_bringToFront() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " Button button = new Button(this, SWT.NONE);", - " Text text = new Text(this, SWT.NONE);", - " Table table = new Table(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + Button button = new Button(this, SWT.NONE); + Text text = new Text(this, SWT.NONE); + Table table = new Table(this, SWT.NONE); + } + }"""); ControlInfo button = shell.getChildrenControls().get(0); ControlInfo text = shell.getChildrenControls().get(1); ControlInfo table = shell.getChildrenControls().get(2); // run action getOrderAction(createOrderManager(table), "Bring to Front").run(); // check result - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " Table table = new Table(this, SWT.NONE);", - " Button button = new Button(this, SWT.NONE);", - " Text text = new Text(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + Table table = new Table(this, SWT.NONE); + Button button = new Button(this, SWT.NONE); + Text text = new Text(this, SWT.NONE); + } + }"""); Assertions.assertThat(shell.getChildrenControls()).containsExactly(table, button, text); } @Test public void test_bringForward() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " Button button = new Button(this, SWT.NONE);", - " Text text = new Text(this, SWT.NONE);", - " Table table = new Table(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + Button button = new Button(this, SWT.NONE); + Text text = new Text(this, SWT.NONE); + Table table = new Table(this, SWT.NONE); + } + }"""); ControlInfo button = shell.getChildrenControls().get(0); ControlInfo text = shell.getChildrenControls().get(1); ControlInfo table = shell.getChildrenControls().get(2); // run action getOrderAction(createOrderManager(table), "Bring Forward").run(); // check result - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " Button button = new Button(this, SWT.NONE);", - " Table table = new Table(this, SWT.NONE);", - " Text text = new Text(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + Button button = new Button(this, SWT.NONE); + Table table = new Table(this, SWT.NONE); + Text text = new Text(this, SWT.NONE); + } + }"""); Assertions.assertThat(shell.getChildrenControls()).containsExactly(button, table, text); } @Test public void test_sendToBack() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " Button button = new Button(this, SWT.NONE);", - " Text text = new Text(this, SWT.NONE);", - " Table table = new Table(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + Button button = new Button(this, SWT.NONE); + Text text = new Text(this, SWT.NONE); + Table table = new Table(this, SWT.NONE); + } + }"""); ControlInfo button = shell.getChildrenControls().get(0); ControlInfo text = shell.getChildrenControls().get(1); ControlInfo table = shell.getChildrenControls().get(2); // run action getOrderAction(createOrderManager(button), "Send to Back").run(); // check result - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " Text text = new Text(this, SWT.NONE);", - " Table table = new Table(this, SWT.NONE);", - " Button button = new Button(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + Text text = new Text(this, SWT.NONE); + Table table = new Table(this, SWT.NONE); + Button button = new Button(this, SWT.NONE); + } + }"""); Assertions.assertThat(shell.getChildrenControls()).containsExactly(text, table, button); } @Test public void test_sendBackward() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " Button button = new Button(this, SWT.NONE);", - " Text text = new Text(this, SWT.NONE);", - " Table table = new Table(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + Button button = new Button(this, SWT.NONE); + Text text = new Text(this, SWT.NONE); + Table table = new Table(this, SWT.NONE); + } + }"""); ControlInfo button = shell.getChildrenControls().get(0); ControlInfo text = shell.getChildrenControls().get(1); ControlInfo table = shell.getChildrenControls().get(2); // run action getOrderAction(createOrderManager(button), "Send Backward").run(); // check result - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " Text text = new Text(this, SWT.NONE);", - " Button button = new Button(this, SWT.NONE);", - " Table table = new Table(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + Text text = new Text(this, SWT.NONE); + Button button = new Button(this, SWT.NONE); + Table table = new Table(this, SWT.NONE); + } + }"""); Assertions.assertThat(shell.getChildrenControls()).containsExactly(text, button, table); } diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/AbsoluteLayoutSelectionActionsTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/AbsoluteLayoutSelectionActionsTest.java index 6f0ada8a0..5fc8a2aab 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/AbsoluteLayoutSelectionActionsTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/AbsoluteLayoutSelectionActionsTest.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 @@ -51,31 +51,30 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_selectionActions() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, 27, 83, 22);", - " button.setText('New Button1');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(41, 129, 134, 84);", - " button.setText('New Button');", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(286, 135, 134, 120);", - " {", - " Label label = new Label(composite, SWT.NONE);", - " label.setBounds(41, 53, 51, 13);", - " label.setText('New Label');", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, 27, 83, 22); + button.setText("New Button1"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(41, 129, 134, 84); + button.setText("New Button"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(286, 135, 134, 120); + { + Label label = new Label(composite, SWT.NONE); + label.setBounds(41, 53, 51, 13); + label.setText("New Label"); + } + } + } + }"""); ControlInfo button = shell.getChildrenControls().get(0); CompositeInfo composite = (CompositeInfo) shell.getChildrenControls().get(2); ControlInfo label = composite.getChildrenControls().get(0); @@ -176,21 +175,21 @@ public void test_selectionActions() throws Exception { */ @Test public void test_align_left_edges_1a() throws Exception { - check_align_horizontal(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(20, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(20, 50, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Align left edges", true); + check_align_horizontal(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(20, 10, 100, 20); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(20, 50, 150, 30); + button.setText("111"); + } + } + }""", "Align left edges", true); } /** @@ -198,21 +197,21 @@ public void test_align_left_edges_1a() throws Exception { */ @Test public void test_align_left_edges_1b() throws Exception { - check_align_horizontal(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 50, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Align left edges", false); + check_align_horizontal(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 100, 20); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 50, 150, 30); + button.setText("111"); + } + } + }""", "Align left edges", false); } /** @@ -220,25 +219,25 @@ public void test_align_left_edges_1b() throws Exception { */ @Test public void test_align_left_edges_2a() throws Exception { - check_align_horizontal2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(30, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(5, 40, 300, 100);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(25, 55, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, "Align left edges", true); + check_align_horizontal2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(30, 10, 100, 20); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(5, 40, 300, 100); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(25, 55, 150, 30); + button.setText("111"); + } + } + } + }""", "Align left edges", true); } /** @@ -246,25 +245,25 @@ public void test_align_left_edges_2a() throws Exception { */ @Test public void test_align_left_edges_2b() throws Exception { - check_align_horizontal2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(5, 40, 300, 100);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(5, 55, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, "Align left edges", false); + check_align_horizontal2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 100, 20); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(5, 40, 300, 100); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(5, 55, 150, 30); + button.setText("111"); + } + } + } + }""", "Align left edges", false); } /** @@ -272,21 +271,21 @@ public void test_align_left_edges_2b() throws Exception { */ @Test public void test_align_right_edges_1a() throws Exception { - check_align_horizontal(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(20, 50, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Align right edges", true); + check_align_horizontal(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, 10, 100, 20); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(20, 50, 150, 30); + button.setText("111"); + } + } + }""", "Align right edges", true); } /** @@ -294,21 +293,21 @@ public void test_align_right_edges_1a() throws Exception { */ @Test public void test_align_right_edges_1b() throws Exception { - check_align_horizontal(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(-40, 50, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Align right edges", false); + check_align_horizontal(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 100, 20); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(-40, 50, 150, 30); + button.setText("111"); + } + } + }""", "Align right edges", false); } /** @@ -316,25 +315,25 @@ public void test_align_right_edges_1b() throws Exception { */ @Test public void test_align_right_edges_2a() throws Exception { - check_align_horizontal2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(80, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(5, 40, 300, 100);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(25, 55, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, "Align right edges", true); + check_align_horizontal2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(80, 10, 100, 20); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(5, 40, 300, 100); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(25, 55, 150, 30); + button.setText("111"); + } + } + } + }""", "Align right edges", true); } /** @@ -342,25 +341,25 @@ public void test_align_right_edges_2a() throws Exception { */ @Test public void test_align_right_edges_2b() throws Exception { - check_align_horizontal2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(5, 40, 300, 100);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(-45, 55, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, "Align right edges", false); + check_align_horizontal2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 100, 20); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(5, 40, 300, 100); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(-45, 55, 150, 30); + button.setText("111"); + } + } + } + }""", "Align right edges", false); } /** @@ -368,21 +367,21 @@ public void test_align_right_edges_2b() throws Exception { */ @Test public void test_align_horizontal_centers_1a() throws Exception { - check_align_horizontal(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(45, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(20, 50, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Align horizontal centers", true); + check_align_horizontal(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(45, 10, 100, 20); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(20, 50, 150, 30); + button.setText("111"); + } + } + }""", "Align horizontal centers", true); } /** @@ -390,21 +389,21 @@ public void test_align_horizontal_centers_1a() throws Exception { */ @Test public void test_align_horizontal_centers_1b() throws Exception { - check_align_horizontal(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(-15, 50, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Align horizontal centers", false); + check_align_horizontal(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 100, 20); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(-15, 50, 150, 30); + button.setText("111"); + } + } + }""", "Align horizontal centers", false); } /** @@ -412,25 +411,25 @@ public void test_align_horizontal_centers_1b() throws Exception { */ @Test public void test_align_horizontal_centers_2a() throws Exception { - check_align_horizontal2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(55, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(5, 40, 300, 100);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(25, 55, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, "Align horizontal centers", true); + check_align_horizontal2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(55, 10, 100, 20); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(5, 40, 300, 100); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(25, 55, 150, 30); + button.setText("111"); + } + } + } + }""", "Align horizontal centers", true); } /** @@ -438,67 +437,67 @@ public void test_align_horizontal_centers_2a() throws Exception { */ @Test public void test_align_horizontal_centers_2b() throws Exception { - check_align_horizontal2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(5, 40, 300, 100);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(-20, 55, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, "Align horizontal centers", false); + check_align_horizontal2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 100, 20); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(5, 40, 300, 100); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(-20, 55, 150, 30); + button.setText("111"); + } + } + } + }""", "Align horizontal centers", false); } - private void check_align_horizontal(String[] expectedSource, String action, boolean toUp) + private void check_align_horizontal(String expectedSource, String action, boolean toUp) throws Exception { - check_align(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(20, 50, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - "}"}, expectedSource, action, toUp); + check_align(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 100, 20); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(20, 50, 150, 30); + button.setText("111"); + } + } + }""", expectedSource, action, toUp); } - private void check_align_horizontal2(String[] expectedSource, String action, boolean toUp) + private void check_align_horizontal2(String expectedSource, String action, boolean toUp) throws Exception { - check_align2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 100, 20);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(5, 40, 300, 100);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(25, 55, 150, 30);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, expectedSource, action, toUp); + check_align2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 100, 20); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(5, 40, 300, 100); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(25, 55, 150, 30); + button.setText("111"); + } + } + } + }""", expectedSource, action, toUp); } //////////////////////////////////////////////////////////////////////////// @@ -511,21 +510,21 @@ private void check_align_horizontal2(String[] expectedSource, String action, boo */ @Test public void test_align_top_edges_1a() throws Exception { - check_align_vertical(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 100, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, 100, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Align top edges", true); + check_align_vertical(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 100, 50, 40); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, 100, 100, 80); + button.setText("111"); + } + } + }""", "Align top edges", true); } /** @@ -533,21 +532,21 @@ public void test_align_top_edges_1a() throws Exception { */ @Test public void test_align_top_edges_1b() throws Exception { - check_align_vertical(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, 10, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Align top edges", false); + check_align_vertical(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 40); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, 10, 100, 80); + button.setText("111"); + } + } + }""", "Align top edges", false); } /** @@ -555,25 +554,25 @@ public void test_align_top_edges_1b() throws Exception { */ @Test public void test_align_top_edges_2a() throws Exception { - check_align_vertical2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 100, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(65, 5, 300, 300);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(5, 95, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, "Align top edges", true); + check_align_vertical2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 100, 50, 40); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(65, 5, 300, 300); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(5, 95, 100, 80); + button.setText("111"); + } + } + } + }""", "Align top edges", true); } /** @@ -581,25 +580,25 @@ public void test_align_top_edges_2a() throws Exception { */ @Test public void test_align_top_edges_2b() throws Exception { - check_align_vertical2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(65, 5, 300, 300);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(5, 5, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, "Align top edges", false); + check_align_vertical2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 40); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(65, 5, 300, 300); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(5, 5, 100, 80); + button.setText("111"); + } + } + } + }""", "Align top edges", false); } /** @@ -608,21 +607,21 @@ public void test_align_top_edges_2b() throws Exception { @Test public void test_align_bottom_edges_1a() throws Exception { // y2:100 + h2:80 - h1:40 = y1:140 - check_align_vertical(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 140, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, 100, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Align bottom edges", true); + check_align_vertical(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 140, 50, 40); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, 100, 100, 80); + button.setText("111"); + } + } + }""", "Align bottom edges", true); } /** @@ -631,21 +630,21 @@ public void test_align_bottom_edges_1a() throws Exception { @Test public void test_align_bottom_edges_1b() throws Exception { // y2:100 + h2:80 - h1:40 = y1:140 - check_align_vertical(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, -30, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Align bottom edges", false); + check_align_vertical(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 40); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, -30, 100, 80); + button.setText("111"); + } + } + }""", "Align bottom edges", false); } /** @@ -653,25 +652,25 @@ public void test_align_bottom_edges_1b() throws Exception { */ @Test public void test_align_bottom_edges_2a() throws Exception { - check_align_vertical2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 140, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(65, 5, 300, 300);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(5, 95, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, "Align bottom edges", true); + check_align_vertical2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 140, 50, 40); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(65, 5, 300, 300); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(5, 95, 100, 80); + button.setText("111"); + } + } + } + }""", "Align bottom edges", true); } /** @@ -679,25 +678,25 @@ public void test_align_bottom_edges_2a() throws Exception { */ @Test public void test_align_bottom_edges_2b() throws Exception { - check_align_vertical2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(65, 5, 300, 300);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(5, -35, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, "Align bottom edges", false); + check_align_vertical2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 40); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(65, 5, 300, 300); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(5, -35, 100, 80); + button.setText("111"); + } + } + } + }""", "Align bottom edges", false); } /** @@ -706,21 +705,21 @@ public void test_align_bottom_edges_2b() throws Exception { @Test public void test_align_vertical_centers_1a() throws Exception { // y2:100 + (h2:80 / 2) - (h1:40 / 2) = y1:120 - check_align_vertical(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 120, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, 100, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Align vertical centers", true); + check_align_vertical(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 120, 50, 40); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, 100, 100, 80); + button.setText("111"); + } + } + }""", "Align vertical centers", true); } /** @@ -729,21 +728,21 @@ public void test_align_vertical_centers_1a() throws Exception { @Test public void test_align_vertical_centers_1b() throws Exception { // y2:100 + (h2:80 / 2) - (h1:40 / 2) = y1:120 - check_align_vertical(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, -10, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Align vertical centers", false); + check_align_vertical(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 40); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, -10, 100, 80); + button.setText("111"); + } + } + }""", "Align vertical centers", false); } /** @@ -751,25 +750,25 @@ public void test_align_vertical_centers_1b() throws Exception { */ @Test public void test_align_vertical_centers_2a() throws Exception { - check_align_vertical2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 120, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(65, 5, 300, 300);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(5, 95, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, "Align vertical centers", true); + check_align_vertical2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 120, 50, 40); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(65, 5, 300, 300); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(5, 95, 100, 80); + button.setText("111"); + } + } + } + }""", "Align vertical centers", true); } /** @@ -777,67 +776,67 @@ public void test_align_vertical_centers_2a() throws Exception { */ @Test public void test_align_vertical_centers_2b() throws Exception { - check_align_vertical2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(65, 5, 300, 300);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(5, -15, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, "Align vertical centers", false); + check_align_vertical2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 40); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(65, 5, 300, 300); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(5, -15, 100, 80); + button.setText("111"); + } + } + } + }""", "Align vertical centers", false); } - private void check_align_vertical(String[] newSource, String action, boolean toUp) + private void check_align_vertical(String newSource, String action, boolean toUp) throws Exception { - check_align(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, 100, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - "}"}, newSource, action, toUp); + check_align(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 40); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, 100, 100, 80); + button.setText("111"); + } + } + }""", newSource, action, toUp); } - private void check_align_vertical2(String[] newSource, String action, boolean toUp) + private void check_align_vertical2(String newSource, String action, boolean toUp) throws Exception { - check_align2(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setBounds(65, 5, 300, 300);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(5, 95, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - " }", - "}"}, newSource, action, toUp); + check_align2(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 40); + button.setText("000"); + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setBounds(65, 5, 300, 300); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(5, 95, 100, 80); + button.setText("111"); + } + } + } + }""", newSource, action, toUp); } //////////////////////////////////////////////////////////////////////////// @@ -847,68 +846,68 @@ private void check_align_vertical2(String[] newSource, String action, boolean to //////////////////////////////////////////////////////////////////////////// @Test public void test_align_replicate_width() throws Exception { - check_align(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, 100, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - "}"}, new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 100, 40);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, 100, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Replicate width", true); + check_align(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 40); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, 100, 100, 80); + button.setText("111"); + } + } + }""", """ + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 100, 40); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, 100, 100, 80); + button.setText("111"); + } + } + }""", "Replicate width", true); } @Test public void test_align_replicate_height() throws Exception { - check_align(new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 40);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, 100, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - "}"}, new String[]{ - "class Test extends Shell {", - " Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 80);", - " button.setText(\"000\");", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(70, 100, 100, 80);", - " button.setText(\"111\");", - " }", - " }", - "}"}, "Replicate height", true); + check_align(""" + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 40); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, 100, 100, 80); + button.setText("111"); + } + } + }""", """ + class Test extends Shell { + Test() { + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 80); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(70, 100, 100, 80); + button.setText("111"); + } + } + }""", "Replicate height", true); } //////////////////////////////////////////////////////////////////////////// @@ -921,23 +920,22 @@ public void test_align_replicate_height() throws Exception { */ @Test public void test_align_space_equally_1() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setSize(600, 400);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(30, 90, 100, 70);", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(40, 200, 50, 30);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setSize(600, 400); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(30, 90, 100, 70); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(40, 200, 50, 30); + button.setText("111"); + } + } + }"""); setupSelectionActions(shell); shell.refresh(); // prepare selection @@ -951,22 +949,22 @@ public void test_align_space_equally_1() throws Exception { findAction(actions, "Space equally, horizontally").run(); findAction(actions, "Space equally, vertically").run(); // - assertEditor( - "class Test extends Shell {", - " Test() {", - " setSize(600, 400);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(150, 100, 100, 70);", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(400, 270, 50, 30);", - " button.setText('111');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setSize(600, 400); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(150, 100, 100, 70); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(400, 270, 50, 30); + button.setText("111"); + } + } + }"""); } /** @@ -974,28 +972,27 @@ public void test_align_space_equally_1() throws Exception { */ @Test public void test_align_space_equally_2() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setSize(400, 400);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 50);", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(90, 90, 60, 60);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(220, 220, 70, 70);", - " button.setText('222');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setSize(400, 400); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 50); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(90, 90, 60, 60); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(220, 220, 70, 70); + button.setText("222"); + } + } + }"""); setupSelectionActions(shell); shell.refresh(); // prepare selection @@ -1015,27 +1012,27 @@ public void test_align_space_equally_2() throws Exception { ReflectionUtils.setField(DesignerPlugin.class, "m_ctrlPressed", false); } // - assertEditor( - "class Test extends Shell {", - " Test() {", - " setSize(400, 400);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 50, 50);", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(110, 110, 60, 60);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(220, 220, 70, 70);", - " button.setText('222');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setSize(400, 400); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 50, 50); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(110, 110, 60, 60); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(220, 220, 70, 70); + button.setText("222"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1046,18 +1043,17 @@ public void test_align_space_equally_2() throws Exception { @Disabled @Test public void test_align_center_in_window() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setSize(600, 400);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 10, 60, 40);", - " button.setText('000');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setSize(600, 400); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 10, 60, 40); + button.setText("000"); + } + } + }"""); setupSelectionActions(shell); shell.refresh(); // prepare selection @@ -1070,17 +1066,17 @@ public void test_align_center_in_window() throws Exception { findAction(actions, "Center horizontally in window").run(); findAction(actions, "Center vertically in window").run(); // - assertEditor( - "class Test extends Shell {", - " Test() {", - " setSize(600, 400);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(262, 180, 60, 40);", - " button.setText('000');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setSize(600, 400); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(262, 180, 60, 40); + button.setText("000"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1090,27 +1086,26 @@ public void test_align_center_in_window() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_ScrolledComposite_onWayToRoot() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.NONE);", - " {", - " Composite composite = new Composite(scrolledComposite, SWT.NONE);", - " composite.setLayout(null);", - " {", - " Button button_1 = new Button(composite, SWT.NONE);", - " button_1.setBounds(10, 10, 100, 20);", - " }", - " {", - " Button button_2 = new Button(composite, SWT.NONE);", - " button_2.setBounds(20, 100, 100, 20);", - " }", - " scrolledComposite.setContent(composite);", - " scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.NONE); + { + Composite composite = new Composite(scrolledComposite, SWT.NONE); + composite.setLayout(null); + { + Button button_1 = new Button(composite, SWT.NONE); + button_1.setBounds(10, 10, 100, 20); + } + { + Button button_2 = new Button(composite, SWT.NONE); + button_2.setBounds(20, 100, 100, 20); + } + scrolledComposite.setContent(composite); + scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + } + } + }"""); shell.refresh(); // // prepare selection @@ -1136,8 +1131,8 @@ public void test_ScrolledComposite_onWayToRoot() throws Exception { // Utils // //////////////////////////////////////////////////////////////////////////// - private void check_align(String[] initialSource, - String[] expectedSource, + private void check_align(String initialSource, + String expectedSource, String action, boolean toUp) throws Exception { CompositeInfo shell = parseComposite(initialSource); @@ -1161,8 +1156,8 @@ private void check_align(String[] initialSource, assertEditor(expectedSource); } - private void check_align2(String[] initialSource, - String[] expectedSource, + private void check_align2(String initialSource, + String expectedSource, String action, boolean toUp) throws Exception { CompositeInfo shell = parseComposite(initialSource); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/AbsoluteLayoutTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/AbsoluteLayoutTest.java index dfab5748d..4cbf3811d 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/AbsoluteLayoutTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/AbsoluteLayoutTest.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 @@ -104,24 +104,23 @@ public void _test_exit() throws Exception { */ @Test public void test_invalidAbsoluteLayoutToolkit() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test {", - " /**", - " * @wbp.nonvisual location=571,523", - " */", - " private static final Object myStaticBean = new java.util.ArrayList();", - " protected Shell shell;", - " public static void main(String[] args) {", - " Test window = new Test();", - " window.open();", - " }", - " public void open() {", - " shell = new Shell(SWT.NONE);", - " Button button_1 = new Button(shell, SWT.NONE);", - " button_1.setBounds(42, 118, 81, 20);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test { + /** + * @wbp.nonvisual location=571,523 + */ + private static final Object myStaticBean = new java.util.ArrayList(); + protected Shell shell; + public static void main(String[] args) { + Test window = new Test(); + window.open(); + } + public void open() { + shell = new Shell(SWT.NONE); + Button button_1 = new Button(shell, SWT.NONE); + button_1.setBounds(42, 118, 81, 20); + } + }"""); shell.refresh(); AbsoluteLayoutInfo layout = (AbsoluteLayoutInfo) shell.getLayout(); assertSame(ToolkitProvider.DESCRIPTION, layout.getDescription().getToolkit()); @@ -134,15 +133,14 @@ public void test_invalidAbsoluteLayoutToolkit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_parse() throws Exception { - CompositeInfo shellInfo = - parseComposite( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setSize(320, 240);", - " shell.setLayout(null);", - " }", - "}"); + CompositeInfo shellInfo = parseComposite(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setSize(320, 240); + shell.setLayout(null); + } + }"""); // prepare layout AbsoluteLayoutInfo layout = (AbsoluteLayoutInfo) shellInfo.getLayout(); { @@ -168,13 +166,12 @@ public void test_parse() throws Exception { @Test public void test_setLayout() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + } + }"""); // check initial layout { LayoutInfo layout = shell.getLayout(); @@ -185,12 +182,12 @@ public void test_setLayout() throws Exception { shell.setLayout(absoluteLayout); // check result assertSame(absoluteLayout, shell.getLayout()); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + } + }"""); // listen for AbsoluteLayoutInfo setObject() during refresh { final boolean[] absoluteLayout_objectSet = new boolean[1]; @@ -215,17 +212,16 @@ public void invoke(JavaInfo target, Object o) throws Exception { */ @Test public void test_onSet() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new RowData(200, 100));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new RowData(200, 100)); + } + } + }"""); shell.refresh(); // set absolute layout AbsoluteLayoutInfo absoluteLayout = @@ -238,16 +234,16 @@ public void test_onSet() throws Exception { Rectangle bounds = button.getBounds(); // check result assertSame(absoluteLayout, shell.getLayout()); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(3, 3, " + bounds.width + ", " + bounds.height + ");", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(3, 3, %d, %d); + } + } + }""".formatted(bounds.width, bounds.height)); } //////////////////////////////////////////////////////////////////////////// @@ -261,15 +257,15 @@ public void test_onSet() throws Exception { */ @Test public void test_onSetLayout_forChild_keepAbsolute() throws Exception { - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " {", - " Composite inner = new Composite(this, SWT.NONE);", - " inner.setBounds(10, 20, 200, 100);", - " }", - " }", - "}"); + parseComposite(""" + public class Test extends Shell { + public Test() { + { + Composite inner = new Composite(this, SWT.NONE); + inner.setBounds(10, 20, 200, 100); + } + } + }"""); refresh(); // set RowLayout for "inner" new UiContext().executeAndCheck(new FailableRunnable<>() { @@ -286,16 +282,16 @@ public void accept(SWTBot bot) { shell.button("No, keep 'null' layout").click(); } }); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " {", - " Composite inner = new Composite(this, SWT.NONE);", - " inner.setBounds(10, 20, 200, 100);", - " inner.setLayout(new RowLayout(SWT.HORIZONTAL));", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + { + Composite inner = new Composite(this, SWT.NONE); + inner.setBounds(10, 20, 200, 100); + inner.setLayout(new RowLayout(SWT.HORIZONTAL)); + } + } + }"""); } /** @@ -304,15 +300,15 @@ public void accept(SWTBot bot) { */ @Test public void test_onSetLayout_forChild_useFormLayout() throws Exception { - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " {", - " Composite inner = new Composite(this, SWT.NONE);", - " inner.setBounds(10, 20, 200, 100);", - " }", - " }", - "}"); + parseComposite(""" + public class Test extends Shell { + public Test() { + { + Composite inner = new Composite(this, SWT.NONE); + inner.setBounds(10, 20, 200, 100); + } + } + }"""); refresh(); // set RowLayout for "inner" new UiContext().executeAndCheck(new FailableRunnable<>() { @@ -329,24 +325,24 @@ public void accept(SWTBot bot) { shell.button("Yes, use FormLayout").click(); } }); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new FormLayout());", - " {", - " Composite inner = new Composite(this, SWT.NONE);", - " {", - " FormData formData = new FormData();", - " formData.bottom = new FormAttachment(0, 120);", - " formData.right = new FormAttachment(0, 210);", - " formData.top = new FormAttachment(0, 20);", - " formData.left = new FormAttachment(0, 10);", - " inner.setLayoutData(formData);", - " }", - " inner.setLayout(new RowLayout(SWT.HORIZONTAL));", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new FormLayout()); + { + Composite inner = new Composite(this, SWT.NONE); + { + FormData formData = new FormData(); + formData.bottom = new FormAttachment(0, 120); + formData.right = new FormAttachment(0, 210); + formData.top = new FormAttachment(0, 20); + formData.left = new FormAttachment(0, 10); + inner.setLayoutData(formData); + } + inner.setLayout(new RowLayout(SWT.HORIZONTAL)); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -360,23 +356,22 @@ public void accept(SWTBot bot) { */ @Test public void test_delete() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " button.setLocation(0, 0);", - " button.setLocation(new Point(0, 0));", - " button.setSize(0, 0);", - " button.setSize(new Point(0, 0));", - " button.setBounds(0, 0, 0, 0);", - " button.setBounds(new Rectangle(0, 0, 0, 0));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + button.setLocation(0, 0); + button.setLocation(new Point(0, 0)); + button.setSize(0, 0); + button.setSize(new Point(0, 0)); + button.setBounds(0, 0, 0, 0); + button.setBounds(new Rectangle(0, 0, 0, 0)); + } + } + }"""); // AbsoluteLayoutInfo absoluteLayout = (AbsoluteLayoutInfo) shell.getLayout(); assertInstanceOf(InvocationChildAssociation.class, absoluteLayout.getAssociation()); @@ -384,16 +379,16 @@ public void test_delete() throws Exception { // LayoutInfo rowLayout = BTestUtils.createLayout("org.eclipse.swt.layout.RowLayout"); shell.setLayout(rowLayout); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout(SWT.HORIZONTAL));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout(SWT.HORIZONTAL)); + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -406,26 +401,25 @@ public void test_delete() throws Exception { */ @Test public void test_create() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + } + }"""); AbsoluteLayoutInfo layout = (AbsoluteLayoutInfo) shell.getLayout(); // ControlInfo button = BTestUtils.createButton(); layout.commandCreate(button, null); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } /** @@ -433,33 +427,32 @@ public void test_create() throws Exception { */ @Test public void test_create_withReference() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Text text = new Text(this, SWT.BORDER);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Text text = new Text(this, SWT.BORDER); + } + } + }"""); AbsoluteLayoutInfo layout = (AbsoluteLayoutInfo) shell.getLayout(); ControlInfo referenceControl = shell.getChildrenControls().get(0); // ControlInfo button = BTestUtils.createButton(); layout.commandCreate(button, referenceControl); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " {", - " Text text = new Text(this, SWT.BORDER);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + } + { + Text text = new Text(this, SWT.BORDER); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -470,33 +463,23 @@ public void test_create_withReference() throws Exception { /** * generic check for bounds changing. */ - private void check_changeBounds(String[] initial, - String[] expected, + private void check_changeBounds(String initial, + String expected, Point location, Dimension size) throws Exception { - String[] initialCode = - new String[]{ - "class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " Button button = new Button(this, SWT.NONE);", - " button.setText(\"test\");", - " }", - "}"}; + String initialCode = """ + class Test extends Shell { + public Test() { + setLayout(null); + Button button = new Button(this, SWT.NONE); + %s + button.setText("test"); + } + }"""; // prepare initial code - String[] initialLines = ArrayUtils.clone(initialCode); - for (int i = 0; i < initial.length; i++) { - if (!StringUtils.isEmpty(initial[i])) { - initialLines = ArrayUtils.insert(4 + i, initialLines, initial[i]); - } - } + String initialLines = initialCode.formatted(initial); // prepare expected code - String[] expectedLines = ArrayUtils.clone(initialCode); - for (int i = 0; i < expected.length; i++) { - if (!StringUtils.isEmpty(expected[i])) { - expectedLines = ArrayUtils.insert(4 + i, expectedLines, expected[i]); - } - } + String expectedLines = initialCode.formatted(expected); // prepare model CompositeInfo shellInfo = parseComposite(initialLines); shellInfo.refresh(); @@ -510,137 +493,140 @@ private void check_changeBounds(String[] initial, @Test public void test_command_changeBounds_set_location_only() throws Exception { - check_changeBounds( - new String[]{""}, - new String[]{" button.setLocation(10, 10);"}, + check_changeBounds(""" + """, """ + button.setLocation(10, 10); + """, new Point(10, 10), null); } @Test public void test_command_changeBounds_set_size_after_location() throws Exception { - check_changeBounds(new String[]{" button.setLocation(10, 10);"}, new String[]{ - " button.setSize(25, 60);", - " button.setLocation(10, 10);"}, new Point(10, 10), new Dimension(25, 60)); + check_changeBounds(""" + button.setLocation(10, 10); + """, """ + button.setSize(25, 60); + button.setLocation(10, 10); + """, new Point(10, 10), new Dimension(25, 60)); } @Test public void test_command_changeBounds_set_size_only() throws Exception { - check_changeBounds(new String[]{ - " button.setSize(25, 60);", - " button.setLocation(20, 20);"}, new String[]{ - " button.setSize(30, 100);", - " button.setLocation(20, 20);"}, null, new Dimension(30, 100)); + check_changeBounds(""" + button.setSize(25, 60); + button.setLocation(20, 20); + """, """ + button.setSize(30, 100); + button.setLocation(20, 20); + """, null, new Dimension(30, 100)); } @Test public void test_command_changeBounds_set_location_and_size() throws Exception { - check_changeBounds( - new String[]{""}, - new String[]{" button.setBounds(10, 10, 25, 70);"}, - new Point(10, 10), - new Dimension(25, 70)); + check_changeBounds(""" + """, """ + button.setBounds(10, 10, 25, 70); + """, new Point(10, 10), new Dimension(25, 70)); } @Test public void test_command_changeBounds_set_location_only_after_setBounds_set() throws Exception { - check_changeBounds( - new String[]{" button.setBounds(10, 10, 25, 70);"}, - new String[]{" button.setBounds(30, 30, 25, 70);"}, - new Point(30, 30), - null); + check_changeBounds(""" + button.setBounds(10, 10, 25, 70); + """, """ + button.setBounds(30, 30, 25, 70); + """, new Point(30, 30), null); } @Test public void test_command_changeBounds_set_size_only_after_setBounds_set() throws Exception { - check_changeBounds( - new String[]{" button.setBounds(30, 30, 25, 70);"}, - new String[]{" button.setBounds(30, 30, 100, 100);"}, - null, - new Dimension(100, 100)); + check_changeBounds(""" + button.setBounds(30, 30, 25, 70); + """, """ + button.setBounds(30, 30, 100, 100); + """, null, new Dimension(100, 100)); } @Test public void test_command_changeBounds_set_location_and_size_after_setBounds_set() throws Exception { - check_changeBounds( - new String[]{" button.setBounds(30, 30, 100, 100);"}, - new String[]{" button.setBounds(10, 10, 25, 70);"}, - new Point(10, 10), - new Dimension(25, 70)); + check_changeBounds(""" + button.setBounds(30, 30, 100, 100); + """, """ + button.setBounds(10, 10, 25, 70); + """, new Point(10, 10), new Dimension(25, 70)); } @Test public void test_command_changeBounds_set_location_only_as_Rectangle() throws Exception { - check_changeBounds( - new String[]{" button.setBounds(new Rectangle(10, 10, 25, 80));"}, - new String[]{" button.setBounds(new Rectangle(0, 0, 25, 80));"}, - new Point(0, 0), - null); + check_changeBounds(""" + button.setBounds(new Rectangle(10, 10, 25, 80)); + """, """ + button.setBounds(new Rectangle(0, 0, 25, 80)); + """, new Point(0, 0), null); } @Test public void test_command_changeBounds_set_size_only_as_Rectangle() throws Exception { - check_changeBounds( - new String[]{" button.setBounds(new Rectangle(0, 0, 25, 80));"}, - new String[]{" button.setBounds(new Rectangle(0, 0, 20, 60));"}, - null, - new Dimension(20, 60)); + check_changeBounds(""" + button.setBounds(new Rectangle(0, 0, 25, 80)); + """, """ + button.setBounds(new Rectangle(0, 0, 20, 60)); + """, null, new Dimension(20, 60)); } @Test public void test_command_changeBounds_set_location_and_size_as_Rectangle() throws Exception { - check_changeBounds( - new String[]{" button.setBounds(new Rectangle(0, 0, 20, 60));"}, - new String[]{" button.setBounds(new Rectangle(10, 10, 25, 80));"}, - new Point(10, 10), - new Dimension(25, 80)); + check_changeBounds(""" + button.setBounds(new Rectangle(0, 0, 20, 60)); + """, """ + button.setBounds(new Rectangle(10, 10, 25, 80)); + """, new Point(10, 10), new Dimension(25, 80)); } @Test public void test_command_changeBounds_set_location_only_as_Point() throws Exception { - check_changeBounds( - new String[]{" button.setLocation(new Point(10, 10));"}, - new String[]{" button.setLocation(new Point(0, 0));"}, - new Point(0, 0), - null); + check_changeBounds(""" + button.setLocation(new Point(10, 10)); + """, """ + button.setLocation(new Point(0, 0)); + """, new Point(0, 0), null); } @Test public void test_command_changeBounds_set_size_only_as_Point() throws Exception { - check_changeBounds( - new String[]{" button.setSize(new Point(20, 50));"}, - new String[]{" button.setSize(new Point(25, 40));"}, - null, - new Dimension(25, 40)); + check_changeBounds(""" + button.setSize(new Point(20, 50)); + """, """ + button.setSize(new Point(25, 40)); + """, null, new Dimension(25, 40)); } @Test public void test_command_changeBounds_setBoundsInts_removeUnused() throws Exception { - check_changeBounds( - new String[]{ - " button.setBounds(10, 20, 100, 50);", - " button.setLocation(10, 20);", - " button.setSize(100, 50);", - " button.setLocation(new Point(10, 20));", - " button.setSize(new Point(100, 50));"}, - new String[]{" button.setBounds(1, 2, 25, 40);"}, - new Point(1, 2), - new Dimension(25, 40)); + check_changeBounds(""" + button.setBounds(10, 20, 100, 50); + button.setLocation(10, 20); + button.setSize(100, 50); + button.setLocation(new Point(10, 20)); + button.setSize(new Point(100, 50)); + """, """ + button.setBounds(1, 2, 25, 40); + """, new Point(1, 2), new Dimension(25, 40)); } @Test public void test_command_changeBounds_setBoundsRectangle_removeUnused() throws Exception { - check_changeBounds( - new String[]{ - " button.setBounds(new Rectangle(10, 20, 100, 50));", - " button.setLocation(10, 20);", - " button.setSize(100, 50);", - " button.setLocation(new Point(10, 20));", - " button.setSize(new Point(100, 50));"}, - new String[]{" button.setBounds(new Rectangle(1, 2, 25, 40));"}, - new Point(1, 2), - new Dimension(25, 40)); + check_changeBounds(""" + button.setBounds(new Rectangle(10, 20, 100, 50)); + button.setLocation(10, 20); + button.setSize(100, 50); + button.setLocation(new Point(10, 20)); + button.setSize(new Point(100, 50)); + """, """ + button.setBounds(new Rectangle(1, 2, 25, 40)); + """, new Point(1, 2), new Dimension(25, 40)); } //////////////////////////////////////////////////////////////////////////// @@ -653,17 +639,16 @@ public void test_command_changeBounds_setBoundsRectangle_removeUnused() throws E */ @Test public void test_autoSize_otherProperty() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(0, 0, 10, 10);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(0, 0, 10, 10); + } + } + }"""); preferences.setValue(IPreferenceConstants.P_AUTOSIZE_ON_PROPERTY_CHANGE, true); // ControlInfo button = shell.getChildrenControls().get(0); @@ -681,18 +666,17 @@ public void test_autoSize_otherProperty() throws Exception { */ @Test public void test_autoSize_textProperty() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New');", - " button.setBounds(0, 0, 10, 10);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + button.setText("New"); + button.setBounds(0, 0, 10, 10); + } + } + }"""); preferences.setValue(IPreferenceConstants.P_AUTOSIZE_ON_PROPERTY_CHANGE, true); // ControlInfo button = shell.getChildrenControls().get(0); @@ -710,17 +694,16 @@ public void test_autoSize_textProperty() throws Exception { */ @Test public void test_autoSize_imageProperty() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(0, 0, 10, 10);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(0, 0, 10, 10); + } + } + }"""); preferences.setValue(IPreferenceConstants.P_AUTOSIZE_ON_PROPERTY_CHANGE, true); // ControlInfo button = shell.getChildrenControls().get(0); @@ -741,18 +724,17 @@ public void test_autoSize_imageProperty() throws Exception { */ @Test public void test_autoSize_textProperty_notEnabled() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New');", - " button.setBounds(0, 0, 10, 10);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + button.setText("New"); + button.setBounds(0, 0, 10, 10); + } + } + }"""); preferences.setValue(IPreferenceConstants.P_AUTOSIZE_ON_PROPERTY_CHANGE, false); // ControlInfo button = shell.getChildrenControls().get(0); @@ -775,17 +757,16 @@ public void test_autoSize_textProperty_notEnabled() throws Exception { */ @Test public void test_autoSizeAction_1() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New');", - " button.setBounds(10, 20, 10, 10);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + { + Button button = new Button(this, SWT.NONE); + button.setText("New"); + button.setBounds(10, 20, 10, 10); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); Dimension buttonPrefSize = button.getPreferredSize(); @@ -799,20 +780,16 @@ public void test_autoSizeAction_1() throws Exception { } // perform auto-size autoSizeAction.run(); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New');", - " button.setBounds(10, 20, " - + buttonPrefSize.width - + ", " - + buttonPrefSize.height - + ");", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + { + Button button = new Button(this, SWT.NONE); + button.setText("New"); + button.setBounds(10, 20, %d, %d); + } + } + }""".formatted(buttonPrefSize.width, buttonPrefSize.height)); } /** @@ -820,18 +797,17 @@ public void test_autoSizeAction_1() throws Exception { */ @Test public void test_autoSizeAction_2() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " {", - " Button button = new Button(shell, SWT.NONE);", - " button.setText('New');", - " button.setBounds(10, 20, 10, 10);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + { + Button button = new Button(shell, SWT.NONE); + button.setText("New"); + button.setBounds(10, 20, 10, 10); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // prepare action @@ -853,17 +829,16 @@ public void test_autoSizeAction_2() throws Exception { * Helper method preparing to test "Bounds" property. */ private Property prepareBoundsProperty() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 30, 100, 200);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 30, 100, 200); + } + } + }"""); shell.refresh(); Property boundsProperty = shell.getChildrenControls().get(0).getPropertyByTitle("Bounds"); return boundsProperty; @@ -904,16 +879,16 @@ public void test_BoundsProperty_set_x() throws Exception { Property subProperty = getBoundsPropertySubProperty("x"); assertNotNull(subProperty); subProperty.setValue(0); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(0, 30, 100, 200);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(0, 30, 100, 200); + } + } + }"""); } /** @@ -936,16 +911,16 @@ public void test_BoundsProperty_set_y() throws Exception { Property subProperty = getBoundsPropertySubProperty("y"); assertNotNull(subProperty); subProperty.setValue(5); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 5, 100, 200);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 5, 100, 200); + } + } + }"""); } /** @@ -968,16 +943,16 @@ public void test_BoundsProperty_set_width() throws Exception { Property subProperty = getBoundsPropertySubProperty("width"); assertNotNull(subProperty); subProperty.setValue(150); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 30, 150, 200);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 30, 150, 200); + } + } + }"""); } /** @@ -1000,16 +975,16 @@ public void test_BoundsProperty_set_height() throws Exception { Property subProperty = getBoundsPropertySubProperty("height"); assertNotNull(subProperty); subProperty.setValue(220); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 30, 100, 220);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 30, 100, 220); + } + } + }"""); } /** @@ -1035,40 +1010,39 @@ public void test_BoundsProperty_get_height() throws Exception { @Test public void test_changeBounds_CreationFlow() throws Exception { preferences.setValue(IPreferenceConstants.P_CREATION_FLOW, true); - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(5, 5, 100, 30);", - " }", - " {", - " Text text = new Text(this, SWT.BORDER);", - " text.setBounds(50, 50, 100, 30);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button = new Button(this, SWT.NONE); + button.setBounds(5, 5, 100, 30); + } + { + Text text = new Text(this, SWT.BORDER); + text.setBounds(50, 50, 100, 30); + } + } + }"""); shell.refresh(); AbsoluteLayoutInfo layout = (AbsoluteLayoutInfo) shell.getLayout(); ControlInfo button = getJavaInfoByName("button"); // Change bounds layout.commandChangeBounds(button, new Point(100, 100), null); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Text text = new Text(this, SWT.BORDER);", - " text.setBounds(50, 50, 100, 30);", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(100, 100, 100, 30);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Text text = new Text(this, SWT.BORDER); + text.setBounds(50, 50, 100, 30); + } + { + Button button = new Button(this, SWT.NONE); + button.setBounds(100, 100, 100, 30); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1078,20 +1052,19 @@ public void test_changeBounds_CreationFlow() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_clipboard() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(10, 20, 100, 50);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(10, 20, 100, 50); + } + } + } + }"""); shell.refresh(); FillLayoutInfo fillLayout = (FillLayoutInfo) shell.getLayout(); // prepare memento @@ -1106,26 +1079,26 @@ public void test_clipboard() throws Exception { fillLayout.command_CREATE(composite, null); memento.apply(); } - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(10, 20, 100, 50);", - " }", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setBounds(10, 20, 100, 50);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(10, 20, 100, 50); + } + } + { + Composite composite = new Composite(this, SWT.NONE); + { + Button button = new Button(composite, SWT.NONE); + button.setBounds(10, 20, 100, 50); + } + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1139,28 +1112,25 @@ public void test_clipboard() throws Exception { */ @Test public void test_canMove() throws Exception { - setFileContentSrc( - "test/MyShell.java", - getTestSource( - "public class MyShell extends Shell {", - " private Button m_button;", - " public MyShell() {", - " setLayout(null);", - " m_button = new Button(this, SWT.NONE);", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + setFileContentSrc("test/MyShell.java", getTestSource(""" + public class MyShell extends Shell { + private Button m_button; + public MyShell() { + setLayout(null); + m_button = new Button(this, SWT.NONE); + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo panel = - parseComposite( - "// filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " }", - "}"); + CompositeInfo panel = parseComposite(""" + // filler filler filler + public class Test extends MyShell { + public Test() { + } + }"""); assertInstanceOf(AbsoluteLayoutInfo.class, panel.getLayout()); ControlInfo button = panel.getChildrenControls().get(0); // check permissions diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/FillLayoutTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/FillLayoutTest.java index 30f7a41d1..706f7ae49 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/FillLayoutTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/FillLayoutTest.java @@ -52,27 +52,27 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_isHorizontal_1() throws Exception { - test_isHorizontal(new String[]{ - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new FillLayout(SWT.HORIZONTAL));", - " }", - "}"}); + test_isHorizontal(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout(SWT.HORIZONTAL)); + } + }"""); } @Test public void test_isHorizontal_2() throws Exception { - test_isHorizontal(new String[]{ - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new FillLayout());", - " }", - "}"}); + test_isHorizontal(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout()); + } + }"""); } - private void test_isHorizontal(String[] lines) throws Exception { + private void test_isHorizontal(String lines) throws Exception { CompositeInfo shellInfo = parseComposite(lines); // check layout FillLayoutInfo layoutInfo = (FillLayoutInfo) shellInfo.getLayout(); @@ -96,13 +96,12 @@ private void test_isHorizontal(String[] lines) throws Exception { */ @Test public void test_NoVirtualLayoutData() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + } + }"""); assertTrue(shell.getChildrenControls().isEmpty()); FillLayoutInfo layout = (FillLayoutInfo) shell.getLayout(); // @@ -111,14 +110,13 @@ public void test_NoVirtualLayoutData() throws Exception { @Test public void test_AddControls() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new FillLayout());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout()); + } + }"""); assertTrue(shell.getChildrenControls().isEmpty()); FillLayoutInfo layout = (FillLayoutInfo) shell.getLayout(); // add "Button" to end @@ -133,16 +131,16 @@ public void test_AddControls() throws Exception { } assertEquals(1, shell.getChildrenControls().size()); assertSame(button, shell.getChildrenControls().get(0)); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new FillLayout());", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout()); + { + Button button = new Button(shell, SWT.NONE); + } + } + }"""); // add "Label" before "Button" ControlInfo label = BTestUtils.createControl("org.eclipse.swt.widgets.Label"); layout.command_CREATE(label, button); @@ -150,41 +148,40 @@ public void test_AddControls() throws Exception { assertEquals(2, shell.getChildrenControls().size()); assertSame(label, shell.getChildrenControls().get(0)); assertSame(button, shell.getChildrenControls().get(1)); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new FillLayout());", - " {", - " Label label = new Label(shell, SWT.NONE);", - " label.setText('New Label');", - " }", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout()); + { + Label label = new Label(shell, SWT.NONE); + label.setText("New Label"); + } + { + Button button = new Button(shell, SWT.NONE); + } + } + }"""); } @Test public void test_MoveControls() throws Exception { - CompositeInfo shellInfo = - parseComposite( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new FillLayout());", - " {", - " Label label = new Label(shell, SWT.NONE);", - " }", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " {", - " Combo combo = new Combo(shell, SWT.READ_ONLY);", - " }", - " }", - "}"); + CompositeInfo shellInfo = parseComposite(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout()); + { + Label label = new Label(shell, SWT.NONE); + } + { + Button button = new Button(shell, SWT.NONE); + } + { + Combo combo = new Combo(shell, SWT.READ_ONLY); + } + } + }"""); FillLayoutInfo layout = (FillLayoutInfo) shellInfo.getLayout(); ControlInfo labelInfo = shellInfo.getChildrenControls().get(0); ControlInfo buttonInfo = shellInfo.getChildrenControls().get(1); @@ -204,22 +201,22 @@ public void test_MoveControls() throws Exception { assertSame(labelAssociation, labelInfo.getAssociation()); assertSame(buttonAssociation, buttonInfo.getAssociation()); assertSame(comboAssociation, comboInfo.getAssociation()); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new FillLayout());", - " {", - " Label label = new Label(shell, SWT.NONE);", - " }", - " {", - " Combo combo = new Combo(shell, SWT.READ_ONLY);", - " }", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout()); + { + Label label = new Label(shell, SWT.NONE); + } + { + Combo combo = new Combo(shell, SWT.READ_ONLY); + } + { + Button button = new Button(shell, SWT.NONE); + } + } + }"""); // move "Label" to end layout.command_MOVE(labelInfo, null); assertSame(comboInfo, shellInfo.getChildrenControls().get(0)); @@ -228,47 +225,46 @@ public void test_MoveControls() throws Exception { assertSame(labelAssociation, labelInfo.getAssociation()); assertSame(buttonAssociation, buttonInfo.getAssociation()); assertSame(comboAssociation, comboInfo.getAssociation()); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new FillLayout());", - " {", - " Combo combo = new Combo(shell, SWT.READ_ONLY);", - " }", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " {", - " Label label = new Label(shell, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout()); + { + Combo combo = new Combo(shell, SWT.READ_ONLY); + } + { + Button button = new Button(shell, SWT.NONE); + } + { + Label label = new Label(shell, SWT.NONE); + } + } + }"""); } @Test public void test_ReparentControls() throws Exception { - CompositeInfo shellInfo = - parseComposite( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new FillLayout());", - " {", - " Label label = new Label(shell, SWT.NONE);", - " }", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " {", - " Composite composite = new Composite(shell, SWT.NONE);", - " composite.setLayout(new FillLayout());", - " {", - " Combo combo = new Combo(composite, SWT.READ_ONLY);", - " }", - " }", - " }", - "}"); + CompositeInfo shellInfo = parseComposite(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout()); + { + Label label = new Label(shell, SWT.NONE); + } + { + Button button = new Button(shell, SWT.NONE); + } + { + Composite composite = new Composite(shell, SWT.NONE); + composite.setLayout(new FillLayout()); + { + Combo combo = new Combo(composite, SWT.READ_ONLY); + } + } + } + }"""); assertEquals(3, shellInfo.getChildrenControls().size()); ControlInfo labelInfo = shellInfo.getChildrenControls().get(0); ControlInfo buttonInfo = shellInfo.getChildrenControls().get(1); @@ -294,26 +290,26 @@ public void test_ReparentControls() throws Exception { assertSame(labelAssociation, labelInfo.getAssociation()); assertSame(buttonAssociation, buttonInfo.getAssociation()); assertSame(comboAssociation, comboInfo.getAssociation()); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new FillLayout());", - " {", - " Label label = new Label(shell, SWT.NONE);", - " }", - " {", - " Composite composite = new Composite(shell, SWT.NONE);", - " composite.setLayout(new FillLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " }", - " {", - " Combo combo = new Combo(composite, SWT.READ_ONLY);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout()); + { + Label label = new Label(shell, SWT.NONE); + } + { + Composite composite = new Composite(shell, SWT.NONE); + composite.setLayout(new FillLayout()); + { + Button button = new Button(composite, SWT.NONE); + } + { + Combo combo = new Combo(composite, SWT.READ_ONLY); + } + } + } + }"""); // move "Label" to end of "Composite" layoutInfo.command_MOVE(labelInfo, null); assertEquals(1, shellInfo.getChildrenControls().size()); @@ -325,25 +321,25 @@ public void test_ReparentControls() throws Exception { assertSame(labelAssociation, labelInfo.getAssociation()); assertSame(buttonAssociation, buttonInfo.getAssociation()); assertSame(comboAssociation, comboInfo.getAssociation()); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new FillLayout());", - " {", - " Composite composite = new Composite(shell, SWT.NONE);", - " composite.setLayout(new FillLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " }", - " {", - " Combo combo = new Combo(composite, SWT.READ_ONLY);", - " }", - " {", - " Label label = new Label(composite, SWT.NONE);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout()); + { + Composite composite = new Composite(shell, SWT.NONE); + composite.setLayout(new FillLayout()); + { + Button button = new Button(composite, SWT.NONE); + } + { + Combo combo = new Combo(composite, SWT.READ_ONLY); + } + { + Label label = new Label(composite, SWT.NONE); + } + } + } + }"""); } } \ No newline at end of file diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/ImplicitLayoutDataTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/ImplicitLayoutDataTest.java index edfbbd428..5a67e8c27 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/ImplicitLayoutDataTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/ImplicitLayoutDataTest.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,13 +59,12 @@ public void _test_exit() throws Exception { @Test public void test_implicitData() throws Exception { prepareGridComposite_forImplicit(); - CompositeInfo composite = - parseComposite( - "public class Test extends GridComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " }", - "}"); + CompositeInfo composite = parseComposite(""" + public class Test extends GridComposite { + public Test(Composite parent, int style) { + super(parent, style); + } + }"""); composite.refresh(); ControlInfo button = composite.getChildrenControls().get(0); // @@ -95,13 +94,13 @@ public void test_implicitData() throws Exception { // set new value for "widthHint" property.setValue(110); assertEquals(110, property.getValue()); - assertEditor( - "public class Test extends GridComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " ((GridData) getButton().getLayoutData()).widthHint = 110;", - " }", - "}"); + assertEditor(""" + public class Test extends GridComposite { + public Test(Composite parent, int style) { + super(parent, style); + ((GridData) getButton().getLayoutData()).widthHint = 110; + } + }"""); // check supports assertSame(creationSupport, gridData.getCreationSupport()); assertNotSame(variableSupport, gridData.getVariableSupport()); @@ -110,12 +109,12 @@ public void test_implicitData() throws Exception { } // delete, so any "explicit" ASTNode's are removed, we GridData is still "implicit" gridData.delete(); - assertEditor( - "public class Test extends GridComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " }", - "}"); + assertEditor(""" + public class Test extends GridComposite { + public Test(Composite parent, int style) { + super(parent, style); + } + }"""); assertSame(creationSupport, gridData.getCreationSupport()); assertInstanceOf(ImplicitLayoutDataVariableSupport.class, gridData.getVariableSupport()); assertInstanceOf(ImplicitObjectAssociation.class, gridData.getAssociation()); @@ -129,13 +128,12 @@ public void test_implicitData() throws Exception { public void test_implicitData_advanced() throws Exception { prepareGridComposite_forImplicit(); // extend GridComposite - CompositeInfo composite = - parseComposite( - "public class Test extends GridComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " }", - "}"); + CompositeInfo composite = parseComposite(""" + public class Test extends GridComposite { + public Test(Composite parent, int style) { + super(parent, style); + } + }"""); composite.refresh(); ControlInfo button = composite.getChildrenControls().get(0); // @@ -165,13 +163,13 @@ public void test_implicitData_advanced() throws Exception { // set new value for "widthHint" property.setValue(110); assertEquals(110, property.getValue()); - assertEditor( - "public class Test extends GridComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " ((GridData) getButton().getLayoutData()).widthHint = 110;", - " }", - "}"); + assertEditor(""" + public class Test extends GridComposite { + public Test(Composite parent, int style) { + super(parent, style); + ((GridData) getButton().getLayoutData()).widthHint = 110; + } + }"""); // check supports assertSame(creationSupport, gridData.getCreationSupport()); assertNotSame(variableSupport, gridData.getVariableSupport()); @@ -185,51 +183,49 @@ public void test_implicitData_advanced() throws Exception { // set value, so force variable (and Block) property.setValue(60); assertEquals(60, property.getValue()); - assertEditor( - "public class Test extends GridComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " {", - " GridData gridData = (GridData) getButton().getLayoutData();", - " gridData.heightHint = 60;", - " gridData.widthHint = 110;", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends GridComposite { + public Test(Composite parent, int style) { + super(parent, style); + { + GridData gridData = (GridData) getButton().getLayoutData(); + gridData.heightHint = 60; + gridData.widthHint = 110; + } + } + }"""); // remove value, so inline property.setValue(Property.UNKNOWN_VALUE); assertEquals(50, property.getValue()); - assertEditor( - "public class Test extends GridComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " ((GridData) getButton().getLayoutData()).widthHint = 110;", - " }", - "}"); + assertEditor(""" + public class Test extends GridComposite { + public Test(Composite parent, int style) { + super(parent, style); + ((GridData) getButton().getLayoutData()).widthHint = 110; + } + }"""); } } private void prepareGridComposite_forImplicit() throws Exception { - setFileContentSrc( - "test/GridComposite.java", - getTestSource( - "public class GridComposite extends Composite {", - " private Button m_button;", - " public GridComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " {", - " m_button = new Button(this, SWT.NONE);", - " GridData data = new GridData();", - " data.widthHint = 100;", - " data.heightHint = 50;", - " m_button.setLayoutData(data);", - " }", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + setFileContentSrc("test/GridComposite.java", getTestSource(""" + public class GridComposite extends Composite { + private Button m_button; + public GridComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + { + m_button = new Button(this, SWT.NONE); + GridData data = new GridData(); + data.widthHint = 100; + data.heightHint = 50; + m_button.setLayoutData(data); + } + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); } @@ -238,32 +234,28 @@ private void prepareGridComposite_forImplicit() throws Exception { */ @Test public void test_implicitReplace_withExplicitData() throws Exception { - createASTCompilationUnit( - "test", - "MyComposite.java", - getTestSource( - "public class MyComposite extends Composite {", - " private Button m_button;", - " public MyComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " m_button = new Button(this, SWT.NONE);", - " m_button.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + createASTCompilationUnit("test", "MyComposite.java", getTestSource(""" + public class MyComposite extends Composite { + private Button m_button; + public MyComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + m_button = new Button(this, SWT.NONE); + m_button.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " myComposite.getButton().setLayoutData(new GridData());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + myComposite.getButton().setLayoutData(new GridData()); + } + }"""); shell.refresh(); CompositeInfo myComposite = (CompositeInfo) shell.getChildrenControls().get(0); ControlInfo button = myComposite.getChildrenControls().get(0); @@ -286,31 +278,27 @@ public void test_implicitReplace_withExplicitData() throws Exception { */ @Test public void test_delete_shouldKeepSameInstance() throws Exception { - createASTCompilationUnit( - "test", - "MyComposite.java", - getTestSource( - "public class MyComposite extends Composite {", - " private Button m_button;", - " public MyComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " m_button = new Button(this, SWT.NONE);", - " m_button.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + createASTCompilationUnit("test", "MyComposite.java", getTestSource(""" + public class MyComposite extends Composite { + private Button m_button; + public MyComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + m_button = new Button(this, SWT.NONE); + m_button.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + } + }"""); shell.refresh(); CompositeInfo myComposite = (CompositeInfo) shell.getChildrenControls().get(0); ControlInfo button = myComposite.getChildrenControls().get(0); @@ -330,12 +318,12 @@ public void test_delete_shouldKeepSameInstance() throws Exception { // delete "button", same LayoutData should be kept assertTrue(button.canDelete()); button.delete(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + } + }"""); { LayoutDataInfo newData = LayoutInfo.getLayoutData(button); assertSame(initialData, newData); @@ -351,33 +339,29 @@ public void test_delete_shouldKeepSameInstance() throws Exception { */ @Test public void test_delete_removeMaterialized() throws Exception { - createASTCompilationUnit( - "test", - "MyComposite.java", - getTestSource( - "public class MyComposite extends Composite {", - " private Button m_button;", - " public MyComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " m_button = new Button(this, SWT.NONE);", - " m_button.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + createASTCompilationUnit("test", "MyComposite.java", getTestSource(""" + public class MyComposite extends Composite { + private Button m_button; + public MyComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + m_button = new Button(this, SWT.NONE); + m_button.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " GridData gridData = (GridData) myComposite.getButton().getLayoutData();", - " gridData.grabExcessVerticalSpace = true;", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + GridData gridData = (GridData) myComposite.getButton().getLayoutData(); + gridData.grabExcessVerticalSpace = true; + } + }"""); shell.refresh(); CompositeInfo myComposite = (CompositeInfo) shell.getChildrenControls().get(0); ControlInfo button = myComposite.getChildrenControls().get(0); @@ -397,12 +381,12 @@ public void test_delete_removeMaterialized() throws Exception { // delete "button", same LayoutData should be kept assertTrue(button.canDelete()); button.delete(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + } + }"""); { LayoutDataInfo newData = LayoutInfo.getLayoutData(button); assertSame(initialData, newData); @@ -428,51 +412,48 @@ public void test_delete_removeMaterialized() throws Exception { */ @Test public void test_addNewComposite_withExposedControl_andImplicitLayoutData() throws Exception { - setFileContentSrc( - "test/MyComposite.java", - getTestSource( - "public class MyComposite extends Composite {", - " private Button m_button;", - " public MyComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " {", - " m_button = new Button(this, SWT.NONE);", - " m_button.setLayoutData(new GridData());", - " }", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + setFileContentSrc("test/MyComposite.java", getTestSource(""" + public class MyComposite extends Composite { + private Button m_button; + public MyComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + { + m_button = new Button(this, SWT.NONE); + m_button.setLayoutData(new GridData()); + } + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new FillLayout());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new FillLayout()); + } + }"""); FillLayoutInfo layout = (FillLayoutInfo) shell.getLayout(); // create MyComposite CompositeInfo myComposite = createJavaInfo("test.MyComposite"); layout.command_CREATE(myComposite, null); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new FillLayout());", - " {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " }", - " }", - "}"); - assertHierarchy( - "{this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new FillLayout())/ /new MyComposite(this, SWT.NONE)/}", - " {new: org.eclipse.swt.layout.FillLayout} {empty} {/setLayout(new FillLayout())/}", - " {new: test.MyComposite} {local-unique: myComposite} {/new MyComposite(this, SWT.NONE)/}", - " {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {}", - " {method: public org.eclipse.swt.widgets.Button test.MyComposite.getButton()} {property} {}", - " {implicit-layout-data: org.eclipse.swt.layout.GridData} {implicit-layout-data} {}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new FillLayout()); + { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + } + } + }"""); + assertHierarchy(""" + {this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new FillLayout())/ /new MyComposite(this, SWT.NONE)/} + {new: org.eclipse.swt.layout.FillLayout} {empty} {/setLayout(new FillLayout())/} + {new: test.MyComposite} {local-unique: myComposite} {/new MyComposite(this, SWT.NONE)/} + {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {} + {method: public org.eclipse.swt.widgets.Button test.MyComposite.getButton()} {property} {} + {implicit-layout-data: org.eclipse.swt.layout.GridData} {implicit-layout-data} {}"""); } } \ No newline at end of file diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/LayoutDataTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/LayoutDataTest.java index 75eb56922..c0ead93e1 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/LayoutDataTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/LayoutDataTest.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,37 +56,36 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_deleteLayoutData() throws Exception { - CompositeInfo shellInfo = - parseComposite( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " RowLayout layout = new RowLayout();", - " shell.setLayout(layout);", - " //", - " Button button = new Button(shell, SWT.NONE);", - " RowData data = new RowData();", - " data.width = 50;", - " data.height = 40;", - " button.setLayoutData(data);", - " }", - "}"); + CompositeInfo shellInfo = parseComposite(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + RowLayout layout = new RowLayout(); + shell.setLayout(layout); + // + Button button = new Button(shell, SWT.NONE); + RowData data = new RowData(); + data.width = 50; + data.height = 40; + button.setLayoutData(data); + } + }"""); shellInfo.refresh(); // ControlInfo button = shellInfo.getChildrenControls().get(0); Property property = button.getPropertyByTitle("LayoutData"); // property.setValue(Property.UNKNOWN_VALUE); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " RowLayout layout = new RowLayout();", - " shell.setLayout(layout);", - " //", - " Button button = new Button(shell, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + RowLayout layout = new RowLayout(); + shell.setLayout(layout); + // + Button button = new Button(shell, SWT.NONE); + } + }"""); } /** @@ -94,18 +93,17 @@ public void test_deleteLayoutData() throws Exception { */ @Test public void test_excludeProperties() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " RowData data = new RowData(100, 100);", - " button.setLayoutData(data);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + RowData data = new RowData(100, 100); + button.setLayoutData(data); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); Property layoutDataProperty = button.getPropertyByTitle("LayoutData"); @@ -122,72 +120,70 @@ public void test_excludeProperties() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_codeGeneration_Block() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); RowDataInfo layoutData = RowLayoutInfo.getRowData(button); // set "width" property, so materialize RowData layoutData.getPropertyByTitle("width").setValue(100); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new RowData(100, SWT.DEFAULT));", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new RowData(100, SWT.DEFAULT)); + } + } + }"""); // set "exclude" property, so force variable layoutData.getPropertyByTitle("exclude").setValue(true); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " RowData rowData = new RowData(100, SWT.DEFAULT);", - " rowData.exclude = true;", - " button.setLayoutData(rowData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + { + RowData rowData = new RowData(100, SWT.DEFAULT); + rowData.exclude = true; + button.setLayoutData(rowData); + } + } + } + }"""); // set "exclude" property to default, so no reason to have variable layoutData.getPropertyByTitle("exclude").setValue(false); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new RowData(100, SWT.DEFAULT));", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new RowData(100, SWT.DEFAULT)); + } + } + }"""); } @Test public void test_codeGeneration_Flat() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " ", - " Button button = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + + Button button = new Button(this, SWT.NONE); + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); RowDataInfo layoutData = RowLayoutInfo.getRowData(button); @@ -198,39 +194,39 @@ public void test_codeGeneration_Flat() throws Exception { try { // set "width" property, so materialize RowData layoutData.getPropertyByTitle("width").setValue(100); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " ", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new RowData(100, SWT.DEFAULT));", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new RowData(100, SWT.DEFAULT)); + } + }"""); // set "exclude" property, so force variable layoutData.getPropertyByTitle("exclude").setValue(true); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " ", - " Button button = new Button(this, SWT.NONE);", - " RowData rowData = new RowData(100, SWT.DEFAULT);", - " rowData.exclude = true;", - " button.setLayoutData(rowData);", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + + Button button = new Button(this, SWT.NONE); + RowData rowData = new RowData(100, SWT.DEFAULT); + rowData.exclude = true; + button.setLayoutData(rowData); + } + }"""); // set "exclude" property to default, so no reason to have variable layoutData.getPropertyByTitle("exclude").setValue(false); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " ", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new RowData(100, SWT.DEFAULT));", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new RowData(100, SWT.DEFAULT)); + } + }"""); } finally { generationSettings.setStatement(generationSettings.getDefaultStatement()); } @@ -241,31 +237,30 @@ public void test_codeGeneration_Flat() throws Exception { */ @Test public void test_codeGeneration_ignoreIfDelete() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " RowData rowData = new RowData(100, SWT.DEFAULT);", - " rowData.exclude = false;", - " button.setLayoutData(rowData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + { + RowData rowData = new RowData(100, SWT.DEFAULT); + rowData.exclude = false; + button.setLayoutData(rowData); + } + } + } + }"""); shell.refresh(); final ControlInfo button = shell.getChildrenControls().get(0); // do delete button.delete(); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -278,16 +273,15 @@ public void test_codeGeneration_ignoreIfDelete() throws Exception { */ @Test public void test_nameTemplate_useDefaultName() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); ControlInfo button = getJavaInfoByName("button"); // @@ -295,20 +289,20 @@ public void test_nameTemplate_useDefaultName() throws Exception { org.eclipse.wb.internal.swt.preferences.IPreferenceConstants.P_LAYOUT_DATA_NAME_TEMPLATE, org.eclipse.wb.internal.core.model.variable.SyncParentChildVariableNameSupport.TEMPLATE_FOR_DEFAULT); RowLayoutInfo.getRowData(button).getPropertyByTitle("exclude").setValue(true); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " RowData rowData = new RowData(SWT.DEFAULT, SWT.DEFAULT);", - " rowData.exclude = true;", - " button.setLayoutData(rowData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + { + RowData rowData = new RowData(SWT.DEFAULT, SWT.DEFAULT); + rowData.exclude = true; + button.setLayoutData(rowData); + } + } + } + }"""); } /** @@ -316,16 +310,15 @@ public void test_nameTemplate_useDefaultName() throws Exception { */ @Test public void test_nameTemplate_alternativeTemplate_1() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); ControlInfo button = getJavaInfoByName("button"); // @@ -333,20 +326,20 @@ public void test_nameTemplate_alternativeTemplate_1() throws Exception { org.eclipse.wb.internal.swt.preferences.IPreferenceConstants.P_LAYOUT_DATA_NAME_TEMPLATE, "${dataAcronym}${controlName-cap}"); RowLayoutInfo.getRowData(button).getPropertyByTitle("exclude").setValue(true); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " RowData rdButton = new RowData(SWT.DEFAULT, SWT.DEFAULT);", - " rdButton.exclude = true;", - " button.setLayoutData(rdButton);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + { + RowData rdButton = new RowData(SWT.DEFAULT, SWT.DEFAULT); + rdButton.exclude = true; + button.setLayoutData(rdButton); + } + } + } + }"""); } /** @@ -354,16 +347,15 @@ public void test_nameTemplate_alternativeTemplate_1() throws Exception { */ @Test public void test_nameTemplate_alternativeTemplate_2() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); ControlInfo button = getJavaInfoByName("button"); // @@ -371,20 +363,20 @@ public void test_nameTemplate_alternativeTemplate_2() throws Exception { org.eclipse.wb.internal.swt.preferences.IPreferenceConstants.P_LAYOUT_DATA_NAME_TEMPLATE, "${controlName}${dataClassName}"); RowLayoutInfo.getRowData(button).getPropertyByTitle("exclude").setValue(true); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " RowData buttonRowData = new RowData(SWT.DEFAULT, SWT.DEFAULT);", - " buttonRowData.exclude = true;", - " button.setLayoutData(buttonRowData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + { + RowData buttonRowData = new RowData(SWT.DEFAULT, SWT.DEFAULT); + buttonRowData.exclude = true; + button.setLayoutData(buttonRowData); + } + } + } + }"""); } /** @@ -392,39 +384,38 @@ public void test_nameTemplate_alternativeTemplate_2() throws Exception { */ @Test public void test_nameTemplate_renameWithControl() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " RowData rowData = new RowData(100, SWT.DEFAULT);", - " rowData.exclude = false;", - " button.setLayoutData(rowData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + { + RowData rowData = new RowData(100, SWT.DEFAULT); + rowData.exclude = false; + button.setLayoutData(rowData); + } + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // button.getVariableSupport().setName("myButton"); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button myButton = new Button(this, SWT.NONE);", - " {", - " RowData rowData = new RowData(100, SWT.DEFAULT);", - " rowData.exclude = false;", - " myButton.setLayoutData(rowData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button myButton = new Button(this, SWT.NONE); + { + RowData rowData = new RowData(100, SWT.DEFAULT); + rowData.exclude = false; + myButton.setLayoutData(rowData); + } + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -434,188 +425,182 @@ public void test_nameTemplate_renameWithControl() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_deleteIfDefault() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT)); + } + } + }"""); shell.refresh(); // perform edit operation, see that no reason to have RowData ExecutionUtils.refresh(shell); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } @Test public void test_deleteIfDefault_negativeValue() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new RowData(-1, SWT.DEFAULT));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new RowData(-1, SWT.DEFAULT)); + } + } + }"""); shell.refresh(); // perform edit operation, see that no reason to have RowData ExecutionUtils.refresh(shell); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } @Test public void test_deleteIfDefault_notLiterals() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " int width = SWT.DEFAULT;", - " button.setLayoutData(new RowData(width, SWT.DEFAULT));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + int width = SWT.DEFAULT; + button.setLayoutData(new RowData(width, SWT.DEFAULT)); + } + } + }"""); shell.refresh(); // perform edit operation, variable in constructor - keep LayoutData ExecutionUtils.refresh(shell); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " int width = SWT.DEFAULT;", - " button.setLayoutData(new RowData(width, SWT.DEFAULT));", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + int width = SWT.DEFAULT; + button.setLayoutData(new RowData(width, SWT.DEFAULT)); + } + } + }"""); } @Test public void test_deleteIfDefault_hasVariable() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " RowData rowData = new RowData(SWT.DEFAULT, SWT.DEFAULT);", - " button.setLayoutData(rowData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + { + RowData rowData = new RowData(SWT.DEFAULT, SWT.DEFAULT); + button.setLayoutData(rowData); + } + } + } + }"""); shell.refresh(); // perform edit operation, see that no reason to have RowData ExecutionUtils.refresh(shell); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } @Test public void test_deleteIfDefault_hasMethodInvocation() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " RowData rowData = new RowData(SWT.DEFAULT, SWT.DEFAULT);", - " rowData.hashCode();", - " button.setLayoutData(rowData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + { + RowData rowData = new RowData(SWT.DEFAULT, SWT.DEFAULT); + rowData.hashCode(); + button.setLayoutData(rowData); + } + } + } + }"""); shell.refresh(); // no changes, because has MethodInvocation ExecutionUtils.refresh(shell); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " RowData rowData = new RowData(SWT.DEFAULT, SWT.DEFAULT);", - " rowData.hashCode();", - " button.setLayoutData(rowData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + { + RowData rowData = new RowData(SWT.DEFAULT, SWT.DEFAULT); + rowData.hashCode(); + button.setLayoutData(rowData); + } + } + } + }"""); } @Test public void test_deleteIfDefault_hasFieldAssignment() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " RowData rowData = new RowData(SWT.DEFAULT, SWT.DEFAULT);", - " rowData.exclude = true;", - " button.setLayoutData(rowData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + { + RowData rowData = new RowData(SWT.DEFAULT, SWT.DEFAULT); + rowData.exclude = true; + button.setLayoutData(rowData); + } + } + } + }"""); shell.refresh(); // no changes, because has assignment ExecutionUtils.refresh(shell); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " RowData rowData = new RowData(SWT.DEFAULT, SWT.DEFAULT);", - " rowData.exclude = true;", - " button.setLayoutData(rowData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + { + RowData rowData = new RowData(SWT.DEFAULT, SWT.DEFAULT); + rowData.exclude = true; + button.setLayoutData(rowData); + } + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -628,16 +613,15 @@ public void test_deleteIfDefault_hasFieldAssignment() throws Exception { */ @Test public void test_noParentControl() throws Exception { - CompositeInfo composite = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " RowData dangling = new RowData();", - " }", - "}"); - assertHierarchy( - "{this: org.eclipse.swt.widgets.Shell} {this} {}", - " {implicit-layout: absolute} {implicit-layout} {}"); + CompositeInfo composite = parseComposite(""" + class Test extends Shell { + public Test() { + RowData dangling = new RowData(); + } + }"""); + assertHierarchy(""" + {this: org.eclipse.swt.widgets.Shell} {this} {} + {implicit-layout: absolute} {implicit-layout} {}"""); // composite.refresh(); assertNoErrors(composite); @@ -649,17 +633,16 @@ public void test_noParentControl() throws Exception { */ @Test public void test_noParentComposite_noLayout() throws Exception { - CompositeInfo composite = - parseComposite( - "class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayoutData(new RowData());", - " }", - "}"); - assertHierarchy( - "{this: org.eclipse.swt.widgets.Composite} {this} {/setLayoutData(new RowData())/}", - " {implicit-layout: absolute} {implicit-layout} {}"); + CompositeInfo composite = parseComposite(""" + class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayoutData(new RowData()); + } + }"""); + assertHierarchy(""" + {this: org.eclipse.swt.widgets.Composite} {this} {/setLayoutData(new RowData())/} + {implicit-layout: absolute} {implicit-layout} {}"""); // composite.refresh(); assertNoErrors(composite); @@ -670,18 +653,17 @@ public void test_noParentComposite_noLayout() throws Exception { */ @Test public void test_hasParentLayout_notCompatible() throws Exception { - CompositeInfo composite = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new RowData());", - " }", - "}"); - assertHierarchy( - "{this: org.eclipse.swt.widgets.Shell} {this} {/new Button(this, SWT.NONE)/}", - " {implicit-layout: absolute} {implicit-layout} {}", - " {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/ /button.setLayoutData(new RowData())/}"); + CompositeInfo composite = parseComposite(""" + class Test extends Shell { + public Test() { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new RowData()); + } + }"""); + assertHierarchy(""" + {this: org.eclipse.swt.widgets.Shell} {this} {/new Button(this, SWT.NONE)/} + {implicit-layout: absolute} {implicit-layout} {} + {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/ /button.setLayoutData(new RowData())/}"""); // composite.refresh(); assertNoErrors(composite); @@ -693,23 +675,22 @@ public void test_hasParentLayout_notCompatible() throws Exception { */ @Test public void test_hasParentLayout_notCompatible_alreadyRemoved() throws Exception { - CompositeInfo composite = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new RowData());", - " button.setLayoutData(new GridData());", - " }", - " }", - "}"); - assertHierarchy( - "{this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new GridLayout())/ /new Button(this, SWT.NONE)/}", - " {new: org.eclipse.swt.layout.GridLayout} {empty} {/setLayout(new GridLayout())/}", - " {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/ /button.setLayoutData(new RowData())/ /button.setLayoutData(new GridData())/}", - " {new: org.eclipse.swt.layout.GridData} {empty} {/button.setLayoutData(new GridData())/}"); + CompositeInfo composite = parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new GridLayout()); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new RowData()); + button.setLayoutData(new GridData()); + } + } + }"""); + assertHierarchy(""" + {this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new GridLayout())/ /new Button(this, SWT.NONE)/} + {new: org.eclipse.swt.layout.GridLayout} {empty} {/setLayout(new GridLayout())/} + {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/ /button.setLayoutData(new RowData())/ /button.setLayoutData(new GridData())/} + {new: org.eclipse.swt.layout.GridData} {empty} {/button.setLayoutData(new GridData())/}"""); // composite.refresh(); assertNoErrors(composite); @@ -722,38 +703,33 @@ public void test_hasParentLayout_notCompatible_alreadyRemoved() throws Exception */ @Test public void test_hasParentComposite_noLayout() throws Exception { - setFileContentSrc( - "test/MyComposite.java", - getTestSource( - "public class MyComposite extends Composite {", - " public MyComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new RowLayout());", - " }", - "}")); - setFileContentSrc( - "test/MyComposite.wbp-component.xml", - getSource( - "", - "", - " ", - " false", - " ", - "")); + setFileContentSrc("test/MyComposite.java", getTestSource(""" + public class MyComposite extends Composite { + public MyComposite(Composite parent, int style) { + super(parent, style); + setLayout(new RowLayout()); + } + }""")); + setFileContentSrc("test/MyComposite.wbp-component.xml", """ + + + + false + + """); waitForAutoBuild(); // parse - CompositeInfo composite = - parseComposite( - "public class Test extends MyComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new RowData());", - " }", - "}"); - assertHierarchy( - "{this: test.MyComposite} {this} {/new Button(this, SWT.NONE)/}", - " {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/ /button.setLayoutData(new RowData())/}"); + CompositeInfo composite = parseComposite(""" + public class Test extends MyComposite { + public Test(Composite parent, int style) { + super(parent, style); + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new RowData()); + } + }"""); + assertHierarchy(""" + {this: test.MyComposite} {this} {/new Button(this, SWT.NONE)/} + {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/ /button.setLayoutData(new RowData())/}"""); // composite.refresh(); assertNoErrors(composite); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/LayoutLayoutDataCompatibilityTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/LayoutLayoutDataCompatibilityTest.java index b144a9195..e5c318760 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/LayoutLayoutDataCompatibilityTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/LayoutLayoutDataCompatibilityTest.java @@ -51,22 +51,21 @@ public void _test_exit() throws Exception { */ @Test public void test_compatible() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData());", - " }", - " }", - "}"); - assertHierarchy( - "{this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new GridLayout())/ /new Button(this, SWT.NONE)/}", - " {new: org.eclipse.swt.layout.GridLayout} {empty} {/setLayout(new GridLayout())/}", - " {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/ /button.setLayoutData(new GridData())/}", - " {new: org.eclipse.swt.layout.GridData} {empty} {/button.setLayoutData(new GridData())/}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout()); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData()); + } + } + }"""); + assertHierarchy(""" + {this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new GridLayout())/ /new Button(this, SWT.NONE)/} + {new: org.eclipse.swt.layout.GridLayout} {empty} {/setLayout(new GridLayout())/} + {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/ /button.setLayoutData(new GridData())/} + {new: org.eclipse.swt.layout.GridData} {empty} {/button.setLayoutData(new GridData())/}"""); // refresh() shell.refresh(); assertNoErrors(shell); @@ -77,20 +76,19 @@ public void test_compatible() throws Exception { */ @Test public void test_noData() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); - assertHierarchy( - "{this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new FillLayout())/ /new Button(this, SWT.NONE)/}", - " {new: org.eclipse.swt.layout.FillLayout} {empty} {/setLayout(new FillLayout())/}", - " {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); + assertHierarchy(""" + {this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new FillLayout())/ /new Button(this, SWT.NONE)/} + {new: org.eclipse.swt.layout.FillLayout} {empty} {/setLayout(new FillLayout())/} + {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/}"""); // refresh() shell.refresh(); assertNoErrors(shell); @@ -101,16 +99,16 @@ public void test_noData() throws Exception { */ @Test public void test_notCompatible() throws Exception { - Throwable e = assertThrows(Throwable.class, () -> parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new RowData());", - " }", - " }", - "}")); + Throwable e = assertThrows(Throwable.class, () -> parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout()); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new RowData()); + } + } + }""")); DesignerException de = DesignerExceptionUtils.getDesignerException(e); assertEquals(IExceptionConstants.INCOMPATIBLE_LAYOUT_DATA, de.getCode()); } @@ -121,33 +119,30 @@ public void test_notCompatible() throws Exception { */ @Test public void test_FillLayout_generatedFillData() throws Exception { - setFileContentSrc( - "test/MyShell.java", - getTestSource( - "public class MyShell extends Shell {", - " public MyShell() {", - " setLayout(new FillLayout());", - " }", - " protected void setDoComputeSize(boolean b) {", - " computeSize(-1, -1); // force FillData assignment", - " }", - " protected void checkSubclass() {", - " }", - "}")); + setFileContentSrc("test/MyShell.java", getTestSource(""" + public class MyShell extends Shell { + public MyShell() { + setLayout(new FillLayout()); + } + protected void setDoComputeSize(boolean b) { + computeSize(-1, -1); // force FillData assignment + } + protected void checkSubclass() { + } + }""")); waitForAutoBuild(); // parse - CompositeInfo shell = - parseComposite( - "public class Test extends MyShell {", - " public Test() {", - " Button button = new Button(this, SWT.NONE);", - " setDoComputeSize(true);", - " }", - "}"); - assertHierarchy( - "{this: test.MyShell} {this} {/new Button(this, SWT.NONE)/ /setDoComputeSize(true)/}", - " {implicit-layout: org.eclipse.swt.layout.FillLayout} {implicit-layout} {}", - " {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/}"); + CompositeInfo shell = parseComposite(""" + public class Test extends MyShell { + public Test() { + Button button = new Button(this, SWT.NONE); + setDoComputeSize(true); + } + }"""); + assertHierarchy(""" + {this: test.MyShell} {this} {/new Button(this, SWT.NONE)/ /setDoComputeSize(true)/} + {implicit-layout: org.eclipse.swt.layout.FillLayout} {implicit-layout} {} + {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/}"""); // refresh() shell.refresh(); assertNoErrors(shell); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/LayoutTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/LayoutTest.java index 8d3ee323a..674f75b19 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/LayoutTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/LayoutTest.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 @@ -14,6 +14,7 @@ import org.eclipse.wb.core.model.ObjectInfo; import org.eclipse.wb.internal.core.editor.errors.ErrorEntryInfo; +import org.eclipse.wb.internal.core.model.variable.SyncParentChildVariableNameSupport; import org.eclipse.wb.internal.core.utils.exception.DesignerExceptionUtils; import org.eclipse.wb.internal.rcp.RcpToolkitDescription; import org.eclipse.wb.internal.swt.IExceptionConstants; @@ -58,26 +59,26 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_parse_setLayout_single() throws Exception { - parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " }", - "}"); - assertHierarchy( - "{this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new RowLayout())/}", - " {new: org.eclipse.swt.layout.RowLayout} {empty} {/setLayout(new RowLayout())/}"); + parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + } + }"""); + assertHierarchy(""" + {this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new RowLayout())/} + {new: org.eclipse.swt.layout.RowLayout} {empty} {/setLayout(new RowLayout())/}"""); } @Test public void test_parse_setLayout_double() throws Exception { - Throwable t = assertThrows(Throwable.class, () -> parseComposite( - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " setLayout(new FillLayout());", - " }", - "}")); + Throwable t = assertThrows(Throwable.class, () -> parseComposite(""" + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + setLayout(new FillLayout()); + } + }""")); ErrorEntryInfo errorEntry = DesignerExceptionUtils.getErrorEntry(t); assertEquals(IExceptionConstants.DOUBLE_SET_LAYOUT, errorEntry.getCode()); assertEquals(""" @@ -92,13 +93,12 @@ public void test_parse_setLayout_double() throws Exception { */ @Test public void test_isActive() throws Exception { - CompositeInfo shell = - parseComposite( - "// filler filler filler", - "public class Test extends Shell {", - " public Test() {", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + // filler filler filler + public class Test extends Shell { + public Test() { + } + }"""); // prepare implicit layout LayoutInfo oldLayout = shell.getLayout(); assertTrue(oldLayout.isActive()); @@ -118,21 +118,20 @@ public void test_isActive() throws Exception { @Test public void test_changeLayout() throws Exception { - CompositeInfo shellInfo = - parseComposite( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " RowLayout layout = new RowLayout();", - " shell.setLayout(layout);", - " //", - " Button button = new Button(shell, SWT.NONE);", - " RowData data = new RowData();", - " data.width = 50;", - " data.height = 40;", - " button.setLayoutData(data);", - " }", - "}"); + CompositeInfo shellInfo = parseComposite(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + RowLayout layout = new RowLayout(); + shell.setLayout(layout); + // + Button button = new Button(shell, SWT.NONE); + RowData data = new RowData(); + data.width = 50; + data.height = 40; + button.setLayoutData(data); + } + }"""); // check layout RowLayoutInfo layoutInfo = (RowLayoutInfo) shellInfo.getLayout(); assertNotNull(layoutInfo); @@ -150,48 +149,45 @@ public void test_changeLayout() throws Exception { assertFalse(child instanceof GridLayoutInfo); } // - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new FillLayout(SWT.HORIZONTAL));", - " //", - " Button button = new Button(shell, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new FillLayout(SWT.HORIZONTAL)); + // + Button button = new Button(shell, SWT.NONE); + } + }"""); assertTrue(buttonInfo.getChildrenJava().isEmpty()); } } @Test public void test_visualInheritance_withOverride() throws Exception { - setFileContentSrc( - "test/MyComposite.java", - getTestSource( - "public class MyComposite extends Composite {", - " public MyComposite(Composite parent, int style) {", - " super(parent, style);", - " init();", - " }", - " protected void init() {", - " setLayout(new FillLayout());", - " }", - "}")); + setFileContentSrc("test/MyComposite.java", getTestSource(""" + public class MyComposite extends Composite { + public MyComposite(Composite parent, int style) { + super(parent, style); + init(); + } + protected void init() { + setLayout(new FillLayout()); + } + }""")); waitForAutoBuild(); // parse - CompositeInfo composite = - parseComposite( - "public class Test extends MyComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " }", - " protected void init() {", - " super.init();", - " }", - "}"); - assertHierarchy( - "{this: test.MyComposite} {this} {}", - " {implicit-layout: org.eclipse.swt.layout.FillLayout} {implicit-layout} {}"); + CompositeInfo composite = parseComposite(""" + public class Test extends MyComposite { + public Test(Composite parent, int style) { + super(parent, style); + } + protected void init() { + super.init(); + } + }"""); + assertHierarchy(""" + {this: test.MyComposite} {this} {} + {implicit-layout: org.eclipse.swt.layout.FillLayout} {implicit-layout} {}"""); // refresh() composite.refresh(); assertNoErrors(composite); @@ -207,14 +203,13 @@ public void test_visualInheritance_withOverride() throws Exception { */ @Test public void test_isManagedObject_simpleFalse() throws Exception { - CompositeInfo shell = - parseComposite( - "// filler filler filler", - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + // filler filler filler + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + } + }"""); LayoutInfo layout = shell.getLayout(); // not ControlInfo { @@ -233,14 +228,13 @@ public void test_isManagedObject_simpleFalse() throws Exception { */ @Test public void test_isManagedObject_simpleTrue() throws Exception { - CompositeInfo shell = - parseComposite( - "// filler filler filler", - "public class Test extends Shell {", - " public Test() {", - " Button button = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + // filler filler filler + public class Test extends Shell { + public Test() { + Button button = new Button(this, SWT.NONE); + } + }"""); ControlInfo button = getJavaInfoByName("button"); LayoutInfo layout = shell.getLayout(); // @@ -252,14 +246,13 @@ public void test_isManagedObject_simpleTrue() throws Exception { */ @Test public void test_isManagedObject_falseBecauseNotActive() throws Exception { - CompositeInfo shell = - parseComposite( - "// filler filler filler", - "public class Test extends Shell {", - " public Test() {", - " Button button = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + // filler filler filler + public class Test extends Shell { + public Test() { + Button button = new Button(this, SWT.NONE); + } + }"""); ControlInfo button = getJavaInfoByName("button"); // prepare implicit layout LayoutInfo oldLayout = shell.getLayout(); @@ -288,28 +281,25 @@ public void test_isManagedObject_falseBecauseNotActive() throws Exception { */ @Test public void test_hasImplicitControls_RowLayout() throws Exception { - setFileContentSrc( - "test/ImplicitComposite.java", - getTestSource( - "public class ImplicitComposite extends Composite {", - " public ImplicitComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new RowLayout());", - " new Button(this, SWT.NONE);", - " }", - "}")); + setFileContentSrc("test/ImplicitComposite.java", getTestSource(""" + public class ImplicitComposite extends Composite { + public ImplicitComposite(Composite parent, int style) { + super(parent, style); + setLayout(new RowLayout()); + new Button(this, SWT.NONE); + } + }""")); waitForAutoBuild(); // parse - CompositeInfo composite = - parseComposite( - "public class Test extends ImplicitComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " }", - "}"); - assertHierarchy( - "{this: test.ImplicitComposite} {this} {}", - " {implicit-layout: org.eclipse.swt.layout.RowLayout} {implicit-layout} {}"); + CompositeInfo composite = parseComposite(""" + public class Test extends ImplicitComposite { + public Test(Composite parent, int style) { + super(parent, style); + } + }"""); + assertHierarchy(""" + {this: test.ImplicitComposite} {this} {} + {implicit-layout: org.eclipse.swt.layout.RowLayout} {implicit-layout} {}"""); assertTrue(composite.hasLayout()); // refresh composite.refresh(); @@ -326,28 +316,25 @@ public void test_hasImplicitControls_RowLayout() throws Exception { */ @Test public void test_hasImplicitControls_GridLayout() throws Exception { - setFileContentSrc( - "test/ImplicitComposite.java", - getTestSource( - "public class ImplicitComposite extends Composite {", - " public ImplicitComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " new Button(this, SWT.NONE);", - " }", - "}")); + setFileContentSrc("test/ImplicitComposite.java", getTestSource(""" + public class ImplicitComposite extends Composite { + public ImplicitComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + new Button(this, SWT.NONE); + } + }""")); waitForAutoBuild(); // parse - CompositeInfo composite = - parseComposite( - "public class Test extends ImplicitComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " }", - "}"); - assertHierarchy( - "{this: test.ImplicitComposite} {this} {}", - " {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {}"); + CompositeInfo composite = parseComposite(""" + public class Test extends ImplicitComposite { + public Test(Composite parent, int style) { + super(parent, style); + } + }"""); + assertHierarchy(""" + {this: test.ImplicitComposite} {this} {} + {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {}"""); assertTrue(composite.hasLayout()); // refresh composite.refresh(); @@ -363,36 +350,33 @@ public void test_hasImplicitControls_GridLayout() throws Exception { */ @Test public void test_hasImplicitControls_directExposedChild() throws Exception { - setFileContentSrc( - "test/ImplicitComposite.java", - getTestSource( - "public class ImplicitComposite extends Composite {", - " private Button m_button;", - " public ImplicitComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " {", - " m_button = new Button(this, SWT.NONE);", - " }", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + setFileContentSrc("test/ImplicitComposite.java", getTestSource(""" + public class ImplicitComposite extends Composite { + private Button m_button; + public ImplicitComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + { + m_button = new Button(this, SWT.NONE); + } + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo composite = - parseComposite( - "public class Test extends ImplicitComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " }", - "}"); - assertHierarchy( - "{this: test.ImplicitComposite} {this} {}", - " {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {}", - " {method: public org.eclipse.swt.widgets.Button test.ImplicitComposite.getButton()} {property} {}", - " {virtual-layout_data: org.eclipse.swt.layout.GridData} {virtual-layout-data} {}"); + CompositeInfo composite = parseComposite(""" + public class Test extends ImplicitComposite { + public Test(Composite parent, int style) { + super(parent, style); + } + }"""); + assertHierarchy(""" + {this: test.ImplicitComposite} {this} {} + {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {} + {method: public org.eclipse.swt.widgets.Button test.ImplicitComposite.getButton()} {property} {} + {virtual-layout_data: org.eclipse.swt.layout.GridData} {virtual-layout-data} {}"""); assertTrue(composite.hasLayout()); LayoutInfo layout = composite.getLayout(); Assertions.assertThat(layout.getControls()).hasSize(1); @@ -411,40 +395,37 @@ public void test_hasImplicitControls_directExposedChild() throws Exception { */ @Test public void test_hasImplicitControls_indirectExposedChild() throws Exception { - setFileContentSrc( - "test/ImplicitComposite.java", - getTestSource( - "public class ImplicitComposite extends Composite {", - " private Button m_button;", - " public ImplicitComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " {", - " Composite container = new Composite(this, SWT.NONE);", - " container.setLayout(new RowLayout());", - " {", - " m_button = new Button(container, SWT.NONE);", - " m_button.setLayoutData(new RowData());", - " }", - " }", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + setFileContentSrc("test/ImplicitComposite.java", getTestSource(""" + public class ImplicitComposite extends Composite { + private Button m_button; + public ImplicitComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + { + Composite container = new Composite(this, SWT.NONE); + container.setLayout(new RowLayout()); + { + m_button = new Button(container, SWT.NONE); + m_button.setLayoutData(new RowData()); + } + } + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo composite = - parseComposite( - "public class Test extends ImplicitComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " }", - "}"); - assertHierarchy( - "{this: test.ImplicitComposite} {this} {}", - " {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {}", - " {method: public org.eclipse.swt.widgets.Button test.ImplicitComposite.getButton()} {property} {}"); + CompositeInfo composite = parseComposite(""" + public class Test extends ImplicitComposite { + public Test(Composite parent, int style) { + super(parent, style); + } + }"""); + assertHierarchy(""" + {this: test.ImplicitComposite} {this} {} + {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {} + {method: public org.eclipse.swt.widgets.Button test.ImplicitComposite.getButton()} {property} {}"""); assertTrue(composite.hasLayout()); LayoutInfo layout = composite.getLayout(); Assertions.assertThat(layout.getControls()).isEmpty(); @@ -462,37 +443,34 @@ public void test_hasImplicitControls_indirectExposedChild() throws Exception { */ @Test public void test_hasImplicitControls_directExposedChild_Viewer() throws Exception { - setFileContentSrc( - "test/ImplicitComposite.java", - getTestSource( - "public class ImplicitComposite extends Composite {", - " private TableViewer m_viewer;", - " public ImplicitComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " {", - " m_viewer = new TableViewer(this, SWT.NONE);", - " }", - " }", - " public TableViewer getViewer() {", - " return m_viewer;", - " }", - "}")); + setFileContentSrc("test/ImplicitComposite.java", getTestSource(""" + public class ImplicitComposite extends Composite { + private TableViewer m_viewer; + public ImplicitComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + { + m_viewer = new TableViewer(this, SWT.NONE); + } + } + public TableViewer getViewer() { + return m_viewer; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo composite = - parseComposite( - "public class Test extends ImplicitComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " }", - "}"); - assertHierarchy( - "{this: test.ImplicitComposite} {this} {}", - " {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {}", - " {viewer: public org.eclipse.swt.widgets.Table org.eclipse.jface.viewers.TableViewer.getTable()} {viewer} {}", - " {method: public org.eclipse.jface.viewers.TableViewer test.ImplicitComposite.getViewer()} {property} {}", - " {virtual-layout_data: org.eclipse.swt.layout.GridData} {virtual-layout-data} {}"); + CompositeInfo composite = parseComposite(""" + public class Test extends ImplicitComposite { + public Test(Composite parent, int style) { + super(parent, style); + } + }"""); + assertHierarchy(""" + {this: test.ImplicitComposite} {this} {} + {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {} + {viewer: public org.eclipse.swt.widgets.Table org.eclipse.jface.viewers.TableViewer.getTable()} {viewer} {} + {method: public org.eclipse.jface.viewers.TableViewer test.ImplicitComposite.getViewer()} {property} {} + {virtual-layout_data: org.eclipse.swt.layout.GridData} {virtual-layout-data} {}"""); assertTrue(composite.hasLayout()); LayoutInfo layout = composite.getLayout(); Assertions.assertThat(layout.getControls()).hasSize(1); @@ -511,40 +489,37 @@ public void test_hasImplicitControls_directExposedChild_Viewer() throws Exceptio */ @Test public void test_hasImplicitControls_indirectExposedChild_Viewer() throws Exception { - setFileContentSrc( - "test/ImplicitComposite.java", - getTestSource( - "public class ImplicitComposite extends Composite {", - " private TableViewer m_viewer;", - " public ImplicitComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " {", - " Composite container = new Composite(this, SWT.NONE);", - " container.setLayout(new RowLayout());", - " {", - " m_viewer = new TableViewer(container, SWT.NONE);", - " }", - " }", - " }", - " public TableViewer getViewer() {", - " return m_viewer;", - " }", - "}")); + setFileContentSrc("test/ImplicitComposite.java", getTestSource(""" + public class ImplicitComposite extends Composite { + private TableViewer m_viewer; + public ImplicitComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + { + Composite container = new Composite(this, SWT.NONE); + container.setLayout(new RowLayout()); + { + m_viewer = new TableViewer(container, SWT.NONE); + } + } + } + public TableViewer getViewer() { + return m_viewer; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo composite = - parseComposite( - "public class Test extends ImplicitComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " }", - "}"); - assertHierarchy( - "{this: test.ImplicitComposite} {this} {}", - " {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {}", - " {viewer: public org.eclipse.swt.widgets.Table org.eclipse.jface.viewers.TableViewer.getTable()} {viewer} {}", - " {method: public org.eclipse.jface.viewers.TableViewer test.ImplicitComposite.getViewer()} {property} {}"); + CompositeInfo composite = parseComposite(""" + public class Test extends ImplicitComposite { + public Test(Composite parent, int style) { + super(parent, style); + } + }"""); + assertHierarchy(""" + {this: test.ImplicitComposite} {this} {} + {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {} + {viewer: public org.eclipse.swt.widgets.Table org.eclipse.jface.viewers.TableViewer.getTable()} {viewer} {} + {method: public org.eclipse.jface.viewers.TableViewer test.ImplicitComposite.getViewer()} {property} {}"""); assertTrue(composite.hasLayout()); LayoutInfo layout = composite.getLayout(); Assertions.assertThat(layout.getControls()).isEmpty(); @@ -564,46 +539,43 @@ public void test_hasImplicitControls_indirectExposedChild_Viewer() throws Except */ @Test public void test_indirectExposedChildren_andLocalLayoutData() throws Exception { - setFileContentSrc( - "test/ImplicitComposite.java", - getTestSource( - "public class ImplicitComposite extends Composite {", - " private Button m_button;", - " public ImplicitComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " {", - " Composite container = new Composite(this, SWT.NONE);", - " container.setLayout(new RowLayout());", - " {", - " m_button = new Button(container, SWT.NONE);", - " m_button.setLayoutData(new RowData());", - " }", - " }", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + setFileContentSrc("test/ImplicitComposite.java", getTestSource(""" + public class ImplicitComposite extends Composite { + private Button m_button; + public ImplicitComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + { + Composite container = new Composite(this, SWT.NONE); + container.setLayout(new RowLayout()); + { + m_button = new Button(container, SWT.NONE); + m_button.setLayoutData(new RowData()); + } + } + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo composite = - parseComposite( - "public class Test extends ImplicitComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " {", - " Text text = new Text(this, SWT.BORDER);", - " text.setLayoutData(new GridData());", - " }", - " }", - "}"); - assertHierarchy( - "{this: test.ImplicitComposite} {this} {/new Text(this, SWT.BORDER)/}", - " {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {}", - " {method: public org.eclipse.swt.widgets.Button test.ImplicitComposite.getButton()} {property} {}", - " {new: org.eclipse.swt.widgets.Text} {local-unique: text} {/new Text(this, SWT.BORDER)/ /text.setLayoutData(new GridData())/}", - " {new: org.eclipse.swt.layout.GridData} {empty} {/text.setLayoutData(new GridData())/}"); + CompositeInfo composite = parseComposite(""" + public class Test extends ImplicitComposite { + public Test(Composite parent, int style) { + super(parent, style); + { + Text text = new Text(this, SWT.BORDER); + text.setLayoutData(new GridData()); + } + } + }"""); + assertHierarchy(""" + {this: test.ImplicitComposite} {this} {/new Text(this, SWT.BORDER)/} + {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {} + {method: public org.eclipse.swt.widgets.Button test.ImplicitComposite.getButton()} {property} {} + {new: org.eclipse.swt.widgets.Text} {local-unique: text} {/new Text(this, SWT.BORDER)/ /text.setLayoutData(new GridData())/} + {new: org.eclipse.swt.layout.GridData} {empty} {/text.setLayoutData(new GridData())/}"""); assertTrue(composite.hasLayout()); // refresh composite.refresh(); @@ -616,16 +588,15 @@ public void test_indirectExposedChildren_andLocalLayoutData() throws Exception { // //////////////////////////////////////////////////////////////////////////// private void check_nameTemplate(String template, String... lines) throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new FillLayout(SWT.HORIZONTAL));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new FillLayout(SWT.HORIZONTAL)); + } + } + }"""); shell.refresh(); CompositeInfo composite = (CompositeInfo) shell.getChildrenControls().get(0); LayoutInfo layout = composite.getLayout(); @@ -643,18 +614,17 @@ private void check_nameTemplate(String template, String... lines) throws Excepti */ @Test public void test_nameTemplate_useDefaultName() throws Exception { - check_nameTemplate( - org.eclipse.wb.internal.core.model.variable.SyncParentChildVariableNameSupport.TEMPLATE_FOR_DEFAULT, - "class Test extends Shell {", - " public Test() {", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);", - " fillLayout.spacing = 5;", - " composite.setLayout(fillLayout);", - " }", - " }", - "}"); + check_nameTemplate(SyncParentChildVariableNameSupport.TEMPLATE_FOR_DEFAULT, """ + class Test extends Shell { + public Test() { + { + Composite composite = new Composite(this, SWT.NONE); + FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL); + fillLayout.spacing = 5; + composite.setLayout(fillLayout); + } + } + }"""); } /** @@ -662,18 +632,17 @@ public void test_nameTemplate_useDefaultName() throws Exception { */ @Test public void test_nameTemplate_alternativeTemplate_1() throws Exception { - check_nameTemplate( - "${layoutAcronym}_${compositeName}", - "class Test extends Shell {", - " public Test() {", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " FillLayout fl_composite = new FillLayout(SWT.HORIZONTAL);", - " fl_composite.spacing = 5;", - " composite.setLayout(fl_composite);", - " }", - " }", - "}"); + check_nameTemplate("${layoutAcronym}_${compositeName}", """ + class Test extends Shell { + public Test() { + { + Composite composite = new Composite(this, SWT.NONE); + FillLayout fl_composite = new FillLayout(SWT.HORIZONTAL); + fl_composite.spacing = 5; + composite.setLayout(fl_composite); + } + } + }"""); } /** @@ -681,17 +650,16 @@ public void test_nameTemplate_alternativeTemplate_1() throws Exception { */ @Test public void test_nameTemplate_alternativeTemplate_2() throws Exception { - check_nameTemplate( - "${compositeName}${layoutClassName}", - "class Test extends Shell {", - " public Test() {", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " FillLayout compositeFillLayout = new FillLayout(SWT.HORIZONTAL);", - " compositeFillLayout.spacing = 5;", - " composite.setLayout(compositeFillLayout);", - " }", - " }", - "}"); + check_nameTemplate("${compositeName}${layoutClassName}", """ + class Test extends Shell { + public Test() { + { + Composite composite = new Composite(this, SWT.NONE); + FillLayout compositeFillLayout = new FillLayout(SWT.HORIZONTAL); + compositeFillLayout.spacing = 5; + composite.setLayout(compositeFillLayout); + } + } + }"""); } } \ No newline at end of file diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/RowLayoutTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/RowLayoutTest.java index 8f3eaeea2..da94c6b5f 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/RowLayoutTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/RowLayoutTest.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 @@ -52,64 +52,63 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_typeField() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " RowLayout layout = new RowLayout(SWT.VERTICAL);", - " setLayout(layout);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + RowLayout layout = new RowLayout(SWT.VERTICAL); + setLayout(layout); + } + }"""); RowLayoutInfo layout = (RowLayoutInfo) shell.getLayout(); // prepare "type" property GenericProperty typeProperty = (GenericProperty) layout.getPropertyByTitle("type"); // set "type" to HORIZONTAL { typeProperty.setExpression("org.eclipse.swt.SWT.HORIZONTAL", SWT.HORIZONTAL); - assertEditor( - "class Test extends Shell {", - " Test() {", - " RowLayout layout = new RowLayout(SWT.HORIZONTAL);", - " setLayout(layout);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + RowLayout layout = new RowLayout(SWT.HORIZONTAL); + setLayout(layout); + } + }"""); } // set "type" to VERTICAL { typeProperty.setExpression("org.eclipse.swt.SWT.VERTICAL", SWT.VERTICAL); - assertEditor( - "class Test extends Shell {", - " Test() {", - " RowLayout layout = new RowLayout(SWT.VERTICAL);", - " setLayout(layout);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + RowLayout layout = new RowLayout(SWT.VERTICAL); + setLayout(layout); + } + }"""); } } @Test public void test_isHorizontal_1() throws Exception { - test_isHorizontal(new String[]{ - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout(SWT.HORIZONTAL));", - " }", - "}"}); + test_isHorizontal(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout(SWT.HORIZONTAL)); + } + }"""); } @Test public void test_isHorizontal_2() throws Exception { - test_isHorizontal(new String[]{ - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout());", - " }", - "}"}); + test_isHorizontal(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout()); + } + }"""); } - private void test_isHorizontal(String[] lines) throws Exception { + private void test_isHorizontal(String lines) throws Exception { CompositeInfo shellInfo = parseComposite(lines); // check layout RowLayoutInfo layoutInfo = (RowLayoutInfo) shellInfo.getLayout(); @@ -128,14 +127,13 @@ private void test_isHorizontal(String[] lines) throws Exception { @Test public void test_AddControls() throws Exception { - CompositeInfo shellInfo = - parseComposite( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout());", - " }", - "}"); + CompositeInfo shellInfo = parseComposite(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout()); + } + }"""); assertTrue(shellInfo.getChildrenControls().isEmpty()); RowLayoutInfo layout = (RowLayoutInfo) shellInfo.getLayout(); // add "Button" to end @@ -144,16 +142,16 @@ public void test_AddControls() throws Exception { assertNotNull(buttonInfo.getAssociation()); assertEquals(1, shellInfo.getChildrenControls().size()); assertSame(buttonInfo, shellInfo.getChildrenControls().get(0)); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout());", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout()); + { + Button button = new Button(shell, SWT.NONE); + } + } + }"""); assertRelatedNodes(shellInfo, new String[]{ "new Shell()", "shell.setLayout(new RowLayout())", @@ -165,42 +163,41 @@ public void test_AddControls() throws Exception { assertEquals(2, shellInfo.getChildrenControls().size()); assertSame(labelInfo, shellInfo.getChildrenControls().get(0)); assertSame(buttonInfo, shellInfo.getChildrenControls().get(1)); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout());", - " {", - " Label label = new Label(shell, SWT.NONE);", - " label.setText('New Label');", - " }", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout()); + { + Label label = new Label(shell, SWT.NONE); + label.setText("New Label"); + } + { + Button button = new Button(shell, SWT.NONE); + } + } + }"""); assertInstanceOf(RowDataInfo.class, LayoutInfo.getLayoutData(labelInfo)); } @Test public void test_MoveControls() throws Exception { - CompositeInfo shellInfo = - parseComposite( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout());", - " {", - " Label label = new Label(shell, SWT.NONE);", - " }", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " {", - " Combo combo = new Combo(shell, SWT.READ_ONLY);", - " }", - " }", - "}"); + CompositeInfo shellInfo = parseComposite(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout()); + { + Label label = new Label(shell, SWT.NONE); + } + { + Button button = new Button(shell, SWT.NONE); + } + { + Combo combo = new Combo(shell, SWT.READ_ONLY); + } + } + }"""); RowLayoutInfo layout = (RowLayoutInfo) shellInfo.getLayout(); ControlInfo labelInfo = shellInfo.getChildrenControls().get(0); ControlInfo buttonInfo = shellInfo.getChildrenControls().get(1); @@ -220,22 +217,22 @@ public void test_MoveControls() throws Exception { assertSame(labelAssociation, labelInfo.getAssociation()); assertSame(buttonAssociation, buttonInfo.getAssociation()); assertSame(comboAssociation, comboInfo.getAssociation()); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout());", - " {", - " Label label = new Label(shell, SWT.NONE);", - " }", - " {", - " Combo combo = new Combo(shell, SWT.READ_ONLY);", - " }", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout()); + { + Label label = new Label(shell, SWT.NONE); + } + { + Combo combo = new Combo(shell, SWT.READ_ONLY); + } + { + Button button = new Button(shell, SWT.NONE); + } + } + }"""); // move "Label" to end layout.command_MOVE(labelInfo, null); assertSame(comboInfo, shellInfo.getChildrenControls().get(0)); @@ -244,47 +241,46 @@ public void test_MoveControls() throws Exception { assertSame(labelAssociation, labelInfo.getAssociation()); assertSame(buttonAssociation, buttonInfo.getAssociation()); assertSame(comboAssociation, comboInfo.getAssociation()); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout());", - " {", - " Combo combo = new Combo(shell, SWT.READ_ONLY);", - " }", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " {", - " Label label = new Label(shell, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout()); + { + Combo combo = new Combo(shell, SWT.READ_ONLY); + } + { + Button button = new Button(shell, SWT.NONE); + } + { + Label label = new Label(shell, SWT.NONE); + } + } + }"""); } @Test public void test_ReparentControls() throws Exception { - CompositeInfo shellInfo = - parseComposite( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout());", - " {", - " Label label = new Label(shell, SWT.NONE);", - " }", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " {", - " Composite composite = new Composite(shell, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " {", - " Combo combo = new Combo(composite, SWT.READ_ONLY);", - " }", - " }", - " }", - "}"); + CompositeInfo shellInfo = parseComposite(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout()); + { + Label label = new Label(shell, SWT.NONE); + } + { + Button button = new Button(shell, SWT.NONE); + } + { + Composite composite = new Composite(shell, SWT.NONE); + composite.setLayout(new RowLayout()); + { + Combo combo = new Combo(composite, SWT.READ_ONLY); + } + } + } + }"""); assertEquals(3, shellInfo.getChildrenControls().size()); ControlInfo labelInfo = shellInfo.getChildrenControls().get(0); ControlInfo buttonInfo = shellInfo.getChildrenControls().get(1); @@ -310,26 +306,26 @@ public void test_ReparentControls() throws Exception { assertSame(labelAssociation, labelInfo.getAssociation()); assertSame(buttonAssociation, buttonInfo.getAssociation()); assertSame(comboAssociation, comboInfo.getAssociation()); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout());", - " {", - " Label label = new Label(shell, SWT.NONE);", - " }", - " {", - " Composite composite = new Composite(shell, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " }", - " {", - " Combo combo = new Combo(composite, SWT.READ_ONLY);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout()); + { + Label label = new Label(shell, SWT.NONE); + } + { + Composite composite = new Composite(shell, SWT.NONE); + composite.setLayout(new RowLayout()); + { + Button button = new Button(composite, SWT.NONE); + } + { + Combo combo = new Combo(composite, SWT.READ_ONLY); + } + } + } + }"""); // move "Label" to end of "Composite" layoutInfo.command_MOVE(labelInfo, null); assertEquals(1, shellInfo.getChildrenControls().size()); @@ -341,42 +337,41 @@ public void test_ReparentControls() throws Exception { assertSame(labelAssociation, labelInfo.getAssociation()); assertSame(buttonAssociation, buttonInfo.getAssociation()); assertSame(comboAssociation, comboInfo.getAssociation()); - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(shell, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " }", - " {", - " Combo combo = new Combo(composite, SWT.READ_ONLY);", - " }", - " {", - " Label label = new Label(composite, SWT.NONE);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout()); + { + Composite composite = new Composite(shell, SWT.NONE); + composite.setLayout(new RowLayout()); + { + Button button = new Button(composite, SWT.NONE); + } + { + Combo combo = new Combo(composite, SWT.READ_ONLY); + } + { + Label label = new Label(composite, SWT.NONE); + } + } + } + }"""); } @Test public void test_changeRowData() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout());", - " {", - " Button button = new Button(shell, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout()); + { + Button button = new Button(shell, SWT.NONE); + button.setText("New Button"); + } + } + }"""); // ControlInfo button = shell.getChildrenControls().get(0); RowDataInfo dataInfo = (RowDataInfo) button.getChildrenJava().get(0); @@ -394,18 +389,18 @@ public void test_changeRowData() throws Exception { dataInfo.setHeight(30); assertEquals(30, height.getValue()); // - assertEditor( - "class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new RowLayout());", - " {", - " Button button = new Button(shell, SWT.NONE);", - " button.setLayoutData(new RowData(40, 30));", - " button.setText('New Button');", - " }", - " }", - "}"); + assertEditor(""" + class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new RowLayout()); + { + Button button = new Button(shell, SWT.NONE); + button.setLayoutData(new RowData(40, 30)); + button.setText("New Button"); + } + } + }"""); } /** @@ -414,16 +409,15 @@ public void test_changeRowData() throws Exception { */ @Test public void test_addBefore_nameConflict() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " ", - " Button button = new Button(this, SWT.NONE);", - " button.setText('0');", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + + Button button = new Button(this, SWT.NONE); + button.setText("0"); + } + }"""); RowLayoutInfo rowLayout = (RowLayoutInfo) shell.getLayout(); ControlInfo existingButton = shell.getChildrenControls().get(0); // add new Button @@ -440,16 +434,16 @@ public void test_addBefore_nameConflict() throws Exception { } } // check result - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " ", - " Button button_1 = new Button(this, SWT.NONE);", - " ", - " Button button = new Button(this, SWT.NONE);", - " button.setText('0');", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + \t\t + Button button_1 = new Button(this, SWT.NONE); + + Button button = new Button(this, SWT.NONE); + button.setText("0"); + } + }"""); } } \ No newline at end of file diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/VirtualLayoutDataTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/VirtualLayoutDataTest.java index a79dc3fbe..58a51adac 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/VirtualLayoutDataTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/VirtualLayoutDataTest.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 @@ -60,16 +60,15 @@ public void _test_exit() throws Exception { */ @Test public void test_virtual_initial() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " //", - " Button button = new Button(this, SWT.NONE);", - " button.setText('new button');", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + // + Button button = new Button(this, SWT.NONE); + button.setText("new button"); + } + }"""); shell.refresh(); // prepare layout data ControlInfo button = shell.getChildrenControls().get(0); @@ -106,18 +105,17 @@ public void test_virtual_initial() throws Exception { */ @Test public void test_virtual_whenDeleteReal() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " //", - " Button button = new Button(this, SWT.NONE);", - " button.setText('new button');", - " RowData data = new RowData();", - " button.setLayoutData(data);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + // + Button button = new Button(this, SWT.NONE); + button.setText("new button"); + RowData data = new RowData(); + button.setLayoutData(data); + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // check real LayoutDataInfo @@ -131,15 +129,15 @@ public void test_virtual_whenDeleteReal() throws Exception { assertInstanceOf(InvocationChildAssociation.class, dataInfo.getAssociation()); // delete layout data dataInfo.delete(); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " //", - " Button button = new Button(this, SWT.NONE);", - " button.setText('new button');", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + // + Button button = new Button(this, SWT.NONE); + button.setText("new button"); + } + }"""); } // check virtual { @@ -159,14 +157,13 @@ public void test_virtual_whenDeleteReal() throws Exception { */ @Test public void test_virtual_materialize() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " Button button = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + Button button = new Button(this, SWT.NONE); + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // check "virtual" supports @@ -177,25 +174,25 @@ public void test_virtual_materialize() throws Exception { assertInstanceOf(EmptyAssociation.class, dataInfo.getAssociation()); // set property value, so "materialize" LayoutDataInfo dataInfo.getPropertyByTitle("width").setValue(100); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new RowData(100, SWT.DEFAULT));", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new RowData(100, SWT.DEFAULT)); + } + }"""); assertInstanceOf(ConstructorCreationSupport.class, dataInfo.getCreationSupport()); assertInstanceOf(EmptyVariableSupport.class, dataInfo.getVariableSupport()); // delete layout data, so "virtual" should be created dataInfo.delete(); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " Button button = new Button(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + Button button = new Button(this, SWT.NONE); + } + }"""); // check new "virtual" assertEquals(1, button.getChildrenJava().size()); LayoutDataInfo newDataInfo = (LayoutDataInfo) button.getChildrenJava().get(0); @@ -211,13 +208,12 @@ public void test_virtual_materialize() throws Exception { */ @Test public void test_virtual_whenAdd() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + } + }"""); shell.refresh(); RowLayoutInfo layout = (RowLayoutInfo) shell.getLayout(); // add new button @@ -233,15 +229,15 @@ public void test_virtual_whenAdd() throws Exception { assertInstanceOf(VirtualLayoutDataVariableSupport.class, dataInfo.getVariableSupport()); assertInstanceOf(EmptyAssociation.class, dataInfo.getAssociation()); // check source - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } /** @@ -250,22 +246,21 @@ public void test_virtual_whenAdd() throws Exception { */ @Test public void test_virtual_whenMove() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " //", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new FillLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + // + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new FillLayout()); + { + Button button = new Button(composite, SWT.NONE); + button.setText("New Button"); + } + } + } + }"""); shell.refresh(); // RowLayoutInfo layout = (RowLayoutInfo) shell.getLayout(); @@ -283,21 +278,21 @@ public void test_virtual_whenMove() throws Exception { assertInstanceOf(VirtualLayoutDataVariableSupport.class, dataInfo.getVariableSupport()); assertInstanceOf(EmptyAssociation.class, dataInfo.getAssociation()); // check source - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " //", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new FillLayout());", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + // + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new FillLayout()); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); } /** @@ -306,22 +301,21 @@ public void test_virtual_whenMove() throws Exception { */ @Test public void test_virtual_removeWhenMoveFrom() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " //", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new FillLayout());", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + // + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new FillLayout()); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); shell.refresh(); // ControlInfo button = shell.getChildrenControls().get(1); @@ -342,21 +336,21 @@ public void test_virtual_removeWhenMoveFrom() throws Exception { // no "virtual" LayoutDataInfo expected assertTrue(button.getChildrenJava().isEmpty()); // check source - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " //", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new FillLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + // + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new FillLayout()); + { + Button button = new Button(composite, SWT.NONE); + button.setText("New Button"); + } + } + } + }"""); } /** @@ -364,15 +358,14 @@ public void test_virtual_removeWhenMoveFrom() throws Exception { */ @Test public void test_virtual_whenNewLayout() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " Button button = new Button(this, SWT.NONE);", - " button.setText('new button');", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + Button button = new Button(this, SWT.NONE); + button.setText("new button"); + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // check "virtual" supports @@ -391,14 +384,14 @@ public void test_virtual_whenNewLayout() throws Exception { // no "virtual" LayoutDataInfo expected assertTrue(button.getChildrenJava().isEmpty()); // check source - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout(SWT.HORIZONTAL));", - " Button button = new Button(this, SWT.NONE);", - " button.setText('new button');", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new FillLayout(SWT.HORIZONTAL)); + Button button = new Button(this, SWT.NONE); + button.setText("new button"); + } + }"""); } /** @@ -406,19 +399,18 @@ public void test_virtual_whenNewLayout() throws Exception { */ @Test public void test_real_whenNewLayout() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " Button button = new Button(this, SWT.NONE);", - " button.setText('new button');", - " RowData data = new RowData();", - " data.width = 50;", - " data.height = 70;", - " button.setLayoutData(data);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + Button button = new Button(this, SWT.NONE); + button.setText("new button"); + RowData data = new RowData(); + data.width = 50; + data.height = 70; + button.setLayoutData(data); + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // check virtual Creation/Variable Support @@ -437,14 +429,14 @@ public void test_real_whenNewLayout() throws Exception { // no "virtual" LayoutDataInfo expected assertTrue(button.getChildrenJava().isEmpty()); // check source - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout(SWT.HORIZONTAL));", - " Button button = new Button(this, SWT.NONE);", - " button.setText('new button');", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new FillLayout(SWT.HORIZONTAL)); + Button button = new Button(this, SWT.NONE); + button.setText("new button"); + } + }"""); } /** @@ -453,18 +445,17 @@ public void test_real_whenNewLayout() throws Exception { */ @Test public void test_virtual_whenNewLayout2() throws Exception { - CompositeInfo composite = - parseComposite( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + CompositeInfo composite = parseComposite(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); composite.refresh(); assertInstanceOf(GridLayoutInfo.class, composite.getLayout()); ControlInfo button = composite.getChildrenControls().get(0); @@ -483,17 +474,17 @@ public void test_virtual_whenNewLayout2() throws Exception { assertSame(newLayout, composite.getLayout()); } // check source - assertEditor( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new RowLayout(SWT.HORIZONTAL));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new RowLayout(SWT.HORIZONTAL)); + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); // check "virtual" RowData { assertEquals(1, button.getChildrenJava().size()); @@ -515,26 +506,23 @@ public void test_virtual_whenNewLayout2() throws Exception { @Test public void test_implicitLayout_1() throws Exception { // create GridComposite with GridLayout - setFileContentSrc( - "test/GridComposite.java", - getTestSource( - "public class GridComposite extends Composite {", - " public GridComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " }", - "}")); + setFileContentSrc("test/GridComposite.java", getTestSource(""" + public class GridComposite extends Composite { + public GridComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + } + }""")); waitForAutoBuild(); // extend GridComposite - CompositeInfo composite = - parseComposite( - "public class Test extends GridComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - "}"); + CompositeInfo composite = parseComposite(""" + public class Test extends GridComposite { + public Test(Composite parent, int style) { + super(parent, style); + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + }"""); composite.refresh(); ControlInfo button = composite.getChildrenControls().get(0); // implicit GridLayout expected @@ -552,15 +540,15 @@ public void test_implicitLayout_1() throws Exception { composite.setLayout(newLayout); assertSame(newLayout, composite.getLayout()); // check source - assertEditor( - "public class Test extends GridComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new RowLayout(SWT.HORIZONTAL));", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - "}"); + assertEditor(""" + public class Test extends GridComposite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new RowLayout(SWT.HORIZONTAL)); + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + }"""); // check "virtual" RowData { assertEquals(1, button.getChildrenJava().size()); @@ -575,14 +563,14 @@ public void test_implicitLayout_1() throws Exception { // we again have "implicit" GridLayout and "virtual" GridData { assertInstanceOf(GridLayoutInfo.class, composite.getLayout()); - assertEditor( - "public class Test extends GridComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - "}"); + assertEditor(""" + public class Test extends GridComposite { + public Test(Composite parent, int style) { + super(parent, style); + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + }"""); // check "virtual" GridData { assertEquals(1, button.getChildrenJava().size()); @@ -600,27 +588,24 @@ public void test_implicitLayout_1() throws Exception { @Test public void test_implicitLayout_2() throws Exception { // create GridComposite with GridLayout - setFileContentSrc( - "test/GridComposite.java", - getTestSource( - "public class GridComposite extends Composite {", - " public GridComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " }", - "}")); + setFileContentSrc("test/GridComposite.java", getTestSource(""" + public class GridComposite extends Composite { + public GridComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + } + }""")); waitForAutoBuild(); // extend GridComposite - CompositeInfo composite = - parseComposite( - "public class Test extends GridComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new RowLayout(SWT.HORIZONTAL));", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - "}"); + CompositeInfo composite = parseComposite(""" + public class Test extends GridComposite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new RowLayout(SWT.HORIZONTAL)); + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + }"""); composite.refresh(); ControlInfo button = composite.getChildrenControls().get(0); // explicit RowLayout expected @@ -654,14 +639,14 @@ public void test_implicitLayout_2() throws Exception { assertInstanceOf(GridLayoutInfo.class, composite.getLayout()); } // check source - assertEditor( - "public class Test extends GridComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - "}"); + assertEditor(""" + public class Test extends GridComposite { + public Test(Composite parent, int style) { + super(parent, style); + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + }"""); // check that button has "virtual" GridData { assertEquals(1, button.getChildrenJava().size()); @@ -677,30 +662,27 @@ public void test_implicitLayout_2() throws Exception { */ @Test public void test_whenExposedControl_deleteExplicitData_restoreVirtual() throws Exception { - setFileContentSrc( - "test/MyComposite.java", - getTestSource( - "public class MyComposite extends Composite {", - " private Button m_button;", - " public MyComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " m_button = new Button(this, SWT.NONE);", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + setFileContentSrc("test/MyComposite.java", getTestSource(""" + public class MyComposite extends Composite { + private Button m_button; + public MyComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + m_button = new Button(this, SWT.NONE); + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " myComposite.getButton().setLayoutData(new GridData());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + myComposite.getButton().setLayoutData(new GridData()); + } + }"""); shell.refresh(); CompositeInfo myComposite = getJavaInfoByName("myComposite"); ControlInfo button = getJavaInfoByName("getButton()"); @@ -716,12 +698,12 @@ public void test_whenExposedControl_deleteExplicitData_restoreVirtual() throws E // delete, "explicit" GridData is gone assertTrue(button.canDelete()); button.delete(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + } + }"""); assertTrue(myComposite.getChildren().contains(button)); // check new GridData { @@ -743,14 +725,13 @@ public void test_whenExposedControl_deleteExplicitData_restoreVirtual() throws E */ @Test public void test_delete_shouldKeepSameInstance() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " Button button = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + Button button = new Button(this, SWT.NONE); + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); LayoutDataInfo initialData = LayoutInfo.getLayoutData(button); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridDataTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridDataTest.java index 99bb41a22..432385847 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridDataTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridDataTest.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 @@ -56,20 +56,19 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_modernHorizontalAlignment() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData(-1, -1, false, false);", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(-1, -1, false, false); + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); shell.startEdit(); // @@ -90,20 +89,19 @@ public void test_modernHorizontalAlignment() throws Exception { @Test public void test_modernVerticalAlignment() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData(-1, -1, false, false);", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(-1, -1, false, false); + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); shell.startEdit(); // @@ -185,30 +183,29 @@ private void check_modernAlignments(CompositeInfo shell, */ @Test public void test_setHorizontalAlignment() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); GridDataInfo gridData = getGridData(button); // SWT.LEFT is default alignment, so nothing should be changed gridData.setHorizontalAlignment(SWT.LEFT); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } /** @@ -216,30 +213,29 @@ public void test_setHorizontalAlignment() throws Exception { */ @Test public void test_setVerticalAlignment() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); GridDataInfo gridData = getGridData(button); // SWT.CENTER is default alignment, so nothing should be changed gridData.setVerticalAlignment(SWT.CENTER); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -249,16 +245,15 @@ public void test_setVerticalAlignment() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_getSmallAlignmentImage() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); ControlInfo button = shell.getChildrenControls().get(0); // shell.refresh(); @@ -310,17 +305,16 @@ private static void check_getSmallAlignmentImage(GridDataInfo gridData, */ @Test public void test_getSmallAlignmentImage_invalid() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(-1, -1, false, false));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(-1, -1, false, false)); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // @@ -339,16 +333,15 @@ public void test_getSmallAlignmentImage_invalid() throws Exception { */ @Test public void test_sizeHint_width() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); GridDataInfo gridData = GridLayoutInfo.getGridData(button); @@ -357,32 +350,32 @@ public void test_sizeHint_width() throws Exception { // set hint gridData.setWidthHint(200); assertEquals(200, gridData.getWidthHint()); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);", - " gridData.widthHint = 200;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gridData.widthHint = 200; + button.setLayoutData(gridData); + } + } + } + }"""); // remove hint gridData.setWidthHint(-1); assertEquals(-1, gridData.getWidthHint()); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } /** @@ -390,16 +383,15 @@ public void test_sizeHint_width() throws Exception { */ @Test public void test_sizeHint_height() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); GridDataInfo gridData = GridLayoutInfo.getGridData(button); @@ -408,32 +400,32 @@ public void test_sizeHint_height() throws Exception { // set hint gridData.setHeightHint(200); assertEquals(200, gridData.getHeightHint()); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);", - " gridData.heightHint = 200;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gridData.heightHint = 200; + button.setLayoutData(gridData); + } + } + } + }"""); // remove hint gridData.setHeightHint(-1); assertEquals(-1, gridData.getHeightHint()); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -443,21 +435,20 @@ public void test_sizeHint_height() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_grabHorizontal() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.grabExcessHorizontalSpace = true;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.grabExcessHorizontalSpace = true; + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // initial state, set new @@ -467,15 +458,15 @@ public void test_grabHorizontal() throws Exception { gridData.setHorizontalGrab(false); } // check new state - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); { GridDataInfo gridData = getGridData(button); assertFalse(gridData.getHorizontalGrab()); @@ -484,20 +475,19 @@ public void test_grabHorizontal() throws Exception { @Test public void test_grabVertical() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // initial state, set new @@ -507,20 +497,20 @@ public void test_grabVertical() throws Exception { gridData.setVerticalGrab(true); } // check new state - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.grabExcessVerticalSpace = true;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.grabExcessVerticalSpace = true; + button.setLayoutData(gridData); + } + } + } + }"""); { GridDataInfo gridData = getGridData(button); assertTrue(gridData.getVerticalGrab()); @@ -529,21 +519,20 @@ public void test_grabVertical() throws Exception { @Test public void test_grab_usingProperty() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.grabExcessHorizontalSpace = true;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.grabExcessHorizontalSpace = true; + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // initial state, set new @@ -553,15 +542,15 @@ public void test_grab_usingProperty() throws Exception { gridData.getPropertyByTitle("grabExcessHorizontalSpace").setValue(Boolean.FALSE); } // check new state - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); { GridDataInfo gridData = getGridData(button); assertFalse(gridData.getHorizontalGrab()); @@ -578,37 +567,37 @@ public void test_grab_usingProperty() throws Exception { */ @Test public void test_setHorizontalSpan() throws Exception { - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + } + { + Button button_2 = new Button(this, SWT.NONE); + } + } + }"""); refresh(); ControlInfo button = getJavaInfoByName("button_1"); // GridDataInfo gridData = getGridData(button); gridData.setHorizontalSpan(2); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); + } + { + Button button_2 = new Button(this, SWT.NONE); + } + new Label(this, SWT.NONE); + } + }"""); } /** @@ -616,18 +605,18 @@ public void test_setHorizontalSpan() throws Exception { */ @Test public void test_setProperty_horizontalSpan() throws Exception { - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + } + { + Button button_2 = new Button(this, SWT.NONE); + } + } + }"""); refresh(); ControlInfo button = getJavaInfoByName("button_1"); Property property = getGridData(button).getPropertyByTitle("horizontalSpan"); @@ -645,20 +634,20 @@ public void test_setProperty_horizontalSpan() throws Exception { } // set "2" property.setValue(2); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); + } + { + Button button_2 = new Button(this, SWT.NONE); + } + new Label(this, SWT.NONE); + } + }"""); } /** @@ -666,50 +655,49 @@ public void test_setProperty_horizontalSpan() throws Exception { */ @Test public void test_setVerticalSpan() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_4 = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + } + { + Button button_2 = new Button(this, SWT.NONE); + } + { + Button button_3 = new Button(this, SWT.NONE); + } + { + Button button_4 = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); ControlInfo button = getJavaInfoByName("button_2"); // GridDataInfo gridData = getGridData(button); gridData.setVerticalSpan(2); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2));", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_4 = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2)); + } + { + Button button_3 = new Button(this, SWT.NONE); + } + { + Button button_4 = new Button(this, SWT.NONE); + } + new Label(this, SWT.NONE); + } + }"""); } /** @@ -717,25 +705,24 @@ public void test_setVerticalSpan() throws Exception { */ @Test public void test_setProperty_verticalSpan() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_4 = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + } + { + Button button_2 = new Button(this, SWT.NONE); + } + { + Button button_3 = new Button(this, SWT.NONE); + } + { + Button button_4 = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); ControlInfo button = getJavaInfoByName("button_2"); Property property = getGridData(button).getPropertyByTitle("verticalSpan"); @@ -753,26 +740,26 @@ public void test_setProperty_verticalSpan() throws Exception { } // set "2" property.setValue(2); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2));", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_4 = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2)); + } + { + Button button_3 = new Button(this, SWT.NONE); + } + { + Button button_4 = new Button(this, SWT.NONE); + } + new Label(this, SWT.NONE); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -782,16 +769,15 @@ public void test_setProperty_verticalSpan() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_contextMenu_horizontal() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); ControlInfo button = shell.getChildrenControls().get(0); // GridDataInfo gridData = (GridDataInfo) button.getChildrenJava().get(0); @@ -821,31 +807,31 @@ public void test_contextMenu_horizontal() throws Exception { IAction action = findChildAction(manager2, "&Right"); action.setChecked(true); action.run(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + } + } + }"""); } // use "Grab action" { IAction action = findChildAction(manager2, "&Grab excess space"); action.run(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1)); + } + } + }"""); } } finally { shell.refresh_dispose(); @@ -854,16 +840,15 @@ public void test_contextMenu_horizontal() throws Exception { @Test public void test_contextMenu_vertical() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); ControlInfo button = shell.getChildrenControls().get(0); // GridDataInfo gridData = (GridDataInfo) button.getChildrenJava().get(0); @@ -890,31 +875,31 @@ public void test_contextMenu_vertical() throws Exception { IAction action = findChildAction(manager2, "&Bottom"); action.setChecked(true); action.run(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1));", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1)); + } + } + }"""); } // use "Grab action" { IAction action = findChildAction(manager2, "&Grab excess space"); action.run(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, true, 1, 1));", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, true, 1, 1)); + } + } + }"""); } } finally { shell.refresh_dispose(); @@ -923,21 +908,20 @@ public void test_contextMenu_vertical() throws Exception { @Test public void test_contextMenu_horizontalHint() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.widthHint = 200;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.widthHint = 200; + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // clear "widthHint" @@ -947,15 +931,15 @@ public void test_contextMenu_horizontalHint() throws Exception { assertNotNull(clearHintAction); // use action clearHintAction.run(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } // no "widthHint" value, so no action { @@ -966,21 +950,20 @@ public void test_contextMenu_horizontalHint() throws Exception { @Test public void test_contextMenu_verticalHint() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.heightHint = 200;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.heightHint = 200; + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // clear "heightHint" @@ -990,15 +973,15 @@ public void test_contextMenu_verticalHint() throws Exception { assertNotNull(clearHintAction); // use action clearHintAction.run(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } // no "widthHint" value, so no action { @@ -1026,16 +1009,15 @@ private IAction getClearHintAction(ControlInfo button, boolean horizontal) throw */ @Test public void test_defaultValues() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); GridDataInfo gridData = getGridData(button); @@ -1058,17 +1040,16 @@ public void test_defaultValues() throws Exception { */ @Test public void test_separateValuesFor_GridData_FILL_BOTH() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(GridData.FILL_BOTH));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(GridData.FILL_BOTH)); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); GridDataInfo gridData = getGridData(button); @@ -1086,167 +1067,161 @@ public void test_separateValuesFor_GridData_FILL_BOTH() throws Exception { @Test public void test_deleteIfDefault_emptyConstructor() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData());", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData()); + } + } + }"""); shell.refresh(); // refresh(), force check ExecutionUtils.refresh(shell); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } @Test public void test_deleteIfDefault_constructor4_yes() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + } + } + }"""); shell.refresh(); // refresh(), force check ExecutionUtils.refresh(shell); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } @Test public void test_deleteIfDefault_constructor4_no1() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + } + } + }"""); shell.refresh(); // refresh(), force check ExecutionUtils.refresh(shell); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + } + } + }"""); } @Test public void test_deleteIfDefault_constructor4_no2() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); + } + } + }"""); shell.refresh(); // refresh(), force check ExecutionUtils.refresh(shell); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); + } + } + }"""); } @Test public void test_deleteIfDefault_constructor6_yes() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + } + } + }"""); shell.refresh(); // refresh(), force check ExecutionUtils.refresh(shell); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } @Test public void test_deleteIfDefault_constructor6_no1() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); + } + } + }"""); shell.refresh(); // refresh(), force check ExecutionUtils.refresh(shell); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1259,18 +1234,17 @@ public void test_deleteIfDefault_constructor6_no1() throws Exception { */ @Test public void test_hasParentLayout_notCompatible() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " public Test() {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData());", - " }", - "}"); - assertHierarchy( - "{this: org.eclipse.swt.widgets.Shell} {this} {/new Button(this, SWT.NONE)/}", - " {implicit-layout: absolute} {implicit-layout} {}", - " {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/ /button.setLayoutData(new GridData())/}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + public Test() { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData()); + } + }"""); + assertHierarchy(""" + {this: org.eclipse.swt.widgets.Shell} {this} {/new Button(this, SWT.NONE)/} + {implicit-layout: absolute} {implicit-layout} {} + {new: org.eclipse.swt.widgets.Button} {local-unique: button} {/new Button(this, SWT.NONE)/ /button.setLayoutData(new GridData())/}"""); // shell.refresh(); assertNoErrors(shell); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutConverterTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutConverterTest.java index 48b67ce90..7678175f5 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutConverterTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutConverterTest.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 @@ -50,20 +50,19 @@ public void _test_exit() throws Exception { */ @Test public void test_empty() throws Exception { - CompositeInfo shell = - parseComposite( - "// filler filler filler", - "public class Test extends Shell {", - " public Test() {", - " }", - "}"); - setGridLayout(shell, new String[]{ - "// filler filler filler", - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " }", - "}"}, new Rectangle[]{}); + CompositeInfo shell = parseComposite(""" + // filler filler filler + public class Test extends Shell { + public Test() { + } + }"""); + setGridLayout(shell, """ + // filler filler filler + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + } + }""", new Rectangle[] {}); } /** @@ -71,32 +70,31 @@ public void test_empty() throws Exception { */ @Test public void test_singleColumn_normalOrder() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " button_0.setBounds(10, 10, 100, 20);", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setBounds(20, 40, 100, 20);", - " }", - " }", - "}"); - setGridLayout(shell, new String[]{ - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " }", - "}"}, new Rectangle[]{new Rectangle(0, 0, 1, 1), new Rectangle(0, 1, 1, 1)}); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + { + Button button_0 = new Button(this, SWT.NONE); + button_0.setBounds(10, 10, 100, 20); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setBounds(20, 40, 100, 20); + } + } + }"""); + setGridLayout(shell, """ + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button_0 = new Button(this, SWT.NONE); + } + { + Button button_1 = new Button(this, SWT.NONE); + } + } + }""", new Rectangle(0, 0, 1, 1), new Rectangle(0, 1, 1, 1)); } /** @@ -104,34 +102,33 @@ public void test_singleColumn_normalOrder() throws Exception { */ @Test public void test_noReorderIfRightOrder() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " button_0.setBounds(10, 10, 100, 20);", - " }", - " int marker;", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setBounds(10, 50, 100, 20);", - " }", - " }", - "}"); - setGridLayout(shell, new String[]{ - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " }", - " int marker;", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " }", - "}"}); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + { + Button button_0 = new Button(this, SWT.NONE); + button_0.setBounds(10, 10, 100, 20); + } + int marker; + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setBounds(10, 50, 100, 20); + } + } + }"""); + setGridLayout(shell, """ + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button_0 = new Button(this, SWT.NONE); + } + int marker; + { + Button button_1 = new Button(this, SWT.NONE); + } + } + }"""); } /** @@ -139,32 +136,31 @@ public void test_noReorderIfRightOrder() throws Exception { */ @Test public void test_singleColumn_reverseOrder() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setBounds(20, 40, 100, 20);", - " }", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " button_0.setBounds(10, 10, 100, 20);", - " }", - " }", - "}"); - setGridLayout(shell, new String[]{ - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " }", - "}"}, new Rectangle[]{new Rectangle(0, 0, 1, 1), new Rectangle(0, 1, 1, 1)}); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setBounds(20, 40, 100, 20); + } + { + Button button_0 = new Button(this, SWT.NONE); + button_0.setBounds(10, 10, 100, 20); + } + } + }"""); + setGridLayout(shell, """ + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button_0 = new Button(this, SWT.NONE); + } + { + Button button_1 = new Button(this, SWT.NONE); + } + } + }""", new Rectangle(0, 0, 1, 1), new Rectangle(0, 1, 1, 1)); } /** @@ -172,32 +168,31 @@ public void test_singleColumn_reverseOrder() throws Exception { */ @Test public void test_twoRows_noFillers() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " button_0.setBounds(10, 10, 100, 20);", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setBounds(120, 15, 100, 20);", - " }", - " }", - "}"); - setGridLayout(shell, new String[]{ - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " }", - "}"}, new Rectangle[]{new Rectangle(0, 0, 1, 1), new Rectangle(1, 0, 1, 1)}); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + { + Button button_0 = new Button(this, SWT.NONE); + button_0.setBounds(10, 10, 100, 20); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setBounds(120, 15, 100, 20); + } + } + }"""); + setGridLayout(shell, """ + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(2, false)); + { + Button button_0 = new Button(this, SWT.NONE); + } + { + Button button_1 = new Button(this, SWT.NONE); + } + } + }""", new Rectangle(0, 0, 1, 1), new Rectangle(1, 0, 1, 1)); } /** @@ -205,34 +200,33 @@ public void test_twoRows_noFillers() throws Exception { */ @Test public void test_twoRows_withFillers() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " button_0.setBounds(10, 10, 100, 20);", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setBounds(120, 40, 100, 20);", - " }", - " }", - "}"); - setGridLayout(shell, new String[]{ - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " }", - "}"}, new Rectangle[]{new Rectangle(0, 0, 1, 1), new Rectangle(1, 1, 1, 1)}); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + { + Button button_0 = new Button(this, SWT.NONE); + button_0.setBounds(10, 10, 100, 20); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setBounds(120, 40, 100, 20); + } + } + }"""); + setGridLayout(shell, """ + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(2, false)); + { + Button button_0 = new Button(this, SWT.NONE); + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button_1 = new Button(this, SWT.NONE); + } + } + }""", new Rectangle(0, 0, 1, 1), new Rectangle(1, 1, 1, 1)); } /** @@ -240,43 +234,39 @@ public void test_twoRows_withFillers() throws Exception { */ @Test public void test_spanHorizontal() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " button_0.setBounds(10, 10, 10, 10);", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setBounds(30, 10, 10, 10);", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setBounds(10, 30, 30, 10);", - " }", - " }", - "}"); - setGridLayout(shell, new String[]{ - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));", - " }", - " }", - "}"}, new Rectangle[]{ - new Rectangle(0, 0, 1, 1), - new Rectangle(1, 0, 1, 1), - new Rectangle(0, 1, 2, 1)}); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + { + Button button_0 = new Button(this, SWT.NONE); + button_0.setBounds(10, 10, 10, 10); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setBounds(30, 10, 10, 10); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setBounds(10, 30, 30, 10); + } + } + }"""); + setGridLayout(shell, """ + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(2, false)); + { + Button button_0 = new Button(this, SWT.NONE); + } + { + Button button_1 = new Button(this, SWT.NONE); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); + } + } + }""", new Rectangle(0, 0, 1, 1), new Rectangle(1, 0, 1, 1), new Rectangle(0, 1, 2, 1)); } /** @@ -284,43 +274,39 @@ public void test_spanHorizontal() throws Exception { */ @Test public void test_spanVertical() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " button_0.setBounds(10, 10, 10, 10);", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setBounds(30, 10, 10, 30);", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setBounds(10, 30, 10, 10);", - " }", - " }", - "}"); - setGridLayout(shell, new String[]{ - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_0 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2));", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " }", - " }", - "}"}, new Rectangle[]{ - new Rectangle(0, 0, 1, 1), - new Rectangle(1, 0, 1, 2), - new Rectangle(0, 1, 1, 1)}); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + { + Button button_0 = new Button(this, SWT.NONE); + button_0.setBounds(10, 10, 10, 10); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setBounds(30, 10, 10, 30); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setBounds(10, 30, 10, 10); + } + } + }"""); + setGridLayout(shell, """ + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(2, false)); + { + Button button_0 = new Button(this, SWT.NONE); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2)); + } + { + Button button_2 = new Button(this, SWT.NONE); + } + } + }""", new Rectangle(0, 0, 1, 1), new Rectangle(1, 0, 1, 2), new Rectangle(0, 1, 1, 1)); } //////////////////////////////////////////////////////////////////////////// @@ -331,7 +317,7 @@ public void test_spanVertical() throws Exception { /** * Sets the {@link GridLayout} for given {@link CompositeInfo}. */ - private void setGridLayout(CompositeInfo composite, String[] expectedLines, Rectangle[] cells) + private void setGridLayout(CompositeInfo composite, String expectedLines, Rectangle... cells) throws Exception { GridLayoutInfo layout = setGridLayout(composite, expectedLines); // check cells for control's @@ -347,7 +333,7 @@ private void setGridLayout(CompositeInfo composite, String[] expectedLines, Rect } } - private GridLayoutInfo setGridLayout(CompositeInfo composite, String[] expectedLines) + private GridLayoutInfo setGridLayout(CompositeInfo composite, String expectedLines) throws Exception { composite.getRoot().refresh(); // set GridLayout diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutExposedTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutExposedTest.java index 89bf143c3..ea1c048f0 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutExposedTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutExposedTest.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 @@ -53,13 +53,12 @@ public void _test_exit() throws Exception { public void test_deleteExposedComponent_noExplicitData() throws Exception { configureForDelete(); // parse - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + } + }"""); shell.refresh(); CompositeInfo myComposite = (CompositeInfo) shell.getChildrenControls().get(0); ControlInfo button = myComposite.getChildrenControls().get(0); @@ -75,12 +74,12 @@ public void test_deleteExposedComponent_noExplicitData() throws Exception { // delete, no visible change expected assertTrue(button.canDelete()); button.delete(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + } + }"""); assertFalse(button.isDeleted()); // check new GridData { @@ -98,14 +97,13 @@ public void test_deleteExposedComponent_noExplicitData() throws Exception { public void test_deleteExposedComponent_withExplicitData() throws Exception { configureForDelete(); // parse - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " myComposite.getButton().setLayoutData(new GridData());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + myComposite.getButton().setLayoutData(new GridData()); + } + }"""); shell.refresh(); CompositeInfo myComposite = (CompositeInfo) shell.getChildrenControls().get(0); ControlInfo button = myComposite.getChildrenControls().get(0); @@ -121,12 +119,12 @@ public void test_deleteExposedComponent_withExplicitData() throws Exception { // delete, "explicit" GridData is gone assertTrue(button.canDelete()); button.delete(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + } + }"""); assertTrue(myComposite.getChildren().contains(button)); // check new GridData { @@ -142,47 +140,43 @@ public void test_deleteExposedComponent_withExplicitData() throws Exception { */ @Test public void test_deleteWhenTwoExposed() throws Exception { - createASTCompilationUnit( - "test", - "MyComposite.java", - getTestSource( - "public class MyComposite extends Composite {", - " private Button m_button;", - " private Text m_text;", - " public MyComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " m_button = new Button(this, SWT.NONE);", - " m_text = new Text(this, SWT.NONE);", - " }", - " public Button getButton() {", - " return m_button;", - " }", - " public Text getText() {", - " return m_text;", - " }", - "}")); + createASTCompilationUnit("test", "MyComposite.java", getTestSource(""" + public class MyComposite extends Composite { + private Button m_button; + private Text m_text; + public MyComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + m_button = new Button(this, SWT.NONE); + m_text = new Text(this, SWT.NONE); + } + public Button getButton() { + return m_button; + } + public Text getText() { + return m_text; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + } + }"""); shell.refresh(); CompositeInfo myComposite = (CompositeInfo) shell.getChildrenControls().get(0); ControlInfo button = myComposite.getChildrenControls().get(0); // do operations { button.delete(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " MyComposite myComposite = new MyComposite(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + MyComposite myComposite = new MyComposite(this, SWT.NONE); + } + }"""); } } @@ -190,21 +184,19 @@ public void test_deleteWhenTwoExposed() throws Exception { * Configures project for delete tests. */ private void configureForDelete() throws Exception { - setFileContentSrc( - "test/MyComposite.java", - getTestSource( - "public class MyComposite extends Composite {", - " private Button m_button;", - " public MyComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " m_button = new Button(this, SWT.NONE);", - " m_button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + setFileContentSrc("test/MyComposite.java", getTestSource(""" + public class MyComposite extends Composite { + private Button m_button; + public MyComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + m_button = new Button(this, SWT.NONE); + m_button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); } } \ No newline at end of file diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutGefTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutGefTest.java index 412e73d6d..9db3edc92 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutGefTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutGefTest.java @@ -74,24 +74,24 @@ public void _test_exit() throws Exception { */ @Test public void test_deleteChildAndAncestorResize() throws Exception { - openPanel( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new GridLayout());", - " {", - " Label label = new Label(composite, SWT.NONE);", - " label.setText('Label');", - " }", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setText('Button');", - " }", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new GridLayout()); + { + Label label = new Label(composite, SWT.NONE); + label.setText("Label"); + } + { + Button button = new Button(composite, SWT.NONE); + button.setText("Button"); + } + } + } + }"""); assertJavaInfo("composite"); assertJavaInfo("label"); @@ -106,20 +106,20 @@ public void test_deleteChildAndAncestorResize() throws Exception { IAction deleteAction = getDeleteAction(); assertTrue(deleteAction.isEnabled()); deleteAction.run(); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new GridLayout());", - " {", - " Label label = new Label(composite, SWT.NONE);", - " label.setText('Label');", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new GridLayout()); + { + Label label = new Label(composite, SWT.NONE); + label.setText("Label"); + } + } + } + }"""); } } @@ -130,20 +130,20 @@ public void test_deleteChildAndAncestorResize() throws Exception { @Test public void test_replaceGridLayout_withAbsolute() throws Exception { prepareComponent(); - openPanel( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button_2 = new Button(this, SWT.NONE); + } + } + }"""); // select "shell", so show headers canvas.select(composite); waitEventLoop(20); @@ -156,20 +156,20 @@ public void test_replaceGridLayout_withAbsolute() throws Exception { waitEventLoop(20); } // validate - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(null);", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setBounds(5, 5, 100, 50);", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setBounds(110, 60, 100, 50);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(null); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setBounds(5, 5, 100, 50); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setBounds(110, 60, 100, 50); + } + } + }"""); } /** @@ -178,14 +178,14 @@ public void test_replaceGridLayout_withAbsolute() throws Exception { */ @Test public void test_change_numColumns() throws Exception { - openPanel( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " Button button_00 = new Button(this, SWT.NONE);", - " Button button_01 = new Button(this, SWT.NONE);", - " }", - "}"); + openPanel(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + Button button_00 = new Button(this, SWT.NONE); + Button button_01 = new Button(this, SWT.NONE); + } + }"""); // select "shell", so show headers canvas.select(composite); // initially: 1 column, 2 rows @@ -197,14 +197,14 @@ public void test_change_numColumns() throws Exception { assertNoLoggedExceptions(); assertEquals(2, layout.getColumns().size()); assertEquals(1, layout.getRows().size()); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " Button button_00 = new Button(this, SWT.NONE);", - " Button button_01 = new Button(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + Button button_00 = new Button(this, SWT.NONE); + Button button_01 = new Button(this, SWT.NONE); + } + }"""); } /** @@ -213,15 +213,15 @@ public void test_change_numColumns() throws Exception { */ @Test public void test_markAsExcluded() throws Exception { - openPanel( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); ControlInfo button = getJavaInfoByName("button"); GraphicalEditPart buttonPart = canvas.getEditPart(button); // select "button", so show grid selection @@ -232,20 +232,20 @@ public void test_markAsExcluded() throws Exception { assertNoLoggedExceptions(); assertInstanceOf(NonResizableSelectionEditPolicy.class, buttonPart.getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE)); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gd_button = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);", - " gd_button.exclude = true;", - " button.setLayoutData(gd_button);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gd_button = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_button.exclude = true; + button.setLayoutData(gd_button); + } + } + } + }"""); } /** @@ -253,15 +253,15 @@ public void test_markAsExcluded() throws Exception { */ @Test public void test_indirectlyExposed() throws Exception { - openPanel( - "import org.eclipse.ui.dialogs.FilteredTree;", - "import org.eclipse.ui.dialogs.PatternFilter;", - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " FilteredTree filteredTree = new FilteredTree(this, SWT.NONE, new PatternFilter());", - " }", - "}"); + openPanel(""" + import org.eclipse.ui.dialogs.FilteredTree; + import org.eclipse.ui.dialogs.PatternFilter; + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + FilteredTree filteredTree = new FilteredTree(this, SWT.NONE, new PatternFilter()); + } + }"""); CompositeInfo filteredTree = getJavaInfoByName("filteredTree"); ControlInfo filterControl = filteredTree.getChildrenControls().get(0); // select "filterControl" has simple selection policy @@ -275,20 +275,20 @@ public void test_indirectlyExposed() throws Exception { */ @Test public void test_moveOut() throws Exception { - openPanel( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Group group = new Group(this, SWT.NONE);", - " group.setLayout(new FillLayout());", - " group.setText('My Group');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Group group = new Group(this, SWT.NONE); + group.setLayout(new FillLayout()); + group.setText("My Group"); + } + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); CompositeInfo group = getJavaInfoByName("group"); ControlInfo button = getJavaInfoByName("button"); // select "button", check for "grid" selection @@ -300,20 +300,20 @@ public void test_moveOut() throws Exception { } // drag "button" to "group" canvas.beginDrag(button).dragTo(group, 0.5, 0.5).endDrag(); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Group group = new Group(this, SWT.NONE);", - " group.setLayout(new FillLayout());", - " group.setText('My Group');", - " {", - " Button button = new Button(group, SWT.NONE);", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(1, false)); + { + Group group = new Group(this, SWT.NONE); + group.setLayout(new FillLayout()); + group.setText("My Group"); + { + Button button = new Button(group, SWT.NONE); + } + } + } + }"""); // no "grid" selection { GraphicalEditPart buttonPart = canvas.getEditPart(button); @@ -329,69 +329,69 @@ public void test_moveOut() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_setSizeHint_width() throws Exception { - openPanel( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + openPanel(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); ControlInfo button = getJavaInfoByName("button"); // resize EAST of "button" canvas.toResizeHandle(button, "resize_size", PositionConstants.EAST).beginDrag(); canvas.target(button).in(200, 0).drag().endDrag(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gd_button = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);", - " gd_button.widthHint = 200;", - " button.setLayoutData(gd_button);", - " }", - " button.setText('New Button');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gd_button = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_button.widthHint = 200; + button.setLayoutData(gd_button); + } + button.setText("New Button"); + } + } + }"""); } @Test public void test_setSizeHint_height() throws Exception { - openPanel( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + openPanel(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); ControlInfo button = getJavaInfoByName("button"); // resize SOUTH of "button" canvas.toResizeHandle(button, "resize_size", PositionConstants.SOUTH).beginDrag(); canvas.target(button).in(0, 50).drag(); canvas.endDrag(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gd_button = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);", - " gd_button.heightHint = 50;", - " button.setLayoutData(gd_button);", - " }", - " button.setText('New Button');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gd_button = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_button.heightHint = 50; + button.setLayoutData(gd_button); + } + button.setText("New Button"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -401,16 +401,16 @@ public void test_setSizeHint_height() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_setAlignment_usingKeyboard() throws Exception { - openPanel( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + openPanel(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); ControlInfo button = getJavaInfoByName("button"); canvas.select(button); // horizontal @@ -464,28 +464,28 @@ public void test_setAlignment_usingKeyboard() throws Exception { private void assert_setAlignment(String alignmentString) { if (alignmentString != null) { - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(" + alignmentString + ", 1, 1));", - " button.setText('New Button');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(%s, 1, 1)); + button.setText("New Button"); + } + } + }""".formatted(alignmentString)); } else { - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); } } @@ -496,17 +496,17 @@ private void assert_setAlignment(String alignmentString) { //////////////////////////////////////////////////////////////////////////// @Test public void test_CREATE_filled() throws Exception { - openPanel( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button existingButton = new Button(this, SWT.NONE);", - " existingButton.setText('Existing Button');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button existingButton = new Button(this, SWT.NONE); + existingButton.setText("Existing Button"); + } + } + }"""); // loadButtonWithText(); canvas.moveTo(composite, M, M); @@ -515,30 +515,28 @@ public void test_CREATE_filled() throws Exception { @Test public void test_CREATE_filledByInherited() throws Exception { - setFileContentSrc( - "test/MyShell.java", - getTestSource2( - "public class MyShell extends Shell {", - " public MyShell() {", - " super(SWT.NONE);", - " setLayout(new GridLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('Implicit Button');", - " }", - " }", - " protected void checkSubclass() {", - " }", - "}")); + setFileContentSrc("test/MyShell.java", getTestSource2(""" + public class MyShell extends Shell { + public MyShell() { + super(SWT.NONE); + setLayout(new GridLayout()); + { + Button button = new Button(this, SWT.NONE); + button.setText("Implicit Button"); + } + } + protected void checkSubclass() { + } + }""")); waitForAutoBuild(); // parse - openPanel( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " }", - "}"); + openPanel(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + } + }"""); // loadButtonWithText(); { @@ -552,281 +550,281 @@ public void test_CREATE_filledByInherited() throws Exception { @Test public void test_CREATE_virtual_0x0() throws Exception { - openPanel( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " }", - "}"); + openPanel(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + } + }"""); // loadButtonWithText(); canvas.moveTo(composite, M, M); canvas.click(); - assertEditor( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); } @Test public void test_CREATE_virtual_0x1() throws Exception { - openPanel( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " }", - "}"); + openPanel(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + } + }"""); // loadButtonWithText(); canvas.moveTo(composite, M + VS + VG, M); canvas.click(); - assertEditor( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(2, false));", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(2, false)); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); } @Test public void test_CREATE_appendToColumn_1x0() throws Exception { - openPanel( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button existingButton = new Button(this, SWT.NONE);", - " existingButton.setText('Existing Button');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button existingButton = new Button(this, SWT.NONE); + existingButton.setText("Existing Button"); + } + } + }"""); JavaInfo existingButton = getJavaInfoByName("existingButton"); // loadButtonWithText(); canvas.target(existingButton).inX(0.5).outY(S + 1).move(); canvas.click(); - assertEditor( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button existingButton = new Button(this, SWT.NONE);", - " existingButton.setText('Existing Button');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button existingButton = new Button(this, SWT.NONE); + existingButton.setText("Existing Button"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); } @Test public void test_CREATE_appendToRow_0x1() throws Exception { - openPanel( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button existingButton = new Button(this, SWT.NONE);", - " existingButton.setText('Existing Button');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button existingButton = new Button(this, SWT.NONE); + existingButton.setText("Existing Button"); + } + } + }"""); JavaInfo existingButton = getJavaInfoByName("existingButton"); // loadButtonWithText(); canvas.target(existingButton).inY(0.5).outX(S + 1).move(); canvas.click(); - assertEditor( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(2, false));", - " {", - " Button existingButton = new Button(this, SWT.NONE);", - " existingButton.setText('Existing Button');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(2, false)); + { + Button existingButton = new Button(this, SWT.NONE); + existingButton.setText("Existing Button"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + } + }"""); } @Test public void test_CREATE_beforeFirstRow() throws Exception { - openPanel( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button existingButton = new Button(this, SWT.NONE);", - " existingButton.setText('Existing Button');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button existingButton = new Button(this, SWT.NONE); + existingButton.setText("Existing Button"); + } + } + }"""); JavaInfo existingButton = getJavaInfoByName("existingButton"); // loadButtonWithText(); canvas.target(existingButton).inX(0.5).outY(-2).move(); canvas.click(); - assertEditor( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " {", - " Button existingButton = new Button(this, SWT.NONE);", - " existingButton.setText('Existing Button');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + { + Button existingButton = new Button(this, SWT.NONE); + existingButton.setText("Existing Button"); + } + } + }"""); } @Test public void test_CREATE_beforeFirstColumn() throws Exception { - openPanel( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button existingButton = new Button(this, SWT.NONE);", - " existingButton.setText('Existing Button');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button existingButton = new Button(this, SWT.NONE); + existingButton.setText("Existing Button"); + } + } + }"""); JavaInfo existingButton = getJavaInfoByName("existingButton"); // loadButtonWithText(); canvas.target(existingButton).inY(0.5).outX(-2).move(); canvas.click(); - assertEditor( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " {", - " Button existingButton = new Button(this, SWT.NONE);", - " existingButton.setText('Existing Button');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + { + Button existingButton = new Button(this, SWT.NONE); + existingButton.setText("Existing Button"); + } + } + }"""); } @Test public void test_CREATE_insertColumn() throws Exception { - openPanel( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button 1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button 2');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button 1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button 2"); + } + } + }"""); JavaInfo button_1 = getJavaInfoByName("button_1"); // loadButtonWithText(); canvas.target(button_1).inY(0.5).outX(S / 2).move(); canvas.click(); - assertEditor( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(3, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button 1');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button 2');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(3, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button 1"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button 2"); + } + } + }"""); } @Test public void test_CREATE_insertRow() throws Exception { - openPanel( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button 1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button 2');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button 1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button 2"); + } + } + }"""); JavaInfo button_1 = getJavaInfoByName("button_1"); // loadButtonWithText(); canvas.target(button_1).inX(0.5).outY(S / 2).move(); canvas.click(); - assertEditor( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button 1');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button 2');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button 1"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button 2"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -839,42 +837,40 @@ public void test_CREATE_insertRow() throws Exception { */ @Test public void test_CREATE_inherited_columnOperations() throws Exception { - setFileContentSrc( - "test/MyShell.java", - getTestSource2( - "public class MyShell extends Shell {", - " public MyShell() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Implicit #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Implicit #2');", - " }", - " }", - " protected void checkSubclass() {", - " }", - "}")); + setFileContentSrc("test/MyShell.java", getTestSource2(""" + public class MyShell extends Shell { + public MyShell() { + super(SWT.NONE); + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Implicit #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Implicit #2"); + } + } + protected void checkSubclass() { + } + }""")); waitForAutoBuild(); // parse - openPanel( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Explicit #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Explicit #2');", - " }", - " }", - "}"); + openPanel(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Explicit #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Explicit #2"); + } + } + }"""); loadButton(); // can not insert column { @@ -896,34 +892,32 @@ public void test_CREATE_inherited_columnOperations() throws Exception { */ @Test public void test_CREATE_inheritedEmpty_columnOperations() throws Exception { - setFileContentSrc( - "test/MyShell.java", - getTestSource2( - "public class MyShell extends Shell {", - " public MyShell() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(2, false));", - " }", - " protected void checkSubclass() {", - " }", - "}")); + setFileContentSrc("test/MyShell.java", getTestSource2(""" + public class MyShell extends Shell { + public MyShell() { + super(SWT.NONE); + setLayout(new GridLayout(2, false)); + } + protected void checkSubclass() { + } + }""")); waitForAutoBuild(); // parse - openPanel( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Explicit #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Explicit #2');", - " }", - " }", - "}"); + openPanel(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Explicit #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Explicit #2"); + } + } + }"""); loadButton(); // can insert column { @@ -944,42 +938,40 @@ public void test_CREATE_inheritedEmpty_columnOperations() throws Exception { */ @Test public void test_CREATE_inherited_rowOperations() throws Exception { - setFileContentSrc( - "test/MyShell.java", - getTestSource2( - "public class MyShell extends Shell {", - " public MyShell() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Implicit #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Implicit #2');", - " }", - " }", - " protected void checkSubclass() {", - " }", - "}")); + setFileContentSrc("test/MyShell.java", getTestSource2(""" + public class MyShell extends Shell { + public MyShell() { + super(SWT.NONE); + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Implicit #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Implicit #2"); + } + } + protected void checkSubclass() { + } + }""")); waitForAutoBuild(); // parse - openPanel( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Explicit #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Explicit #2');", - " }", - " }", - "}"); + openPanel(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Explicit #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Explicit #2"); + } + } + }"""); loadButton(); // can not insert before "implicit" row { @@ -1007,37 +999,37 @@ public void test_CREATE_inherited_rowOperations() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_PASTE_virtual_1x0() throws Exception { - openPanel( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button existingButton = new Button(this, SWT.NONE);", - " existingButton.setText('My Button');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button existingButton = new Button(this, SWT.NONE); + existingButton.setText("My Button"); + } + } + }"""); JavaInfo existingButton = getJavaInfoByName("existingButton"); // doCopyPaste(existingButton); canvas.target(existingButton).inX(0.5).outY(S + 1).move(); canvas.click(); - assertEditor( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button existingButton = new Button(this, SWT.NONE);", - " existingButton.setText('My Button');", - " }", - " {", - " Button existingButton = new Button(this, SWT.NONE);", - " existingButton.setText('My Button');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button existingButton = new Button(this, SWT.NONE); + existingButton.setText("My Button"); + } + { + Button existingButton = new Button(this, SWT.NONE); + existingButton.setText("My Button"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1047,74 +1039,74 @@ public void test_PASTE_virtual_1x0() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_MOVE_virtual_1x0() throws Exception { - openPanel( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('Existing Button');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("Existing Button"); + } + } + }"""); JavaInfo button = getJavaInfoByName("button"); // canvas.beginDrag(button); canvas.target(button).inX(0.5).outY(S + 1).drag(); canvas.endDrag(); - assertEditor( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout(1, false));", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('Existing Button');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout(1, false)); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("Existing Button"); + } + } + }"""); } @Test public void test_ADD_virtual_0x0() throws Exception { - openPanel( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new FillLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('Existing Button');", - " }", - " {", - " Composite target = new Composite(this, SWT.NONE);", - " target.setLayout(new GridLayout(1, false));", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new FillLayout()); + { + Button button = new Button(this, SWT.NONE); + button.setText("Existing Button"); + } + { + Composite target = new Composite(this, SWT.NONE); + target.setLayout(new GridLayout(1, false)); + } + } + }"""); JavaInfo button = getJavaInfoByName("button"); JavaInfo target = getJavaInfoByName("target"); // canvas.beginDrag(button); canvas.dragTo(target, M + VS / 2, M + VS / 2); canvas.endDrag(); - assertEditor( - "public class Test extends Composite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new FillLayout());", - " {", - " Composite target = new Composite(this, SWT.NONE);", - " target.setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(target, SWT.NONE);", - " button.setText('Existing Button');", - " }", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Composite { + public Test(Composite parent, int style) { + super(parent, style); + setLayout(new FillLayout()); + { + Composite target = new Composite(this, SWT.NONE); + target.setLayout(new GridLayout(1, false)); + { + Button button = new Button(target, SWT.NONE); + button.setText("Existing Button"); + } + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1127,34 +1119,32 @@ public void test_ADD_virtual_0x0() throws Exception { */ @Test public void test_headerColumn_MOVE_inherited() throws Exception { - setFileContentSrc( - "test/MyShell.java", - getTestSource2( - "public class MyShell extends Shell {", - " public MyShell() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Implicit #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Implicit #2');", - " }", - " }", - " protected void checkSubclass() {", - " }", - "}")); + setFileContentSrc("test/MyShell.java", getTestSource2(""" + public class MyShell extends Shell { + public MyShell() { + super(SWT.NONE); + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Implicit #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Implicit #2"); + } + } + protected void checkSubclass() { + } + }""")); waitForAutoBuild(); // parse - openPanel( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " }", - "}"); + openPanel(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + } + }"""); // select "composite" to show headers canvas.select(composite); // animate headers @@ -1169,21 +1159,21 @@ public void test_headerColumn_MOVE_inherited() throws Exception { @Test public void test_headerColumn_MOVE_beforeFirst() throws Exception { - openPanel( - "public class Test extends Shell {", - " public Test() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Implicit #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Implicit #2');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Shell { + public Test() { + super(SWT.NONE); + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Implicit #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Implicit #2"); + } + } + }"""); // select "composite" to show headers canvas.select(composite); // animate headers @@ -1195,44 +1185,44 @@ public void test_headerColumn_MOVE_beforeFirst() throws Exception { horizontalRobot.assertCommandNotNull(); horizontalRobot.endDrag(); } - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Implicit #2');", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Implicit #1');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + super(SWT.NONE); + setLayout(new GridLayout(2, false)); + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Implicit #2"); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Implicit #1"); + } + } + }"""); } @Test public void test_headerColumn_MOVE_afterLast() throws Exception { - openPanel( - "public class Test extends Shell {", - " public Test() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(3, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button #2');", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " button_3.setText('Button #3');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Shell { + public Test() { + super(SWT.NONE); + setLayout(new GridLayout(3, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button #2"); + } + { + Button button_3 = new Button(this, SWT.NONE); + button_3.setText("Button #3"); + } + } + }"""); // select "composite" to show headers canvas.select(composite); // animate headers @@ -1244,48 +1234,48 @@ public void test_headerColumn_MOVE_afterLast() throws Exception { horizontalRobot.assertCommandNotNull(); horizontalRobot.endDrag(); } - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(3, false));", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button #2');", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " button_3.setText('Button #3');", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button #1');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + super(SWT.NONE); + setLayout(new GridLayout(3, false)); + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button #2"); + } + { + Button button_3 = new Button(this, SWT.NONE); + button_3.setText("Button #3"); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button #1"); + } + } + }"""); } @Test public void test_headerColumn_MOVE_beforeOther() throws Exception { - openPanel( - "public class Test extends Shell {", - " public Test() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(3, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button #2');", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " button_3.setText('Button #3');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Shell { + public Test() { + super(SWT.NONE); + setLayout(new GridLayout(3, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button #2"); + } + { + Button button_3 = new Button(this, SWT.NONE); + button_3.setText("Button #3"); + } + } + }"""); // select "composite" to show headers canvas.select(composite); // animate headers @@ -1297,48 +1287,48 @@ public void test_headerColumn_MOVE_beforeOther() throws Exception { horizontalRobot.assertCommandNotNull(); horizontalRobot.endDrag(); } - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(3, false));", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button #2');", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button #1');", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " button_3.setText('Button #3');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + super(SWT.NONE); + setLayout(new GridLayout(3, false)); + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button #2"); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button #1"); + } + { + Button button_3 = new Button(this, SWT.NONE); + button_3.setText("Button #3"); + } + } + }"""); } @Test public void test_headerColumn_MOVE_beforeOther_RTL() throws Exception { - openPanel( - "public class Test extends Shell {", - " public Test() {", - " super(SWT.RIGHT_TO_LEFT);", - " setLayout(new GridLayout(3, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button #2');", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " button_3.setText('Button #3');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Shell { + public Test() { + super(SWT.RIGHT_TO_LEFT); + setLayout(new GridLayout(3, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button #2"); + } + { + Button button_3 = new Button(this, SWT.NONE); + button_3.setText("Button #3"); + } + } + }"""); // select "composite" to show headers canvas.select(composite); // animate headers @@ -1350,25 +1340,25 @@ public void test_headerColumn_MOVE_beforeOther_RTL() throws Exception { horizontalRobot.assertCommandNotNull(); horizontalRobot.endDrag(); } - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " super(SWT.RIGHT_TO_LEFT);", - " setLayout(new GridLayout(3, false));", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button #2');", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button #1');", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " button_3.setText('Button #3');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + super(SWT.RIGHT_TO_LEFT); + setLayout(new GridLayout(3, false)); + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button #2"); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button #1"); + } + { + Button button_3 = new Button(this, SWT.NONE); + button_3.setText("Button #3"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1381,34 +1371,32 @@ public void test_headerColumn_MOVE_beforeOther_RTL() throws Exception { */ @Test public void test_headerRow_MOVE_inherited_moveImplicitRow() throws Exception { - setFileContentSrc( - "test/MyShell.java", - getTestSource2( - "public class MyShell extends Shell {", - " public MyShell() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(1, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Implicit #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Implicit #2');", - " }", - " }", - " protected void checkSubclass() {", - " }", - "}")); + setFileContentSrc("test/MyShell.java", getTestSource2(""" + public class MyShell extends Shell { + public MyShell() { + super(SWT.NONE); + setLayout(new GridLayout(1, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Implicit #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Implicit #2"); + } + } + protected void checkSubclass() { + } + }""")); waitForAutoBuild(); // parse - openPanel( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " }", - "}"); + openPanel(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + } + }"""); // select "composite" to show headers canvas.select(composite); // animate headers @@ -1426,38 +1414,36 @@ public void test_headerRow_MOVE_inherited_moveImplicitRow() throws Exception { */ @Test public void test_headerRow_MOVE_inherited_moveBeforeImplicitRow() throws Exception { - setFileContentSrc( - "test/MyShell.java", - getTestSource2( - "public class MyShell extends Shell {", - " public MyShell() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(1, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Implicit #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Implicit #2');", - " }", - " }", - " protected void checkSubclass() {", - " }", - "}")); + setFileContentSrc("test/MyShell.java", getTestSource2(""" + public class MyShell extends Shell { + public MyShell() { + super(SWT.NONE); + setLayout(new GridLayout(1, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Implicit #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Implicit #2"); + } + } + protected void checkSubclass() { + } + }""")); waitForAutoBuild(); // parse - openPanel( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('Explicit Button');", - " }", - " }", - "}"); + openPanel(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + { + Button button = new Button(this, SWT.NONE); + button.setText("Explicit Button"); + } + } + }"""); // select "composite" to show headers canvas.select(composite); // animate headers @@ -1472,25 +1458,25 @@ public void test_headerRow_MOVE_inherited_moveBeforeImplicitRow() throws Excepti @Test public void test_headerRow_MOVE_beforeOther() throws Exception { - openPanel( - "public class Test extends Shell {", - " public Test() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(1, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button #2');", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " button_3.setText('Button #3');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Shell { + public Test() { + super(SWT.NONE); + setLayout(new GridLayout(1, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button #2"); + } + { + Button button_3 = new Button(this, SWT.NONE); + button_3.setText("Button #3"); + } + } + }"""); // select "composite" to show headers canvas.select(composite); // animate headers @@ -1502,48 +1488,48 @@ public void test_headerRow_MOVE_beforeOther() throws Exception { verticalRobot.assertCommandNotNull(); verticalRobot.endDrag(); } - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(1, false));", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " button_3.setText('Button #3');", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button #2');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + super(SWT.NONE); + setLayout(new GridLayout(1, false)); + { + Button button_3 = new Button(this, SWT.NONE); + button_3.setText("Button #3"); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button #2"); + } + } + }"""); } @Test public void test_headerRow_MOVE_afterLast() throws Exception { - openPanel( - "public class Test extends Shell {", - " public Test() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(1, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button #1');", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button #2');", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " button_3.setText('Button #3');", - " }", - " }", - "}"); + openPanel(""" + public class Test extends Shell { + public Test() { + super(SWT.NONE); + setLayout(new GridLayout(1, false)); + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button #1"); + } + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button #2"); + } + { + Button button_3 = new Button(this, SWT.NONE); + button_3.setText("Button #3"); + } + } + }"""); // select "composite" to show headers canvas.select(composite); // animate headers @@ -1555,25 +1541,25 @@ public void test_headerRow_MOVE_afterLast() throws Exception { verticalRobot.assertCommandNotNull(); verticalRobot.endDrag(); } - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " super(SWT.NONE);", - " setLayout(new GridLayout(1, false));", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " button_2.setText('Button #2');", - " }", - " {", - " Button button_3 = new Button(this, SWT.NONE);", - " button_3.setText('Button #3');", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('Button #1');", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + super(SWT.NONE); + setLayout(new GridLayout(1, false)); + { + Button button_2 = new Button(this, SWT.NONE); + button_2.setText("Button #2"); + } + { + Button button_3 = new Button(this, SWT.NONE); + button_3.setText("Button #3"); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("Button #1"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutParametersTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutParametersTest.java index 5c3904f37..4d6242792 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutParametersTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutParametersTest.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 @@ -53,28 +53,27 @@ public void _test_exit() throws Exception { */ @Test public void test_CREATE_Text() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newText = BTestUtils.createControl("org.eclipse.swt.widgets.Text"); layout.command_CREATE(newText, 0, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Text text = new Text(this, SWT.BORDER);", - " text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Text text = new Text(this, SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + } + } + }"""); } /** @@ -82,13 +81,12 @@ public void test_CREATE_Text() throws Exception { */ @Test public void test_CREATE_Text_disabled() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -98,15 +96,15 @@ public void test_CREATE_Text_disabled() throws Exception { preferences.setValue(IPreferenceConstants.P_ENABLE_GRAB, false); ControlInfo newText = BTestUtils.createControl("org.eclipse.swt.widgets.Text"); layout.command_CREATE(newText, 0, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Text text = new Text(this, SWT.BORDER);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Text text = new Text(this, SWT.BORDER); + } + } + }"""); } finally { preferences.restore(); } @@ -117,30 +115,29 @@ public void test_CREATE_Text_disabled() throws Exception { */ @Test public void test_CREATE_Table() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newTable = BTestUtils.createControl("org.eclipse.swt.widgets.Table"); layout.command_CREATE(newTable, 0, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Table table = new Table(this, SWT.BORDER | SWT.FULL_SELECTION);", - " table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));", - " table.setHeaderVisible(true);", - " table.setLinesVisible(true);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Table table = new Table(this, SWT.BORDER | SWT.FULL_SELECTION); + table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); + table.setHeaderVisible(true); + table.setLinesVisible(true); + } + } + }"""); } /** @@ -149,36 +146,35 @@ public void test_CREATE_Table() throws Exception { */ @Test public void test_CREATE_LabelBeforeText() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " new Label(this, SWT.NONE);", - " {", - " Text text = new Text(this, SWT.BORDER);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + new Label(this, SWT.NONE); + { + Text text = new Text(this, SWT.BORDER); + } + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newLabel = BTestUtils.createControl("org.eclipse.swt.widgets.Label"); layout.command_CREATE(newLabel, 0, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Label label = new Label(this, SWT.NONE);", - " label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));", - " label.setText('New Label');", - " }", - " {", - " Text text = new Text(this, SWT.BORDER);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Label label = new Label(this, SWT.NONE); + label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + label.setText("New Label"); + } + { + Text text = new Text(this, SWT.BORDER); + } + } + }"""); } /** @@ -186,17 +182,16 @@ public void test_CREATE_LabelBeforeText() throws Exception { */ @Test public void test_CREATE_LabelBeforeText_disabled() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " new Label(this, SWT.NONE);", - " {", - " Text text = new Text(this, SWT.BORDER);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + new Label(this, SWT.NONE); + { + Text text = new Text(this, SWT.BORDER); + } + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -206,19 +201,19 @@ public void test_CREATE_LabelBeforeText_disabled() throws Exception { preferences.setValue(IPreferenceConstants.P_ENABLE_RIGHT_ALIGNMENT, false); ControlInfo newLabel = BTestUtils.createControl("org.eclipse.swt.widgets.Label"); layout.command_CREATE(newLabel, 0, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Label label = new Label(this, SWT.NONE);", - " label.setText('New Label');", - " }", - " {", - " Text text = new Text(this, SWT.BORDER);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Label label = new Label(this, SWT.NONE); + label.setText("New Label"); + } + { + Text text = new Text(this, SWT.BORDER); + } + } + }"""); } finally { preferences.restore(); } @@ -230,36 +225,35 @@ public void test_CREATE_LabelBeforeText_disabled() throws Exception { */ @Test public void test_CREATE_Text_afterLabel() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Label label = new Label(this, SWT.NONE);", - " }", - " new Label(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Label label = new Label(this, SWT.NONE); + } + new Label(this, SWT.NONE); + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newText = createJavaInfo("org.eclipse.swt.widgets.Text"); layout.command_CREATE(newText, 1, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Label label = new Label(this, SWT.NONE);", - " label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));", - " }", - " {", - " Text text = new Text(this, SWT.BORDER);", - " text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Label label = new Label(this, SWT.NONE); + label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + } + { + Text text = new Text(this, SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + } + } + }"""); } /** @@ -267,30 +261,29 @@ public void test_CREATE_Text_afterLabel() throws Exception { */ @Test public void test_CREATE_Text_afterFiller() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newText = createJavaInfo("org.eclipse.swt.widgets.Text"); layout.command_CREATE(newText, 1, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " new Label(this, SWT.NONE);", - " {", - " Text text = new Text(this, SWT.BORDER);", - " text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + new Label(this, SWT.NONE); + { + Text text = new Text(this, SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + } + } + }"""); } } \ No newline at end of file diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutSelectionActionsTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutSelectionActionsTest.java index ab0a52d15..396c4fa09 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutSelectionActionsTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutSelectionActionsTest.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 @@ -47,13 +47,12 @@ public void _test_exit() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_emptySelection() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout()); + } + }"""); shell.refresh(); // prepare actions List actions = getSelectionActions(); @@ -63,25 +62,24 @@ public void test_emptySelection() throws Exception { @Test public void test_selectionActions() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Label label = new Label(this, SWT.NONE);", - " label.setText('Label:');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.grabExcessHorizontalSpace = true;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Label label = new Label(this, SWT.NONE); + label.setText("Label:"); + } + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.grabExcessHorizontalSpace = true; + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); List actions; ControlInfo label = shell.getChildrenControls().get(0); @@ -112,25 +110,24 @@ public void test_selectionActions() throws Exception { @Test public void test_grabAction() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Label label = new Label(this, SWT.NONE);", - " label.setText('Label:');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.grabExcessHorizontalSpace = true;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Label label = new Label(this, SWT.NONE); + label.setText("Label:"); + } + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.grabExcessHorizontalSpace = true; + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(1); // prepare actions: button @@ -144,46 +141,45 @@ public void test_grabAction() throws Exception { horizontalGrab.setChecked(false); horizontalGrab.run(); // - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Label label = new Label(this, SWT.NONE);", - " label.setText('Label:');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.grabExcessVerticalSpace = true;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Label label = new Label(this, SWT.NONE); + label.setText("Label:"); + } + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.grabExcessVerticalSpace = true; + button.setLayoutData(gridData); + } + } + } + }"""); } @Test public void test_alignmentAction() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Label label = new Label(this, SWT.NONE);", - " label.setText('Label:');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Label label = new Label(this, SWT.NONE); + label.setText("Label:"); + } + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false); + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); List actions; ControlInfo button = shell.getChildrenControls().get(1); @@ -198,20 +194,20 @@ public void test_alignmentAction() throws Exception { bottomAction.setChecked(true); bottomAction.run(); // - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Label label = new Label(this, SWT.NONE);", - " label.setText('Label:');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false));", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Label label = new Label(this, SWT.NONE); + label.setText("Label:"); + } + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false)); + } + } + }"""); // prepare actions: wrong selection { actions = getSelectionActions(shell, button); @@ -224,40 +220,37 @@ public void test_alignmentAction() throws Exception { */ @Test public void test_indirectExposedChild() throws Exception { - setFileContentSrc( - "test/ImplicitComposite.java", - getTestSource( - "public class ImplicitComposite extends Composite {", - " private Button m_button;", - " public ImplicitComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " {", - " Composite container = new Composite(this, SWT.NONE);", - " container.setLayout(new RowLayout());", - " {", - " m_button = new Button(container, SWT.NONE);", - " m_button.setLayoutData(new RowData());", - " }", - " }", - " }", - " public Button getButton() {", - " return m_button;", - " }", - "}")); + setFileContentSrc("test/ImplicitComposite.java", getTestSource(""" + public class ImplicitComposite extends Composite { + private Button m_button; + public ImplicitComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + { + Composite container = new Composite(this, SWT.NONE); + container.setLayout(new RowLayout()); + { + m_button = new Button(container, SWT.NONE); + m_button.setLayoutData(new RowData()); + } + } + } + public Button getButton() { + return m_button; + } + }""")); waitForAutoBuild(); // parse - CompositeInfo composite = - parseComposite( - "public class Test extends ImplicitComposite {", - " public Test(Composite parent, int style) {", - " super(parent, style);", - " }", - "}"); - assertHierarchy( - "{this: test.ImplicitComposite} {this} {}", - " {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {}", - " {method: public org.eclipse.swt.widgets.Button test.ImplicitComposite.getButton()} {property} {}"); + CompositeInfo composite = parseComposite(""" + public class Test extends ImplicitComposite { + public Test(Composite parent, int style) { + super(parent, style); + } + }"""); + assertHierarchy(""" + {this: test.ImplicitComposite} {this} {} + {implicit-layout: org.eclipse.swt.layout.GridLayout} {implicit-layout} {} + {method: public org.eclipse.swt.widgets.Button test.ImplicitComposite.getButton()} {property} {}"""); composite.refresh(); ControlInfo button = composite.getChildrenControls().get(0); // prepare actions: button diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutTest.java index cbe19246e..1e1aa8d21 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/layouts/grid/GridLayoutTest.java @@ -72,13 +72,12 @@ public void _test_exit() throws Exception { */ @Test public void test_parseEmpty() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + } + }"""); shell.refresh(); } @@ -89,17 +88,17 @@ public void test_parseEmpty() throws Exception { */ @Test public void test_doubleConvertTo_GridData2() throws Exception { - parseComposite( - "class Test extends Composite {", - " Test(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " new Button(this, SWT.NONE);", - " }", - " public Point computeSize(int wHint, int hHint, boolean changed) {", - " return super.computeSize(600, 490, false);", - " }", - "}"); + parseComposite(""" + class Test extends Composite { + Test(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + new Button(this, SWT.NONE); + } + public Point computeSize(int wHint, int hHint, boolean changed) { + return super.computeSize(600, 490, false); + } + }"""); refresh(); assertNoErrors(m_lastParseInfo); } @@ -109,17 +108,16 @@ public void test_doubleConvertTo_GridData2() throws Exception { */ @Test public void test_excludeFillersFromPresentationChildren_1() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + } + new Label(this, SWT.NONE); + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); ControlInfo filler = shell.getChildrenControls().get(1); @@ -140,33 +138,30 @@ public void test_excludeFillersFromPresentationChildren_1() throws Exception { */ @Test public void test_excludeFillersFromPresentationChildren_2() throws Exception { - setFileContentSrc( - "test/MyFactory.java", - getTestSource( - "public class MyFactory {", - " public Label createLabel(Composite parent) {", - " return new Label(parent, SWT.NONE);", - " }", - "}")); + setFileContentSrc("test/MyFactory.java", getTestSource(""" + public class MyFactory { + public Label createLabel(Composite parent) { + return new Label(parent, SWT.NONE); + } + }""")); waitForAutoBuild(); // parse - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " private final MyFactory factory = new MyFactory();", - " Test() {", - " setLayout(new GridLayout());", - " factory.createLabel(this);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + private final MyFactory factory = new MyFactory(); + Test() { + setLayout(new GridLayout()); + factory.createLabel(this); + } + }"""); shell.refresh(); - assertHierarchy( - "{this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new GridLayout())/ /factory.createLabel(this)/}", - " {new: org.eclipse.swt.layout.GridLayout} {empty} {/setLayout(new GridLayout())/}", - " {instance factory: {field-initializer: factory} createLabel(org.eclipse.swt.widgets.Composite)} {empty} {/factory.createLabel(this)/}", - " {virtual-layout_data: org.eclipse.swt.layout.GridData} {virtual-layout-data} {}", - " {instance factory container}", - " {new: test.MyFactory} {field-initializer: factory} {/new MyFactory()/ /factory.createLabel(this)/}"); + assertHierarchy(""" + {this: org.eclipse.swt.widgets.Shell} {this} {/setLayout(new GridLayout())/ /factory.createLabel(this)/} + {new: org.eclipse.swt.layout.GridLayout} {empty} {/setLayout(new GridLayout())/} + {instance factory: {field-initializer: factory} createLabel(org.eclipse.swt.widgets.Composite)} {empty} {/factory.createLabel(this)/} + {virtual-layout_data: org.eclipse.swt.layout.GridData} {virtual-layout-data} {} + {instance factory container} + {new: test.MyFactory} {field-initializer: factory} {/new MyFactory()/ /factory.createLabel(this)/}"""); ControlInfo label = shell.getChildrenControls().get(0); // factory created "label" is visible IObjectPresentation presentation = shell.getPresentation(); @@ -181,14 +176,13 @@ public void test_excludeFillersFromPresentationChildren_2() throws Exception { */ @Test public void test_fillersWith_setText() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " new Label(this, SWT.NONE).setText('txt');", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + new Label(this, SWT.NONE).setText("txt"); + } + }"""); shell.refresh(); ControlInfo label = shell.getChildrenControls().get(0); // @@ -205,14 +199,13 @@ public void test_fillersWith_setText() throws Exception { @Test public void test_fillersWithout_setText() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " new Label(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + new Label(this, SWT.NONE); + } + }"""); shell.refresh(); ControlInfo label = shell.getChildrenControls().get(0); // @@ -232,23 +225,22 @@ public void test_fillersWithout_setText() throws Exception { */ @Test public void test_fixGrid_noControls() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout());", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout()); + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // do "fix" ReflectionUtils.invokeMethod(layout, "fixGrid()"); - assertEditor( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout());", - " }", - "}"); + assertEditor(""" + public class Test extends Shell { + public Test() { + setLayout(new GridLayout()); + } + }"""); } /** @@ -257,40 +249,37 @@ public void test_fixGrid_noControls() throws Exception { */ @Test public void test_fixGrid_leadingImplicitControls() throws Exception { - setFileContentSrc( - "test/MyShell.java", - getTestSource( - "public class MyShell extends Shell {", - " public MyShell() {", - " setLayout(new GridLayout());", - " new Text(this, SWT.NONE);", - " }", - " protected void checkSubclass() {", - " }", - "}")); + setFileContentSrc("test/MyShell.java", getTestSource(""" + public class MyShell extends Shell { + public MyShell() { + setLayout(new GridLayout()); + new Text(this, SWT.NONE); + } + protected void checkSubclass() { + } + }""")); waitForAutoBuild(); // - CompositeInfo shell = - parseComposite( - "public class Test extends MyShell {", - " public Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends MyShell { + public Test() { + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // do "fix" ReflectionUtils.invokeMethod(layout, "fixGrid()"); - assertEditor( - "public class Test extends MyShell {", - " public Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + public class Test extends MyShell { + public Test() { + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } /** @@ -298,32 +287,31 @@ public void test_fixGrid_leadingImplicitControls() throws Exception { */ @Test public void test_gridInfo() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 2;", - " button.setLayoutData(gridData);", - " }", - " button.setText('222');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 2; + button.setLayoutData(gridData); + } + button.setText("222"); + } + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button_0 = shell.getChildrenControls().get(0); @@ -393,16 +381,15 @@ public void test_gridInfo() throws Exception { */ @Test public void test_gridInfo2() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setSize(300, 200);", - " setLayout(new GridLayout());", - " new Button(this, SWT.NONE);", - " new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setSize(300, 200); + setLayout(new GridLayout()); + new Button(this, SWT.NONE); + new Button(this, SWT.NONE); + } + }"""); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button_0 = shell.getChildrenControls().get(0); ControlInfo button_1 = shell.getChildrenControls().get(1); @@ -418,13 +405,12 @@ public void test_gridInfo2() throws Exception { */ @Test public void test_gridInfo_empty() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -435,21 +421,20 @@ public void test_gridInfo_empty() throws Exception { @Test public void test_gridInfo_tooBigHorizontalSpan() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 10;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 10; + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = shell.getChildrenControls().get(0); @@ -468,17 +453,16 @@ public void test_gridInfo_tooBigHorizontalSpan() throws Exception { @Test public void test_gridInfo_implicitControls() throws Exception { prepareShell_withImplicit(); - CompositeInfo shell = - parseComposite( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = getJavaInfoByName("button"); @@ -503,15 +487,14 @@ public void test_gridInfo_implicitControls() throws Exception { */ @Test public void test_canChangeDimensions_explicit() throws Exception { - CompositeInfo shell = - parseComposite( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends Shell {", - " public Test() {", - " setLayout(new GridLayout(2, false));", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends Shell { + public Test() { + setLayout(new GridLayout(2, false)); + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // is explicit @@ -524,14 +507,13 @@ public void test_canChangeDimensions_explicit() throws Exception { @Test public void test_canChangeDimensions_implicit() throws Exception { prepareShell_withImplicit(); - CompositeInfo shell = - parseComposite( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // is implicit @@ -547,14 +529,13 @@ public void test_canChangeDimensions_implicit() throws Exception { @Test public void test_canChangeDimensions_implicit_withoutControls() throws Exception { prepareShell_withImplicitEmpty(); - CompositeInfo shell = - parseComposite( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // is implicit, but no implicit controls @@ -568,23 +549,22 @@ public void test_canChangeDimensions_implicit_withoutControls() throws Exception //////////////////////////////////////////////////////////////////////////// @Test public void test_setCells_horizontalSpan_inc() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.LEFT);", - " new Label(this, SWT.RIGHT);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.LEFT); + new Label(this, SWT.RIGHT); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = shell.getChildrenControls().get(0); @@ -598,22 +578,22 @@ public void test_setCells_horizontalSpan_inc() throws Exception { } // set horizontal span layout.command_setCells(button, new Rectangle(0, 0, 2, 1), true); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));", - " button.setText('000');", - " }", - " new Label(this, SWT.RIGHT);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); + button.setText("000"); + } + new Label(this, SWT.RIGHT); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); // check GridData { assertEquals(0, getInt(gridData, "x")); @@ -625,48 +605,47 @@ public void test_setCells_horizontalSpan_inc() throws Exception { @Test public void test_setCells_horizontalSpan_dec() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 2;", - " button.setLayoutData(gridData);", - " }", - " button.setText('000');", - " }", - " new Label(this, SWT.RIGHT);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 2; + button.setLayoutData(gridData); + } + button.setText("000"); + } + new Label(this, SWT.RIGHT); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = shell.getChildrenControls().get(0); // layout.command_setCells(button, new Rectangle(0, 0, 1, 1), true); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.RIGHT);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + new Label(this, SWT.RIGHT); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); } /** @@ -676,93 +655,91 @@ public void test_setCells_horizontalSpan_dec() throws Exception { */ @Test public void test_setCells_horizontalSpan_incToEmptyColumns() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(5, false));", - " Button button_1 = new Button(this, SWT.NONE);", - " Button button_2 = new Button(this, SWT.NONE);", - " Button button_3 = new Button(this, SWT.NONE);", - " {", - " Button toResize = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 3;", - " toResize.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(5, false)); + Button button_1 = new Button(this, SWT.NONE); + Button button_2 = new Button(this, SWT.NONE); + Button button_3 = new Button(this, SWT.NONE); + { + Button toResize = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 3; + toResize.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo toResize = getJavaInfoByName("toResize"); // grid was fixed - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(5, false));", - " Button button_1 = new Button(this, SWT.NONE);", - " Button button_2 = new Button(this, SWT.NONE);", - " Button button_3 = new Button(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button toResize = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 3;", - " toResize.setLayoutData(gridData);", - " }", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(5, false)); + Button button_1 = new Button(this, SWT.NONE); + Button button_2 = new Button(this, SWT.NONE); + Button button_3 = new Button(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button toResize = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 3; + toResize.setLayoutData(gridData); + } + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + } + }"""); assertEquals(5, layout.getColumns().size()); assertEquals(2, layout.getRows().size()); // set cells layout.command_setCells(toResize, new Rectangle(0, 1, 5, 1), true); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(5, false));", - " Button button_1 = new Button(this, SWT.NONE);", - " Button button_2 = new Button(this, SWT.NONE);", - " Button button_3 = new Button(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button toResize = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 5;", - " toResize.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(5, false)); + Button button_1 = new Button(this, SWT.NONE); + Button button_2 = new Button(this, SWT.NONE); + Button button_3 = new Button(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button toResize = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 5; + toResize.setLayoutData(gridData); + } + } + } + }"""); } @Test public void test_setCells_verticalSpan_inc() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.LEFT);", - " new Label(this, SWT.RIGHT);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.LEFT); + new Label(this, SWT.RIGHT); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = shell.getChildrenControls().get(0); @@ -776,22 +753,22 @@ public void test_setCells_verticalSpan_inc() throws Exception { } // set vertical span layout.command_setCells(button, new Rectangle(0, 0, 1, 2), true); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2));", - " button.setText('000');", - " }", - " new Label(this, SWT.LEFT);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2)); + button.setText("000"); + } + new Label(this, SWT.LEFT); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); // check GridData { assertEquals(0, getInt(gridData, "x")); @@ -803,78 +780,76 @@ public void test_setCells_verticalSpan_inc() throws Exception { @Test public void test_setCells_verticalSpan_dec() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.verticalSpan = 2;", - " button.setLayoutData(gridData);", - " }", - " button.setText('111');", - " }", - " new Label(this, SWT.RIGHT);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.verticalSpan = 2; + button.setLayoutData(gridData); + } + button.setText("111"); + } + new Label(this, SWT.RIGHT); + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = shell.getChildrenControls().get(1); // layout.command_setCells(button, new Rectangle(1, 1, 1, 1), true); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.RIGHT);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + new Label(this, SWT.RIGHT); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); } @Test public void test_setCells_move() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " Button button_00 = new Button(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " Button button_01 = new Button(this, SWT.NONE);", - " Button button_11 = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + Button button_00 = new Button(this, SWT.NONE); + new Label(this, SWT.NONE); + Button button_01 = new Button(this, SWT.NONE); + Button button_11 = new Button(this, SWT.NONE); + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button_01 = shell.getChildrenControls().get(2); // layout.command_setCells(button_01, new Rectangle(1, 0, 1, 1), true); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " Button button_00 = new Button(this, SWT.NONE);", - " Button button_01 = new Button(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " Button button_11 = new Button(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + Button button_00 = new Button(this, SWT.NONE); + Button button_01 = new Button(this, SWT.NONE); + new Label(this, SWT.NONE); + Button button_11 = new Button(this, SWT.NONE); + } + }"""); // check x/y for new filler { ControlInfo filler = shell.getChildrenControls().get(2); @@ -896,35 +871,34 @@ public void test_setCells_move() throws Exception { */ @Test public void test_setSizeHint_width() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = shell.getChildrenControls().get(0); // set hint layout.command_setSizeHint(button, true, new Dimension(200, -1)); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);", - " gridData.widthHint = 200;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gridData.widthHint = 200; + button.setLayoutData(gridData); + } + } + } + }"""); } /** @@ -932,35 +906,34 @@ public void test_setSizeHint_width() throws Exception { */ @Test public void test_setSizeHint_height() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = shell.getChildrenControls().get(0); // set hint layout.command_setSizeHint(button, false, new Dimension(-1, 50)); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);", - " gridData.heightHint = 50;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gridData.heightHint = 50; + button.setLayoutData(gridData); + } + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -973,31 +946,30 @@ public void test_setSizeHint_height() throws Exception { */ @Test public void test_delete_replaceWithFillers() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " Button button_00 = new Button(this, SWT.NONE);", - " Button button_10 = new Button(this, SWT.NONE);", - " Button button_01 = new Button(this, SWT.NONE);", - " Button button_11 = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + Button button_00 = new Button(this, SWT.NONE); + Button button_10 = new Button(this, SWT.NONE); + Button button_01 = new Button(this, SWT.NONE); + Button button_11 = new Button(this, SWT.NONE); + } + }"""); shell.refresh(); ControlInfo button_01 = shell.getChildrenControls().get(2); // button_01.delete(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " Button button_00 = new Button(this, SWT.NONE);", - " Button button_10 = new Button(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " Button button_11 = new Button(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + Button button_00 = new Button(this, SWT.NONE); + Button button_10 = new Button(this, SWT.NONE); + new Label(this, SWT.NONE); + Button button_11 = new Button(this, SWT.NONE); + } + }"""); } /** @@ -1005,49 +977,47 @@ public void test_delete_replaceWithFillers() throws Exception { */ @Test public void test_delete_keepOneColumn() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(0); // button.delete(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + } + }"""); } @Test public void test_delete_removeEmptyDimensions() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); ControlInfo button = shell.getChildrenControls().get(5); // @@ -1058,16 +1028,16 @@ public void test_delete_removeEmptyDimensions() throws Exception { } // button.delete(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1077,406 +1047,397 @@ public void test_delete_removeEmptyDimensions() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_CREATE_inEmptyCell() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.LEFT);", - " new Label(this, SWT.RIGHT);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.LEFT); + new Label(this, SWT.RIGHT); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 1, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.RIGHT);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + } + new Label(this, SWT.RIGHT); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); } @Test public void test_CREATE_insertRow() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.LEFT);", - " new Label(this, SWT.RIGHT);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.LEFT); + new Label(this, SWT.RIGHT); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 1, false, 1, true); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.LEFT);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.RIGHT);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.LEFT); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + } + new Label(this, SWT.RIGHT); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); } @Test public void test_CREATE_insertColumn() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.LEFT);", - " new Label(this, SWT.RIGHT);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.LEFT); + new Label(this, SWT.RIGHT); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 1, true, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(3, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.LEFT);", - " new Label(this, SWT.RIGHT);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(3, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + } + new Label(this, SWT.LEFT); + new Label(this, SWT.RIGHT); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); } @Test public void test_CREATE_insertColumnRow() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 0, true, 0, true); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + } + }"""); // delete - should return in initial state newButton.delete(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + } + }"""); } @Test public void test_CREATE_appendRow() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 0, false, 2, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } @Test public void test_CREATE_appendColumn() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 2, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(3, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(3, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } @Test public void test_CREATE_appendColumnRow() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 1, false, 1, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } @Test public void test_CREATE_insertColumnHorizontalSpan() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 2;", - " button.setLayoutData(gridData);", - " }", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('222');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 2; + button.setLayoutData(gridData); + } + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("222"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 1, true, 1, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(3, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 3;", - " button.setLayoutData(gridData);", - " }", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('222');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(3, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 3; + button.setLayoutData(gridData); + } + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("222"); + } + } + }"""); } @Test public void test_CREATE_insertRowVerticalSpan() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.verticalSpan = 2;", - " button.setLayoutData(gridData);", - " }", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('222');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.verticalSpan = 2; + button.setLayoutData(gridData); + } + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("222"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 1, false, 1, true); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.verticalSpan = 3;", - " button.setLayoutData(gridData);", - " }", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('222');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.verticalSpan = 3; + button.setLayoutData(gridData); + } + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("222"); + } + } + }"""); } /** @@ -1484,33 +1445,32 @@ public void test_CREATE_insertRowVerticalSpan() throws Exception { */ @Test public void test_CREATE_notBalanced() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + } + }"""); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); shell.refresh(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 1, false, 1, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1520,62 +1480,60 @@ public void test_CREATE_notBalanced() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_CREATE_Shell_open() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new GridLayout(1, false));", - " shell.open();", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new GridLayout(1, false)); + shell.open(); + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 1, false, 0, false); - assertEditor( - "public class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new GridLayout(2, false));", - " new Label(shell, SWT.NONE);", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " shell.open();", - " }", - "}"); + assertEditor(""" + public class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new GridLayout(2, false)); + new Label(shell, SWT.NONE); + { + Button button = new Button(shell, SWT.NONE); + } + shell.open(); + } + }"""); } @Test public void test_CREATE_Shell_layout() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new GridLayout(1, false));", - " shell.layout();", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new GridLayout(1, false)); + shell.layout(); + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 1, false, 0, false); - assertEditor( - "public class Test {", - " public static void main(String[] args) {", - " Shell shell = new Shell();", - " shell.setLayout(new GridLayout(2, false));", - " new Label(shell, SWT.NONE);", - " {", - " Button button = new Button(shell, SWT.NONE);", - " }", - " shell.layout();", - " }", - "}"); + assertEditor(""" + public class Test { + public static void main(String[] args) { + Shell shell = new Shell(); + shell.setLayout(new GridLayout(2, false)); + new Label(shell, SWT.NONE); + { + Button button = new Button(shell, SWT.NONE); + } + shell.layout(); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -1589,15 +1547,14 @@ public void test_CREATE_Shell_layout() throws Exception { @Test public void test_implicitLayout_isExplicitRow() throws Exception { prepareShell_withImplicit(); - CompositeInfo shell = - parseComposite( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " Button button = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + Button button = new Button(this, SWT.NONE); + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // has 1 implicit and 1 explicit row @@ -1612,14 +1569,13 @@ public void test_implicitLayout_isExplicitRow() throws Exception { @Test public void test_implicitLayout_CREATE() throws Exception { prepareShell_withImplicit(); - CompositeInfo shell = - parseComposite( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // initial state @@ -1628,17 +1584,17 @@ public void test_implicitLayout_CREATE() throws Exception { // add new Button ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 1, false, 1, false); - assertEditor( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } /** @@ -1647,63 +1603,58 @@ public void test_implicitLayout_CREATE() throws Exception { @Test public void test_implicitLayout_MOVE() throws Exception { prepareShell_withImplicit(); - CompositeInfo shell = - parseComposite( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + { + Button button = new Button(this, SWT.NONE); + } + new Label(this, SWT.NONE); + } + }"""); refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = getJavaInfoByName("button"); // move "button" layout.command_MOVE(button, 1, false, 1, false); - assertEditor( - "// filler filler filler filler filler", - "// filler filler filler filler filler", - "public class Test extends MyShell {", - " public Test() {", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + // filler filler filler filler filler + // filler filler filler filler filler + public class Test extends MyShell { + public Test() { + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } private void prepareShell_withImplicit() throws Exception { - setFileContentSrc( - "test/MyShell.java", - getTestSource( - "public class MyShell extends Shell {", - " public MyShell() {", - " setLayout(new GridLayout(2, false));", - " new Button(this, SWT.NONE);", - " new Button(this, SWT.NONE);", - " }", - " protected void checkSubclass() {", - " }", - "}")); + setFileContentSrc("test/MyShell.java", getTestSource(""" + public class MyShell extends Shell { + public MyShell() { + setLayout(new GridLayout(2, false)); + new Button(this, SWT.NONE); + new Button(this, SWT.NONE); + } + protected void checkSubclass() { + } + }""")); waitForAutoBuild(); } private void prepareShell_withImplicitEmpty() throws Exception { - setFileContentSrc( - "test/MyShell.java", - getTestSource( - "public class MyShell extends Shell {", - " public MyShell() {", - " setLayout(new GridLayout(1, false));", - " }", - " protected void checkSubclass() {", - " }", - "}")); + setFileContentSrc("test/MyShell.java", getTestSource(""" + public class MyShell extends Shell { + public MyShell() { + setLayout(new GridLayout(1, false)); + } + protected void checkSubclass() { + } + }""")); waitForAutoBuild(); } @@ -1714,26 +1665,25 @@ private void prepareShell_withImplicitEmpty() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_columnAccess() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('0 x 0');", - " }", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('0 x 1');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('1 x 1');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("0 x 0"); + } + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("0 x 1"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("1 x 1"); + } + } + }"""); shell.refresh(); final GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); final GridColumnInfo column = layout.getColumns().get(0); @@ -1744,51 +1694,51 @@ public void test_columnAccess() throws Exception { assertEquals(SWT.LEFT, column.getAlignment().intValue()); // flip grab column.flipGrab(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));", - " button.setText('0 x 0');", - " }", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));", - " button.setText('0 x 1');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('1 x 1');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); + button.setText("0 x 0"); + } + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); + button.setText("0 x 1"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("1 x 1"); + } + } + }"""); assertEquals("left, grab", column.getTitle()); // set alignment column.setAlignment(SWT.FILL); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));", - " button.setText('0 x 0');", - " }", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));", - " button.setText('0 x 1');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('1 x 1');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + button.setText("0 x 0"); + } + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + button.setText("0 x 1"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("1 x 1"); + } + } + }"""); assertEquals("fill, grab", column.getTitle()); // set different alignment for "0 x 1" button { @@ -1806,41 +1756,40 @@ public void test_columnAccess() throws Exception { } // delete ExecutionUtils.run(shell, column::delete); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('1 x 1');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("1 x 1"); + } + } + }"""); } @Test public void test_rowAccess() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('0 x 0');", - " }", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('0 x 1');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('1 x 1');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("0 x 0"); + } + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("0 x 1"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("1 x 1"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -1852,51 +1801,51 @@ public void test_rowAccess() throws Exception { assertEquals(SWT.CENTER, row.getAlignment().intValue()); // flip grab row.flipGrab(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('0 x 0');", - " }", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true, 1, 1));", - " button.setText('0 x 1');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true, 1, 1));", - " button.setText('1 x 1');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("0 x 0"); + } + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true, 1, 1)); + button.setText("0 x 1"); + } + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true, 1, 1)); + button.setText("1 x 1"); + } + } + }"""); assertEquals("center, grab", row.getTitle()); // set alignment row.setAlignment(SWT.FILL); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('0 x 0');", - " }", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 1));", - " button.setText('0 x 1');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 1));", - " button.setText('1 x 1');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("0 x 0"); + } + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 1)); + button.setText("0 x 1"); + } + { + Button button = new Button(this, SWT.NONE); + button.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 1)); + button.setText("1 x 1"); + } + } + }"""); assertEquals("fill, grab", row.getTitle()); // set different alignment for "0 x 1" button { @@ -1914,48 +1863,47 @@ public void test_rowAccess() throws Exception { } // delete row.delete(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('0 x 0');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("0 x 0"); + } + } + }"""); } @Test public void test_deleteColumn() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(3, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 3;", - " button.setLayoutData(gridData);", - " }", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('New Button');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('222');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(3, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 3; + button.setLayoutData(gridData); + } + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("New Button"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("222"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -1965,50 +1913,49 @@ public void test_deleteColumn() throws Exception { } finally { shell.endEdit(); } - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 2;", - " button.setLayoutData(gridData);", - " }", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('222');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 2; + button.setLayoutData(gridData); + } + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("222"); + } + } + }"""); } @Test public void test_deleteColumn_deleteAlsoEmptyRows() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -2018,16 +1965,16 @@ public void test_deleteColumn_deleteAlsoEmptyRows() throws Exception { } finally { shell.endEdit(); } - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + } + }"""); } /** @@ -2036,28 +1983,27 @@ public void test_deleteColumn_deleteAlsoEmptyRows() throws Exception { */ @Test public void test_delete_missingFillers() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " Button button_00 = new Button(this, SWT.NONE);", - " Button button_10 = new Button(this, SWT.NONE);", - " Button button_01 = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + Button button_00 = new Button(this, SWT.NONE); + Button button_10 = new Button(this, SWT.NONE); + Button button_01 = new Button(this, SWT.NONE); + } + }"""); shell.refresh(); // grid was fixed - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " Button button_00 = new Button(this, SWT.NONE);", - " Button button_10 = new Button(this, SWT.NONE);", - " Button button_01 = new Button(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + Button button_00 = new Button(this, SWT.NONE); + Button button_10 = new Button(this, SWT.NONE); + Button button_01 = new Button(this, SWT.NONE); + new Label(this, SWT.NONE); + } + }"""); // prepare all Control's List controls = shell.getChildrenControls(); Assertions.assertThat(controls).hasSize(4); @@ -2065,46 +2011,45 @@ public void test_delete_missingFillers() throws Exception { ControlInfo button_01 = controls.get(2); button_01.delete(); // ..."row 1" should be removed - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " Button button_00 = new Button(this, SWT.NONE);", - " Button button_10 = new Button(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + Button button_00 = new Button(this, SWT.NONE); + Button button_10 = new Button(this, SWT.NONE); + } + }"""); } @Test public void test_deleteRow() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.verticalSpan = 3;", - " button.setLayoutData(gridData);", - " }", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " button_1.setText('New Button');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('222');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.verticalSpan = 3; + button.setLayoutData(gridData); + } + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + { + Button button_1 = new Button(this, SWT.NONE); + button_1.setText("New Button"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("222"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -2115,50 +2060,49 @@ public void test_deleteRow() throws Exception { shell.endEdit(); } // - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.verticalSpan = 2;", - " button.setLayoutData(gridData);", - " }", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('222');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.verticalSpan = 2; + button.setLayoutData(gridData); + } + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("222"); + } + } + }"""); } @Test public void test_deleteRow_deleteAlsoEmptyColumns() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -2168,16 +2112,16 @@ public void test_deleteRow_deleteAlsoEmptyColumns() throws Exception { } finally { shell.endEdit(); } - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2187,23 +2131,22 @@ public void test_deleteRow_deleteAlsoEmptyColumns() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_MOVE_COLUMN_before() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -2213,43 +2156,42 @@ public void test_MOVE_COLUMN_before() throws Exception { } finally { layout.endEdit(); } - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + new Label(this, SWT.NONE); + } + }"""); } @Test public void test_MOVE_COLUMN_after() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -2259,22 +2201,22 @@ public void test_MOVE_COLUMN_after() throws Exception { } finally { layout.endEdit(); } - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + new Label(this, SWT.NONE); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2284,23 +2226,22 @@ public void test_MOVE_COLUMN_after() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_MOVE_ROW_before() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -2310,43 +2251,42 @@ public void test_MOVE_ROW_before() throws Exception { } finally { layout.endEdit(); } - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + } + }"""); } @Test public void test_MOVE_ROW_after() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -2356,22 +2296,22 @@ public void test_MOVE_ROW_after() throws Exception { } finally { layout.endEdit(); } - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2385,34 +2325,33 @@ public void test_MOVE_ROW_after() throws Exception { */ @Test public void test_normalizeSpanning_1() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 2;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 2; + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // layout.command_normalizeSpanning(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } /** @@ -2421,34 +2360,33 @@ public void test_normalizeSpanning_1() throws Exception { */ @Test public void test_normalizeSpanning_2() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.verticalSpan = 2;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.verticalSpan = 2; + button.setLayoutData(gridData); + } + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // layout.command_normalizeSpanning(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } /** @@ -2457,47 +2395,46 @@ public void test_normalizeSpanning_2() throws Exception { */ @Test public void test_normalizeSpanning_3() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 2;", - " button_1.setLayoutData(gridData);", - " }", - " }", - " new Label(this, SWT.NONE);", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 2; + button_1.setLayoutData(gridData); + } + } + new Label(this, SWT.NONE); + { + Button button_2 = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // layout.command_normalizeSpanning(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 2;", - " button_1.setLayoutData(gridData);", - " }", - " }", - " new Label(this, SWT.NONE);", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 2; + button_1.setLayoutData(gridData); + } + } + new Label(this, SWT.NONE); + { + Button button_2 = new Button(this, SWT.NONE); + } + } + }"""); } /** @@ -2506,41 +2443,40 @@ public void test_normalizeSpanning_3() throws Exception { */ @Test public void test_normalizeSpanning_4() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.horizontalSpan = 2;", - " button_1.setLayoutData(gridData);", - " }", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " }", - " new Label(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button_1 = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.horizontalSpan = 2; + button_1.setLayoutData(gridData); + } + } + { + Button button_2 = new Button(this, SWT.NONE); + } + new Label(this, SWT.NONE); + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // layout.command_normalizeSpanning(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button_1 = new Button(this, SWT.NONE);", - " }", - " {", - " Button button_2 = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button_1 = new Button(this, SWT.NONE); + } + { + Button button_2 = new Button(this, SWT.NONE); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2550,149 +2486,145 @@ public void test_normalizeSpanning_4() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_MOVE() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('222');", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("222"); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = shell.getChildrenControls().get(2); // layout.command_MOVE(button, 1, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('000');", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('111');", - " }", - " new Label(this, SWT.NONE);", - " {", - " Button button = new Button(this, SWT.NONE);", - " button.setText('222');", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + { + Button button = new Button(this, SWT.NONE); + button.setText("000"); + } + { + Button button = new Button(this, SWT.NONE); + button.setText("111"); + } + new Label(this, SWT.NONE); + { + Button button = new Button(this, SWT.NONE); + button.setText("222"); + } + } + }"""); } @Test public void test_MOVE_out() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new RowLayout()); + } + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); CompositeInfo composite = (CompositeInfo) shell.getChildrenControls().get(0); RowLayoutInfo layout = (RowLayoutInfo) composite.getLayout(); ControlInfo button = shell.getChildrenControls().get(1); // layout.command_MOVE(button, null); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new RowLayout()); + { + Button button = new Button(composite, SWT.NONE); + } + } + } + }"""); } @Test public void test_MOVE_error_1() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(4, false));", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " Button button = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(4, false)); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + Button button = new Button(this, SWT.NONE); + } + }"""); shell.refresh(); GridLayoutInfo gridLayout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = shell.getChildrenControls().get(7); // gridLayout.command_MOVE(button, 1, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " new Label(this, SWT.NONE);", - " Button button = new Button(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + new Label(this, SWT.NONE); + Button button = new Button(this, SWT.NONE); + } + }"""); } @Test public void test_MOVE_error_2() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(3, false));", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " Button button = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(3, false)); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + Button button = new Button(this, SWT.NONE); + } + }"""); shell.refresh(); GridLayoutInfo gridLayout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = shell.getChildrenControls().get(5); // gridLayout.command_MOVE(button, 0, false, 0, false); gridLayout.getGridInfo(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " Button button = new Button(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + Button button = new Button(this, SWT.NONE); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2702,39 +2634,38 @@ public void test_MOVE_error_2() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_ADD() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " {", - " Button button = new Button(composite, SWT.NONE);", - " }", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new RowLayout()); + { + Button button = new Button(composite, SWT.NONE); + } + } + } + }"""); shell.refresh(); CompositeInfo composite = (CompositeInfo) shell.getChildrenControls().get(0); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = composite.getChildrenControls().get(0); // layout.command_ADD(button, 0, false, 1, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new RowLayout());", - " }", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new RowLayout()); + } + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2744,38 +2675,36 @@ public void test_ADD() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_CREATE_noReference() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // ControlInfo newButton = BTestUtils.createButton(); layout.command_CREATE(newButton, 0, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); } @Test public void test_CREATE_viewer() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // @@ -2783,17 +2712,17 @@ public void test_CREATE_viewer() throws Exception { TableInfo table = (TableInfo) JavaInfoUtils.getWrapped(viewer); // layout.command_CREATE(table, 0, false, 0, false); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " TableViewer tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION);", - " Table table = tableViewer.getTable();", - " table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + TableViewer tableViewer = new TableViewer(this, SWT.BORDER | SWT.FULL_SELECTION); + Table table = tableViewer.getTable(); + table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2806,29 +2735,28 @@ public void test_CREATE_viewer() throws Exception { */ @Test public void test_numColumns_inc() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " Button button_1 = new Button(this, SWT.NONE);", - " Button button_2 = new Button(this, SWT.NONE);", - " Button button_3 = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + Button button_1 = new Button(this, SWT.NONE); + Button button_2 = new Button(this, SWT.NONE); + Button button_3 = new Button(this, SWT.NONE); + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // grid was fixed - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " Button button_1 = new Button(this, SWT.NONE);", - " Button button_2 = new Button(this, SWT.NONE);", - " Button button_3 = new Button(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + Button button_1 = new Button(this, SWT.NONE); + Button button_2 = new Button(this, SWT.NONE); + Button button_3 = new Button(this, SWT.NONE); + new Label(this, SWT.NONE); + } + }"""); // initial state assertEquals(2, layout.getColumns().size()); assertEquals(2, layout.getRows().size()); @@ -2836,18 +2764,18 @@ public void test_numColumns_inc() throws Exception { layout.getPropertyByTitle("numColumns").setValue(3); assertEquals(3, layout.getColumns().size()); assertEquals(2, layout.getRows().size()); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(3, false));", - " Button button_1 = new Button(this, SWT.NONE);", - " Button button_2 = new Button(this, SWT.NONE);", - " Button button_3 = new Button(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(3, false)); + Button button_1 = new Button(this, SWT.NONE); + Button button_2 = new Button(this, SWT.NONE); + Button button_3 = new Button(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + new Label(this, SWT.NONE); + } + }"""); } /** @@ -2855,16 +2783,15 @@ public void test_numColumns_inc() throws Exception { */ @Test public void test_numColumns_dec() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(3, false));", - " Button button_1 = new Button(this, SWT.NONE);", - " Button button_2 = new Button(this, SWT.NONE);", - " Button button_3 = new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(3, false)); + Button button_1 = new Button(this, SWT.NONE); + Button button_2 = new Button(this, SWT.NONE); + Button button_3 = new Button(this, SWT.NONE); + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); // initial state @@ -2874,16 +2801,16 @@ public void test_numColumns_dec() throws Exception { layout.getPropertyByTitle("numColumns").setValue(2); assertEquals(2, layout.getColumns().size()); assertEquals(2, layout.getRows().size()); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(2, false));", - " Button button_1 = new Button(this, SWT.NONE);", - " Button button_2 = new Button(this, SWT.NONE);", - " Button button_3 = new Button(this, SWT.NONE);", - " new Label(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(2, false)); + Button button_1 = new Button(this, SWT.NONE); + Button button_2 = new Button(this, SWT.NONE); + Button button_3 = new Button(this, SWT.NONE); + new Label(this, SWT.NONE); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -2896,16 +2823,15 @@ public void test_numColumns_dec() throws Exception { */ @Test public void test_excludeFlag() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " }", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + } + } + }"""); shell.refresh(); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); ControlInfo button = shell.getChildrenControls().get(0); @@ -2914,20 +2840,20 @@ public void test_excludeFlag() throws Exception { // exclude "button" GridLayoutInfo.getGridData(button).getPropertyByTitle("exclude").setValue(true); Assertions.assertThat(layout.getControls()).isEmpty(); - assertEditor( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);", - " gridData.exclude = true;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gridData.exclude = true; + button.setLayoutData(gridData); + } + } + } + }"""); } /** @@ -2935,34 +2861,31 @@ public void test_excludeFlag() throws Exception { */ @Test public void test_excludeFlag_forImplicit() throws Exception { - setFileContentSrc( - "test/MyComposite.java", - getTestSource( - "class MyComposite extends Composite {", - " MyComposite(Composite parent, int style) {", - " super(parent, style);", - " setLayout(new GridLayout());", - " {", - " Button button = new Button(this, SWT.NONE);", - " {", - " GridData gridData = new GridData();", - " gridData.exclude = true;", - " button.setLayoutData(gridData);", - " }", - " }", - " }", - "}")); + setFileContentSrc("test/MyComposite.java", getTestSource(""" + class MyComposite extends Composite { + MyComposite(Composite parent, int style) { + super(parent, style); + setLayout(new GridLayout()); + { + Button button = new Button(this, SWT.NONE); + { + GridData gridData = new GridData(); + gridData.exclude = true; + button.setLayoutData(gridData); + } + } + } + }""")); waitForAutoBuild(); // parse - CompositeInfo shell = - parseComposite( - "// filler filler filler filler filler", - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " new MyComposite(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + // filler filler filler filler filler + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + new MyComposite(this, SWT.NONE); + } + }"""); shell.refresh(); assertNoErrors(shell); } @@ -2978,15 +2901,14 @@ public void test_excludeFlag_forImplicit() throws Exception { */ @Test public void test_DELETE_removeFillers() throws Exception { - CompositeInfo shell = - parseComposite( - "class Test extends Shell {", - " Test() {", - " setLayout(new GridLayout(1, false));", - " new Label(this, SWT.NONE);", - " new Button(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + class Test extends Shell { + Test() { + setLayout(new GridLayout(1, false)); + new Label(this, SWT.NONE); + new Button(this, SWT.NONE); + } + }"""); GridLayoutInfo layout = (GridLayoutInfo) shell.getLayout(); shell.refresh(); // initially 2 controls - filler and Button @@ -2994,12 +2916,12 @@ public void test_DELETE_removeFillers() throws Exception { // after delete - only Button layout.delete(); assertEquals(1, shell.getChildrenControls().size()); - assertEditor( - "class Test extends Shell {", - " Test() {", - " new Button(this, SWT.NONE);", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + Test() { + new Button(this, SWT.NONE); + } + }"""); } //////////////////////////////////////////////////////////////////////////// @@ -3009,66 +2931,65 @@ public void test_DELETE_removeFillers() throws Exception { //////////////////////////////////////////////////////////////////////////// @Test public void test_clipboard() throws Exception { - final CompositeInfo shell = - parseJavaInfo( - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(composite, SWT.NONE);", - " GridData gridData = new GridData();", - " gridData.horizontalAlignment = GridData.FILL;", - " button.setLayoutData(gridData);", - " }", - " new Label(composite, SWT.NONE);", - " new Label(composite, SWT.NONE);", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " }", - " }", - " }", - "}"); + final CompositeInfo shell = parseJavaInfo(""" + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + { + Button button = new Button(composite, SWT.NONE); + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + button.setLayoutData(gridData); + } + new Label(composite, SWT.NONE); + new Label(composite, SWT.NONE); + { + Button button = new Button(composite, SWT.CHECK); + } + } + } + }"""); refresh(); // ControlInfo composite = getJavaInfoByName("composite"); doCopyPaste(composite, copy -> shell.getLayout().command_CREATE(copy, null)); - assertEditor( - "class Test extends Shell {", - " public Test() {", - " setLayout(new RowLayout());", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(composite, SWT.NONE);", - " GridData gridData = new GridData();", - " gridData.horizontalAlignment = GridData.FILL;", - " button.setLayoutData(gridData);", - " }", - " new Label(composite, SWT.NONE);", - " new Label(composite, SWT.NONE);", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " }", - " }", - " {", - " Composite composite = new Composite(this, SWT.NONE);", - " composite.setLayout(new GridLayout(2, false));", - " {", - " Button button = new Button(composite, SWT.NONE);", - " button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));", - " }", - " new Label(composite, SWT.NONE);", - " new Label(composite, SWT.NONE);", - " {", - " Button button = new Button(composite, SWT.CHECK);", - " }", - " }", - " }", - "}"); + assertEditor(""" + class Test extends Shell { + public Test() { + setLayout(new RowLayout()); + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + { + Button button = new Button(composite, SWT.NONE); + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + button.setLayoutData(gridData); + } + new Label(composite, SWT.NONE); + new Label(composite, SWT.NONE); + { + Button button = new Button(composite, SWT.CHECK); + } + } + { + Composite composite = new Composite(this, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + { + Button button = new Button(composite, SWT.NONE); + button.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); + } + new Label(composite, SWT.NONE); + new Label(composite, SWT.NONE); + { + Button button = new Button(composite, SWT.CHECK); + } + } + } + }"""); } //////////////////////////////////////////////////////////////////////////// diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/support/CoordinateUtilsTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/support/CoordinateUtilsTest.java index 60502398a..29e789035 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/support/CoordinateUtilsTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/support/CoordinateUtilsTest.java @@ -53,13 +53,13 @@ public void _test_exit() throws Exception { @Disabled @Test public void test_1() throws Exception { - ShellInfo shell = (ShellInfo) parseComposite( - "public class Test extends Shell {", - " public Test() {", - " Button button = new Button(this, SWT.NONE);", - " button.setBounds(10, 20, 50, 30);", - " }", - "}"); + ShellInfo shell = (ShellInfo) parseComposite(""" + public class Test extends Shell { + public Test() { + Button button = new Button(this, SWT.NONE); + button.setBounds(10, 20, 50, 30); + } + }"""); ControlInfo button = shell.getChildrenControls().get(0); shell.refresh(); // On GTK, the bounds are only calculated if the shell is visible @@ -101,14 +101,13 @@ public void test_1() throws Exception { @Disabled @Test public void test_withGroup() throws Exception { - CompositeInfo shell = - parseComposite( - "public class Test extends Shell {", - " public Test() {", - " setLayout(new FillLayout());", - " Group group = new Group(this, SWT.NONE);", - " }", - "}"); + CompositeInfo shell = parseComposite(""" + public class Test extends Shell { + public Test() { + setLayout(new FillLayout()); + Group group = new Group(this, SWT.NONE); + } + }"""); shell.refresh(); CompositeInfo group = (CompositeInfo) shell.getChildrenControls().get(0); //