Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Obuchowicz2019-09-13 14:38:04 -0400
committerAndrew Obuchowicz2019-09-19 14:59:13 -0400
commitb4ca5bddb0bb5b94ee079ba332f8d7e79e6b0047 (patch)
treeb043ced9521db39cb5ac46b91ce316cd0ba584c1 /org.eclipse.ui.genericeditor.tests
parent58f91bfc319901c60999a9f6ac226d152fcde15d (diff)
downloadeclipse.platform.text-b4ca5bddb0bb5b94ee079ba332f8d7e79e6b0047.tar.gz
eclipse.platform.text-b4ca5bddb0bb5b94ee079ba332f8d7e79e6b0047.tar.xz
eclipse.platform.text-b4ca5bddb0bb5b94ee079ba332f8d7e79e6b0047.zip
Bug 544448 - Add extension point for quickAssistantProcessorsI20190919-1800
Change-Id: If9e4aab45c7389b92475e07b955c45c50bbdd251 Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
Diffstat (limited to 'org.eclipse.ui.genericeditor.tests')
-rw-r--r--org.eclipse.ui.genericeditor.tests/plugin.xml7
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java17
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/TestQuickAssist.java84
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/MockQuickAssistProcessor.java46
4 files changed, 146 insertions, 8 deletions
diff --git a/org.eclipse.ui.genericeditor.tests/plugin.xml b/org.eclipse.ui.genericeditor.tests/plugin.xml
index 2bf886673..b029e501c 100644
--- a/org.eclipse.ui.genericeditor.tests/plugin.xml
+++ b/org.eclipse.ui.genericeditor.tests/plugin.xml
@@ -279,4 +279,11 @@
contentType="org.eclipse.ui.genericeditor.tests.sub-specialized-content-type"
icon="platform:/plugin/org.eclipse.ui.ide/icons/full/etool16/newprj_wiz.png"/>
</extension>
+ <extension
+ point="org.eclipse.ui.genericeditor.quickAssistProcessors">
+ <quickAssistProcessor
+ class="org.eclipse.ui.genericeditor.tests.contributions.QuickAssistProcessor"
+ contentType="org.eclipse.ui.genericeditor.tests.content-type">
+ </quickAssistProcessor>
+ </extension>
</plugin>
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java
index d6504cd62..31be5ba31 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java
@@ -29,6 +29,7 @@ import org.eclipse.swt.custom.ST;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
@@ -58,7 +59,7 @@ public class CompletionTest extends AbstratGenericEditorTest {
final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
editor.selectAndReveal(3, 0);
openConentAssist();
- this.completionShell= findNewShell(beforeShells);
+ this.completionShell= findNewShell(beforeShells, editor.getSite().getShell().getDisplay());
final Table completionProposalList = findCompletionSelectionControl(completionShell);
checkCompletionContent(completionProposalList);
// TODO find a way to actually trigger completion and verify result against Editor content
@@ -71,7 +72,7 @@ public class CompletionTest extends AbstratGenericEditorTest {
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("abc");
editor.selectAndReveal(0, 3);
openConentAssist();
- this.completionShell= findNewShell(beforeShells);
+ this.completionShell= findNewShell(beforeShells, editor.getSite().getShell().getDisplay());
final Table completionProposalList = findCompletionSelectionControl(completionShell);
assertTrue(new DisplayHelper() {
@Override
@@ -102,7 +103,7 @@ public class CompletionTest extends AbstratGenericEditorTest {
final Set<Shell> beforeEnabledShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
editor.selectAndReveal(3, 0);
openConentAssist();
- assertNotNull(findNewShell(beforeEnabledShells));
+ assertNotNull(findNewShell(beforeEnabledShells, editor.getSite().getShell().getDisplay()));
}
private void openConentAssist() {
@@ -147,8 +148,8 @@ public class CompletionTest extends AbstratGenericEditorTest {
assertEquals("Addition of completion proposal should keep selection", selectedProposal, completionProposalList.getSelection()[0].getData());
}
- private Shell findNewShell(Set<Shell> beforeShells) {
- Shell[] afterShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells())
+ public static Shell findNewShell(Set<Shell> beforeShells, Display display) {
+ Shell[] afterShells = Arrays.stream(display.getShells())
.filter(Shell::isVisible)
.filter(shell -> !beforeShells.contains(shell))
.toArray(Shell[]::new);
@@ -161,7 +162,7 @@ public class CompletionTest extends AbstratGenericEditorTest {
final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
editor.selectAndReveal(3, 0);
openConentAssist();
- this.completionShell= findNewShell(beforeShells);
+ this.completionShell= findNewShell(beforeShells, editor.getSite().getShell().getDisplay());
final Table completionProposalList = findCompletionSelectionControl(this.completionShell);
// should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
new DisplayHelper() {
@@ -188,7 +189,7 @@ public class CompletionTest extends AbstratGenericEditorTest {
testCompletion();
emulatePressLeftArrowKey();
DisplayHelper.sleep(editor.getSite().getShell().getDisplay(), LongRunningBarContentAssistProcessor.DELAY + 500); // adding delay is a workaround for bug521484, use only 100ms without the bug
- this.completionShell= findNewShell(beforeShells);
+ this.completionShell= findNewShell(beforeShells, editor.getSite().getShell().getDisplay());
final Table completionProposalList = findCompletionSelectionControl(this.completionShell);
assertEquals("Missing proposals from a Processor", 2, completionProposalList.getItemCount()); // replace with line below when #5214894 is done
// checkCompletionContent(completionProposalList); // use this instead of assert above when #521484 is done
@@ -205,7 +206,7 @@ public class CompletionTest extends AbstratGenericEditorTest {
styledText.notifyListeners(ST.VerifyKey, e);
}
- private Table findCompletionSelectionControl(Widget control) {
+ public static Table findCompletionSelectionControl(Widget control) {
if (control instanceof Table) {
return (Table)control;
} else if (control instanceof Composite) {
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/TestQuickAssist.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/TestQuickAssist.java
new file mode 100644
index 000000000..cbc6d4d3d
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/TestQuickAssist.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2016-2019 Red Hat Inc. and others
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Andrew Obuchowicz (Red Hat Inc.)
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.junit.After;
+import org.junit.Test;
+
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+
+import org.eclipse.jface.text.tests.util.DisplayHelper;
+
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+import org.eclipse.ui.texteditor.TextOperationAction;
+
+/**
+ * @since 1.2
+ */
+public class TestQuickAssist extends AbstratGenericEditorTest {
+
+ private Shell completionShell;
+
+ @Test
+ public void testCompletion() throws Exception {
+ final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
+ openQuickAssist();
+ this.completionShell= CompletionTest.findNewShell(beforeShells, editor.getSite().getShell().getDisplay());
+ final Table completionProposalList = CompletionTest.findCompletionSelectionControl(completionShell);
+ checkCompletionContent(completionProposalList);
+ }
+
+ private void openQuickAssist() {
+ editor.selectAndReveal(3, 0);
+ TextOperationAction action = (TextOperationAction) editor.getAction(ITextEditorActionConstants.QUICK_ASSIST);
+ action.update();
+ action.run();
+ waitAndDispatch(100);
+ }
+
+ /**
+ * Checks that a mock quick assist proposal comes up
+ * @param completionProposalList the quick assist proposal list
+ */
+ private void checkCompletionContent(final Table completionProposalList) {
+ // should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
+ new DisplayHelper() {
+ @Override
+ protected boolean condition() {
+ return completionProposalList.getItemCount() == 1;
+ }
+ }.waitForCondition(completionProposalList.getDisplay(), 200);
+ assertEquals(1, completionProposalList.getItemCount());
+ final TableItem quickAssistItem = completionProposalList.getItem(0);
+ assertTrue("Missing quick assist proposal", quickAssistItem.getText().contains("QUICK ASSIST PROPOSAL")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ }
+
+
+ @After
+ public void closeShell() {
+ if (this.completionShell != null && !completionShell.isDisposed()) {
+ completionShell.close();
+ }
+ }
+}
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/MockQuickAssistProcessor.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/MockQuickAssistProcessor.java
new file mode 100644
index 000000000..4b46e2517
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/MockQuickAssistProcessor.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Red Hat Inc. and others
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Andrew Obuchowicz (Red Hat Inc.)
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.tests.contributions;
+
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
+import org.eclipse.jface.text.quickassist.IQuickAssistProcessor;
+import org.eclipse.jface.text.source.Annotation;
+
+public class MockQuickAssistProcessor implements IQuickAssistProcessor{
+
+ @Override
+ public String getErrorMessage() {
+ return "A MOCK ERROR MESSAGE";
+ }
+
+ @Override
+ public boolean canFix(Annotation annotation) {
+ return true;
+ }
+
+ @Override
+ public boolean canAssist(IQuickAssistInvocationContext invocationContext) {
+ return true;
+ }
+
+ @Override
+ public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
+ CompletionProposal proposal = new CompletionProposal("QUICK ASSIST PROPOSAL", 0, 10, 0);
+ ICompletionProposal[] proposals = {proposal};
+ return proposals;
+ }
+
+}

Back to the top