use of org.eclipse.jface.text.hyperlink.IHyperlink in project xtext-xtend by eclipse.
the class DetectImplHyperlinksTest method testComputeHyperlink_1.
@Test
public void testComputeHyperlink_1() throws Exception {
String content = "package foo class Foo { def b|ar(String a) {} }";
XtextEditor xtextEditor = openEditor(content.replace("|", ""));
int offset = content.indexOf("|");
IHyperlink[] detectHyperlinks = hyperlinkDetector.detectHyperlinks(xtextEditor.getInternalSourceViewer(), new Region(offset, 1), true);
assertEquals(2, detectHyperlinks.length);
IHyperlink hyperlink = detectHyperlinks[0];
assertTrue(hyperlink instanceof JdtHyperlink);
JdtHyperlink casted = (JdtHyperlink) hyperlink;
assertEquals(offset - 1, casted.getHyperlinkRegion().getOffset());
assertEquals(3, casted.getHyperlinkRegion().getLength());
IJavaElement element = ((JdtHyperlink) hyperlink).getJavaElement();
assertTrue(element instanceof IType);
assertEquals("Object", element.getElementName());
assertEquals("Open Inferred Type - Object", casted.getHyperlinkText());
}
use of org.eclipse.jface.text.hyperlink.IHyperlink in project xtext-xtend by eclipse.
the class OpenImplHyperlinksTest method testComputeHyperlink_1.
@Test
public void testComputeHyperlink_1() throws Exception {
String content = "package foo class Foo implements IBar { override bar(String a) { b|ar('foo') } } interface IBar { def String bar(String a) }";
XtextEditor xtextEditor = openEditor(content.replace("|", ""));
int offset = content.indexOf("|");
IHyperlink[] detectHyperlinks = hyperlinkDetector.detectHyperlinks(xtextEditor.getInternalSourceViewer(), new Region(offset, 1), true);
XbaseImplementatorsHyperlink casted = null;
for (IHyperlink iHyperlink : detectHyperlinks) {
if (iHyperlink instanceof XbaseImplementatorsHyperlink) {
casted = (XbaseImplementatorsHyperlink) iHyperlink;
}
}
@SuppressWarnings("null") Field field = casted.getClass().getDeclaredField("opener");
field.setAccessible(true);
TestJvmImplementationOpener testOpener = new TestJvmImplementationOpener();
field.set(casted, testOpener);
casted.open();
assertTrue(testOpener.isOpenInEditor);
assertFalse(testOpener.isOpenQuickHierarchy);
}
use of org.eclipse.jface.text.hyperlink.IHyperlink in project xtext-xtend by eclipse.
the class OpenImplHyperlinksTest method testComputeHyperlink_2.
@Test
public void testComputeHyperlink_2() throws Exception {
String content = "package foo interface IBar {def void bar(String a)} class Foo implements IBar { override bar(String a){ val IBar x = null; x.b|ar('foo'} } class Foo2 implements IBar { override bar(String a) {} }";
XtextEditor xtextEditor = openEditor(content.replace("|", ""));
int offset = content.indexOf("|");
IHyperlink[] detectHyperlinks = hyperlinkDetector.detectHyperlinks(xtextEditor.getInternalSourceViewer(), new Region(offset, 1), true);
XbaseImplementatorsHyperlink casted = null;
for (IHyperlink iHyperlink : detectHyperlinks) {
if (iHyperlink instanceof XbaseImplementatorsHyperlink) {
casted = (XbaseImplementatorsHyperlink) iHyperlink;
}
}
@SuppressWarnings("null") Field field = casted.getClass().getDeclaredField("opener");
field.setAccessible(true);
TestJvmImplementationOpener testOpener = new TestJvmImplementationOpener();
field.set(casted, testOpener);
casted.open();
assertFalse(testOpener.isOpenInEditor);
assertTrue(testOpener.isOpenQuickHierarchy);
}
use of org.eclipse.jface.text.hyperlink.IHyperlink in project linuxtools by eclipse.
the class MailHyperlinkDetectorTest method testDetectHyperlinksNoRegionAndTextViewer.
@Test
public void testDetectHyperlinksNoRegionAndTextViewer() {
MailHyperlinkDetector elementDetector = new MailHyperlinkDetector();
elementDetector.setEditor(editor);
IHyperlink[] returned = elementDetector.detectHyperlinks(null, null, false);
assertNull(returned);
}
use of org.eclipse.jface.text.hyperlink.IHyperlink in project linuxtools by eclipse.
the class SourcesFileHyperlinkDetectorTest method testDetectHyperlinksNoRegionAndTextViewer.
@Test
public void testDetectHyperlinksNoRegionAndTextViewer() {
SourcesFileHyperlinkDetector elementDetector = new SourcesFileHyperlinkDetector();
elementDetector.setEditor(editor);
IHyperlink[] returned = elementDetector.detectHyperlinks(null, null, false);
assertNull(returned);
}
Aggregations