Search in sources :

Example 1 with RelatedResource

use of org.eclipse.xtext.ide.serializer.impl.RelatedResourcesProvider.RelatedResource 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)

Example 2 with RelatedResource

use of org.eclipse.xtext.ide.serializer.impl.RelatedResourcesProvider.RelatedResource in project xtext-core by eclipse.

the class ChangeSerializer method endRecordChanges.

protected void endRecordChanges(IAcceptor<IEmfResourceChange> changeAcceptor) {
    if (updaters.isEmpty()) {
        return;
    }
    List<IResourceSnapshot> snapshots = getSnapshots();
    Deltas deltas = deltaProvider.getDelta(this, snapshots);
    List<ResourceUpdater> updaters = Lists.newArrayList(this.updaters.values());
    if (updateRelatedFiles && updateCrossReferences) {
        List<RelatedResource> related = relatedResourcesProvider.getRelatedResources(deltas.getSnapshots());
        for (RelatedResource ref : related) {
            RelatedResourceUpdater updater = createResourceUpdater(ref);
            updaters.add(updater);
        }
    }
    monitor.beginTask("Creating Text Changes...", updaters.size());
    for (ResourceUpdater updater : updaters) {
        updater.applyChange(deltas, changeAcceptor);
        monitor.worked(1);
        checkCanceled();
    }
    for (ResourceUpdater updater : updaters) {
        updater.unload();
    }
}
Also used : Deltas(org.eclipse.xtext.ide.serializer.impl.EObjectDescriptionDeltaProvider.Deltas) RelatedResource(org.eclipse.xtext.ide.serializer.impl.RelatedResourcesProvider.RelatedResource) IResourceSnapshot(org.eclipse.xtext.ide.serializer.hooks.IResourceSnapshot)

Aggregations

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