use of org.eclipse.xtext.resource.IResourceDescription.Delta in project dsl-devkit by dsldevkit.
the class AbstractCachingResourceDescriptionManager method getAffectedResources.
/**
* Bulk method to return all resources (managed by this manager) which are affected by the given set of deltas.
*
* @param deltas
* deltas
* @param filter
* filter for affected resources
* @param context
* context index
* @return collection of affected resources
*/
protected Set<URI> getAffectedResources(final Collection<Delta> deltas, final Predicate<URI> filter, final IResourceDescriptions2 context) {
// NOPMD
final Set<IResourceDescription> changedOrDeletedResources = Sets.newHashSet();
final Set<IEObjectDescription> changedOrDeletedObjects = Sets.newHashSet();
final SetMultimap<String, IResourceDescription> addedResources = HashMultimap.create();
final SetMultimap<String, IEObjectDescription> addedObjects = HashMultimap.create();
final IAllContainersState containersState = containersStateProvider.get(context);
for (Delta delta : deltas) {
if (delta.haveEObjectDescriptionsChanged()) {
if (delta instanceof ResourceDescriptionDelta && ((ResourceDescriptionDelta) delta).hasObjectFingerprints()) {
ResourceDescriptionDelta detailedDelta = (ResourceDescriptionDelta) delta;
changedOrDeletedObjects.addAll(detailedDelta.getChangedObjects());
changedOrDeletedObjects.addAll(detailedDelta.getDeletedObjects());
addedObjects.putAll(containersState.getContainerHandle(delta.getUri()), detailedDelta.getAddedObjects());
} else {
IResourceDescription oldDesc = delta.getOld();
IResourceDescription newDesc = delta.getNew();
if (oldDesc != null) {
changedOrDeletedResources.add(newDesc != null ? newDesc : oldDesc);
} else {
addedResources.put(containersState.getContainerHandle(delta.getUri()), newDesc);
}
}
}
}
// find all resources matching provided filter with physical references to changed-or-deleted resources and objects
Set<URI> references = Sets.newHashSet(Iterables.filter(Iterables.transform(Iterables.concat(context.findAllReferencingResources(changedOrDeletedResources, ReferenceMatchPolicy.REFERENCES), context.findExactReferencingResources(changedOrDeletedObjects, ReferenceMatchPolicy.REFERENCES)), new Function<IResourceDescription, URI>() {
@Override
public URI apply(final IResourceDescription from) {
return from.getURI();
}
}), filter));
// find all resources matching provided filter with physical or imported name references to added resources and objects
for (String container : addedResources.keySet()) {
// using ReferenceMatchPolicy.UNRESOLVED_IMPORTED_NAMES is not enough: a lower index layer may contain physical references
for (IResourceDescription res : context.findAllReferencingResources(addedResources.get(container), ReferenceMatchPolicy.ALL)) {
URI uri = res.getURI();
if (!references.contains(uri) && filter.apply(uri) && containersState.getVisibleContainerHandles(containersState.getContainerHandle(uri)).contains(container)) {
references.add(uri);
}
}
}
for (String container : addedObjects.keySet()) {
// using ReferenceMatchPolicy.UNRESOLVED_IMPORTED_NAMES is not enough: a lower index layer may contain physical references
for (IResourceDescription res : context.findExactReferencingResources(addedObjects.get(container), ReferenceMatchPolicy.ALL)) {
URI uri = res.getURI();
if (!references.contains(uri) && filter.apply(uri) && containersState.getVisibleContainerHandles(containersState.getContainerHandle(uri)).contains(container)) {
references.add(uri);
}
}
}
return references;
}
use of org.eclipse.xtext.resource.IResourceDescription.Delta in project dsl-devkit by dsldevkit.
the class FormatBuilderParticipantTest method beforeAllTests.
/**
* Prepare mocks for all tests.
*/
@Override
protected void beforeAllTests() {
super.beforeAllTests();
participant = new FormatBuilderParticipant();
delta = mock(Delta.class);
uriCorrect = mock(URI.class);
when(delta.getUri()).thenReturn(uriCorrect);
}
use of org.eclipse.xtext.resource.IResourceDescription.Delta in project n4js by eclipse.
the class BuilderUtil method print.
/**
*/
public static String print(ImmutableList<Delta> deltas) {
int i = 1;
String buff = "Deltas : \n";
for (Delta delta : deltas) {
buff += "Delta " + i + "[" + delta.getUri() + "]: {\n";
buff += " old : " + toString(delta.getOld()) + "\n";
buff += " new : " + toString(delta.getNew()) + "\n";
buff += "}\n\n";
i++;
}
return buff;
}
use of org.eclipse.xtext.resource.IResourceDescription.Delta in project xtext-core by eclipse.
the class Indexer method computeAndIndexAffected.
/**
* Compute an updated index.
*/
public Indexer.IndexResult computeAndIndexAffected(BuildRequest request, BuildContext context) {
ResourceDescriptionsData previousIndex = context.getOldState().getResourceDescriptions();
ResourceDescriptionsData newIndex = request.getState().getResourceDescriptions();
List<IResourceDescription.Delta> deltas = new ArrayList<>();
deltas.addAll(getDeltasForDeletedResources(request, previousIndex, context));
deltas.addAll(getDeltasForChangedResources(request.getDirtyFiles(), previousIndex, context));
for (IResourceDescription.Delta delta : deltas) {
newIndex.register(delta);
}
Set<IResourceDescription.Delta> allDeltas = new HashSet<>(deltas);
allDeltas.addAll(request.getExternalDeltas());
Set<URI> remainingURIs = FluentIterable.from(previousIndex.getAllResourceDescriptions()).transform(IResourceDescription::getURI).copyInto(new HashSet<>());
remainingURIs.removeAll(FluentIterable.from(deltas).transform(Delta::getUri).toSet());
List<URI> allAffected = FluentIterable.from(remainingURIs).filter(it -> {
IResourceServiceProvider resourceServiceProvider = context.getResourceServiceProvider(it);
if (resourceServiceProvider != null) {
IResourceDescription.Manager manager = resourceServiceProvider.getResourceDescriptionManager();
IResourceDescription resourceDescription = previousIndex.getResourceDescription(it);
return isAffected(resourceDescription, manager, allDeltas, allDeltas, newIndex);
} else {
IResourceDescription.Delta delta = getDeltaForDeletedResource(it, previousIndex);
if (delta != null) {
deltas.add(delta);
}
return false;
}
}).toList();
deltas.addAll(getDeltasForChangedResources(allAffected, previousIndex, context));
return new Indexer.IndexResult(deltas, newIndex);
}
use of org.eclipse.xtext.resource.IResourceDescription.Delta in project xtext-eclipse by eclipse.
the class JdtToBeBuiltComputer method queueJavaChange.
protected void queueJavaChange(String typeName) {
URI typeURI = URIHelperConstants.OBJECTS_URI.appendSegment(typeName);
QualifiedName qualifiedName = QualifiedName.create(Strings.split(typeName, '.'));
NameBasedEObjectDescription nameBasedEObjectDescription = new NameBasedEObjectDescription(qualifiedName);
TypeResourceDescription oldDescription = new TypeResourceDescription(typeURI, Collections.<IEObjectDescription>singletonList(nameBasedEObjectDescription));
Delta delta = new ChangedResourceDescriptionDelta(oldDescription, null);
queuedBuildData.queueChange(delta);
}
Aggregations