Search in sources :

Example 1 with IDList

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

the class CommentFormatterTest method MLSL_inline.

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

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

the class CommentFormatterTest method MLSL_paragraph.

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

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

the class CommentFormatterTest method MLML_inline.

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

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

the class FormattingConflictTest method enableDebugTracingFalse.

@Test
public void enableDebugTracingFalse() {
    final Wrapper<Throwable> wrapper = new Wrapper<Throwable>();
    final Wrapper<Integer> execution = new Wrapper<Integer>(Integer.valueOf(0));
    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) {
                Integer _get = execution.get();
                int _plus = ((_get).intValue() + 1);
                execution.set(Integer.valueOf(_plus));
                final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
                    it_1.setSpace(" ");
                };
                document.append(regions.regionFor(model).keyword("idlist"), _function);
                final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
                    it_1.setSpace("\t");
                };
                document.append(regions.regionFor(model).keyword("idlist"), _function_1);
            }
        };
        it.setFormatter(_function_1);
        FormatterRequest _request = it.getRequest();
        _request.setEnableDebugTracing(false);
        FormatterRequest _request_1 = it.getRequest();
        final IAcceptor<Exception> _function_2 = (Exception e) -> {
            wrapper.set(e);
        };
        _request_1.setExceptionHandler(_function_2);
    };
    this._genericFormatterTester.assertFormatted(_function);
    Throwable _get = wrapper.get();
    final ConflictingRegionsException exception = ((ConflictingRegionsException) _get);
    Assert.assertEquals(2, (execution.get()).intValue());
    Assert.assertEquals(2, exception.getTraces().size());
}
Also used : Wrapper(org.eclipse.xtext.util.Wrapper) GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) ConflictingRegionsException(org.eclipse.xtext.formatting2.internal.ConflictingRegionsException) ConflictingRegionsException(org.eclipse.xtext.formatting2.internal.ConflictingRegionsException) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IAcceptor(org.eclipse.xtext.util.IAcceptor) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest) Test(org.junit.Test)

Example 5 with IDList

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

the class FormattingConflictTest method enableDebugTracingTrue.

@Test
public void enableDebugTracingTrue() {
    final Wrapper<Throwable> wrapper = new Wrapper<Throwable>();
    final Wrapper<Integer> execution = new Wrapper<Integer>(Integer.valueOf(0));
    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) {
                Integer _get = execution.get();
                int _plus = ((_get).intValue() + 1);
                execution.set(Integer.valueOf(_plus));
                final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
                    it_1.setSpace(" ");
                };
                document.append(regions.regionFor(model).keyword("idlist"), _function);
                final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
                    it_1.setSpace("\t");
                };
                document.append(regions.regionFor(model).keyword("idlist"), _function_1);
            }
        };
        it.setFormatter(_function_1);
        FormatterRequest _request = it.getRequest();
        _request.setEnableDebugTracing(true);
        FormatterRequest _request_1 = it.getRequest();
        final IAcceptor<Exception> _function_2 = (Exception e) -> {
            wrapper.set(e);
        };
        _request_1.setExceptionHandler(_function_2);
    };
    this._genericFormatterTester.assertFormatted(_function);
    Throwable _get = wrapper.get();
    final ConflictingRegionsException exception = ((ConflictingRegionsException) _get);
    Assert.assertEquals(1, (execution.get()).intValue());
    Assert.assertEquals(2, exception.getTraces().size());
}
Also used : Wrapper(org.eclipse.xtext.util.Wrapper) GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) ConflictingRegionsException(org.eclipse.xtext.formatting2.internal.ConflictingRegionsException) ConflictingRegionsException(org.eclipse.xtext.formatting2.internal.ConflictingRegionsException) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IAcceptor(org.eclipse.xtext.util.IAcceptor) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)15 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)15 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)15 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)10 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)10 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)10 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)10 FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 TextRegion (org.eclipse.xtext.util.TextRegion)3 Joiner (com.google.common.base.Joiner)2 Lists (com.google.common.collect.Lists)2 Inject (com.google.inject.Inject)2 Provider (com.google.inject.Provider)2 List (java.util.List)2 URI (org.eclipse.emf.common.util.URI)2 EObject (org.eclipse.emf.ecore.EObject)2 ConflictingRegionsException (org.eclipse.xtext.formatting2.internal.ConflictingRegionsException)2