Search in sources :

Example 1 with TextSegment

use of org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment 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 TextSegment

use of org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment in project xtext-core by eclipse.

the class SubDocument method requireFitsInLine.

@Override
public IFormattableSubDocument requireFitsInLine(int offset, int length, int maxLineWidth) {
    TextSegment segment = new TextSegment(getTextRegionAccess(), offset, length);
    MaxLineWidthDocument document = new MaxLineWidthDocument(segment, this, maxLineWidth);
    addReplacer(document);
    return document;
}
Also used : TextSegment(org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment)

Example 3 with TextSegment

use of org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment in project xtext-core by eclipse.

the class RegionSetTest method testNoMergeConflic1.

@Test
public void testNoMergeConflic1() {
    String expectation = "issues=\n" + "set=[[20,0], [20,1]]\n";
    test(expectation, (TestableTextSegmentSet it) -> {
        it.add(new TextSegment(null, 20, 0));
        it.add(new TextSegment(null, 20, 1));
    });
}
Also used : TextSegment(org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment) Test(org.junit.Test)

Example 4 with TextSegment

use of org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment in project xtext-core by eclipse.

the class RegionSetTest method testNoMergeConflic2.

@Test
public void testNoMergeConflic2() {
    String expectation = "issues=\n" + "set=[[20,0], [20,1]]\n";
    test(expectation, (TestableTextSegmentSet it) -> {
        it.add(new TextSegment(null, 20, 1));
        it.add(new TextSegment(null, 20, 0));
    });
}
Also used : TextSegment(org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment) Test(org.junit.Test)

Example 5 with TextSegment

use of org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment in project xtext-core by eclipse.

the class RegionSetTest method testMergeConflic4.

@Test
public void testMergeConflic4() {
    String expectation = "issues=mergeConflict:[20,2]<>[21,5]\n" + "set=[[21,5]]\n";
    test(expectation, (TestableTextSegmentSet it) -> {
        it.add(new TextSegment(null, 21, 5));
        it.add(new TextSegment(null, 20, 2));
    });
}
Also used : TextSegment(org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment) Test(org.junit.Test)

Aggregations

ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)12 TextSegment (org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment)12 Test (org.junit.Test)8 AbstractFormatter2 (org.eclipse.xtext.formatting2.AbstractFormatter2)2 IHiddenRegionFormatting (org.eclipse.xtext.formatting2.IHiddenRegionFormatting)2 ITextReplacer (org.eclipse.xtext.formatting2.ITextReplacer)2 IComment (org.eclipse.xtext.formatting2.regionaccess.IComment)2 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)2 ArrayList (java.util.ArrayList)1 IHiddenRegionPart (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegionPart)1 IWhitespace (org.eclipse.xtext.formatting2.regionaccess.IWhitespace)1