Search in sources :

Example 1 with KWList

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

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

the class FormattableDocumentTest method conditionalFormatting2.

@Test
public void conditionalFormatting2() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(30));
        };
        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 kw1 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 3 with KWList

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

the class FormattableDocumentTest method autowrapNotInPreviousLineInFormattedRegion.

@Test
public void autowrapNotInPreviousLineInFormattedRegion() {
    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 kw3 kw4  kw5");
        _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();
                    it_1.oneSpace();
                };
                document.append(regions.regionFor(model).keyword("kwlist"), _function);
                final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
                    it_1.newLine();
                };
                document.append(regions.regionFor(model).keyword("kw1"), _function_1);
                final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it_1) -> {
                    it_1.oneSpace();
                };
                document.append(regions.regionFor(model).keyword("kw4"), _function_2);
            }
        };
        it.setFormatter(_function_2);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("kwlist kw1");
        _builder_1.newLine();
        _builder_1.append("kw2 kw3 kw4 kw5");
        _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) 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) Test(org.junit.Test)

Example 4 with KWList

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

the class FormattableDocumentTest method autowrapNotInPreviousLineBetweenFormattedRegions.

@Test
public void autowrapNotInPreviousLineBetweenFormattedRegions() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(5));
        };
        it.preferences(_function_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("kwlist kw1");
        _builder.newLine();
        _builder.append("kw2 kw3 kw4  kw5");
        _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();
                    it_1.oneSpace();
                };
                document.append(regions.regionFor(model).keyword("kwlist"), _function);
                final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
                    it_1.oneSpace();
                };
                document.append(regions.regionFor(model).keyword("kw4"), _function_1);
            }
        };
        it.setFormatter(_function_2);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("kwlist kw1");
        _builder_1.newLine();
        _builder_1.append("kw2 kw3 kw4 kw5");
        _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) 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) Test(org.junit.Test)

Example 5 with KWList

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

the class FormatterTestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == FormattertestlanguagePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case FormattertestlanguagePackage.ID_LIST:
                sequence_IDList(context, (IDList) semanticObject);
                return;
            case FormattertestlanguagePackage.KW_LIST:
                sequence_KWList(context, (KWList) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) KWList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.KWList) Parameter(org.eclipse.xtext.Parameter) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) EPackage(org.eclipse.emf.ecore.EPackage)

Aggregations

KWList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.KWList)8 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)7 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)7 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)7 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)7 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)7 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)7 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)7 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)7 Test (org.junit.Test)7 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 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)2 Extension (org.eclipse.xtext.xbase.lib.Extension)2 EPackage (org.eclipse.emf.ecore.EPackage)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1