Search in sources :

Example 11 with IDList

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

Example 12 with IDList

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

the class CommentFormatterTest method MLML_paragraph.

@Test
public void MLML_paragraph() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("idlist");
        _builder.newLine();
        _builder.newLine();
        _builder.newLine();
        _builder.append("/*");
        _builder.newLine();
        _builder.append("x");
        _builder.newLine();
        _builder.append("*/");
        _builder.newLine();
        _builder.newLine();
        _builder.newLine();
        _builder.append("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");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("/*");
        _builder_1.newLine();
        _builder_1.append(" ");
        _builder_1.append("* x");
        _builder_1.newLine();
        _builder_1.append(" ");
        _builder_1.append("*/");
        _builder_1.newLine();
        _builder_1.append("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 13 with IDList

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

the class CommentFormatterTest method SL_multiline.

@Test
public void SL_multiline() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("idlist  ");
        _builder.newLine();
        _builder.newLine();
        _builder.append("//x");
        _builder.newLine();
        _builder.newLine();
        _builder.newLine();
        _builder.append("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 //x");
        _builder_1.newLine();
        _builder_1.append("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 14 with IDList

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

the class CommentFormatterTest method SL_inline.

@Test
public void SL_inline() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("idlist  //x");
        _builder.newLine();
        _builder.append("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 //x");
        _builder_1.newLine();
        _builder_1.append("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 15 with IDList

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

Aggregations

Test (org.junit.Test)16 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)15 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)15 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)15 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)15 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)15 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)13 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)13 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)13 FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)4 Collection (java.util.Collection)3 EObject (org.eclipse.emf.ecore.EObject)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)3 XtextResource (org.eclipse.xtext.resource.XtextResource)3 ITextRegion (org.eclipse.xtext.util.ITextRegion)3 TextRegion (org.eclipse.xtext.util.TextRegion)3 ConflictingRegionsException (org.eclipse.xtext.formatting2.internal.ConflictingRegionsException)2 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)2 IAcceptor (org.eclipse.xtext.util.IAcceptor)2