Search in sources :

Example 31 with ITextSegment

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

the class FormattableDocumentTest method autoWrapInsert.

@Test
public void autoWrapInsert() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(10));
        };
        it.preferences(_function_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("kwlist  kw1  kw2");
        _builder.newLine();
        it.setToBeFormatted(_builder);
        final GenericFormatter<KWList> _function_2 = new GenericFormatter<KWList>() {

            @Override
            protected void format(final KWList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
                final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
                    it_1.autowrap();
                    final IAutowrapFormatter _function_1 = (ITextSegment region, IHiddenRegionFormatting wrapped, IFormattableDocument doc) -> {
                        final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_2) -> {
                            it_2.setSpace("!");
                        };
                        doc.append(regions.regionFor(model).keyword("kw1"), _function_2);
                    };
                    it_1.setOnAutowrap(_function_1);
                    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_2) -> {
                        String _property = System.getProperty("line.separator");
                        String _plus = ("@" + _property);
                        it_2.setSpace(_plus);
                    };
                    document.append(regions.regionFor(model).keyword("kw2"), _function_2);
                };
                document.append(regions.regionFor(model).keyword("kwlist"), _function);
            }
        };
        it.setFormatter(_function_2);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("kwlist");
        _builder_1.newLine();
        _builder_1.append("kw1!kw2@");
        _builder_1.newLine();
        it.setExpectation(_builder_1);
    };
    this._genericFormatterTester.assertFormatted(_function);
}
Also used : IHiddenRegionFormatting(org.eclipse.xtext.formatting2.IHiddenRegionFormatting) GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) KWList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.KWList) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment) IAutowrapFormatter(org.eclipse.xtext.formatting2.IAutowrapFormatter) Test(org.junit.Test)

Example 32 with ITextSegment

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

the class TestableTextSegmentSet method toString.

@Override
public String toString() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("issues=");
    String _join = IterableExtensions.join(this.issues, ", ");
    _builder.append(_join);
    _builder.newLineIfNotEmpty();
    _builder.append("set=");
    final Function1<ITextSegment, String> _function = (ITextSegment it) -> {
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("[");
        int _offset = it.getOffset();
        _builder_1.append(_offset);
        _builder_1.append(",");
        int _length = it.getLength();
        _builder_1.append(_length);
        _builder_1.append("]");
        return _builder_1.toString();
    };
    String _replace = IterableExtensions.<ITextSegment, String>map(this.set, _function).toString().replace("\n", ", ");
    _builder.append(_replace);
    _builder.newLineIfNotEmpty();
    return _builder.toString();
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment)

Aggregations

ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)30 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)10 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)8 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)5 String (java.lang.String)4 IComment (org.eclipse.xtext.formatting2.regionaccess.IComment)4 IHiddenRegionPart (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegionPart)4 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 ITextReplacer (org.eclipse.xtext.formatting2.ITextReplacer)3 TextRegionsToString (org.eclipse.xtext.formatting2.debug.TextRegionsToString)3 ILineRegion (org.eclipse.xtext.formatting2.regionaccess.ILineRegion)3 ITextRegionRewriter (org.eclipse.xtext.formatting2.regionaccess.ITextRegionRewriter)3 ITextSegmentDiff (org.eclipse.xtext.formatting2.regionaccess.ITextSegmentDiff)3 IAutowrapFormatter (org.eclipse.xtext.formatting2.IAutowrapFormatter)2 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)2 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)2 IHiddenRegionFormatting (org.eclipse.xtext.formatting2.IHiddenRegionFormatting)2 ITextReplacerContext (org.eclipse.xtext.formatting2.ITextReplacerContext)2 HiddenRegionFormattingToString (org.eclipse.xtext.formatting2.debug.HiddenRegionFormattingToString)2 TextRegionAccessToString (org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)2