Search in sources :

Example 1 with IDomain

use of com.avaloq.tools.ddk.xtext.scoping.IDomain in project dsl-devkit by dsldevkit.

the class CachingStateBasedContainerManager method getContainersForHandlesAndResource.

/**
 * Returns the containers for the given handles, where one of the containers will also include {@code desc} when appropriate.
 *
 * @param handles
 *          handles to get containers for, must not be {@code null}
 * @param desc
 *          description to add, must not be {@code null}
 * @param resourceDescriptions
 *          resource descriptions, must not be {@code null}
 * @return list of containers, never {@code null}
 */
protected List<IContainer> getContainersForHandlesAndResource(final List<String> handles, final IResourceDescription desc, final IResourceDescriptions resourceDescriptions) {
    List<IContainer> result = getVisibleContainers(handles, resourceDescriptions);
    if (!result.isEmpty()) {
        URI descURI = desc.getURI();
        for (int i = 0; i < result.size(); i++) {
            if (result.get(i).getResourceDescription(descURI) != null) {
                return result;
            }
        }
        // getEObjectDescriptions(), leading to a stack overflow since it may in turn invoke getVisibleContainers() again.
        if (desc instanceof DefaultResourceDescription) {
            DefaultResourceDescription d = (DefaultResourceDescription) desc;
            if (BuildPhases.isIndexing(d.getResource())) {
                return result;
            }
        }
        // the IResourceDescription was found nowhere, add it to the first one that matches the description's domain.
        IDomain descDomain = mapper.map(descURI);
        IContainer wrappedContainer = null;
        int index = 0;
        for (int i = 0; i < result.size(); i++) {
            IContainer container = result.get(i);
            IDomain containerDomain = mapper.map(container);
            if (containerDomain != null && containerDomain.equals(descDomain)) {
                wrappedContainer = new DescriptionAddingContainer(desc, container);
                result.set(index, wrappedContainer);
                return result;
            }
            index++;
        }
        // If we get here, we found no container with a matching domain. Add to the first, but use a DescriptionAddingContainer that
        // will add the description at the end.
        wrappedContainer = new DescriptionAtEndAddingContainer(desc, result.get(0));
        result.set(0, wrappedContainer);
    }
    return result;
}
Also used : IDomain(com.avaloq.tools.ddk.xtext.scoping.IDomain) DefaultResourceDescription(org.eclipse.xtext.resource.impl.DefaultResourceDescription) IContainer(org.eclipse.xtext.resource.IContainer) DescriptionAddingContainer(org.eclipse.xtext.resource.containers.DescriptionAddingContainer) URI(org.eclipse.emf.common.util.URI)

Aggregations

IDomain (com.avaloq.tools.ddk.xtext.scoping.IDomain)1 URI (org.eclipse.emf.common.util.URI)1 IContainer (org.eclipse.xtext.resource.IContainer)1 DescriptionAddingContainer (org.eclipse.xtext.resource.containers.DescriptionAddingContainer)1 DefaultResourceDescription (org.eclipse.xtext.resource.impl.DefaultResourceDescription)1