Search in sources :

Example 1 with IHiddenRegionFormatting

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

the class FormattableDocumentTest method autoWrapRewrite.

@Test
public void autoWrapRewrite() {
    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) -> {
                        it_2.setSpace("@");
                        it_2.lowPriority();
                    };
                    document.append(regions.regionFor(model).keyword("kw1"), _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 2 with IHiddenRegionFormatting

use of org.eclipse.xtext.formatting2.IHiddenRegionFormatting 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 3 with IHiddenRegionFormatting

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

the class MaxLineWidthDocument method validate.

protected void validate(HiddenRegionReplacer replacer) throws FormattingNotApplicableException {
    IHiddenRegionFormatting formatting = replacer.getFormatting();
    Integer newLineMin = formatting.getNewLineMin();
    if (newLineMin != null && newLineMin < 0)
        throw new FormattingNotApplicableException();
}
Also used : IHiddenRegionFormatting(org.eclipse.xtext.formatting2.IHiddenRegionFormatting) FormattingNotApplicableException(org.eclipse.xtext.formatting2.FormattingNotApplicableException)

Example 4 with IHiddenRegionFormatting

use of org.eclipse.xtext.formatting2.IHiddenRegionFormatting 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 5 with IHiddenRegionFormatting

use of org.eclipse.xtext.formatting2.IHiddenRegionFormatting 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)

Aggregations

IHiddenRegionFormatting (org.eclipse.xtext.formatting2.IHiddenRegionFormatting)9 ITextReplacer (org.eclipse.xtext.formatting2.ITextReplacer)5 AbstractFormatter2 (org.eclipse.xtext.formatting2.AbstractFormatter2)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 IAutowrapFormatter (org.eclipse.xtext.formatting2.IAutowrapFormatter)2 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)2 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)2 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)2 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)2 KWList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.KWList)2 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)2 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)2 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)2 TextSegment (org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment)2 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 Test (org.junit.Test)2 FormattingNotApplicableException (org.eclipse.xtext.formatting2.FormattingNotApplicableException)1 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)1