Search in sources :

Example 11 with IHiddenRegionFormatter

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

the class FormattableDocument method interior.

@Override
public <T extends EObject> T interior(T object, Procedure1<? super IHiddenRegionFormatter> init) {
    if (object != null) {
        IEObjectRegion objRegion = getTextRegionAccess().regionForEObject(object);
        if (objRegion != null) {
            IHiddenRegion previous = objRegion.getPreviousHiddenRegion();
            IHiddenRegion next = objRegion.getNextHiddenRegion();
            if (previous != null && next != null && previous != next) {
                interior(previous.getNextSemanticRegion(), next.getPreviousSemanticRegion(), init);
            }
        }
    }
    return object;
}
Also used : IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 12 with IHiddenRegionFormatter

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

the class FormattableDocument method prepend.

@Override
public <T extends EObject> T prepend(T owner, Procedure1<? super IHiddenRegionFormatter> before) {
    if (owner != null) {
        IEObjectRegion region = getTextRegionAccess().regionForEObject(owner);
        if (region != null) {
            IHiddenRegion gap = region.getPreviousHiddenRegion();
            set(gap, before);
        }
    }
    return owner;
}
Also used : IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 13 with IHiddenRegionFormatter

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

the class FormattableDocument method surround.

@Override
public <T extends EObject> T surround(T owner, Procedure1<? super IHiddenRegionFormatter> beforeAndAfter) {
    if (owner != null && !owner.eIsProxy()) {
        IEObjectRegion region = getTextRegionAccess().regionForEObject(owner);
        if (region == null)
            return owner;
        IHiddenRegion previous = region.getPreviousHiddenRegion();
        IHiddenRegion next = region.getNextHiddenRegion();
        set(previous, next, beforeAndAfter);
    }
    return owner;
}
Also used : IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 14 with IHiddenRegionFormatter

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

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

Aggregations

IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)34 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)28 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 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)18 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)13 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)12 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)8 KWList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.KWList)7 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)7 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)5 FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)4 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)4 Extension (org.eclipse.xtext.xbase.lib.Extension)4 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)3 IHiddenRegionFormatting (org.eclipse.xtext.formatting2.IHiddenRegionFormatting)3 XExpression (org.eclipse.xtext.xbase.XExpression)3