use of org.eclipse.xtext.formatting2.ITextReplacerContext in project xtext-core by eclipse.
the class TextReplacerContext method withReplacer.
@Override
public ITextReplacerContext withReplacer(ITextReplacer replacer) {
ITextReplacerContext current = this;
while (current != null) {
ITextReplacer lastReplacer = current.getReplacer();
if (lastReplacer != null) {
if (nextReplacerIsChild) {
Preconditions.checkArgument(lastReplacer.getRegion().contains(replacer.getRegion()));
} else {
Preconditions.checkArgument(lastReplacer.getRegion().getEndOffset() <= replacer.getRegion().getOffset());
}
break;
}
current = current.getPreviousContext();
}
return new TextReplacerContext(document, this, indentation, replacer);
}
use of org.eclipse.xtext.formatting2.ITextReplacerContext in project xtext-core by eclipse.
the class TextReplacerContext method getLeadingCharsInLineCount.
@Override
public int getLeadingCharsInLineCount() {
ITextRegionAccess access = getDocument().getRequest().getTextRegionAccess();
int lastOffset = replacer.getRegion().getOffset();
ITextReplacerContext current = this;
int count = 0;
while (current != null) {
Iterator<ITextReplacement> localReplacements = current.getLocalReplacementsReverse().iterator();
while (localReplacements.hasNext()) {
ITextReplacement rep = localReplacements.next();
int endOffset = rep.getEndOffset();
if (endOffset > lastOffset) {
// System.out.println("error");
continue;
}
String between = access.textForOffset(endOffset, lastOffset - endOffset);
int idx = between.lastIndexOf('\n');
if (idx >= 0)
return count + logicalLength(between.substring(idx + 1));
count += logicalLength(between);
String text = rep.getReplacementText();
int idx2 = text.lastIndexOf('\n');
if (idx2 >= 0)
return count + logicalLength(text.substring(idx2 + 1));
count += logicalLength(text);
lastOffset = rep.getOffset();
}
current = current.getPreviousContext();
}
String rest = access.textForOffset(0, lastOffset);
int idx = rest.lastIndexOf('\n');
if (idx >= 0)
return count + logicalLength(rest.substring(idx + 1));
count += lastOffset;
return count;
}
Aggregations