Search in sources :

Example 1 with IContainer

use of org.eclipse.xtext.resource.IContainer in project xtext-eclipse by eclipse.

the class StateBasedContainerManagerTest method testGetVisibleContainers_01.

@Test
public void testGetVisibleContainers_01() {
    IResourceDescription description = new URIBasedTestResourceDescription(uri1);
    List<IContainer> visibleContainers = containerManager.getVisibleContainers(description, this);
    assertEquals(2, visibleContainers.size());
    assertEquals(2, Iterables.size(visibleContainers.get(0).getResourceDescriptions()));
    assertEquals(1, Iterables.size(visibleContainers.get(1).getResourceDescriptions()));
    assertNotNull(visibleContainers.get(0).getResourceDescription(uri1));
    assertNotNull(visibleContainers.get(0).getResourceDescription(uri2));
    assertNotNull(visibleContainers.get(1).getResourceDescription(uri3));
}
Also used : URIBasedTestResourceDescription(org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IContainer(org.eclipse.xtext.resource.IContainer) Test(org.junit.Test)

Example 2 with IContainer

use of org.eclipse.xtext.resource.IContainer in project n4js by eclipse.

the class PolyfillValidatorFragment method holdsSinglePolyfillSource.

/**
 * Constraints 129 (Applying Polyfills) No member must be filled by more than one polyfill.
 */
private boolean holdsSinglePolyfillSource(PolyfillValidationState state) {
    EList<TMember> myPolyMember = state.polyType.getOwnedMembers();
    // a) find references to the filled type
    // b) check, that they are in the same Project
    // c) search for clashing contributions.
    XtextResource res = (XtextResource) state.polyType.eResource();
    IResourceDescriptions index = resourceDescriptionsProvider.getResourceDescriptions(res);
    // a+b) all polyfills to same calssifier in same project:
    IContainer container = containerManager.getContainer(res.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res), index);
    // Iterable over all exported Polyfills
    Iterable<IEObjectDescription> iterEObj = container.getExportedObjects(TypesPackage.Literals.TCLASSIFIER, N4TSQualifiedNameProvider.getPolyfillFQN(state.filledType, qualifiedNameProvider), false);
    // collection of involved TModules for each Member.
    ListMultimap<TMember, TModule> clashProviders = LinkedListMultimap.create();
    for (IEObjectDescription pivotObjectDescription : iterEObj) {
        EObject eob = pivotObjectDescription.getEObjectOrProxy();
        // Resolve
        if (eob.eIsProxy()) {
            eob = EcoreUtil.resolve(eob, res);
        }
        if (eob == state.polyType) {
            // saw myself .-.
            continue;
        }
        EList<TMember> pivotPolyMember = ((TClassifier) eob).getOwnedMembers();
        ListMultimap<TMember, TMember> clashing = findClashingMembersByName(myPolyMember, pivotPolyMember);
        for (TMember myMember : clashing.keySet()) {
            // only interested in the module, so first is sufficient
            clashProviders.put(myMember, clashing.get(myMember).get(0).getContainingModule());
        }
    }
    List<TMember> sortedMembers = clashProviders.keySet().stream().sorted().collect(Collectors.toList());
    for (TMember myMember : sortedMembers) {
        // Combine list of Modules involved in the polyfill clash.
        String uris = Stream.concat(Stream.of(myMember.getContainingModule()), clashProviders.get(myMember).stream()).map(u -> u.getQualifiedName().toString()).sorted().reduce("", (a, b) -> a + PREFIX_LIST + b);
        if (uris.startsWith(PREFIX_LIST))
            uris = uris.substring(PREFIX_LIST.length());
        int lastPrefix_idx = uris.lastIndexOf(PREFIX_LIST);
        if (lastPrefix_idx >= 0) {
            StringBuffer sb = new StringBuffer(uris);
            uris = sb.replace(lastPrefix_idx, lastPrefix_idx + PREFIX_LIST.length(), " and ").toString();
        }
        // give Qualified name filled in Property.
        String memberAxis = myMember.getContainingType().getName() + "." + myMember.getName();
        // Issue on filled Member-name declaration:
        String msg = IssueCodes.getMessageForCLF_POLYFILL_MULTIPOLYFILLS_MEMBER_CONFLICT(uris, memberAxis);
        state.host.addIssue(msg, myMember.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, IssueCodes.CLF_POLYFILL_MULTIPOLYFILLS_MEMBER_CONFLICT);
    }
    return true;
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) XtextResource(org.eclipse.xtext.resource.XtextResource) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) EObject(org.eclipse.emf.ecore.EObject) TMember(org.eclipse.n4js.ts.types.TMember) IContainer(org.eclipse.xtext.resource.IContainer) TModule(org.eclipse.n4js.ts.types.TModule)

Example 3 with IContainer

use of org.eclipse.xtext.resource.IContainer 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)

