use of org.eclipse.xtext.ide.serializer.hooks.IEObjectSnapshot in project xtext-core by eclipse.
the class EObjectDescriptionDeltaProvider method getDelta.
public Deltas getDelta(ChangeSerializer serializer, Collection<IResourceSnapshot> snapshots) {
Map<EObject, IEObjectSnapshot> old = Maps.newHashMap();
Map<EObject, Group> groups = Maps.newHashMap();
for (IResourceSnapshot rs : snapshots) {
old.putAll(rs.getObjects());
}
for (IResourceSnapshot rs : snapshots) {
IEObjectDescriptionProvider p = serializer.getService(rs.getResource(), IEObjectDescriptionProvider.class);
Iterable<IEObjectDescription> descriptions = p.getEObjectDescriptions(rs.getResource());
for (IEObjectDescription desc : descriptions) {
EObject obj = EcoreUtil.resolve(desc.getEObjectOrProxy(), rs.getResource());
Group delta = groups.get(obj);
if (delta == null) {
delta = new Group(obj);
delta.snapshot = old.get(obj);
groups.put(obj, delta);
}
delta.descriptions.add(desc);
}
}
Deltas result = new Deltas();
result.snapshots = snapshots;
for (Group g : groups.values()) {
Delta delta = createDelta(g.object, g.snapshot, g.descriptions);
if (delta.hasQualifiedNameChanged() || delta.hasSimpleNameOrUserdataChanged()) {
result.deltas.put(delta.object, delta);
}
}
return result;
}
use of org.eclipse.xtext.ide.serializer.hooks.IEObjectSnapshot in project xtext-core by eclipse.
the class EObjectSnapshotProvider method createEObjectSnapshots.
protected Map<EObject, IEObjectSnapshot> createEObjectSnapshots(Resource resource) {
Map<EObject, IEObjectSnapshot> result = Maps.newLinkedHashMap();
for (IEObjectDescription desc : descriptionProvider.getEObjectDescriptions(resource)) {
EObject obj = EcoreUtil.resolve(desc.getEObjectOrProxy(), resource);
EObjectSnapshot snapshot = getOrCreate(result, obj);
snapshot.descriptions.add(desc);
}
ResourceSet resourceSet = resource.getResourceSet();
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(resourceSet);
URI uri = resource.getURI();
for (IResourceDescription desc : descriptions.getAllResourceDescriptions()) {
for (IReferenceDescription ref : desc.getReferenceDescriptions()) {
URI targetURI = ref.getTargetEObjectUri();
URI sourceEObjectUri = ref.getSourceEObjectUri();
EReference reference = ref.getEReference();
if (targetURI == null || sourceEObjectUri == null || reference == null) {
continue;
}
if (!uri.equals(targetURI.trimFragment())) {
continue;
}
EObject target = resource.getEObject(targetURI.fragment());
if (target == null || target.eIsProxy()) {
continue;
}
EObjectSnapshot snapshot = getOrCreate(result, target);
ReferenceSnapshot rd = new ReferenceSnapshot(sourceEObjectUri, snapshot, reference, ref.getIndexInList(), ref.getContainerEObjectURI());
snapshot.incomingReferences.add(rd);
}
}
return result;
}
use of org.eclipse.xtext.ide.serializer.hooks.IEObjectSnapshot 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.IEObjectSnapshot in project xtext-core by eclipse.
the class EObjectSnapshotProvider method getOrCreate.
protected EObjectSnapshot getOrCreate(Map<EObject, IEObjectSnapshot> map, EObject obj) {
IEObjectSnapshot result = map.get(obj);
if (result == null) {
result = new EObjectSnapshot(obj);
map.put(obj, result);
}
return (EObjectSnapshot) result;
}
Aggregations