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