Search in sources :

Example 51 with XtextResource

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

the class PartialParserTest method createResource.

protected XtextResource createResource(String model, String fileName) throws IOException {
    XtextResourceSet resourceSet = getResourceSet();
    XtextResource resource = (XtextResource) resourceSet.createResource(URI.createURI(fileName));
    resource.load(new StringInputStream(model), null);
    return resource;
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 52 with XtextResource

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

the class IndexingTest method justLoad.

protected XtextResource justLoad(String contents) throws IOException {
    XtextResourceSet set = getResourceSet();
    String fileName = getFileName(contents);
    Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
    resource.load(new StringInputStream(contents), null);
    return (XtextResource) resource;
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 53 with XtextResource

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

the class ParserTest method testAllGrammarElementsUnique.

@Test
public void testAllGrammarElementsUnique() throws Exception {
    XtendClass clazz = clazz("class Foo { def m() { newArrayList() } }");
    XtextResource resource = (XtextResource) clazz.eResource();
    ICompositeNode root = resource.getParseResult().getRootNode();
    new InvariantChecker().checkInvariant(root);
    assertSame(root, root.getRootNode());
    Set<EObject> grammarElements = Sets.newHashSet();
    for (INode node : root.getAsTreeIterable()) {
        if (node instanceof ICompositeNode) {
            if (node.getGrammarElement() == null) {
                fail("node without grammar element");
            }
            if (!grammarElements.add(node.getGrammarElement())) {
                fail(node.getGrammarElement().toString());
            }
        }
    }
}
Also used : InvariantChecker(org.eclipse.xtext.nodemodel.impl.InvariantChecker) INode(org.eclipse.xtext.nodemodel.INode) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 54 with XtextResource

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

the class TypeUsageCollectorTest method hasUnresolvedType.

private void hasUnresolvedType(final Resource resource, final String... typeNames) {
    final TypeUsages typeUsages = this.typeUsageCollector.collectTypeUsages(((XtextResource) resource));
    final Function1<TypeUsage, String> _function = (TypeUsage it) -> {
        return it.getUsedTypeName();
    };
    final Set<String> usedNames = IterableExtensions.<String>toSet(ListExtensions.<TypeUsage, String>map(typeUsages.getUnresolvedTypeUsages(), _function));
    Assert.assertEquals(IterableExtensions.<String>toSet(((Iterable<String>) Conversions.doWrapArray(typeNames))), usedNames);
}
Also used : TypeUsages(org.eclipse.xtext.xbase.imports.TypeUsages) XtextResource(org.eclipse.xtext.resource.XtextResource) TypeUsage(org.eclipse.xtext.xbase.imports.TypeUsage)

Example 55 with XtextResource

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

the class ImportsCollectorTests method collect.

private ImportsAcceptor.DefaultImportsAcceptor collect(final CharSequence xtendFile) {
    try {
        String contentAsString = xtendFile.toString();
        int start = 0;
        int end = contentAsString.length();
        int selector = contentAsString.indexOf("|");
        if ((selector != (-1))) {
            start = selector;
            contentAsString = contentAsString.replaceFirst("\\|", "");
            selector = contentAsString.indexOf("|");
            end = contentAsString.length();
            if ((selector != (-1))) {
                end = selector;
                contentAsString = contentAsString.replaceFirst("\\|", "");
            }
        }
        final Resource resource = this.file(contentAsString).eResource();
        final ImportsAcceptor.DefaultImportsAcceptor acceptor = new ImportsAcceptor.DefaultImportsAcceptor();
        TextRegion _textRegion = new TextRegion(start, (end - start));
        this.importsCollector.collectImports(((XtextResource) resource), _textRegion, acceptor);
        return acceptor;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : TextRegion(org.eclipse.xtext.util.TextRegion) ImportsAcceptor(org.eclipse.xtext.xbase.imports.ImportsAcceptor) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

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