use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff 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.formatting2.regionaccess.ITextRegionAccessDiff in project xtext-core by eclipse.
the class RegionAccessTestHelper method assertRegions.
public void assertRegions(ITextRegionAccess access, CharSequence expectation) {
if (access instanceof ITextRegionAccessDiff) {
assertDiffs((ITextRegionAccessDiff) access);
}
String tra1 = cfg(new TextRegionAccessToString().withRegionAccess(access)) + "\n";
Assert.assertEquals(Strings.toPlatformLineSeparator(expectation), Strings.toPlatformLineSeparator(tra1));
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff in project xtext-core by eclipse.
the class RegionDiffFormatter method mergeReplacements.
protected List<ITextReplacement> mergeReplacements(ITextRegionAccessDiff regions, List<ITextReplacement> rep) {
ITextRegionRewriter rewriter = regions.getOriginalTextRegionAccess().getRewriter();
List<ITextReplacement> result = Lists.newArrayList();
for (ITextSegmentDiff r : regions.getRegionDifferences()) {
ITextSegment original = r.getOriginalRegion();
ITextSegment modified = r.getModifiedRegion();
List<ITextReplacement> local = Lists.newArrayList();
for (ITextReplacement re : rep) {
if (modified.contains(re)) {
local.add(re);
}
}
String text;
if (local.isEmpty()) {
text = modified.getText();
} else {
text = regions.getRewriter().renderToString(modified, local);
}
ITextReplacement replacement = rewriter.createReplacement(original.getOffset(), original.getLength(), text);
result.add(replacement);
}
return result;
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff in project xtext-core by eclipse.
the class RegionDiffFormatter method createFormatterRequest.
protected FormatterRequest createFormatterRequest(ITextRegionAccessDiff rewritten) {
FormatterRequest request = formatterRequest.get();
request.setTextRegionAccess(rewritten);
request.setRegions(collectRegionsToFormat(rewritten));
return request;
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff in project xtext-core by eclipse.
the class RegionAccessTestHelper method operator_tripleEquals.
public void operator_tripleEquals(final ITextRegionAccess access, final CharSequence expectation) {
if ((access instanceof ITextRegionAccessDiff)) {
this.assertDiffs(((ITextRegionAccessDiff) access));
}
TextRegionAccessToString _cfg = this.cfg(new TextRegionAccessToString().withRegionAccess(access));
final String tra1 = (_cfg + "\n");
Assert.assertEquals(Strings.toPlatformLineSeparator(expectation), Strings.toPlatformLineSeparator(tra1));
}
Aggregations