use of org.eclipse.xtext.ide.serializer.hooks.IReferenceSnapshot in project xtext-core by eclipse.
the class RelatedResourcesProvider method getRelatedResources.
public List<RelatedResource> getRelatedResources(Collection<IResourceSnapshot> snapshots) {
Map<URI, RelatedResource> result = Maps.newLinkedHashMap();
for (IResourceSnapshot res : snapshots) {
for (IEObjectSnapshot obj : res.getObjects().values()) {
for (IReferenceSnapshot ref : obj.getIncomingReferences()) {
URI source = ref.getSourceEObjectUri().trimFragment();
RelatedResource related = result.get(source);
if (related == null) {
related = new RelatedResource(source);
result.put(source, related);
}
related.outgoingReferences.add(ref);
}
}
}
Set<URI> added = Sets.newHashSet();
Set<URI> removed = Sets.newHashSet();
for (IResourceSnapshot res : snapshots) {
URI oldUri = res.getURI();
URI newUri = res.getResource().getURI();
if (!oldUri.equals(newUri)) {
added.add(newUri);
removed.add(oldUri);
} else {
result.remove(newUri);
}
}
removed.removeAll(added);
for (URI uri : removed) {
result.remove(uri);
}
return ImmutableList.copyOf(result.values());
}
use of org.eclipse.xtext.ide.serializer.hooks.IReferenceSnapshot in project xtext-core by eclipse.
the class ResourceLifecycleManager method openAndApplyReferences.
public Resource openAndApplyReferences(ResourceSet resourceSet, RelatedResource toLoad) {
Resource resource = resourceSet.getResource(toLoad.getUri(), true);
for (IReferenceSnapshot desc : toLoad.outgoingReferences) {
EObject source = resource.getEObject(desc.getSourceEObjectUri().fragment());
EObject target = desc.getTarget().getObject();
EReference reference = desc.getEReference();
if (reference.isMany()) {
@SuppressWarnings("unchecked") List<Object> list = (EList<Object>) source.eGet(reference, false);
list.set(desc.getIndexInList(), target);
} else {
source.eSet(reference, target);
}
}
return resource;
}
Aggregations