use of org.eclipse.xtext.formatting2.ITextReplacerContext in project xtext-core by eclipse.
the class FormattableDocument method renderToTextReplacements.
@Override
public List<ITextReplacement> renderToTextReplacements() {
ITextReplacerContext first = getFormatter().createTextReplacerContext(this);
ITextReplacerContext last = createReplacements(first);
List<ITextReplacement> replacements = last.getReplacementsUntil(first);
return replacements;
}
use of org.eclipse.xtext.formatting2.ITextReplacerContext in project xtext-core by eclipse.
the class HiddenRegionReplacer method createReplacements.
@Override
public ITextReplacerContext createReplacements(ITextReplacerContext context) {
AbstractFormatter2 formatter = context.getFormatter();
List<IHiddenRegionPart> hiddens = region.getParts();
if (hiddens.isEmpty()) {
return formatter.createWhitespaceReplacer(region, formatting).createReplacements(context);
} else if ((hiddens.size() == 1 && hiddens.get(0) instanceof IWhitespace)) {
return formatter.createWhitespaceReplacer(hiddens.get(0), formatting).createReplacements(context);
} else {
List<ITextReplacer> replacers = createReplacers(formatter);
applyHiddenRegionFormatting(replacers);
ITextReplacerContext current = context;
current.setNextReplacerIsChild();
for (ITextReplacer replacer : replacers) current = replacer.createReplacements(current.withReplacer(replacer));
return current;
}
}
use of org.eclipse.xtext.formatting2.ITextReplacerContext in project xtext-core by eclipse.
the class MaxLineWidthDocument method createReplacements.
@Override
public ITextReplacerContext createReplacements(ITextReplacerContext context) {
ITextReplacerContext last = super.createReplacements(context);
List<ITextReplacement> replacements = last.getReplacementsUntil(context);
String string = applyTextReplacements(replacements);
if (string.contains("\n"))
throw new FormattingNotApplicableException();
int leadingCharCount = context.getLeadingCharsInLineCount();
int formattedLength = string.length();
int lineLength = leadingCharCount + formattedLength;
if (lineLength > maxLineWidth)
throw new FormattingNotApplicableException();
return last;
}
use of org.eclipse.xtext.formatting2.ITextReplacerContext in project xtext-core by eclipse.
the class SubDocument method createReplacements.
@Override
public ITextReplacerContext createReplacements(ITextReplacerContext previous) {
ITextReplacerContext context = ((TextReplacerContext) previous).withDocument(this);
context.setNextReplacerIsChild();
return ((TextReplacerContext) super.createReplacements(context)).withDocument(previous.getDocument());
}
use of org.eclipse.xtext.formatting2.ITextReplacerContext 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