Search in sources :

Example 1 with ILazyLinkingResource2

use of com.avaloq.tools.ddk.xtext.linking.ILazyLinkingResource2 in project dsl-devkit by dsldevkit.

the class DefaultBuilderResourceLoadStrategy method getFullyLoadedResources.

/**
 * Calculates the number of fully loaded resources of a resource set.
 *
 * @param resourceSet
 *          the resource set
 * @return number of fully loaded resources
 */
private int getFullyLoadedResources(final ResourceSet resourceSet) {
    final int loadedResources = resourceSet.getResources().size();
    int fullyLoaded = loadedResources;
    for (Resource resource : resourceSet.getResources()) {
        if (resource instanceof ILazyLinkingResource2) {
            ILazyLinkingResource2 lazyLinkingResource = (ILazyLinkingResource2) resource;
            if (!lazyLinkingResource.getModelManager().allModelsLoaded()) {
                fullyLoaded--;
            }
        }
    }
    return fullyLoaded;
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) ILazyLinkingResource2(com.avaloq.tools.ddk.xtext.linking.ILazyLinkingResource2)

Example 2 with ILazyLinkingResource2

use of com.avaloq.tools.ddk.xtext.linking.ILazyLinkingResource2 in project dsl-devkit by dsldevkit.

the class LazyLoadingCompositeNode method initializeDelegateNode.

/**
 * Initializes the parent resource's node model and fetches the real node.
 */
private void initializeDelegateNode() {
    if (delegateNode == null) {
        EObject proxiedObject = basicGetSemanticElement();
        Resource resource = proxiedObject.eResource();
        if (resource instanceof ILazyLinkingResource2) {
            ILazyLinkingResource2 lazyLinkingResource = (ILazyLinkingResource2) resource;
            lazyLinkingResource.getModelManager().loadBinaryModels(ResourceModelType.NODE);
            ICompositeNode compositeNode = NodeModelUtils.getNode(proxiedObject);
            if (compositeNode instanceof CompositeNodeWithSemanticElement) {
                delegateNode = (CompositeNodeWithSemanticElement) compositeNode;
            }
            if (delegateNode == null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                throw new IllegalStateException("Resource " + resource.getURI() + " does not have an INode for one of its EObjects");
            }
        } else {
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new IllegalStateException("Unexpected resource type '" + resource.getClass().getSimpleName() + "' for resource " + resource.getURI());
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) CompositeNodeWithSemanticElement(org.eclipse.xtext.nodemodel.impl.CompositeNodeWithSemanticElement) ILazyLinkingResource2(com.avaloq.tools.ddk.xtext.linking.ILazyLinkingResource2)

Example 3 with ILazyLinkingResource2

use of com.avaloq.tools.ddk.xtext.linking.ILazyLinkingResource2 in project dsl-devkit by dsldevkit.

the class ResourceDescription2 method computeExportedObjects.

@Override
protected List<IEObjectDescription> computeExportedObjects() {
    if (!getResource().isLoaded()) {
        try {
            getResource().load(null);
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
            return ImmutableList.of();
        }
    }
    // Maybe we need to install the derived state first. Installing/discarding the derived state will clear the resource cache, so we must
    // make sure at least that the resource description is re-added.
    LazyLinkingResource resource = (LazyLinkingResource) getResource();
    boolean doInitialize = (resource instanceof ILazyLinkingResource2) && !((ILazyLinkingResource2) resource).isInitialized();
    final ResourceDescription2 self = this;
    try {
        if (doInitialize) {
            resource.eSetDeliver(false);
            ((ILazyLinkingResource2) resource).installDerivedState(BuildPhases.isIndexing(resource));
            // Make sure we have at least this resource description itself in the resource cache.
            resource.getCache().get(AbstractCachingResourceDescriptionManager.CACHE_KEY, resource, () -> self);
        }
        return createDecriptions(resource);
    } finally {
        if (doInitialize) {
            // DerivedStateAwareResourceManager does discard the state. Should we do so, too?
            resource.eSetDeliver(true);
            // Make sure we have at least this resource description itself in the resource cache.
            resource.getCache().get(AbstractCachingResourceDescriptionManager.CACHE_KEY, resource, () -> self);
        }
    }
}
Also used : LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) IOException(java.io.IOException) ILazyLinkingResource2(com.avaloq.tools.ddk.xtext.linking.ILazyLinkingResource2) IResourceDescription2(com.avaloq.tools.ddk.xtext.resource.extensions.IResourceDescription2)

Aggregations

ILazyLinkingResource2 (com.avaloq.tools.ddk.xtext.linking.ILazyLinkingResource2)3 Resource (org.eclipse.emf.ecore.resource.Resource)2 IResourceDescription2 (com.avaloq.tools.ddk.xtext.resource.extensions.IResourceDescription2)1 IOException (java.io.IOException)1 EObject (org.eclipse.emf.ecore.EObject)1 LazyLinkingResource (org.eclipse.xtext.linking.lazy.LazyLinkingResource)1 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 CompositeNodeWithSemanticElement (org.eclipse.xtext.nodemodel.impl.CompositeNodeWithSemanticElement)1