Search in sources :

Example 1 with FeatureChange

use of org.eclipse.emf.ecore.change.FeatureChange 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;
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) FeatureChange(org.eclipse.emf.ecore.change.FeatureChange) EList(org.eclipse.emf.common.util.EList) IResourceSnapshot(org.eclipse.xtext.ide.serializer.hooks.IResourceSnapshot) EObject(org.eclipse.emf.ecore.EObject) ResourceChange(org.eclipse.emf.ecore.change.ResourceChange)

Example 2 with FeatureChange

use of org.eclipse.emf.ecore.change.FeatureChange in project xtext-core by eclipse.

the class PartialSerializer method trySerializeIndividualFeatures.

protected List<SerializationStrategy> trySerializeIndividualFeatures(EObjectChange change, IEObjectRegion original, ISerializationContext context, IConstraint constraint) {
    List<SerializationStrategy> result = Lists.newArrayList();
    EObject object = change.getEObject();
    for (FeatureChange featureChange : change.getChanges()) {
        EStructuralFeature feature = featureChange.getFeature();
        List<SerializationStrategy> values = null;
        // } else {
        if (feature.isMany()) {
            values = trySerializeMultiValue(object, featureChange, original, constraint);
        } else {
            values = trySerializeSingleValue(object, featureChange, original, constraint);
        }
        // }
        if (values == null) {
            return null;
        }
        result.addAll(values);
    }
    return result;
}
Also used : FeatureChange(org.eclipse.emf.ecore.change.FeatureChange) EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)2 FeatureChange (org.eclipse.emf.ecore.change.FeatureChange)2 EList (org.eclipse.emf.common.util.EList)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 ResourceChange (org.eclipse.emf.ecore.change.ResourceChange)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 IResourceSnapshot (org.eclipse.xtext.ide.serializer.hooks.IResourceSnapshot)1