Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2017-05-18 08:47:18 -0400
committerMickael Istria2017-09-06 16:32:56 -0400
commit55c3acdef4f74ecddae3e3f6c89fdb691c2c64ad (patch)
tree42a38a3a5f0fc5c634a8797b753f4f380566569f /org.eclipse.ui.genericeditor.tests
parentb3ee795c0b366f5254afb46c633640b78bb06a0a (diff)
downloadeclipse.platform.text-55c3acdef4f74ecddae3e3f6c89fdb691c2c64ad.tar.gz
eclipse.platform.text-55c3acdef4f74ecddae3e3f6c89fdb691c2c64ad.tar.xz
eclipse.platform.text-55c3acdef4f74ecddae3e3f6c89fdb691c2c64ad.zip
Bug 513321 - Aggregate mutliple hover sources
Change-Id: I3cc1fe523f1db9f55095e587ea05a88b1f89dfaa Signed-off-by: Mickael Istria <mistria@redhat.com>
Diffstat (limited to 'org.eclipse.ui.genericeditor.tests')
-rw-r--r--org.eclipse.ui.genericeditor.tests/plugin.xml22
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java41
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java39
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/AlrightyHoverProvider.java (renamed from org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/MagicHoverProvider.java)2
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/HelloHoverProvider.java38
5 files changed, 120 insertions, 22 deletions
diff --git a/org.eclipse.ui.genericeditor.tests/plugin.xml b/org.eclipse.ui.genericeditor.tests/plugin.xml
index d2c3f4580..c7ce8e9b8 100644
--- a/org.eclipse.ui.genericeditor.tests/plugin.xml
+++ b/org.eclipse.ui.genericeditor.tests/plugin.xml
@@ -26,9 +26,13 @@
<extension
point="org.eclipse.ui.genericeditor.hoverProviders">
<hoverProvider
- class="org.eclipse.ui.genericeditor.tests.contributions.MagicHoverProvider"
+ class="org.eclipse.ui.genericeditor.tests.contributions.AlrightyHoverProvider"
contentType="org.eclipse.ui.genericeditor.tests.content-type">
</hoverProvider>
+ <hoverProvider
+ class="org.eclipse.ui.genericeditor.tests.contributions.HelloHoverProvider"
+ contentType="org.eclipse.ui.genericeditor.tests.specialized-content-type-bartxt">
+ </hoverProvider>
</extension>
<extension
point="org.eclipse.ui.genericeditor.reconcilers">
@@ -36,11 +40,11 @@
class="org.eclipse.ui.genericeditor.tests.contributions.TheReconcilerFirst"
contentType="org.eclipse.core.runtime.text">
</reconciler>
- <reconciler
- class="org.eclipse.ui.genericeditor.tests.contributions.TheReconcilerSecond"
- contentType="org.eclipse.ui.genericeditor.tests.reconciled-content-type">
- </reconciler>
- </extension>
+ <reconciler
+ class="org.eclipse.ui.genericeditor.tests.contributions.TheReconcilerSecond"
+ contentType="org.eclipse.ui.genericeditor.tests.specialized-content-type-bartxt">
+ </reconciler>
+ </extension>
<extension
point="org.eclipse.ui.genericeditor.presentationReconcilers">
<presentationReconciler
@@ -80,10 +84,10 @@
priority="normal">
</content-type>
<content-type
- base-type="org.eclipse.core.runtime.text"
+ base-type="org.eclipse.ui.genericeditor.tests.content-type"
file-names="bar.txt"
- id="org.eclipse.ui.genericeditor.tests.reconciled-content-type"
- name="Generic Editor Reconciler Test content-type"
+ id="org.eclipse.ui.genericeditor.tests.specialized-content-type-bartxt"
+ name="Specialized Generic Editor content-type for &apos;bar.txt&apos;"
priority="normal">
</content-type>
</extension>
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java
index 6d12a6f54..2d31f0ad0 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AbstratGenericEditorTest.java
@@ -17,6 +17,8 @@ import org.junit.Before;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.core.runtime.NullProgressMonitor;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -47,17 +49,42 @@ public class AbstratGenericEditorTest {
project = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis());
project.create(null);
project.open(null);
- file = project.getFile("foo.txt");
- file.create(new ByteArrayInputStream("bar 'bar'".getBytes()), true, null);
- editor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getActivePage().openEditor(new FileEditorInput(this.file), "org.eclipse.ui.genericeditor.GenericEditor");
+ createAndOpenFile("foo.txt", "bar 'bar'");
}
+
+ /**
+ * Creates a new file in the project, opens it, and associate that file with the test state
+ * @param name name of the file in the project
+ * @param contents content of the file
+ * @throws Exception ex
+ * @since 1.1
+ */
+ protected void createAndOpenFile(String name, String contents) throws Exception {
+ this.file = project.getFile(name);
+ this.file.create(new ByteArrayInputStream(contents.getBytes()), true, null);
+ this.editor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().openEditor(new FileEditorInput(this.file), "org.eclipse.ui.genericeditor.GenericEditor");
+ }
- @After
- public void tearDown() throws Exception {
+ /**
+ * Closes editor and delete file. Keeps project open.
+ * @throws Exception ex
+ * @since 1.1
+ */
+ protected void cleanFileAndEditor() throws Exception {
+ if (editor != null) {
+ editor.close(false);
+ editor = null;
+ }
if (file != null) {
- file.delete(true, null);
+ file.delete(true, new NullProgressMonitor());
+ file = null;
}
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ cleanFileAndEditor();
if (project != null) {
project.delete(true, null);
}
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java
index a92fea669..e234e340a 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java
@@ -10,13 +10,14 @@
*******************************************************************************/
package org.eclipse.ui.genericeditor.tests;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Collections;
+import java.util.Map;
import org.junit.Assume;
import org.junit.Before;
@@ -46,7 +47,8 @@ import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.tests.util.DisplayHelper;
-import org.eclipse.ui.genericeditor.tests.contributions.MagicHoverProvider;
+import org.eclipse.ui.genericeditor.tests.contributions.AlrightyHoverProvider;
+import org.eclipse.ui.genericeditor.tests.contributions.HelloHoverProvider;
import org.eclipse.ui.genericeditor.tests.contributions.MarkerResolutionGenerator;
import org.eclipse.ui.workbench.texteditor.tests.ScreenshotTest;
@@ -67,9 +69,23 @@ public class HoverTest extends AbstratGenericEditorTest {
}
@Test
- public void testHover() throws Exception {
+ public void testSingleHover() throws Exception {
Shell shell = getHoverShell(triggerCompletionAndRetrieveInformationControlManager());
- assertNotNull(findControl(shell, StyledText.class, MagicHoverProvider.LABEL));
+ assertNotNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL));
+ assertNull(findControl(shell, StyledText.class, HelloHoverProvider.LABEL));
+ }
+
+ /**
+ * @throws Exception ex
+ * @since 1.1
+ */
+ @Test
+ public void testMultipleHover() throws Exception {
+ cleanFileAndEditor();
+ createAndOpenFile("bar.txt", "Hi");
+ Shell shell = getHoverShell(triggerCompletionAndRetrieveInformationControlManager());
+ assertNotNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL));
+ assertNotNull(findControl(shell, StyledText.class, HelloHoverProvider.LABEL));
}
@Test
@@ -85,10 +101,17 @@ public class HoverTest extends AbstratGenericEditorTest {
marker.setAttribute(IMarker.MESSAGE, problemMessage);
marker.setAttribute(MarkerResolutionGenerator.FIXME, true);
AbstractInformationControlManager manager = triggerCompletionAndRetrieveInformationControlManager();
- assertEquals(Collections.singletonList(marker), getHoverData(manager));
+ Object hoverData = getHoverData(manager);
+ assertTrue(hoverData instanceof Map);
+ assertTrue(((Map<?,?>)hoverData).containsValue(Collections.singletonList(marker)));
+ assertTrue(((Map<?,?>)hoverData).containsValue(AlrightyHoverProvider.LABEL));
+ assertFalse(((Map<?,?>)hoverData).containsValue(HelloHoverProvider.LABEL));
// check dialog content
Shell shell= getHoverShell(manager);
assertNotNull(findControl(shell, Label.class, marker.getAttribute(IMarker.MESSAGE, "NONE")));
+ assertNotNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL));
+ assertNull(findControl(shell, StyledText.class, HelloHoverProvider.LABEL));
+ // check quick-fix works
Link link = findControl(shell, Link.class, MarkerResolutionGenerator.FIXME);
assertNotNull(link);
Event event = new Event();
@@ -126,6 +149,12 @@ public class HoverTest extends AbstratGenericEditorTest {
fail();
}
Shell shell = (Shell)new Accessor(control[0], AbstractInformationControl.class).get("fShell");
+ new DisplayHelper() {
+ @Override
+ protected boolean condition() {
+ return shell.isVisible();
+ }
+ }.waitForCondition(this.editor.getSite().getShell().getDisplay(), 2000);
assertTrue(shell.isVisible());
return shell;
}
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/MagicHoverProvider.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/AlrightyHoverProvider.java
index 0bba76cf9..726036e6d 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/MagicHoverProvider.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/AlrightyHoverProvider.java
@@ -16,7 +16,7 @@ import org.eclipse.jface.text.ITextHoverExtension2;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
-public class MagicHoverProvider implements ITextHover,ITextHoverExtension2 {
+public class AlrightyHoverProvider implements ITextHover,ITextHoverExtension2 {
public static final String LABEL= "Alrighty!";
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/HelloHoverProvider.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/HelloHoverProvider.java
new file mode 100644
index 000000000..12f53196e
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/HelloHoverProvider.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Red Hat Inc. and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mickael Istria (Red Hat Inc.)
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.tests.contributions;
+
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.ITextHoverExtension2;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Region;
+
+public class HelloHoverProvider implements ITextHover, ITextHoverExtension2 {
+
+ public static final String LABEL= "Hello!";
+
+ @Deprecated
+ @Override
+ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
+ return null;
+ }
+
+ @Override
+ public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
+ return new Region(0, textViewer.getTextWidget().getText().length());
+ }
+
+ @Override
+ public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
+ return LABEL;
+ }
+}

Back to the top