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;
}
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());
}
}
}
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);
}
}
}
Aggregations