Example 4 with IContainer

use of org.eclipse.xtext.resource.IContainer in project dsl-devkit by dsldevkit.

the class AbstractPolymorphicScopeProvider method newDataMatchScope.

/**
 * Create a new container scope using the results of a given query as its contents.
 *
 * @param id
 *          Human-readable name of the scope, typically used to identify where the scope was created. Useful for debugging.
 * @param outer
 *          The outer scope of the new scope.
 * @param context
 *          The context
 * @param query
 *          The query that defines the scope's contents
 * @param originalResource
 *          The original resource
 * @param filters
 *          to apply
 * @param nameFunctions
 *          The name functions to apply
 * @param caseInsensitive
 *          indicates whether the new scope shall be case insensitive
 * @return The new scope
 */
protected IScope newDataMatchScope(final String id, final IScope outer, final EObject context, final ContainerQuery query, final Resource originalResource, final Iterable<Predicate<IEObjectDescription>> filters, final Iterable<INameFunction> nameFunctions, final boolean caseInsensitive) {
    IScope result = outer;
    final List<String> domains = query.getDomains();
    for (final IContainer container : Lists.reverse(getVisibleContainers(context, originalResource))) {
        if (!domains.isEmpty()) {
            final IDomain domain = domainMapper.map(container);
            if (domain != null && !domains.contains(domain.getName())) {
                // Query not applicable to this container.
                continue;
            }
        }
        // Build a branch in the scope chain so that we can filter each container query separately.
        IScope contents = new ContainerBasedScope(id, IScope.NULLSCOPE, container, query, nameFunctions, caseInsensitive);
        contents = new DataFilteringScope(contents, filters);
        result = new BranchingScope(contents, result);
    }
    return result;
}
Also used : IScope(org.eclipse.xtext.scoping.IScope) DataFilteringScope(com.avaloq.tools.ddk.xtext.scoping.impl.DataFilteringScope) IContainer(org.eclipse.xtext.resource.IContainer) BranchingScope(com.avaloq.tools.ddk.xtext.scoping.impl.BranchingScope)

Example 5 with IContainer

use of org.eclipse.xtext.resource.IContainer in project dsl-devkit by dsldevkit.

the class AbstractPolymorphicScopeProvider method newPrefixedContainerScope.

/**
 * Create a new prefixed container scope using the results of a given query as its contents.
 *
 * @param id
 *          Human-readable name of the scope, typically used to identify where the scope was created. Useful for debugging.
 * @param outer
 *          The outer scope of the new scope.
 * @param context
 *          The context
 * @param query
 *          The query that defines the scope's contents
 * @param originalResource
 *          The original resource
 * @param prefix
 *          prefix to apply for single element lookups
 * @param recursive
 *          whether the qualified name pattern used to search the index should be
 *          {@link com.avaloq.tools.ddk.xtext.naming.QualifiedNamePattern#RECURSIVE_WILDCARD_SEGMENT recursive}
 * @param nameFunctions
 *          The name functions to apply
 * @param caseInsensitive
 *          indicates whether the new scope shall be case insensitive
 * @return The new scope
 */
protected IScope newPrefixedContainerScope(final String id, final IScope outer, final EObject context, final ContainerQuery.Builder query, final Resource originalResource, final String prefix, final boolean recursive, final Iterable<INameFunction> nameFunctions, final boolean caseInsensitive) {
    IScope result = outer;
    final List<String> domains = query.getDomains();
    for (final IContainer container : Lists.reverse(getVisibleContainers(context, originalResource))) {
        if (!domains.isEmpty()) {
            final IDomain domain = domainMapper.map(container);
            if (domain != null && !domains.contains(domain.getName())) {
                // Query not applicable to this container.
                continue;
            }
        }
        result = new PrefixedContainerBasedScope(id, result, container, query, nameFunctions, QualifiedNames.safeQualifiedName(prefix), recursive, caseInsensitive);
    }
    return result;
}
Also used : IScope(org.eclipse.xtext.scoping.IScope) IContainer(org.eclipse.xtext.resource.IContainer)

Aggregations

IContainer (org.eclipse.xtext.resource.IContainer)25 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)13 URI (org.eclipse.emf.common.util.URI)7 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)7 Test (org.junit.Test)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 URIBasedTestResourceDescription (org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription)4 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)4 IScope (org.eclipse.xtext.scoping.IScope)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)3 LiveShadowedChunkedResourceDescriptions (org.eclipse.xtext.resource.impl.LiveShadowedChunkedResourceDescriptions)3 List (java.util.List)2 IFile (org.eclipse.core.resources.IFile)2 EObject (org.eclipse.emf.ecore.EObject)2 QualifiedName (org.eclipse.xtext.naming.QualifiedName)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 ChunkedResourceDescriptions (org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions)2 ProjectDescription (org.eclipse.xtext.resource.impl.ProjectDescription)2