use of org.eclipse.xtext.xbase.ui.navigation.XbaseImplementatorsHyperlink in project xtext-xtend by eclipse.
the class DetectImplHyperlinksTest method testComputeHyperlink_2.
@Test
public void testComputeHyperlink_2() throws Exception {
String content = "package foo class Foo { def bar(String a) { fo|o() } def foo(){}}";
XtextEditor xtextEditor = openEditor(content.replace("|", ""));
int offset = content.indexOf("|");
IHyperlink[] detectHyperlinks = hyperlinkDetector.detectHyperlinks(xtextEditor.getInternalSourceViewer(), new Region(offset, 1), true);
assertEquals(3, detectHyperlinks.length);
XbaseImplementatorsHyperlink hyperlink = Iterables.filter(Lists.newArrayList(detectHyperlinks), XbaseImplementatorsHyperlink.class).iterator().next();
assertEquals(offset - 2, hyperlink.getHyperlinkRegion().getOffset());
assertEquals(3, hyperlink.getHyperlinkRegion().getLength());
IJavaElement element = hyperlink.getElement();
assertTrue(element instanceof IMethod);
assertEquals("foo", element.getElementName());
}
use of org.eclipse.xtext.xbase.ui.navigation.XbaseImplementatorsHyperlink in project xtext-xtend by eclipse.
the class XtendHyperlinkHelper method createHyperlinksByOffset.
@Override
public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) {
super.createHyperlinksByOffset(resource, offset, acceptor);
if (canShowMany(acceptor)) {
final EObject element = getEObjectAtOffsetHelper().resolveElementAt(resource, offset);
if (element instanceof XtendField) {
XtendField member = (XtendField) element;
ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
if (isNameNode(member, XtendPackage.Literals.XTEND_FIELD__NAME, node) && member.getType() == null) {
EObject jvmElement = associations.getPrimaryJvmElement(member);
if (jvmElement instanceof JvmIdentifiableElement) {
addOpenInferredTypeHyperlink(resource, (JvmIdentifiableElement) jvmElement, node, acceptor);
}
}
}
if (element instanceof XtendFunction) {
XtendFunction member = (XtendFunction) element;
ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
if (isNameNode(member, XtendPackage.Literals.XTEND_FUNCTION__NAME, node)) {
EObject jvmElement = associations.getPrimaryJvmElement(member);
if (jvmElement instanceof JvmIdentifiableElement) {
JvmIdentifiableElement identifiableElement = (JvmIdentifiableElement) jvmElement;
if (member.getReturnType() == null) {
addOpenInferredTypeHyperlink(resource, identifiableElement, node, acceptor);
}
IJavaElement javaElement = javaElementFinder.findExactElementFor(identifiableElement);
if (sourceViewer != null && javaElement != null && (javaElement.getElementType() == IJavaElement.METHOD && canBeOverridden((IMethod) javaElement))) {
Region region = new Region(node.getOffset(), node.getLength());
acceptor.accept(new XbaseImplementatorsHyperlink(javaElement, region, sourceViewer, implOpener));
}
}
}
}
}
}
use of org.eclipse.xtext.xbase.ui.navigation.XbaseImplementatorsHyperlink in project xtext-xtend by eclipse.
the class DetectImplHyperlinksTest method testComputeHyperlink_3.
@Test
public void testComputeHyperlink_3() throws Exception {
String content = "package foo class Foo { def bar(S|tring a) { foo() } def foo(){}}";
XtextEditor xtextEditor = openEditor(content.replace("|", ""));
int offset = content.indexOf("|");
IHyperlink[] detectHyperlinks = hyperlinkDetector.detectHyperlinks(xtextEditor.getInternalSourceViewer(), new Region(offset, 1), true);
assertEquals(1, detectHyperlinks.length);
List<XbaseImplementatorsHyperlink> list = Lists.newArrayList(Iterables.filter(Lists.newArrayList(detectHyperlinks), XbaseImplementatorsHyperlink.class));
assertEquals(0, list.size());
}
use of org.eclipse.xtext.xbase.ui.navigation.XbaseImplementatorsHyperlink in project xtext-xtend by eclipse.
the class OpenImplHyperlinksTest method testComputeHyperlink_1.
@Test
public void testComputeHyperlink_1() throws Exception {
String content = "package foo class Foo implements IBar { override bar(String a) { b|ar('foo') } } interface IBar { def String bar(String a) }";
XtextEditor xtextEditor = openEditor(content.replace("|", ""));
int offset = content.indexOf("|");
IHyperlink[] detectHyperlinks = hyperlinkDetector.detectHyperlinks(xtextEditor.getInternalSourceViewer(), new Region(offset, 1), true);
XbaseImplementatorsHyperlink casted = null;
for (IHyperlink iHyperlink : detectHyperlinks) {
if (iHyperlink instanceof XbaseImplementatorsHyperlink) {
casted = (XbaseImplementatorsHyperlink) iHyperlink;
}
}
@SuppressWarnings("null") Field field = casted.getClass().getDeclaredField("opener");
field.setAccessible(true);
TestJvmImplementationOpener testOpener = new TestJvmImplementationOpener();
field.set(casted, testOpener);
casted.open();
assertTrue(testOpener.isOpenInEditor);
assertFalse(testOpener.isOpenQuickHierarchy);
}
use of org.eclipse.xtext.xbase.ui.navigation.XbaseImplementatorsHyperlink in project xtext-xtend by eclipse.
the class OpenImplHyperlinksTest method testComputeHyperlink_2.
@Test
public void testComputeHyperlink_2() throws Exception {
String content = "package foo interface IBar {def void bar(String a)} class Foo implements IBar { override bar(String a){ val IBar x = null; x.b|ar('foo'} } class Foo2 implements IBar { override bar(String a) {} }";
XtextEditor xtextEditor = openEditor(content.replace("|", ""));
int offset = content.indexOf("|");
IHyperlink[] detectHyperlinks = hyperlinkDetector.detectHyperlinks(xtextEditor.getInternalSourceViewer(), new Region(offset, 1), true);
XbaseImplementatorsHyperlink casted = null;
for (IHyperlink iHyperlink : detectHyperlinks) {
if (iHyperlink instanceof XbaseImplementatorsHyperlink) {
casted = (XbaseImplementatorsHyperlink) iHyperlink;
}
}
@SuppressWarnings("null") Field field = casted.getClass().getDeclaredField("opener");
field.setAccessible(true);
TestJvmImplementationOpener testOpener = new TestJvmImplementationOpener();
field.set(casted, testOpener);
casted.open();
assertFalse(testOpener.isOpenInEditor);
assertTrue(testOpener.isOpenQuickHierarchy);
}
Aggregations