use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionRewriter 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.ITextRegionRewriter in project xtext-core by eclipse.
the class RegionAccessTestHelper method assertDiffs.
public void assertDiffs(final ITextRegionAccessDiff regions) {
final ITextRegionRewriter rewriter = regions.getOriginalTextRegionAccess().getRewriter();
final ArrayList<ITextReplacement> result = Lists.<ITextReplacement>newArrayList();
List<ITextSegmentDiff> _regionDifferences = regions.getRegionDifferences();
for (final ITextSegmentDiff r : _regionDifferences) {
{
final ITextSegment originalRegion = r.getOriginalRegion();
final ITextSegment modifiedRegion = r.getModifiedRegion();
final ITextReplacement replacement = originalRegion.replaceWith(modifiedRegion.getText());
result.add(replacement);
}
}
final String actual = rewriter.renderToString(result);
final String expected = regions.regionForDocument().getText();
Assert.assertEquals(expected, actual);
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionRewriter in project xtext-core by eclipse.
the class TextRegionsWithTitleToString method toString.
@Override
public String toString() {
ITextRegionAccess access = getTextRegionAccess();
ITextSegment frame = getFrame();
if (access == null || frame == null)
return "(null)";
ITextRegionRewriter rewriter = access.getRewriter();
StringBuilder builder = new StringBuilder();
List<ITextReplacement> replacements = Lists.newArrayList();
for (int i = 0; i < this.items.size(); i++) {
Item item = this.items.get(i);
ITextSegment region = item.getRegion();
String regionStr = "offset=" + region.getOffset() + " length=" + region.getLength();
String open = i < BRACKETS_OPEN.length ? BRACKETS_OPEN[i] : "[" + i + "[";
String close = i < BRACKETS_CLOSE.length ? BRACKETS_CLOSE[i] : "]" + i + "]";
builder.append(open + close + ": " + item.getTitle() + " at " + regionStr + "\n");
replacements.add(rewriter.createReplacement(region.getOffset(), 0, open));
replacements.add(rewriter.createReplacement(region.getEndOffset(), 0, close));
}
String vizualized = rewriter.renderToString(frame, replacements);
builder.append(box("document snippet", vizualized));
return builder.toString();
}
Aggregations