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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations