Search in sources :

Example 1 with IHiddenRegionFormatter

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

the class RuleEngineFormatter method _format.

@Override
protected void _format(final XSwitchExpression expr, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.indent();
    };
    document.set(this.textRegionExtensions.previousHiddenRegion(expr.getSwitch()), this.textRegionExtensions.nextHiddenRegion(expr), _function);
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    document.append(this.textRegionExtensions.regionFor(expr).keyword("switch"), _function_1);
    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    document.<XExpression>format(document.<XExpression>append(expr.getSwitch(), _function_2));
    EList<XCasePart> _cases = expr.getCases();
    for (final XCasePart c : _cases) {
        {
            if (((c.getTypeGuard() != null) && (c.getCase() != null))) {
                final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
                    it.oneSpace();
                };
                document.<JvmTypeReference>append(c.getTypeGuard(), _function_3);
                final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it) -> {
                    it.noSpace();
                };
                document.<XExpression>append(c.getCase(), _function_4);
            } else {
                JvmTypeReference _typeGuard = c.getTypeGuard();
                boolean _tripleNotEquals = (_typeGuard != null);
                if (_tripleNotEquals) {
                    final Procedure1<IHiddenRegionFormatter> _function_5 = (IHiddenRegionFormatter it) -> {
                        it.noSpace();
                    };
                    document.<JvmTypeReference>append(c.getTypeGuard(), _function_5);
                } else {
                    XExpression _case = c.getCase();
                    boolean _tripleNotEquals_1 = (_case != null);
                    if (_tripleNotEquals_1) {
                        final Procedure1<IHiddenRegionFormatter> _function_6 = (IHiddenRegionFormatter it) -> {
                            it.oneSpace();
                        };
                        final Procedure1<IHiddenRegionFormatter> _function_7 = (IHiddenRegionFormatter it) -> {
                            it.noSpace();
                        };
                        document.<XExpression>append(document.<XExpression>prepend(c.getCase(), _function_6), _function_7);
                    }
                }
            }
            final Procedure1<IHiddenRegionFormatter> _function_8 = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            final Procedure1<IHiddenRegionFormatter> _function_9 = (IHiddenRegionFormatter it) -> {
                it.newLine();
            };
            document.append(document.prepend(this.textRegionExtensions.regionFor(c).feature(XbasePackage.Literals.XCASE_PART__FALL_THROUGH), _function_8), _function_9);
            document.<XExpression>format(c.getCase());
            if ((Objects.equal(c, IterableExtensions.<XCasePart>last(expr.getCases())) && (expr.getDefault() == null))) {
                this.formatBody(c.getThen(), true, document);
            } else {
                this.formatBodyParagraph(c.getThen(), document);
            }
        }
    }
    XExpression _default = expr.getDefault();
    boolean _tripleNotEquals = (_default != null);
    if (_tripleNotEquals) {
        final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        document.append(this.textRegionExtensions.regionFor(expr).keyword("default"), _function_3);
        this.formatBody(expr.getDefault(), true, document);
    }
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XCasePart(org.eclipse.xtext.xbase.XCasePart) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 2 with IHiddenRegionFormatter

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

the class DomainmodelFormatter method _format.

protected void _format(final DomainModel domainmodel, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.setNewLines(0, 0, 1);
        it.noSpace();
    };
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    document.<DomainModel>append(document.<DomainModel>prepend(domainmodel, _function), _function_1);
    this.format(domainmodel.getImportSection(), document);
    EList<AbstractElement> _elements = domainmodel.getElements();
    for (final AbstractElement element : _elements) {
        this.format(element, document);
    }
}
Also used : DomainModel(org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel) AbstractElement(org.eclipse.xtext.example.domainmodel.domainmodel.AbstractElement) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter)

Example 3 with IHiddenRegionFormatter

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

the class DomainmodelFormatter method _format.

protected void _format(final PackageDeclaration pkg, @Extension final IFormattableDocument document) {
    final ISemanticRegion open = this.textRegionExtensions.regionFor(pkg).keyword("{");
    final ISemanticRegion close = this.textRegionExtensions.regionFor(pkg).keyword("}");
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    document.surround(this.textRegionExtensions.regionFor(pkg).feature(DomainmodelPackage.Literals.ABSTRACT_ELEMENT__NAME), _function);
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    document.append(open, _function_1);
    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
        it.indent();
    };
    document.<ISemanticRegion, ISemanticRegion>interior(open, close, _function_2);
    EList<AbstractElement> _elements = pkg.getElements();
    for (final AbstractElement element : _elements) {
        {
            document.<AbstractElement>format(element);
            final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
                it.setNewLines(1, 1, 2);
            };
            document.<AbstractElement>append(element, _function_3);
        }
    }
}
Also used : AbstractElement(org.eclipse.xtext.example.domainmodel.domainmodel.AbstractElement) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 4 with IHiddenRegionFormatter

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

the class DomainmodelFormatter method _format.

protected void _format(final Operation operation, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    document.append(this.textRegionExtensions.regionFor(operation).keyword("op"), _function);
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    document.surround(this.textRegionExtensions.regionFor(operation).keyword("("), _function_1);
    boolean _isEmpty = operation.getParams().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        List<ISemanticRegion> _keywords = this.textRegionExtensions.regionFor(operation).keywords(",");
        for (final ISemanticRegion comma : _keywords) {
            final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
                it.oneSpace();
            };
            document.append(document.prepend(comma, _function_2), _function_3);
        }
        EList<JvmFormalParameter> _params = operation.getParams();
        for (final JvmFormalParameter params : _params) {
            document.<JvmFormalParameter>format(params);
        }
        final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        document.prepend(this.textRegionExtensions.regionFor(operation).keyword(")"), _function_4);
    }
    JvmTypeReference _type = operation.getType();
    boolean _tripleNotEquals = (_type != null);
    if (_tripleNotEquals) {
        final Procedure1<IHiddenRegionFormatter> _function_5 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        document.append(this.textRegionExtensions.regionFor(operation).keyword(")"), _function_5);
        final Procedure1<IHiddenRegionFormatter> _function_6 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        final Procedure1<IHiddenRegionFormatter> _function_7 = (IHiddenRegionFormatter it) -> {
            it.oneSpace();
        };
        document.<JvmTypeReference>append(document.<JvmTypeReference>prepend(operation.getType(), _function_6), _function_7);
        document.<JvmTypeReference>format(operation.getType());
    } else {
        final Procedure1<IHiddenRegionFormatter> _function_8 = (IHiddenRegionFormatter it) -> {
            it.oneSpace();
        };
        document.append(this.textRegionExtensions.regionFor(operation).keyword(")"), _function_8);
    }
    document.<XExpression>format(operation.getBody());
}
Also used : JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XExpression(org.eclipse.xtext.xbase.XExpression) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 5 with IHiddenRegionFormatter

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

the class FileAwareTestLanguageFormatter method _format.

protected void _format(final PackageDeclaration pkg, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.setNewLines(2);
    };
    document.append(this.textRegionExtensions.regionFor(pkg).feature(FileAwarePackage.Literals.PACKAGE_DECLARATION__NAME), _function);
    EList<Import> _imports = pkg.getImports();
    for (final Import imp : _imports) {
        {
            document.<Import>format(imp);
            final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                int _xifexpression = (int) 0;
                Import _last = IterableExtensions.<Import>last(pkg.getImports());
                boolean _tripleEquals = (imp == _last);
                if (_tripleEquals) {
                    _xifexpression = 2;
                } else {
                    _xifexpression = 1;
                }
                it.setNewLines(_xifexpression);
            };
            document.<Import>append(imp, _function_1);
        }
    }
    EList<Element> _contents = pkg.getContents();
    for (final Element element : _contents) {
        document.<Element>format(element);
    }
}
Also used : Import(org.eclipse.xtext.testlanguages.fileAware.fileAware.Import) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) Element(org.eclipse.xtext.testlanguages.fileAware.fileAware.Element)

Aggregations

IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)41 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)27 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)18 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)18 Test (org.junit.Test)18 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)15 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)15 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)15 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)14 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)11 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)7 KWList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.KWList)7 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)7 XExpression (org.eclipse.xtext.xbase.XExpression)7 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)4 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)3 IHiddenRegionFormatting (org.eclipse.xtext.formatting2.IHiddenRegionFormatting)3 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2 JvmTypeConstraint (org.eclipse.xtext.common.types.JvmTypeConstraint)2