Search in sources :

Example 1 with AbstractFormatter2

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);
}
Also used : IHiddenRegionFormatting(org.eclipse.xtext.formatting2.IHiddenRegionFormatting) ITextReplacer(org.eclipse.xtext.formatting2.ITextReplacer) ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) AbstractFormatter2(org.eclipse.xtext.formatting2.AbstractFormatter2) TextSegment(org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment)

Example 2 with AbstractFormatter2

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);
}
Also used : IHiddenRegionFormatting(org.eclipse.xtext.formatting2.IHiddenRegionFormatting) ITextReplacer(org.eclipse.xtext.formatting2.ITextReplacer) AbstractFormatter2(org.eclipse.xtext.formatting2.AbstractFormatter2)

Example 3 with AbstractFormatter2

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;
    }
}
Also used : ITextReplacer(org.eclipse.xtext.formatting2.ITextReplacer) AbstractFormatter2(org.eclipse.xtext.formatting2.AbstractFormatter2) IHiddenRegionPart(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegionPart) List(java.util.List) IWhitespace(org.eclipse.xtext.formatting2.regionaccess.IWhitespace) ITextReplacerContext(org.eclipse.xtext.formatting2.ITextReplacerContext)

Example 4 with AbstractFormatter2

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);
}
Also used : IHiddenRegionFormatting(org.eclipse.xtext.formatting2.IHiddenRegionFormatting) ITextReplacer(org.eclipse.xtext.formatting2.ITextReplacer) ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) AbstractFormatter2(org.eclipse.xtext.formatting2.AbstractFormatter2) TextSegment(org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment)

Example 5 with AbstractFormatter2

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;
}
Also used : ITextReplacer(org.eclipse.xtext.formatting2.ITextReplacer) IComment(org.eclipse.xtext.formatting2.regionaccess.IComment) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment)

Aggregations

ITextReplacer (org.eclipse.xtext.formatting2.ITextReplacer)5 AbstractFormatter2 (org.eclipse.xtext.formatting2.AbstractFormatter2)4 IHiddenRegionFormatting (org.eclipse.xtext.formatting2.IHiddenRegionFormatting)3 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)2 TextSegment (org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment)2 List (java.util.List)1 ITextReplacerContext (org.eclipse.xtext.formatting2.ITextReplacerContext)1 IComment (org.eclipse.xtext.formatting2.regionaccess.IComment)1 IHiddenRegionPart (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegionPart)1 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)1 IWhitespace (org.eclipse.xtext.formatting2.regionaccess.IWhitespace)1