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);
}
}
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;
}
Aggregations