Search in sources :

Example 36 with XtextResource

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

the class JavaDocTypeReferenceProviderTest method testComputation_8.

@Test
public void testComputation_8() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("/**");
        _builder.newLine();
        _builder.append("* @see    String");
        _builder.newLine();
        _builder.append("*/");
        _builder.newLine();
        _builder.append("class Foo{}");
        _builder.newLine();
        final String input = _builder.toString();
        Resource _eResource = this.clazz(input).eResource();
        final XtextResource resource = ((XtextResource) _eResource);
        final ICompositeNode rootNode = resource.getParseResult().getRootNode();
        final List<ReplaceRegion> regions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(rootNode);
        Assert.assertEquals(1, regions.size());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 37 with XtextResource

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

the class JavaDocTypeReferenceProviderTest method testComputation_7.

@Test
public void testComputation_7() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("/**");
        _builder.newLine();
        _builder.append("* {@link    String}");
        _builder.newLine();
        _builder.append("*/");
        _builder.newLine();
        _builder.append("class Foo{}");
        _builder.newLine();
        final String input = _builder.toString();
        Resource _eResource = this.clazz(input).eResource();
        final XtextResource resource = ((XtextResource) _eResource);
        final ICompositeNode rootNode = resource.getParseResult().getRootNode();
        final List<ReplaceRegion> regions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(rootNode);
        Assert.assertEquals(1, regions.size());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 38 with XtextResource

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

the class JavaDocTypeReferenceProviderTest method testComputation_5.

@Test
public void testComputation_5() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo{");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("/**");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("* @param string - a fancy string");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("* @param anotherString-even more fancy");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("* @param zonk");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar(String string, String anotherString, Integer zonk){}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String input = _builder.toString();
        Resource _eResource = this.clazz(input).eResource();
        final XtextResource resource = ((XtextResource) _eResource);
        final ICompositeNode rootNode = resource.getParseResult().getRootNode();
        final List<ReplaceRegion> regions = this.javaDocTypeReferenceProvider.computeParameterTypeRefRegions(rootNode);
        Assert.assertEquals(3, regions.size());
        Assert.assertEquals("string", IterableExtensions.<ReplaceRegion>head(regions).getText());
        Assert.assertEquals(input.indexOf("string"), IterableExtensions.<ReplaceRegion>head(regions).getOffset());
        Assert.assertEquals("string".length(), IterableExtensions.<ReplaceRegion>head(regions).getLength());
        Assert.assertEquals("anotherString", regions.get(1).getText());
        Assert.assertEquals(input.indexOf("anotherString"), regions.get(1).getOffset());
        Assert.assertEquals("anotherString".length(), regions.get(1).getLength());
        Assert.assertEquals("zonk", regions.get(2).getText());
        Assert.assertEquals(input.indexOf("zonk"), regions.get(2).getOffset());
        Assert.assertEquals("zonk".length(), regions.get(2).getLength());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 39 with XtextResource

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

the class AbstractXbaseContentAssistTest method getResourceFor.

@Override
public final XtextResource getResourceFor(InputStream stream) {
    try {
        XtextResource result = (XtextResource) getResourceSet().createResource(URI.createURI("Test." + fileExtension));
        result.load(stream, singletonMap(XtextResource.OPTION_ENCODING, StandardCharsets.ISO_8859_1.name()));
        return result;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) JavaModelException(org.eclipse.jdt.core.JavaModelException)

Example 40 with XtextResource

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

the class AbstractXbaseContentAssistTest method expression.

protected XExpression expression(String string) throws Exception {
    XtextResource resource = getResourceFor(new StringInputStream(string));
    assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    XExpression result = (XExpression) resource.getContents().get(0);
    return result;
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResource(org.eclipse.xtext.resource.XtextResource) XExpression(org.eclipse.xtext.xbase.XExpression)

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