use of org.eclipse.xtext.resource.XtextResource 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.xtext.resource.XtextResource 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.xtext.resource.XtextResource 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());
}
use of org.eclipse.xtext.resource.XtextResource 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());
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class AbstractCodeBuilder method findByFragment.
protected <T extends EObject> T findByFragment(final XtextResource resource, final T object) {
final Resource myResource = object.eResource();
boolean _equals = Objects.equal(myResource, resource);
if (_equals) {
return object;
}
final String fragment = myResource.getURIFragment(object);
EObject _eObject = resource.getEObject(fragment);
final T result = ((T) _eObject);
return result;
}
Aggregations