use of org.eclipse.xtext.formatting2.AbstractFormatter2 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.AbstractFormatter2 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.AbstractFormatter2 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.AbstractFormatter2 in project xtext-xtend by eclipse.
the class RichStringFormatter method setSpace.
protected void setSpace(final IFormattableDocument doc, final int offset, final int length, final String space) {
IHiddenRegionFormatting _createHiddenRegionFormatting = doc.getFormatter().createHiddenRegionFormatting();
final Procedure1<IHiddenRegionFormatting> _function = (IHiddenRegionFormatting it) -> {
it.setSpace(space);
};
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.AbstractFormatter2 in project xtext-core by eclipse.
the class HiddenRegionReplacer method createReplacers.
protected List<ITextReplacer> createReplacers(AbstractFormatter2 formatter) {
List<ITextSegment> regions = region.getAlternatingMergedSpaceAndComments();
List<ITextReplacer> replacers = Lists.newArrayListWithCapacity(regions.size());
for (ITextSegment region : regions) {
if (region instanceof IComment)
replacers.add(formatter.createCommentReplacer((IComment) region));
else
replacers.add(formatter.createWhitespaceReplacer(region, formatter.createHiddenRegionFormatting()));
}
return replacers;
}
Aggregations