use of org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.ResourceRecording in project xtext-core by eclipse.
the class RecordingXtextResourceUpdater method applyChange.
@Override
public void applyChange(Deltas deltas, IAcceptor<IEmfResourceChange> changeAcceptor) {
Resource resource = snapshot.getResource();
ResourceSet rs = resource.getResourceSet();
ReferenceUpdaterContext ctx = new ReferenceUpdaterContext(deltas, document);
if (serializer.isUpdateCrossReferences()) {
referenceUpdater.update(ctx);
for (Runnable run : ctx.getModifications()) {
run.run();
}
}
ChangeDescription recording = recorder.endRecording();
if (recording != null) {
List<IResourceSnapshot> snapshots = Collections.singletonList(snapshot);
ResourceSetRecording tree = changeTreeProvider.createChangeTree(rs, snapshots, recording);
ResourceRecording recordedResource = tree.getRecordedResource(resource);
partialSerializer.serializeChanges(recordedResource, document);
}
recorder.dispose();
List<IUpdatableReference> updatableReferences = ctx.getUpdatableReferences();
for (IUpdatableReference upd : updatableReferences) {
referenceUpdater.updateReference(document, upd);
}
ITextRegionAccessDiff rewritten = document.create();
List<ITextReplacement> rep = formatter.format(rewritten);
URI oldUri = snapshot.getURI();
TextDocumentChange change = new TextDocumentChange(rewritten, oldUri, rep);
changeAcceptor.accept(change);
}
use of org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.ResourceRecording in project xtext-core by eclipse.
the class RelatedXtextResourceUpdater method applyChange.
@Override
public void applyChange(Deltas deltas, IAcceptor<IEmfResourceChange> changeAcceptor) {
XtextResource res = (XtextResource) lifecycleManager.openAndApplyReferences(getResourceSet(), getResource());
if (!referenceUpdater.isAffected(deltas, getResource())) {
return;
}
ITextRegionAccess base = textRegionBuilderProvider.get().forNodeModel(res).create();
ITextRegionDiffBuilder rewriter = new StringBasedTextRegionAccessDiffBuilder(base);
ReferenceUpdaterContext context = new ReferenceUpdaterContext(deltas, rewriter, getResource());
referenceUpdater.update(context);
if (!context.getModifications().isEmpty()) {
ChangeRecorder rec = createChangeRecorder(res);
try {
for (Runnable run : context.getModifications()) {
run.run();
}
ChangeDescription recording = rec.endRecording();
ResourceSet rs = res.getResourceSet();
ResourceSetRecording tree = changeTreeProvider.createChangeTree(rs, Collections.emptyList(), recording);
ResourceRecording recordedResource = tree.getRecordedResource(res);
if (recordedResource != null) {
serializer.serializeChanges(recordedResource, rewriter);
}
} finally {
rec.dispose();
}
}
for (IUpdatableReference upd : context.getUpdatableReferences()) {
referenceUpdater.updateReference(rewriter, upd);
}
ITextRegionAccessDiff rewritten = rewriter.create();
List<ITextReplacement> rep = formatter.format(rewritten);
TextDocumentChange change = new TextDocumentChange(rewritten, getResource().getUri(), rep);
changeAcceptor.accept(change);
}
Aggregations