use of org.eclipse.xtext.formatting2.ITextReplacer in project xtext-xtend by eclipse.
the class RichStringFormatter method setNewLines.
protected void setNewLines(final IFormattableDocument doc, final int offset, final int length, final int indentationIncrease, final int indentationDecrease, final int newLines) {
IHiddenRegionFormatting _createHiddenRegionFormatting = doc.getFormatter().createHiddenRegionFormatting();
final Procedure1<IHiddenRegionFormatting> _function = (IHiddenRegionFormatting it) -> {
it.setIndentationIncrease(Integer.valueOf(indentationIncrease));
it.setIndentationDecrease(Integer.valueOf(indentationDecrease));
it.setNewLinesMin(Integer.valueOf(newLines));
it.setNewLinesDefault(Integer.valueOf(newLines));
it.setNewLinesMax(Integer.valueOf(newLines));
};
final IHiddenRegionFormatting fmt = ObjectExtensions.<IHiddenRegionFormatting>operator_doubleArrow(_createHiddenRegionFormatting, _function);
AbstractFormatter2 _formatter = doc.getFormatter();
ITextRegionAccess _textRegionAccess = this._iTextRegionExtensions.getTextRegionAccess();
TextSegment _textSegment = new TextSegment(_textRegionAccess, offset, length);
final ITextReplacer replacer = _formatter.createWhitespaceReplacer(_textSegment, fmt);
doc.addReplacer(replacer);
}
use of org.eclipse.xtext.formatting2.ITextReplacer in project xtext-core by eclipse.
the class AbstractFormatter2 method createCommentReplacer.
public ITextReplacer createCommentReplacer(IComment comment) {
EObject grammarElement = comment.getGrammarElement();
if (grammarElement instanceof AbstractRule) {
String ruleName = ((AbstractRule) grammarElement).getName();
if (ruleName.startsWith("ML"))
return new MultilineCommentReplacer(comment, '*');
if (ruleName.startsWith("SL")) {
if (comment.getLineRegions().get(0).getIndentation().getLength() > 0)
return new SinglelineDocCommentReplacer(comment, "//");
else
return new SinglelineCodeCommentReplacer(comment, "//");
}
}
String elementName = new GrammarElementTitleSwitch().showQualified().showRule().doSwitch(grammarElement);
throw new IllegalStateException("No " + ITextReplacer.class.getSimpleName() + " configured for " + elementName);
}
use of org.eclipse.xtext.formatting2.ITextReplacer in project xtext-core by eclipse.
the class FormattableDocument method set.
@Override
public Pair<IHiddenRegion, IHiddenRegion> set(IHiddenRegion first, IHiddenRegion second, Procedure1<? super IHiddenRegionFormatter> init) {
if (first != null && second != null) {
AbstractFormatter2 formatter = getFormatter();
IHiddenRegionFormatting f1 = formatter.createHiddenRegionFormatting();
IHiddenRegionFormatting f2 = formatter.createHiddenRegionFormatting();
init.apply(formatter.createHiddenRegionFormatter(f1, f2));
ITextReplacer replacer1 = formatter.createHiddenRegionReplacer(first, f1);
ITextReplacer replacer2 = formatter.createHiddenRegionReplacer(second, f2);
addReplacer(replacer1);
addReplacer(replacer2);
}
return Pair.of(first, second);
}
use of org.eclipse.xtext.formatting2.ITextReplacer 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.ITextReplacer in project xtext-core by eclipse.
the class TextReplacerContext method getRegion.
protected ITextSegment getRegion(int index) {
ITextReplacerContext current = this;
while (current != null) {
ITextReplacer replacer2 = current.getReplacer();
if (replacer2 != null) {
if (index == 0) {
return replacer2.getRegion();
} else
index--;
}
current = current.getPreviousContext();
}
return null;
}
Aggregations