Search in sources :

Example 21 with LazyLinkingResource

use of org.eclipse.xtext.linking.lazy.LazyLinkingResource in project xtext-xtend by eclipse.

the class AbstractSmokeTest method createResource.

protected LazyLinkingResource createResource(final String model) throws IOException {
    if (logger.isTraceEnabled()) {
        logger.trace("createResource: " + model);
    }
    XtextResourceSet set = getResourceSet();
    typeProviderFactory.findOrCreateTypeProvider(set);
    LazyLinkingResource resource = (LazyLinkingResource) resourceFactory.createResource(URI.createURI("Test.xtend"));
    set.getResources().add(resource);
    resource.load(new StringInputStream(model), null);
    resource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
    return resource;
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource)

Example 22 with LazyLinkingResource

use of org.eclipse.xtext.linking.lazy.LazyLinkingResource in project xtext-xtend by eclipse.

the class AbstractSmokeTest method testSkipNodesInBetween.

@Test
public void testSkipNodesInBetween() throws Exception {
    for (String string : smokeTestModels) {
        LazyLinkingResource resource = createResource(string);
        ICompositeNode rootNode = resource.getParseResult().getRootNode();
        ReplaceRegion replaceRegion = null;
        for (INode node : rootNode.getAsTreeIterable()) {
            int offset = node.getTotalOffset();
            int length = node.getTotalLength();
            if (replaceRegion == null || replaceRegion.getOffset() != offset || replaceRegion.getLength() != length) {
                replaceRegion = new ReplaceRegion(offset, length, "");
                StringBuilder builder = new StringBuilder(string);
                replaceRegion.applyTo(builder);
                doParseAndCheckForSmoke(builder.toString());
            }
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Example 23 with LazyLinkingResource

use of org.eclipse.xtext.linking.lazy.LazyLinkingResource in project xtext-eclipse by eclipse.

the class AbstractSmokeTest method testSkipNodesInBetweenWithoutResourceSet.

@Test
public void testSkipNodesInBetweenWithoutResourceSet() throws Exception {
    for (String string : getSmokeTestModels()) {
        LazyLinkingResource resource = createResource(string);
        if (resource != null) {
            ICompositeNode rootNode = resource.getParseResult().getRootNode();
            ReplaceRegion replaceRegion = null;
            for (INode node : rootNode.getAsTreeIterable()) {
                int offset = node.getTotalOffset();
                int length = node.getTotalLength();
                if (replaceRegion == null || replaceRegion.getOffset() != offset || replaceRegion.getLength() != length) {
                    replaceRegion = new ReplaceRegion(offset, length, "");
                    StringBuilder builder = new StringBuilder(string);
                    replaceRegion.applyTo(builder);
                    processModelWithoutResourceSet(builder.toString());
                }
            }
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Aggregations

LazyLinkingResource (org.eclipse.xtext.linking.lazy.LazyLinkingResource)23 Test (org.junit.Test)10 INode (org.eclipse.xtext.nodemodel.INode)8 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)7 ReplaceRegion (org.eclipse.xtext.util.ReplaceRegion)6 XtextResource (org.eclipse.xtext.resource.XtextResource)5 Resource (org.eclipse.emf.ecore.resource.Resource)4 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)4 IOException (java.io.IOException)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 ILazyLinkingResource2 (com.avaloq.tools.ddk.xtext.linking.ILazyLinkingResource2)1 IResourceDescription2 (com.avaloq.tools.ddk.xtext.resource.extensions.IResourceDescription2)1 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)1 CommonToken (org.antlr.runtime.CommonToken)1 Token (org.antlr.runtime.Token)1 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)1