use of org.eclipse.emf.ecore.change.ResourceChange in project xtext-core by eclipse.
the class ChangeTreeProvider method createChangeTree.
public ResourceSetRecording createChangeTree(ResourceSet resourceSet, Collection<IResourceSnapshot> snapshots, ChangeDescription desc) {
ResourceSetRecording rs = new ResourceSetRecording(resourceSet);
Map<Resource, ResourceRecording> result = Maps.newLinkedHashMap();
Map<EObject, EObjectChange> objectChanges = Maps.newLinkedHashMap();
for (IResourceSnapshot snap : snapshots) {
Resource resource = snap.getResource();
ResourceRecording recording = new ResourceRecording(rs, resource);
recording.snapshot = snap;
result.put(resource, recording);
}
for (ResourceChange rc : desc.getResourceChanges()) {
Resource resource = rc.getResource();
ResourceRecording recording = result.get(resource);
if (recording == null) {
recording = new ResourceRecording(rs, resource);
result.put(resource, recording);
}
recording.resourceChange = rc;
}
for (Entry<EObject, EList<FeatureChange>> e : desc.getObjectChanges().entrySet()) {
EList<FeatureChange> featureChange = e.getValue();
EObject object = e.getKey();
objectChanges.put(object, new EObjectChange(object, featureChange));
}
for (EObjectChange change : Lists.newArrayList(objectChanges.values())) {
EObjectChange current = change;
while (true) {
EObject container = current.eObject.eContainer();
if (container != null) {
EObjectChange next = objectChanges.get(container);
if (next == null) {
next = new EObjectChange(container);
next.children.add(current);
objectChanges.put(container, next);
} else {
if (!next.children.add(current)) {
break;
}
}
current = next;
} else {
Resource resource = current.eObject.eResource();
ResourceRecording resourceChange = result.get(resource);
if (resourceChange == null) {
resourceChange = new ResourceRecording(rs, resource);
result.put(resource, resourceChange);
// TODO: check that only recorded resources contain
// modification
}
resourceChange.roots.add(current);
break;
}
}
}
rs.resources = ImmutableList.copyOf(result.values());
rs.objects = ImmutableMap.copyOf(objectChanges);
return rs;
}
Aggregations