Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2019-06-24 09:04:05 -0400
committerMickael Istria2019-09-16 03:42:13 -0400
commitb706c681d2e1dedf9cff05eb1a366db762abc8be (patch)
tree14c8e47e2756a474ec2f6cdb0ff4c6cfb2b836d9
parentac2adad7a6d0be0fc28293d34900f45781810acd (diff)
downloadeclipse.platform.text-b706c681d2e1dedf9cff05eb1a366db762abc8be.tar.gz
eclipse.platform.text-b706c681d2e1dedf9cff05eb1a366db762abc8be.tar.xz
eclipse.platform.text-b706c681d2e1dedf9cff05eb1a366db762abc8be.zip
Bug 547683 - Add non-UI Thread access to last known selection
Adds ITextViewerExtension9.getLastKnownSelection() method that gives access to last known value for the selection without requiring UI Thread. The new Generic Editor test case shows how this can be leveraged in ContentAssistProcessors. Change-Id: I8a4831c08f7ff1ade07f2a12ad8d0d2c682a372c Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.jface.text.tests/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.jface.text.tests/pom.xml2
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java99
-rw-r--r--org.eclipse.jface.text/.settings/.api_filters24
-rw-r--r--org.eclipse.jface.text/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jface.text/pom.xml2
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/BlockTextSelection.java25
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension9.java38
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java31
-rw-r--r--org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.ui.genericeditor.tests/plugin.xml4
-rw-r--r--org.eclipse.ui.genericeditor.tests/pom.xml2
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java26
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/ToUpperCaseContentAssistProcessor.java71
14 files changed, 320 insertions, 14 deletions
diff --git a/org.eclipse.jface.text.tests/META-INF/MANIFEST.MF b/org.eclipse.jface.text.tests/META-INF/MANIFEST.MF
index 1a42f6042..38d402f01 100644
--- a/org.eclipse.jface.text.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jface.text.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.jface.text.tests
-Bundle-Version: 3.11.800.qualifier
+Bundle-Version: 3.11.900.qualifier
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Export-Package:
@@ -16,7 +16,7 @@ Export-Package:
org.eclipse.jface.text.tests.templates.persistence,
org.eclipse.jface.text.tests.util
Require-Bundle:
- org.eclipse.jface.text;bundle-version="[3.5.0,4.0.0)",
+ org.eclipse.jface.text;bundle-version="[3.16.0,4.0.0)",
org.eclipse.jface;bundle-version="[3.5.0,4.0.0)",
org.junit;bundle-version="4.12.0",
org.eclipse.text.tests;bundle-version="[3.5.0,4.0.0)",
diff --git a/org.eclipse.jface.text.tests/pom.xml b/org.eclipse.jface.text.tests/pom.xml
index 805ed7bf7..3b95c9730 100644
--- a/org.eclipse.jface.text.tests/pom.xml
+++ b/org.eclipse.jface.text.tests/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.jface</groupId>
<artifactId>org.eclipse.jface.text.tests</artifactId>
- <version>3.11.800-SNAPSHOT</version>
+ <version>3.11.900-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<testSuite>${project.artifactId}</testSuite>
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
index 2b2dd2e68..a53a00dfc 100644
--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
@@ -11,7 +11,7 @@
* Contributors:
* Sergey Prigogin (Google) - initial API and implementation
* Mickael Istria (Red Hat Inc.) - [Bug 544708] Ctrl+Home
- * Paul Pazderski - [Bug 545530] Test for TextViewer's default IDocumentAdapter implementation.
+ * Paul Pazderski - [Bug 545530] Test for TextViewer's default IDocumentAdapter implementation.
*******************************************************************************/
package org.eclipse.jface.text.tests;
@@ -27,6 +27,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.custom.StyledTextContent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Control;
@@ -35,10 +36,16 @@ import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+
import org.eclipse.jface.util.Util;
+import org.eclipse.jface.text.BlockTextSelection;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocumentAdapter;
+import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.source.SourceViewer;
@@ -76,6 +83,96 @@ public class TextViewerTest {
}
@Test
+ public void testCaretMoveChangesSelection() throws Exception {
+ Shell shell= new Shell();
+ try {
+ TextViewer textViewer= new TextViewer(shell, SWT.NONE);
+ Document document= new Document("abc");
+ textViewer.setDocument(document);
+ int len= document.getLength();
+ // Select the whole document with the caret at the beginning.
+ textViewer.setSelectedRange(0, len);
+ ITextSelection selection = (ITextSelection)textViewer.getSelectionProvider().getSelection();
+ assertEquals(0, selection.getOffset());
+ assertEquals(len, selection.getLength());
+ textViewer.getTextWidget().setCaretOffset(1);
+ selection = (ITextSelection)textViewer.getSelectionProvider().getSelection();
+ assertEquals(1, selection.getOffset());
+ assertEquals(0, selection.getLength());
+ } finally {
+ shell.dispose();
+ }
+ }
+
+ @Test
+ public void testGetCachedSelection() throws Exception {
+ Shell shell= new Shell();
+ try {
+ TextViewer textViewer= new TextViewer(shell, SWT.NONE);
+ Document document= new Document("abc");
+ textViewer.setDocument(document);
+ int len= document.getLength();
+ // Select the whole document with the caret at the beginning.
+ textViewer.setSelectedRange(0, len);
+ checkInAndOutUIThread(() -> {
+ ITextSelection selection = textViewer.getLastKnownSelection();
+ assertEquals(0, selection.getOffset());
+ assertEquals(len, selection.getLength());
+ });
+ } finally {
+ shell.dispose();
+ }
+ }
+
+ @Test
+ public void testBlockSelectionAccessors() throws Exception {
+ Shell shell= new Shell();
+ try {
+ ITextViewer textViewer= new TextViewer(shell, SWT.NONE);
+ Document document= new Document("0123\n4567\n89ab\ncdef");
+ textViewer.setDocument(document);
+ // Select the whole document with the caret at the beginning.
+ StyledText textWidget= textViewer.getTextWidget();
+ textWidget.setBlockSelection(true);
+ shell.setLayout(new FillLayout());
+ shell.open();
+ textViewer.getSelectionProvider().setSelection(new BlockTextSelection(textViewer.getDocument(), 1, 1, 2, 2, textWidget.getTabs()));
+ BlockTextSelection sel = (BlockTextSelection)textViewer.getSelectionProvider().getSelection();
+ assertEquals(1, sel.getStartLine());
+ assertEquals(2, sel.getEndLine());
+ assertEquals(1, sel.getStartColumn());
+ assertEquals(2, sel.getEndColumn());
+ } finally {
+ shell.dispose();
+ }
+ }
+
+
+ private void checkInAndOutUIThread(Runnable r) throws InterruptedException {
+ // first run in UI Thread, forward exceptions
+ r.run();
+ // then run in non-UI Thread
+ Job job = Job.create("Check in non-UI Thread", monitor -> {
+ try {
+ r.run();
+ return Status.OK_STATUS;
+ } catch (Throwable t) {
+ return new Status(IStatus.ERROR, "org.eclipse.jface.text.tests", t.getMessage(), t);
+ }
+ });
+ job.schedule();
+ job.join();
+ if (!job.getResult().isOK()) {
+ Throwable ex = job.getResult().getException();
+ if (ex != null) {
+ throw new AssertionError("Assertion fail in non-UI Thread", ex);
+ } else {
+ fail(job.getResult().toString());
+ }
+ }
+ }
+
+ @Test
public void testCtrlHomeViewportListener() {
Assume.assumeFalse("See bug 541415. For whatever reason, this shortcut doesn't work on Mac", Util.isMac());
Shell shell= new Shell();
diff --git a/org.eclipse.jface.text/.settings/.api_filters b/org.eclipse.jface.text/.settings/.api_filters
index 139627742..9a61dee5d 100644
--- a/org.eclipse.jface.text/.settings/.api_filters
+++ b/org.eclipse.jface.text/.settings/.api_filters
@@ -1,5 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.jface.text" version="2">
+ <resource path="src/META-INF/MANIFEST.MF">
+ <filter comment="Workaround https://bugs.eclipse.org/bugs/show_bug.cgi?id=548680#c11" id="926941240">
+ <message_arguments>
+ <message_argument value="3.16.0"/>
+ <message_argument value="3.15.200"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/META-INF/MANIFEST.MF">
+ <filter comment="Workaround https://bugs.eclipse.org/bugs/show_bug.cgi?id=548680#c11" id="923795461">
+ <message_arguments>
+ <message_argument value="3.16.0"/>
+ <message_argument value="3.15.200"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/jface/text/ITextViewer.java" type="org.eclipse.jface.text.ITextViewer">
+ <filter comment="Method introduction unlikely to collide with existing implementations." id="404000815">
+ <message_arguments>
+ <message_argument value="org.eclipse.jface.text.ITextViewer"/>
+ <message_argument value="getLastKnownSelection()"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/jface/text/TextViewer.java" type="org.eclipse.jface.text.TextViewer">
<filter id="572522506">
<message_arguments>
diff --git a/org.eclipse.jface.text/META-INF/MANIFEST.MF b/org.eclipse.jface.text/META-INF/MANIFEST.MF
index 861f47e4a..38c33e543 100644
--- a/org.eclipse.jface.text/META-INF/MANIFEST.MF
+++ b/org.eclipse.jface.text/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jface.text
-Bundle-Version: 3.15.400.qualifier
+Bundle-Version: 3.16.0.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package:
diff --git a/org.eclipse.jface.text/pom.xml b/org.eclipse.jface.text/pom.xml
index ddbe958b9..3c59bdaaa 100644
--- a/org.eclipse.jface.text/pom.xml
+++ b/org.eclipse.jface.text/pom.xml
@@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.jface</groupId>
<artifactId>org.eclipse.jface.text</artifactId>
- <version>3.15.400-SNAPSHOT</version>
+ <version>3.16.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/BlockTextSelection.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/BlockTextSelection.java
index 473695266..d75a296aa 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/BlockTextSelection.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/BlockTextSelection.java
@@ -159,4 +159,29 @@ public class BlockTextSelection extends TextSelection implements IBlockTextSelec
}
return new IRegion[] {new Region(getOffset(), getLength())};
}
+
+ /**
+ * @since 3.16
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb= new StringBuilder();
+ sb.append("BlockTextSelection [offset: ").append(getOffset()); //$NON-NLS-1$
+ sb.append(", startLine: ").append(fStartLine); //$NON-NLS-1$
+ if (fEndLine != fStartLine) {
+ sb.append(", endLine: ").append(fEndLine); //$NON-NLS-1$
+ }
+ sb.append(", startColumn: ").append(fStartColumn); //$NON-NLS-1$
+ if (fEndColumn != fStartColumn) {
+ sb.append(", endColumn").append(fEndColumn); //$NON-NLS-1$
+ }
+ if (getLength() != 0) {
+ sb.append(", text: ").append(getText()); //$NON-NLS-1$
+ }
+ if (getDocument() != null) {
+ sb.append(", document: ").append(getDocument()); //$NON-NLS-1$
+ }
+ sb.append("]"); //$NON-NLS-1$
+ return sb.toString();
+ }
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension9.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension9.java
new file mode 100644
index 000000000..c26d7e820
--- /dev/null
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension9.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+package org.eclipse.jface.text;
+
+import org.eclipse.jface.viewers.ISelectionProvider;
+
+/**
+ * Extension interface for {@link org.eclipse.jface.text.ITextViewer}. Adds the ability to retrieve
+ * the last known selection from outside of the UI Thread.
+ *
+ * @since 3.16
+ */
+public interface ITextViewerExtension9 {
+
+
+ /**
+ * Returns the last known selection from a cache, without polling widget.
+ * <p>
+ * This may <strong>not</strong> be the current selection. Indeed, operations that change the
+ * selection without sending related events may not refresh the returned value.
+ * </p>
+ * <p>
+ * As opposed to {@link ISelectionProvider#getSelection()} that usually requires UI Thread, this
+ * method can run from any thread.
+ * </p>
+ *
+ * @return the last known selection.
+ */
+ public ITextSelection getLastKnownSelection();
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
index 27ae2c3b0..9a274e3d9 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
@@ -113,7 +113,7 @@ import org.eclipse.jface.text.projection.ChildDocumentManager;
* @noextend This class is not intended to be subclassed by clients.
*/
public class TextViewer extends Viewer implements
- ITextViewer, ITextViewerExtension, ITextViewerExtension2, ITextViewerExtension4, ITextViewerExtension6, ITextViewerExtension7, ITextViewerExtension8,
+ ITextViewer, ITextViewerExtension, ITextViewerExtension2, ITextViewerExtension4, ITextViewerExtension6, ITextViewerExtension7, ITextViewerExtension8, ITextViewerExtension9,
IEditingSupportRegistry, ITextOperationTarget, ITextOperationTargetExtension,
IWidgetTokenOwner, IWidgetTokenOwnerExtension, IPostSelectionProvider {
@@ -1752,6 +1752,12 @@ public class TextViewer extends Viewer implements
selectionChanged(event.x, event.y - event.x);
}
});
+ fTextWidget.addCaretListener(e -> {
+ // caret listener is invoked before widget actually performs the caret (and selection)
+ // change. So we can't update the selection synchronously on event, instead, we
+ // delay the selection update.
+ fTextWidget.getDisplay().asyncExec(() -> selectionChanged(e.caretOffset, 0));
+ });
fCursorListener= new CursorListener();
fCursorListener.install();
@@ -2234,6 +2240,21 @@ public class TextViewer extends Viewer implements
//---- Selection
+ /**
+ * Caches the selection value. Is only modified from inside UI Thread. Can be accessed from any
+ * thread.
+ */
+ private volatile ITextSelection cachedSelection= TextSelection.emptySelection();
+
+ private void updateSelectionCache() {
+ cachedSelection= computeSelection();
+ }
+
+ @Override
+ public ITextSelection getLastKnownSelection() {
+ return cachedSelection;
+ }
+
@Override
public Point getSelectedRange() {
@@ -2272,6 +2293,7 @@ public class TextViewer extends Viewer implements
selectionChanged(selectionRange[0], selectionRange[1]);
}
}
+ updateSelectionCache();
}
/**
@@ -2410,6 +2432,12 @@ public class TextViewer extends Viewer implements
@Override
public ISelection getSelection() {
+ final ITextSelection res= computeSelection();
+ cachedSelection= res;
+ return res;
+ }
+
+ private ITextSelection computeSelection() {
if (fTextWidget != null && fTextWidget.getBlockSelection()) {
int[] ranges= fTextWidget.getSelectionRanges();
int startOffset= ranges[0];
@@ -2574,6 +2602,7 @@ public class TextViewer extends Viewer implements
* @param length the length of the newly selected range in the visible document
*/
protected void selectionChanged(int offset, int length) {
+ updateSelectionCache();
queuePostSelectionChanged(true);
fireSelectionChanged(offset, length);
}
diff --git a/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF b/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF
index a9071960a..a2dcaad22 100644
--- a/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.ui.genericeditor.tests;singleton:=true
-Bundle-Version: 1.1.400.qualifier
+Bundle-Version: 1.1.500.qualifier
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.ui.genericeditor.tests,
@@ -13,7 +13,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
org.eclipse.text;bundle-version="[3.5.0,4.0.0)",
org.eclipse.ui.genericeditor,
org.eclipse.core.resources;bundle-version="3.11.0",
- org.eclipse.jface.text;bundle-version="3.11.0",
+ org.eclipse.jface.text;bundle-version="3.16.0",
org.eclipse.ui;bundle-version="3.108.0",
org.eclipse.ui.workbench.texteditor;bundle-version="3.10.0",
org.eclipse.ui.ide;bundle-version="3.11.0",
diff --git a/org.eclipse.ui.genericeditor.tests/plugin.xml b/org.eclipse.ui.genericeditor.tests/plugin.xml
index c2a259aa1..2bf886673 100644
--- a/org.eclipse.ui.genericeditor.tests/plugin.xml
+++ b/org.eclipse.ui.genericeditor.tests/plugin.xml
@@ -35,6 +35,10 @@
</test>
</enabledWhen>
</contentAssistProcessor>
+ <contentAssistProcessor
+ class="org.eclipse.ui.genericeditor.tests.contributions.ToUpperCaseContentAssistProcessor"
+ contentType="org.eclipse.ui.genericeditor.tests.content-type">
+ </contentAssistProcessor>
</extension>
<extension
point="org.eclipse.ui.genericeditor.hoverProviders">
diff --git a/org.eclipse.ui.genericeditor.tests/pom.xml b/org.eclipse.ui.genericeditor.tests/pom.xml
index 030439183..a417d6d93 100644
--- a/org.eclipse.ui.genericeditor.tests/pom.xml
+++ b/org.eclipse.ui.genericeditor.tests/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.ui</groupId>
<artifactId>org.eclipse.ui.genericeditor.tests</artifactId>
- <version>1.1.400-SNAPSHOT</version>
+ <version>1.1.500-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<testSuite>${project.artifactId}</testSuite>
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 e296de611..d6504cd62 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
@@ -56,6 +56,7 @@ public class CompletionTest extends AbstratGenericEditorTest {
@Test
public void testCompletion() throws Exception {
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);
final Table completionProposalList = findCompletionSelectionControl(completionShell);
@@ -65,11 +66,28 @@ public class CompletionTest extends AbstratGenericEditorTest {
}
@Test
+ public void testCompletionUsingViewerSelection() throws Exception {
+ final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
+ editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("abc");
+ editor.selectAndReveal(0, 3);
+ openConentAssist();
+ this.completionShell= findNewShell(beforeShells);
+ final Table completionProposalList = findCompletionSelectionControl(completionShell);
+ assertTrue(new DisplayHelper() {
+ @Override
+ protected boolean condition() {
+ return Arrays.stream(completionProposalList.getItems()).map(TableItem::getText).anyMatch("ABC"::equals);
+ }
+ }.waitForCondition(completionProposalList.getDisplay(), 200));
+ }
+
+ @Test
public void testEnabledWhenCompletion() throws Exception {
// Confirm that when disabled, a completion shell is present
EnabledPropertyTester.setEnabled(false);
createAndOpenFile("enabledWhen.txt", "bar 'bar'");
final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
+ editor.selectAndReveal(3, 0);
openConentAssist();
Shell[] afterShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells())
.filter(Shell::isVisible)
@@ -82,12 +100,12 @@ public class CompletionTest extends AbstratGenericEditorTest {
EnabledPropertyTester.setEnabled(true);
createAndOpenFile("enabledWhen.txt", "bar 'bar'");
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));
}
private void openConentAssist() {
- editor.selectAndReveal(3, 0);
ContentAssistAction action = (ContentAssistAction) editor.getAction(ITextEditorActionConstants.CONTENT_ASSIST);
action.update();
action.run();
@@ -103,13 +121,12 @@ public class CompletionTest extends AbstratGenericEditorTest {
*/
private void checkCompletionContent(final Table completionProposalList) {
// should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
- new DisplayHelper() {
+ assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return completionProposalList.getItemCount() == 2;
}
- }.waitForCondition(completionProposalList.getDisplay(), 200);
- assertEquals(2, completionProposalList.getItemCount());
+ }.waitForCondition(completionProposalList.getDisplay(), 200));
final TableItem computingItem = completionProposalList.getItem(0);
assertTrue("Missing computing info entry", computingItem.getText().contains("Computing")); //$NON-NLS-1$ //$NON-NLS-2$
TableItem completionProposalItem = completionProposalList.getItem(1);
@@ -142,6 +159,7 @@ public class CompletionTest extends AbstratGenericEditorTest {
@Test
public void testCompletionFreeze_bug521484() throws Exception {
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);
final Table completionProposalList = findCompletionSelectionControl(this.completionShell);
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/ToUpperCaseContentAssistProcessor.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/ToUpperCaseContentAssistProcessor.java
new file mode 100644
index 000000000..9c2b8e56a
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/ToUpperCaseContentAssistProcessor.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.tests.contributions;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.ITextViewerExtension9;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+
+public class ToUpperCaseContentAssistProcessor implements IContentAssistProcessor {
+
+ @Override
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
+ if (!(viewer instanceof ITextViewerExtension9)) {
+ return new ICompletionProposal[0];
+ }
+ ITextSelection selection= ((ITextViewerExtension9)viewer).getLastKnownSelection();
+ if (selection.isEmpty() || selection.getLength() == 0) {
+ return new ICompletionProposal[0];
+ }
+ String initialText;
+ try {
+ initialText= viewer.getDocument().get(selection.getOffset(), selection.getLength());
+ return new ICompletionProposal[] {
+ new CompletionProposal(initialText.toUpperCase(), selection.getOffset(), initialText.length(), selection.getOffset() + initialText.length())
+ };
+ } catch (BadLocationException e) {
+ return new ICompletionProposal[0];
+ }
+
+ }
+
+ @Override
+ public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
+ return new IContextInformation[0];
+ }
+
+ @Override
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ return new char[0];
+ }
+
+ @Override
+ public char[] getContextInformationAutoActivationCharacters() {
+ return new char[0];
+ }
+
+ @Override
+ public String getErrorMessage() {
+ return getClass().getName();
+ }
+
+ @Override
+ public IContextInformationValidator getContextInformationValidator() {
+ return null;
+ }
+
+}

Back to the top