use of org.eclipse.xtext.formatting2.internal.TextReplacementList in project xtext-core by eclipse.
the class TextRegionRewriter method renderToAppendable.
@Override
public void renderToAppendable(ITextSegment input, Iterable<? extends ITextReplacement> rep, Appendable result) throws IOException {
int offset = input.getOffset();
String text = input.getText();
List<ITextReplacement> list = new TextReplacementList<ITextReplacement>(rep);
Collections.sort(list);
int lastOffset = 0;
for (ITextReplacement r : list) {
result.append(text.subSequence(lastOffset, r.getOffset() - offset));
result.append(r.getReplacementText());
lastOffset = (r.getOffset() - offset) + r.getLength();
}
if (lastOffset <= text.length())
result.append(text.subSequence(lastOffset, text.length()));
}
use of org.eclipse.xtext.formatting2.internal.TextReplacementList in project xtext-core by eclipse.
the class TextReplacerContext method getReplacementsUntil.
@Override
public List<ITextReplacement> getReplacementsUntil(ITextReplacerContext first) {
ITextReplacerContext current = this;
List<Iterable<ITextReplacement>> reversedReplacements = Lists.newArrayList();
while (current != null) {
Iterable<ITextReplacement> localReplacements = current.getLocalReplacements();
if (!Iterables.isEmpty(localReplacements))
reversedReplacements.add(localReplacements);
if (current == first)
break;
current = current.getPreviousContext();
}
Collections.reverse(reversedReplacements);
List<ITextReplacement> flattenedReplacements = new TextReplacementList<ITextReplacement>();
for (Iterable<ITextReplacement> chunk : reversedReplacements) Iterables.addAll(flattenedReplacements, chunk);
return flattenedReplacements;
}
Aggregations