Search in sources :

Example 1 with IEObjectSnapshot

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;
}
Also used : IEObjectSnapshot(org.eclipse.xtext.ide.serializer.hooks.IEObjectSnapshot) IResourceSnapshot(org.eclipse.xtext.ide.serializer.hooks.IResourceSnapshot) EObject(org.eclipse.emf.ecore.EObject) IEObjectDescriptionProvider(org.eclipse.xtext.ide.serializer.hooks.IEObjectDescriptionProvider) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 2 with IEObjectSnapshot

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;
}
Also used : IEObjectSnapshot(org.eclipse.xtext.ide.serializer.hooks.IEObjectSnapshot) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) EObject(org.eclipse.emf.ecore.EObject) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEObjectSnapshot(org.eclipse.xtext.ide.serializer.hooks.IEObjectSnapshot) URI(org.eclipse.emf.common.util.URI) IReferenceSnapshot(org.eclipse.xtext.ide.serializer.hooks.IReferenceSnapshot) EReference(org.eclipse.emf.ecore.EReference) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 3 with IEObjectSnapshot

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());
}
Also used : IEObjectSnapshot(org.eclipse.xtext.ide.serializer.hooks.IEObjectSnapshot) IResourceSnapshot(org.eclipse.xtext.ide.serializer.hooks.IResourceSnapshot) URI(org.eclipse.emf.common.util.URI) IReferenceSnapshot(org.eclipse.xtext.ide.serializer.hooks.IReferenceSnapshot)

Example 4 with IEObjectSnapshot

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;
}
Also used : IEObjectSnapshot(org.eclipse.xtext.ide.serializer.hooks.IEObjectSnapshot) IEObjectSnapshot(org.eclipse.xtext.ide.serializer.hooks.IEObjectSnapshot)

Aggregations

IEObjectSnapshot (org.eclipse.xtext.ide.serializer.hooks.IEObjectSnapshot)4 URI (org.eclipse.emf.common.util.URI)2 EObject (org.eclipse.emf.ecore.EObject)2 IReferenceSnapshot (org.eclipse.xtext.ide.serializer.hooks.IReferenceSnapshot)2 IResourceSnapshot (org.eclipse.xtext.ide.serializer.hooks.IResourceSnapshot)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 EReference (org.eclipse.emf.ecore.EReference)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 IEObjectDescriptionProvider (org.eclipse.xtext.ide.serializer.hooks.IEObjectDescriptionProvider)1 IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)1