|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2018, 2022 Red Hat Inc. and others. |
| 2 | + * Copyright (c) 2018, 2023 Red Hat Inc. and others. |
3 | 3 | * |
4 | 4 | * This program and the accompanying materials are made |
5 | 5 | * available under the terms of the Eclipse Public License 2.0 |
@@ -73,14 +73,31 @@ public void setUpProject() throws CoreException { |
73 | 73 |
|
74 | 74 | @Test |
75 | 75 | @Timeout(value = 60, unit = TimeUnit.SECONDS) |
76 | | - public void testRefactoringRename() throws Exception { |
| 76 | + public void testRefactoringRenameInTypeaScript() throws Exception { |
| 77 | + final IFile file = project.getFile("TestJsTs.ts"); |
| 78 | + String content = "function testVar(test) {\n if (\"truetrue\" == \"true\" + test ) {\n" |
| 79 | + + " return true;\n }\n return false;\n}\n" |
| 80 | + + "print(\"Testing var with true argument == \" + testVar(true));\n" |
| 81 | + + "print(\"Testing var with false argument == \" + testVar(false));\n"; |
| 82 | + final String oldName = "testVar"; |
| 83 | + final String newName = "newName"; |
| 84 | + internalTestRename(file, content, oldName, newName); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + @Timeout(value = 60, unit = TimeUnit.SECONDS) |
| 89 | + public void testRefactoringRenameInJavaScript() throws Exception { |
77 | 90 | final IFile file = project.getFile("TestJsTs.js"); |
78 | 91 | String content = "function testVar(test) {\n if (\"truetrue\" == \"true\" + test ) {\n" |
79 | 92 | + " return true;\n }\n return false;\n}\n" |
80 | 93 | + "print(\"Testing var with true argument == \" + testVar(true));\n" |
81 | 94 | + "print(\"Testing var with false argument == \" + testVar(false));\n"; |
82 | 95 | final String oldName = "testVar"; |
83 | 96 | final String newName = "newName"; |
| 97 | + internalTestRename(file, content, oldName, newName); |
| 98 | + } |
| 99 | + |
| 100 | + private void internalTestRename(IFile file, String content, String oldName, String newName) throws Exception { |
84 | 101 | String newContent = content.replaceAll(oldName, newName); |
85 | 102 |
|
86 | 103 | int offset = content.indexOf(oldName); |
@@ -113,41 +130,61 @@ public void testRefactoringRename() throws Exception { |
113 | 130 | Listener pressOKonRenameDialogPaint = event -> { |
114 | 131 | if (event.widget instanceof Composite c) { |
115 | 132 | Shell shell = c.getShell(); |
116 | | - if (shell != ideShell && shell.getData().getClass().getName().startsWith(WIZARD_CLASSNAME_TEMPLATE)) { |
117 | | - if (!newTextIsSet.get()) { |
118 | | - newTextIsSet.set(setNewText(c, newName)); |
119 | | - System.out.println("testRefactoringRename(): New name is set: " + newName); |
120 | | - } |
121 | | - Set<String> buttons = getButtons(c); |
122 | | - if (WIZARD_RENAME.equals(shell.getText())) { |
123 | | - if (!renameDialogOkPressed.get()) { |
124 | | - if (buttons.contains(BUTTON_OK)) { |
125 | | - System.out.println( |
126 | | - "testRefactoringRename(): WIZARD_RENAME Emulating pressOK when BUTTON_OK"); |
127 | | - event.widget.getDisplay().asyncExec(() -> pressOk(shell)); |
128 | | - renameDialogOkPressed.set(true); |
| 133 | + if (shell != ideShell) { |
| 134 | + if (shell.getData().getClass().getName().startsWith(WIZARD_CLASSNAME_TEMPLATE)) { |
| 135 | + if (!newTextIsSet.get()) { |
| 136 | + newTextIsSet.set(setNewText(c, newName)); |
| 137 | + System.out.println("testRefactoringRename(): New name is set: " + newName); |
| 138 | + } |
| 139 | + Set<String> buttons = getButtons(c); |
| 140 | + if (WIZARD_RENAME.equals(shell.getText())) { |
| 141 | + if (!renameDialogOkPressed.get()) { |
| 142 | + if (buttons.contains(BUTTON_OK)) { |
| 143 | + System.out.println( |
| 144 | + "testRefactoringRename(): WIZARD_RENAME Emulating pressOK when BUTTON_OK"); |
| 145 | + event.widget.getDisplay().asyncExec(() -> pressOk(shell)); |
| 146 | + renameDialogOkPressed.set(true); |
| 147 | + } |
| 148 | + } else if (!renameDialogContinuePressed.get()) { |
| 149 | + if (buttons.contains(BUTTON_CONTINUE)) { |
| 150 | + System.out.println( |
| 151 | + "testRefactoringRename(): WIZARD_RENAME Emulating pressOK when BUTTON_CONTINUE"); |
| 152 | + event.widget.getDisplay().asyncExec(() -> pressOk(shell)); |
| 153 | + renameDialogContinuePressed.set(true); |
| 154 | + } else if (!renameDialogCancelPressed.get() && buttons.contains(BUTTON_CANCEL) |
| 155 | + && buttons.contains(BUTTON_BACK)) { |
| 156 | + System.out.println( |
| 157 | + "testRefactoringRename(): WIZARD_RENAME Emulating pressCancel when BUTTON_CANCEL & BUTTON_BACK"); |
| 158 | + event.widget.getDisplay().asyncExec(() -> pressCancel(shell)); |
| 159 | + renameDialogCancelPressed.set(true); |
| 160 | + } |
129 | 161 | } |
130 | | - } else if (!renameDialogContinuePressed.get()) { |
131 | | - if (buttons.contains(BUTTON_CONTINUE)) { |
132 | | - System.out.println( |
133 | | - "testRefactoringRename(): WIZARD_RENAME Emulating pressOK when BUTTON_CONTINUE"); |
134 | | - event.widget.getDisplay().asyncExec(() -> pressOk(shell)); |
135 | | - renameDialogContinuePressed.set(true); |
136 | | - } else if (!renameDialogCancelPressed.get() && buttons.contains(BUTTON_CANCEL) |
137 | | - && buttons.contains(BUTTON_BACK)) { |
138 | | - System.out.println( |
139 | | - "testRefactoringRename(): WIZARD_RENAME Emulating pressCancel when BUTTON_CANCEL & BUTTON_BACK"); |
140 | | - event.widget.getDisplay().asyncExec(() -> pressCancel(shell)); |
141 | | - renameDialogCancelPressed.set(true); |
| 162 | + } else if (WIZARD_REFACTORING.equals(shell.getText())) { |
| 163 | + if (!errorDialogOkPressed.get()) { |
| 164 | + if (buttons.contains(BUTTON_OK)) { |
| 165 | + System.out.println( |
| 166 | + "testRefactoringRename(): WIZARD_REFACTORING Emulating pressOK when BUTTON_OK"); |
| 167 | + event.widget.getDisplay().asyncExec(() -> pressOk(shell)); |
| 168 | + errorDialogOkPressed.set(true); |
| 169 | + } |
142 | 170 | } |
143 | 171 | } |
144 | | - } else if (WIZARD_REFACTORING.equals(shell.getText())) { |
| 172 | + } else if (shell.getData().getClass().getName() |
| 173 | + .startsWith("org.eclipse.jface.dialogs.MessageDialog")) { |
| 174 | + // Most probably it's "The Rename request is not valid at the given position" |
| 175 | + // -like error |
| 176 | + Set<String> buttons = getButtons(c); |
145 | 177 | if (!errorDialogOkPressed.get()) { |
146 | 178 | if (buttons.contains(BUTTON_OK)) { |
147 | 179 | System.out.println( |
148 | | - "testRefactoringRename(): WIZARD_REFACTORING Emulating pressOK when BUTTON_OK"); |
| 180 | + "testRefactoringRename(): MESSAGE_DIALOG Emulating pressOK when BUTTON_OK"); |
149 | 181 | event.widget.getDisplay().asyncExec(() -> pressOk(shell)); |
150 | 182 | errorDialogOkPressed.set(true); |
| 183 | + } else if (buttons.contains(BUTTON_CANCEL)) { |
| 184 | + System.out.println( |
| 185 | + "testRefactoringRename(): MESSAGE_DIALOG Emulating pressCancel when BUTTON_CANCEL"); |
| 186 | + event.widget.getDisplay().asyncExec(() -> pressCancel(shell)); |
| 187 | + errorDialogOkPressed.set(true); // Report as OK pressed just to say the dialog is closed |
151 | 188 | } |
152 | 189 | } |
153 | 190 | } |
|
0 commit comments