Search in sources :

Example 16 with GenericFormatterTestRequest

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

the class FormattableDocumentTest method conditionalFormatting1.

@Test
public void conditionalFormatting1() {
    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 ISubFormatter _function = (IFormattableSubDocument doc) -> {
                    @Extension final IFormattableSubDocument fits = doc.requireFitsInLine();
                    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
                        it_1.oneSpace();
                    };
                    fits.append(regions.regionFor(model).keyword("kwlist"), _function_1);
                    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_1) -> {
                        it_1.oneSpace();
                    };
                    fits.append(regions.regionFor(model).keyword("kw1"), _function_2);
                };
                final ISubFormatter _function_1 = (IFormattableSubDocument doc) -> {
                    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_1) -> {
                        it_1.newLine();
                    };
                    doc.append(regions.regionFor(model).keyword("kwlist"), _function_2);
                    final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it_1) -> {
                        it_1.newLine();
                    };
                    doc.append(regions.regionFor(model).keyword("kw1"), _function_3);
                };
                document.formatConditionally(model, _function, _function_1);
            }
        };
        it.setFormatter(_function_2);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("kwlist");
        _builder_1.newLine();
        _builder_1.append("kw1");
        _builder_1.newLine();
        _builder_1.append("kw2");
        _builder_1.newLine();
        it.setExpectation(_builder_1);
    };
    this._genericFormatterTester.assertFormatted(_function);
}
Also used : 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) IFormattableSubDocument(org.eclipse.xtext.formatting2.IFormattableSubDocument) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Extension(org.eclipse.xtext.xbase.lib.Extension) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) ISubFormatter(org.eclipse.xtext.formatting2.ISubFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 17 with GenericFormatterTestRequest

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

the class FormattableDocumentTest method shouldFormat.

@Test
public void shouldFormat() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        Collection<ITextRegion> _regions = it.getRequest().getRegions();
        TextRegion _textRegion = new TextRegion(0, 6);
        _regions.add(_textRegion);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("idlist");
        it.setToBeFormatted(_builder);
        it.setFormatter(new GenericFormatter() {

            @Override
            protected void format(final EObject model, final ITextRegionExtensions regionAccess, final IFormattableDocument document) {
                throw new IllegalStateException("this method should never be called");
            }

            @Override
            public boolean shouldFormat(final Object obj, final IFormattableDocument document) {
                return false;
            }
        });
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("idlist");
        it.setExpectation(_builder_1);
    };
    this._genericFormatterTester.assertFormatted(_function);
}
Also used : GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Test(org.junit.Test)

Example 18 with GenericFormatterTestRequest

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

the class FormattableDocumentTest method simple.

@Test
public void simple() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("idlist  a");
        _builder.newLine();
        it.setToBeFormatted(_builder);
        final GenericFormatter<IDList> _function_1 = new GenericFormatter<IDList>() {

            @Override
            protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
                final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
                    it_1.oneSpace();
                };
                document.append(regions.regionFor(model).keyword("idlist"), _function);
            }
        };
        it.setFormatter(_function_1);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("idlist a");
        _builder_1.newLine();
        it.setExpectation(_builder_1);
    };
    this._genericFormatterTester.assertFormatted(_function);
}
Also used : GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Test(org.junit.Test)

Example 19 with GenericFormatterTestRequest

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

the class FormattableDocumentTest method autowrap.

@Test
public void autowrap() {
    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("idlist  aaa  bbb  ccc  ddd  eee  fff");
        _builder.newLine();
        it.setToBeFormatted(_builder);
        final GenericFormatter<IDList> _function_2 = new GenericFormatter<IDList>() {

            @Override
            protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
                final Consumer<ISemanticRegion> _function = (ISemanticRegion it_1) -> {
                    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_2) -> {
                        it_2.autowrap();
                        it_2.oneSpace();
                    };
                    document.prepend(it_1, _function_1);
                };
                regions.regionFor(model).ruleCallsTo(FormattableDocumentTest.this._formatterTestLanguageGrammarAccess.getIDRule()).forEach(_function);
            }
        };
        it.setFormatter(_function_2);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("idlist aaa");
        _builder_1.newLine();
        _builder_1.append("bbb ccc");
        _builder_1.newLine();
        _builder_1.append("ddd eee fff");
        _builder_1.newLine();
        it.setExpectation(_builder_1);
    };
    this._genericFormatterTester.assertFormatted(_function);
}
Also used : GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) Consumer(java.util.function.Consumer) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) Test(org.junit.Test)

Example 20 with GenericFormatterTestRequest

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

GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)21 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)20 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)20 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)20 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)20 Test (org.junit.Test)20 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)18 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)18 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)11 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)8 KWList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.KWList)7 Collection (java.util.Collection)3 ITextRegion (org.eclipse.xtext.util.ITextRegion)3 TextRegion (org.eclipse.xtext.util.TextRegion)3 EObject (org.eclipse.emf.ecore.EObject)2 FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)2 IAutowrapFormatter (org.eclipse.xtext.formatting2.IAutowrapFormatter)2 IFormattableSubDocument (org.eclipse.xtext.formatting2.IFormattableSubDocument)2 IHiddenRegionFormatting (org.eclipse.xtext.formatting2.IHiddenRegionFormatting)2 ISubFormatter (org.eclipse.xtext.formatting2.ISubFormatter)2