Search in sources :

Example 1 with LazyLinkingResource

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

the class AbstractSmokeTest method testSkipNodesInBetween.

@Test
public void testSkipNodesInBetween() 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);
                    processModel(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 2 with LazyLinkingResource

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

the class AbstractXtextTests method doGetResource.

protected XtextResource doGetResource(InputStream in, URI uri) throws Exception {
    XtextResourceSet rs = get(XtextResourceSet.class);
    rs.setClasspathURIContext(getClass());
    XtextResource resource = (XtextResource) getResourceFactory().createResource(uri);
    rs.getResources().add(resource);
    resource.load(in, null);
    if (resource instanceof LazyLinkingResource) {
        ((LazyLinkingResource) resource).resolveLazyCrossReferences(CancelIndicator.NullImpl);
    } else {
        EcoreUtil.resolveAll(resource);
    }
    return resource;
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 3 with LazyLinkingResource

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

the class AbstractXtextTests method doGetResource.

protected XtextResource doGetResource(InputStream in, URI uri) throws Exception {
    XtextResourceSet rs = get(XtextResourceSet.class);
    rs.setClasspathURIContext(getClasspathURIContext());
    XtextResource resource = (XtextResource) getResourceFactory().createResource(uri);
    rs.getResources().add(resource);
    resource.load(in, null);
    if (resource instanceof LazyLinkingResource) {
        ((LazyLinkingResource) resource).resolveLazyCrossReferences(CancelIndicator.NullImpl);
    } else {
        EcoreUtil.resolveAll(resource);
    }
    return resource;
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 4 with LazyLinkingResource

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

the class AbstractCleaningLinker method beforeModelLinked.

protected void beforeModelLinked(EObject model, IDiagnosticConsumer diagnosticsConsumer) {
    Resource resource = model.eResource();
    if (resource instanceof LazyLinkingResource) {
        ((LazyLinkingResource) resource).clearLazyProxyInformation();
    }
    ImportedNamesAdapter adapter = ImportedNamesAdapter.find(resource);
    if (adapter != null)
        adapter.clear();
}
Also used : LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 5 with LazyLinkingResource

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

the class RenameElementHandler method findElementForFakeInStatechart.

private NamedElement findElementForFakeInStatechart(NamedElement fakeElement) {
    Resource resource = fakeElement.eResource();
    // only do something if element is really from fake resource
    if (resource instanceof LazyLinkingResource) {
        Statechart sct = getStatechartFromFakeResource((LazyLinkingResource) resource);
        EList<Scope> scopes = sct.getScopes();
        for (Scope scope : scopes) {
            // check all declarations
            EList<Declaration> declarations = scope.getDeclarations();
            for (Declaration decl : declarations) {
                if (decl.eClass().getName().equals(fakeElement.eClass().getName()) && decl.getName().equals(fakeElement.getName())) {
                    return decl;
                }
            }
            // check scope itself it is a named one
            if (scope instanceof NamedElement) {
                NamedElement namedScope = (NamedElement) scope;
                if (namedScope.eClass().getName().equals(fakeElement.eClass().getName()) && namedScope.getName().equals(fakeElement.getName())) {
                    return namedScope;
                }
            }
        }
    }
    return fakeElement;
}
Also used : Scope(org.yakindu.sct.model.sgraph.Scope) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) Resource(org.eclipse.emf.ecore.resource.Resource) Statechart(org.yakindu.sct.model.sgraph.Statechart) Declaration(org.yakindu.base.types.Declaration) NamedElement(org.yakindu.base.base.NamedElement)

Aggregations

LazyLinkingResource (org.eclipse.xtext.linking.lazy.LazyLinkingResource)22 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)4 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 ILazyLinkingResource2 (com.avaloq.tools.ddk.xtext.linking.ILazyLinkingResource2)1 IResourceDescription2 (com.avaloq.tools.ddk.xtext.resource.extensions.IResourceDescription2)1 IOException (java.io.IOException)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 EObject (org.eclipse.emf.ecore.EObject)1 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 InternalXtendLexer (org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer)1 CrossReference (org.eclipse.xtext.CrossReference)1