Search in sources :

Example 1 with EObjectChange

use of org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.EObjectChange in project xtext-core by eclipse.

the class PartialSerializer method serializeChanges.

public void serializeChanges(ResourceRecording changes, ITextRegionDiffBuilder result) {
    assertLanguage(changes);
    SerializationContextMap<IConstraint> constraints = constraintProvider.getConstraints(grammar.getGrammar());
    List<EObjectChange> rootChanges = collectRootChanges(changes.getRootEObjectRecordings());
    List<SerializationStrategy> strategies = Lists.newArrayList();
    while (!rootChanges.isEmpty()) {
        List<EObjectChange> nextRoots = Lists.newArrayList();
        for (EObjectChange change : rootChanges) {
            EObject obj = change.getEObject();
            IEObjectRegion originalEObjectRegion = result.getOriginalTextRegionAccess().regionForEObject(obj);
            ISerializationContext modified = getSerializationContext(obj);
            if (originalEObjectRegion == null) {
                strategies.add(new SerializeRecursiveStrategy(originalEObjectRegion, obj, modified));
                continue;
            }
            ISerializationContext original = getSerializationContext(originalEObjectRegion);
            if (!original.equals(modified)) {
                strategies.add(new SerializeRecursiveStrategy(originalEObjectRegion, obj, modified));
                // TODO: need to serialize container sometimes?
                continue;
            }
            IConstraint constraint = constraints.get(modified);
            List<SerializationStrategy> features = trySerializeIndividualFeatures(change, originalEObjectRegion, modified, constraint);
            if (features != null) {
                strategies.addAll(features);
                nextRoots.addAll(change.getChildren());
            } else {
                strategies.add(new SerializeRecursiveStrategy(originalEObjectRegion, obj, modified));
            }
        }
        rootChanges = collectRootChanges(nextRoots);
    }
    for (SerializationStrategy strategy : strategies) {
        strategy.serialize(result);
    }
}
Also used : IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) EObject(org.eclipse.emf.ecore.EObject) IConstraint(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint) EObjectChange(org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.EObjectChange)

Example 2 with EObjectChange

use of org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.EObjectChange in project xtext-core by eclipse.

the class PartialSerializer method collectRootChanges.

protected List<EObjectChange> collectRootChanges(Collection<? extends EObjectChange> roots) {
    List<EObjectChange> result = Lists.newArrayList();
    LinkedList<EObjectChange> stack = new LinkedList<>();
    stack.addAll(roots);
    while (!stack.isEmpty()) {
        EObjectChange candidate = stack.pop();
        if (candidate.getChanges().isEmpty()) {
            stack.addAll(candidate.getChildren());
        } else {
            result.add(candidate);
        }
    }
    return result;
}
Also used : LinkedList(java.util.LinkedList) EObjectChange(org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.EObjectChange)

Aggregations

EObjectChange (org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.EObjectChange)2 LinkedList (java.util.LinkedList)1 EObject (org.eclipse.emf.ecore.EObject)1 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)1 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)1 IConstraint (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint)1