Search in sources :

Example 11 with IContainer

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

the class AbstractCachingResourceDescriptionManager method isAffected.

/**
 * {@inheritDoc}
 */
@Override
public boolean isAffected(final Collection<Delta> deltas, final IResourceDescription candidate, final IResourceDescriptions context) {
    // NOPMD(NPathComplexity)
    final Collection<Delta> filteredDeltas = getInterestingDeltas(deltas);
    if (filteredDeltas.isEmpty()) {
        return false;
    }
    final List<IContainer> containers = getContainerManager().getVisibleContainers(candidate, context);
    for (final Delta delta : filteredDeltas) {
        // NOPMD - potentially could be lost due to call on getNew() after
        final URI deltaURI = delta.getUri();
        // deleted resources are no longer visible resources so we test them, too.
        if (delta.getNew() == null && isReferencedBy(delta, candidate, context)) {
            if (LOGGER.isDebugEnabled()) {
                // $NON-NLS-1$
                LOGGER.debug(candidate.getURI() + " is affected by " + delta.getUri());
            }
            return true;
        }
        for (IContainer container : containers) {
            if (container.getResourceDescription(deltaURI) != null) {
                if (isReferencedBy(delta, candidate, context)) {
                    if (LOGGER.isDebugEnabled()) {
                        // NOPMD AvoidDeeplyNestedIfStmts
                        // $NON-NLS-1$
                        LOGGER.debug(candidate.getURI() + " is affected by " + delta.getUri());
                    }
                    return true;
                }
                break;
            }
        }
    }
    return false;
}
Also used : Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) IContainer(org.eclipse.xtext.resource.IContainer) URI(org.eclipse.emf.common.util.URI)

Example 12 with IContainer

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

the class XtendUIResourceDescriptionManager method isAffected.

@Override
public boolean isAffected(Collection<Delta> deltas, IResourceDescription candidate, IResourceDescriptions context) {
    // skip collecting the outgoing references since we don't index references anyway
    // Set<URI> outgoingReferences = getDescriptionUtils().collectOutgoingReferences(candidate);
    // if (!outgoingReferences.isEmpty()) {
    // for (IResourceDescription.Delta delta : deltas)
    // if (hasChanges(delta, candidate) && outgoingReferences.contains(delta.getUri()))
    // return true;
    // }
    // this is a tradeoff - we could either check whether a given delta uri is contained
    // in a reachable container and check for intersecting names afterwards, or we can do
    // the other way round
    // unfortunately there is no way to decide reliably which algorithm scales better
    // note that this method is called for each description so we have something like a
    // number of deltas x number of resources which is not really nice
    List<IContainer> containers = null;
    Collection<QualifiedName> importedNames = getImportedNames(candidate);
    Map<String, Boolean> checkedProjects = Maps.newHashMap();
    for (IResourceDescription.Delta delta : deltas) {
        if (hasChanges(delta, candidate)) {
            // not a java resource - delta's resource should be contained in a visible container
            // as long as we did not delete the resource
            URI uri = delta.getUri();
            if ((uri.isPlatform() || uri.isArchive()) && delta.getNew() != null) {
                if (containers == null)
                    containers = getContainerManager().getVisibleContainers(candidate, context);
                boolean descriptionIsContained = false;
                for (int i = 0; i < containers.size() && !descriptionIsContained; i++) {
                    descriptionIsContained = containers.get(i).hasResourceDescription(uri);
                }
                if (!descriptionIsContained && !isProjectDependency(uri, candidate.getURI(), checkedProjects)) {
                    return false;
                }
            }
            if (isAffected(importedNames, delta.getNew()) || isAffected(importedNames, delta.getOld())) {
                return true;
            }
        }
    }
    return false;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) IContainer(org.eclipse.xtext.resource.IContainer) URI(org.eclipse.emf.common.util.URI)

Example 13 with IContainer

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

the class AbstractLiveContainerTest method testContainerAddRemove.

@Test
public void testContainerAddRemove() throws Exception {
    ResourceSet resourceSet = new XtextResourceSet();
    Resource res = parse("local", resourceSet).eResource();
    parse("other", resourceSet);
    IResourceDescription resourceDescription = descriptionManager.getResourceDescription(res);
    IResourceDescriptions resourceDescriptions = descriptionsProvider.getResourceDescriptions(res);
    List<IContainer> containers = containerManager.getVisibleContainers(resourceDescription, resourceDescriptions);
    assertEquals(1, containers.size());
    IContainer container = containers.get(0);
    assertEquals("local, other", format(container.getExportedObjects()));
    Resource foo = parse("foo", resourceSet).eResource();
    assertEquals("foo, local, other", format(container.getExportedObjects()));
    resourceSet.getResources().remove(foo);
    assertEquals("local, other", format(container.getExportedObjects()));
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IContainer(org.eclipse.xtext.resource.IContainer) Test(org.junit.Test)

Example 14 with IContainer

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

the class AbstractLiveContainerTest method testNonNormalizedURIs.

@Test
public // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=382555
void testNonNormalizedURIs() throws Exception {
    ResourceSet resourceSet = new XtextResourceSet();
    parser.parse("B", URI.createURI("a." + parser.fileExtension), resourceSet);
    parser.parse("B", URI.createURI("b." + parser.fileExtension), resourceSet);
    IResourceDescriptions index = descriptionsProvider.getResourceDescriptions(resourceSet);
    IResourceDescription rd = index.getResourceDescription(URI.createURI("a." + parser.fileExtension));
    List<IContainer> containers = containerManager.getVisibleContainers(rd, index);
    List<IEObjectDescription> objects = Lists.newArrayList();
    EClass type = (EClass) grammarAccess.getGrammar().getRules().get(0).getType().getClassifier();
    for (IContainer container : containers) Iterables.addAll(objects, container.getExportedObjects(type, QualifiedName.create("B"), false));
    assertEquals(2, objects.size());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IContainer(org.eclipse.xtext.resource.IContainer) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 15 with IContainer

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

the class StateBasedContainerManager method getVisibleContainers.

@Override
public List<IContainer> getVisibleContainers(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
    if (delegate.shouldUseProjectDescriptionBasedContainers(resourceDescriptions)) {
        return delegate.getVisibleContainers(desc, resourceDescriptions);
    }
    String root = internalGetContainerHandle(desc, resourceDescriptions);
    if (root == null) {
        if (log.isDebugEnabled())
            log.debug("Cannot find IContainer for: " + desc.getURI());
        return Collections.emptyList();
    }
    List<String> handles = getState(resourceDescriptions).getVisibleContainerHandles(root);
    List<IContainer> result = getVisibleContainers(handles, resourceDescriptions);
    if (!result.isEmpty()) {
        IContainer first = result.get(0);
        if (!first.hasResourceDescription(desc.getURI())) {
            first = new DescriptionAddingContainer(desc, first);
            result.set(0, first);
        }
    }
    return result;
}
Also used : 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)5 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