use of org.eclipse.xtext.common.types.xtext.ui.JdtHyperlink 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());
}
use of org.eclipse.xtext.common.types.xtext.ui.JdtHyperlink 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());
}
use of org.eclipse.xtext.common.types.xtext.ui.JdtHyperlink 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.common.types.xtext.ui.JdtHyperlink in project xtext-eclipse by eclipse.
the class DomainmodelHyperlinkHelper method createHyperlinksByOffset.
@Override
public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) {
super.createHyperlinksByOffset(resource, offset, acceptor);
EObject eObject = eObjectAtOffsetHelper.resolveElementAt(resource, offset);
if (eObject instanceof Entity) {
List<INode> nodes = NodeModelUtils.findNodesForFeature(eObject, DomainmodelPackage.Literals.ABSTRACT_ELEMENT__NAME);
if (!nodes.isEmpty()) {
INode node = nodes.get(0);
if (node.getOffset() <= offset && node.getOffset() + node.getLength() > offset) {
String qualifiedJavaName = qualifiedNameConverter.toString(qualifiedNameProvider.getFullyQualifiedName(eObject));
if (resource.getResourceSet() instanceof XtextResourceSet) {
XtextResourceSet resourceSet = (XtextResourceSet) resource.getResourceSet();
Object uriContext = resourceSet.getClasspathURIContext();
if (uriContext instanceof IJavaProject) {
IJavaProject javaProject = (IJavaProject) uriContext;
try {
IType type = javaProject.findType(qualifiedJavaName);
if (type != null) {
JdtHyperlink hyperlink = jdtHyperlinkProvider.get();
hyperlink.setJavaElement(type);
hyperlink.setTypeLabel("Navigate to generated source code.");
hyperlink.setHyperlinkText("Go to type " + qualifiedJavaName);
hyperlink.setHyperlinkRegion(new Region(node.getOffset(), node.getLength()));
acceptor.accept(hyperlink);
}
} catch (JavaModelException e) {
logger.error(e.getMessage(), e);
}
}
}
}
}
}
}
use of org.eclipse.xtext.common.types.xtext.ui.JdtHyperlink 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());
}
Aggregations