Search in sources :

Example 1 with IReferenceSnapshot

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());
}
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 2 with IReferenceSnapshot

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;
}
Also used : EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) RelatedResource(org.eclipse.xtext.ide.serializer.impl.RelatedResourcesProvider.RelatedResource) EObject(org.eclipse.emf.ecore.EObject) IReferenceSnapshot(org.eclipse.xtext.ide.serializer.hooks.IReferenceSnapshot) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

IReferenceSnapshot (org.eclipse.xtext.ide.serializer.hooks.IReferenceSnapshot)2 EList (org.eclipse.emf.common.util.EList)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 EReference (org.eclipse.emf.ecore.EReference)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 IEObjectSnapshot (org.eclipse.xtext.ide.serializer.hooks.IEObjectSnapshot)1 IResourceSnapshot (org.eclipse.xtext.ide.serializer.hooks.IResourceSnapshot)1 RelatedResource (org.eclipse.xtext.ide.serializer.impl.RelatedResourcesProvider.RelatedResource)1