Search in sources :

Example 61 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.

the class HyperlinkingTest method testOpenInferredTypeOnReference_01.

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

Example 62 with XtextResource

use of org.eclipse.xtext.resource.XtextResource 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 63 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.

the class HyperlinkingTest method testOpenInferredType.

@Test
public void testOpenInferredType() 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(1, hyperlinks.length);
    assertEquals("Open Inferred Type - String", hyperlinks[0].getHyperlinkText());
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 64 with XtextResource

use of org.eclipse.xtext.resource.XtextResource 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());
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) XtextHyperlink(org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink) XtextResource(org.eclipse.xtext.resource.XtextResource) JdtHyperlink(org.eclipse.xtext.common.types.xtext.ui.JdtHyperlink) Test(org.junit.Test)

Example 65 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.

the class HyperlinkingTest method testOpenInferredType_01.

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

Aggregations

XtextResource (org.eclipse.xtext.resource.XtextResource)627 Test (org.junit.Test)367 Resource (org.eclipse.emf.ecore.resource.Resource)107 EObject (org.eclipse.emf.ecore.EObject)99 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)67 StringInputStream (org.eclipse.xtext.util.StringInputStream)67 URI (org.eclipse.emf.common.util.URI)62 Diagnostic (org.eclipse.emf.common.util.Diagnostic)55 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)55 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)46 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)40 Grammar (org.eclipse.xtext.Grammar)32 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)31 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)30 IFile (org.eclipse.core.resources.IFile)29 Issue (org.eclipse.xtext.validation.Issue)29 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)28 List (java.util.List)26 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)26 INode (org.eclipse.xtext.nodemodel.INode)23