Search in sources :

Example 6 with IHyperlink

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

the class HyperlinkingTest method testOpenInferredType_on_any.

// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=463247
@Test
public void testOpenInferredType_on_any() throws Exception {
    String modelAsString = "class Baz { def void foo() { var myVar=null 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);
    assertNull(hyperlinks);
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 7 with IHyperlink

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

the class HyperlinkingTest method testOpenInferredTypeOnReference.

@Test
public void testOpenInferredTypeOnReference() throws Exception {
    String modelAsString = "class Baz { def void foo() { var myVar='' 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 - String myVar", hyperlinks[0].getHyperlinkText());
    assertEquals("Open Variable Type - String", hyperlinks[1].getHyperlinkText());
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 8 with IHyperlink

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

the class HyperlinkingTest method testTypeLiteral.

@Test
public void testTypeLiteral() throws Exception {
    String modelAsString = "class C { val x = java.lang.String }";
    XtextResource resource = (XtextResource) testHelper.xtendFile("C", modelAsString).eResource();
    IHyperlink[] hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, modelAsString.indexOf("String"), true);
    assertEquals(1, hyperlinks.length);
    assertEquals("String", hyperlinks[0].getHyperlinkText());
    assertEquals(modelAsString.indexOf("java"), hyperlinks[0].getHyperlinkRegion().getOffset());
    assertEquals("java.lang.String".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 9 with IHyperlink

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

the class HyperlinkingTest method testConstructor.

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

Example 10 with IHyperlink

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

the class HyperlinkingTest method testReturnTypeLabel.

@Test
public void testReturnTypeLabel() throws Exception {
    String modelAsString = "class Baz {def Baz meth(Baz baz, String str) { var vv='' x = baz j = str vv=j x.meth(baz,str) } var x = new Baz var j = '' }";
    XtextResource resource = (XtextResource) testHelper.xtendFile("Baz", modelAsString).eResource();
    int indexOf_x_FieldRef = modelAsString.indexOf("x");
    IHyperlink[] hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_x_FieldRef, true);
    assertEquals(2, hyperlinks.length);
    assertEquals("Open Declaration - x : Baz", hyperlinks[0].getHyperlinkText());
    assertEquals("Open Field Type - Baz", hyperlinks[1].getHyperlinkText());
    int indexOf_Baz_ParamRef = modelAsString.indexOf("baz", indexOf_x_FieldRef);
    hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_Baz_ParamRef, true);
    assertEquals(2, hyperlinks.length);
    assertEquals("Open Declaration - Baz baz", hyperlinks[0].getHyperlinkText());
    assertEquals("Open Parameter Type - Baz", hyperlinks[1].getHyperlinkText());
    int indexOf_j_FieldRef = modelAsString.indexOf("j", indexOf_Baz_ParamRef);
    hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_j_FieldRef, true);
    assertEquals(2, hyperlinks.length);
    assertEquals("Open Declaration - j : String", hyperlinks[0].getHyperlinkText());
    assertEquals("Open Field Type - String", hyperlinks[1].getHyperlinkText());
    assertEquals("String", ((JdtHyperlink) hyperlinks[1]).getJavaElement().getElementName());
    int indexOf_vv_VarRef = modelAsString.indexOf("vv", indexOf_j_FieldRef);
    hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_vv_VarRef, true);
    assertEquals(2, hyperlinks.length);
    assertEquals("Open Declaration - String vv", hyperlinks[0].getHyperlinkText());
    assertEquals("Open Variable Type - String", hyperlinks[1].getHyperlinkText());
    int indexOf_meth_MethodeCall = modelAsString.indexOf("meth", indexOf_vv_VarRef);
    hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_meth_MethodeCall, true);
    assertEquals(2, hyperlinks.length);
    assertEquals("Open Declaration - meth(Baz, String) : Baz", hyperlinks[0].getHyperlinkText());
    assertEquals("Open Return Type - Baz", hyperlinks[1].getHyperlinkText());
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) XtextResource(org.eclipse.xtext.resource.XtextResource) JdtHyperlink(org.eclipse.xtext.common.types.xtext.ui.JdtHyperlink) 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