Search in sources :

Example 11 with IHyperlink

use of org.eclipse.jface.text.hyperlink.IHyperlink in project xtext-xtend by eclipse.

the class HyperlinkingTest method testOpenInferredTypeOnReference_01.

@Test
public void testOpenInferredTypeOnReference_01() throws Exception {
    String modelAsString = "class Baz { def void foo() { for (myVar : #[1,2,3]) { println(myVar) } } }";
    XtextResource resource = (XtextResource) testHelper.xtendFile("Baz", modelAsString).eResource();
    int indexOf_x_FieldRef = modelAsString.indexOf("myVar)");
    IHyperlink[] hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_x_FieldRef, true);
    assertEquals(2, hyperlinks.length);
    assertEquals("Open Declaration - myVar", hyperlinks[0].getHyperlinkText());
    assertEquals("Open Variable Type - Integer", hyperlinks[1].getHyperlinkText());
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 12 with IHyperlink

use of org.eclipse.jface.text.hyperlink.IHyperlink in project xtext-xtend by eclipse.

the class HyperlinkingTest method testDispatchMethod.

@Test
public void testDispatchMethod() throws Exception {
    String modelAsString = "class Foo {\n" + "  def bar() { foo(new Object()) }\n" + "  def dispatch foo(Object o) { null }\n" + "  def dispatch foo(String s) { null }\n" + "  def dispatch foo(Number n) { null }\n" + "}";
    XtextResource resource = (XtextResource) testHelper.xtendFile("Foo", modelAsString).eResource();
    IHyperlink[] hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, modelAsString.indexOf("foo"), true);
    assertEquals(4, hyperlinks.length);
    assertEquals("Open Declaration - foo(Number) : Object", hyperlinks[0].getHyperlinkText());
    assertTrue(((XtextHyperlink) hyperlinks[0]).getURI().isPlatformResource());
    assertEquals("Open Declaration - foo(String) : Object", hyperlinks[1].getHyperlinkText());
    assertTrue(((XtextHyperlink) hyperlinks[1]).getURI().isPlatformResource());
    assertEquals("Open Declaration - foo(Object) : Object", hyperlinks[2].getHyperlinkText());
    assertTrue(((XtextHyperlink) hyperlinks[2]).getURI().isPlatformResource());
    assertEquals("Open Return Type - Object", hyperlinks[3].getHyperlinkText());
    assertEquals("Object", ((JdtHyperlink) hyperlinks[3]).getJavaElement().getElementName());
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) XtextHyperlink(org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink) XtextResource(org.eclipse.xtext.resource.XtextResource) JdtHyperlink(org.eclipse.xtext.common.types.xtext.ui.JdtHyperlink) Test(org.junit.Test)

Example 13 with IHyperlink

use of org.eclipse.jface.text.hyperlink.IHyperlink in project xtext-xtend by eclipse.

the class HyperlinkingTest method testOuterTypeLiteralWithDollar.

@Test
public void testOuterTypeLiteralWithDollar() throws Exception {
    String modelAsString = "class C { val x = java.util.Map$Entry }";
    XtextResource resource = (XtextResource) testHelper.xtendFile("C", modelAsString).eResource();
    IHyperlink[] hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, modelAsString.indexOf("Map"), true);
    assertEquals(1, hyperlinks.length);
    assertEquals("Entry<K, V>", hyperlinks[0].getHyperlinkText());
    assertEquals(modelAsString.indexOf("java"), hyperlinks[0].getHyperlinkRegion().getOffset());
    assertEquals("java.util.Map$Entry".length(), hyperlinks[0].getHyperlinkRegion().getLength());
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 14 with IHyperlink

use of org.eclipse.jface.text.hyperlink.IHyperlink in project xtext-xtend by eclipse.

the class HyperlinkingTest method testPlainMethod.

@Test
public void testPlainMethod() throws Exception {
    String modelAsString = "class Foo {\n" + "  def bar() { foo() }\n" + "  def foo() { null }\n" + "}";
    XtextResource resource = (XtextResource) testHelper.xtendFile("Foo", modelAsString).eResource();
    IHyperlink[] hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, modelAsString.indexOf("foo"), true);
    assertEquals(2, hyperlinks.length);
    assertEquals("Open Declaration - foo() : Object", hyperlinks[0].getHyperlinkText());
    assertTrue(((XtextHyperlink) hyperlinks[0]).getURI().isPlatformResource());
    assertEquals("Open Return Type - Object", hyperlinks[1].getHyperlinkText());
    assertEquals("Object", ((JdtHyperlink) hyperlinks[1]).getJavaElement().getElementName());
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) XtextHyperlink(org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink) XtextResource(org.eclipse.xtext.resource.XtextResource) JdtHyperlink(org.eclipse.xtext.common.types.xtext.ui.JdtHyperlink) Test(org.junit.Test)

Example 15 with IHyperlink

use of org.eclipse.jface.text.hyperlink.IHyperlink in project xtext-xtend by eclipse.

the class HyperlinkingTest method testOpenInferredType_01.

@Test
public void testOpenInferredType_01() throws Exception {
    String modelAsString = "class Baz { def void foo() { for (myVar : #[1,2,3]) { println(myVar) } } }";
    XtextResource resource = (XtextResource) testHelper.xtendFile("Baz", modelAsString).eResource();
    int indexOf_x_FieldRef = modelAsString.indexOf("myVar");
    IHyperlink[] hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_x_FieldRef, true);
    assertEquals(1, hyperlinks.length);
    assertEquals("Open Inferred Type - Integer", hyperlinks[0].getHyperlinkText());
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)47 Test (org.junit.Test)35 XtextResource (org.eclipse.xtext.resource.XtextResource)20 IRegion (org.eclipse.jface.text.IRegion)19 Region (org.eclipse.jface.text.Region)19 IEditorPart (org.eclipse.ui.IEditorPart)9 SourcesFileHyperlinkDetector (org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.SourcesFileHyperlinkDetector)5 IFile (org.eclipse.core.resources.IFile)4 JdtHyperlink (org.eclipse.xtext.common.types.xtext.ui.JdtHyperlink)4 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)4 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)4 IDocument (org.eclipse.jface.text.IDocument)3 URLHyperlink (org.eclipse.jface.text.hyperlink.URLHyperlink)3 SpecfileEditor (org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor)3 XtextHyperlink (org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink)3 XbaseImplementatorsHyperlink (org.eclipse.xtext.xbase.ui.navigation.XbaseImplementatorsHyperlink)3 JsonPointer (com.fasterxml.jackson.core.JsonPointer)2 SwaggerHyperlink (com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink)2 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2