Search in sources :

Example 26 with IFormattableDocument

use of org.eclipse.xtext.formatting2.IFormattableDocument in project xtext-xtend by eclipse.

the class XtendFormatter method _format.

protected void _format(final XtendConstructor func, @Extension final IFormattableDocument format) {
    this.formatAnnotations(func, format, XbaseFormatterPreferenceKeys.newLineAfterConstructorAnnotations);
    this.formatModifiers(func, format);
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    format.append(this.textRegionExtensions.regionFor(func).keyword("new"), _function);
    boolean _isEmpty = func.getTypeParameters().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        format.append(this.textRegionExtensions.regionFor(func).keyword("<"), _function_1);
        EList<JvmTypeParameter> _typeParameters = func.getTypeParameters();
        for (final JvmTypeParameter arg : _typeParameters) {
            {
                format.<JvmTypeParameter>format(arg);
                final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                    it.noSpace();
                };
                final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
                    it.oneSpace();
                };
                format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(arg).keyword(","), _function_2), _function_3);
            }
        }
        final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        format.surround(this.textRegionExtensions.regionFor(func).keyword(">"), _function_2);
    }
    final ISemanticRegion open = this.textRegionExtensions.regionFor(func).keyword("(");
    final ISemanticRegion close = this.textRegionExtensions.regionFor(func).keyword(")");
    format.append(close, XbaseFormatterPreferenceKeys.bracesInNewLine);
    this.formatCommaSeparatedList(func.getParameters(), open, close, format);
    format.<XExpression>format(func.getExpression());
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XExpression(org.eclipse.xtext.xbase.XExpression) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 27 with IFormattableDocument

use of org.eclipse.xtext.formatting2.IFormattableDocument in project xtext-xtend by eclipse.

the class XtendFormatter method _format.

protected void _format(final XtendParameter param, @Extension final IFormattableDocument format) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    format.append(this.textRegionExtensions.regionFor(param).keyword("extension"), _function);
    this.formatAnnotations(param, format, XbaseFormatterPreferenceKeys.newLineAfterParameterAnnotations);
    format.<JvmTypeReference>format(param.getParameterType());
    final ISemanticRegion nameNode = this.textRegionExtensions.regionFor(param).feature(XtendPackage.Literals.XTEND_PARAMETER__NAME);
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    format.prepend(nameNode, _function_1);
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 28 with IFormattableDocument

use of org.eclipse.xtext.formatting2.IFormattableDocument in project xtext-xtend by eclipse.

the class XtendFormatter method formatTypeParameters.

protected ISemanticRegion formatTypeParameters(final XtendMember member, final List<? extends JvmTypeParameter> typeParameters, @Extension final IFormattableDocument format) {
    ISemanticRegion _xifexpression = null;
    boolean _isEmpty = typeParameters.isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        ISemanticRegion _xblockexpression = null;
        {
            final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            format.surround(this.textRegionExtensions.regionFor(member).keyword("<"), _function);
            for (final JvmTypeParameter arg : typeParameters) {
                {
                    format.<JvmTypeParameter>format(arg);
                    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                        it.noSpace();
                    };
                    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                        it.oneSpace();
                    };
                    format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(arg).keyword(","), _function_1), _function_2);
                }
            }
            final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            _xblockexpression = format.prepend(this.textRegionExtensions.regionFor(member).keyword(">"), _function_1);
        }
        _xifexpression = _xblockexpression;
    }
    return _xifexpression;
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 29 with IFormattableDocument

use of org.eclipse.xtext.formatting2.IFormattableDocument in project xtext-xtend by eclipse.

the class XtendFormatter method _format.

protected void _format(final XtendFile xtendFile, @Extension final IFormattableDocument format) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    format.<XtendFile>prepend(xtendFile, _function);
    final ISemanticRegion pkg = this.textRegionExtensions.regionFor(xtendFile).feature(XtendPackage.Literals.XTEND_FILE__PACKAGE);
    if ((pkg != null)) {
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.oneSpace();
        };
        format.prepend(pkg, _function_1);
        final ISemanticRegion pkgSemicolon = pkg.immediatelyFollowing().keyword(";");
        if ((pkgSemicolon != null)) {
            final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            format.append(pkg, _function_2);
            format.append(pkgSemicolon, XtendFormatterPreferenceKeys.blankLinesAfterPackageDecl);
        } else {
            format.append(pkg, XtendFormatterPreferenceKeys.blankLinesAfterPackageDecl);
        }
    }
    XImportSection _importSection = xtendFile.getImportSection();
    if (_importSection != null) {
        format.<XImportSection>format(_importSection);
    }
    EList<XtendTypeDeclaration> _xtendTypes = xtendFile.getXtendTypes();
    for (final XtendTypeDeclaration clazz : _xtendTypes) {
        {
            format.<XtendTypeDeclaration>format(clazz);
            XtendTypeDeclaration _last = IterableExtensions.<XtendTypeDeclaration>last(xtendFile.getXtendTypes());
            boolean _notEquals = (!Objects.equal(clazz, _last));
            if (_notEquals) {
                format.<XtendTypeDeclaration>append(clazz, XtendFormatterPreferenceKeys.blankLinesBetweenClasses);
            }
        }
    }
    final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    format.<XtendFile>append(xtendFile, _function_3);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) XImportSection(org.eclipse.xtext.xtype.XImportSection) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 30 with IFormattableDocument

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

the class TestLanguageFormatter method _format.

protected void _format(final TypeDeclaration type, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    document.append(this.textRegionExtensions.regionFor(type).keyword(this._testLanguageGrammarAccess.getTypeDeclarationAccess().getLeftCurlyBracketKeyword_3()), _function);
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    document.append(document.prepend(this.textRegionExtensions.regionFor(type).keyword(this._testLanguageGrammarAccess.getTypeDeclarationAccess().getRightCurlyBracketKeyword_5()), _function_1), _function_2);
    final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
        it.indent();
    };
    document.<ISemanticRegion, ISemanticRegion>interior(this.textRegionExtensions.regionFor(type).keyword(this._testLanguageGrammarAccess.getTypeDeclarationAccess().getLeftCurlyBracketKeyword_3()), this.textRegionExtensions.regionFor(type).keyword(this._testLanguageGrammarAccess.getTypeDeclarationAccess().getRightCurlyBracketKeyword_5()), _function_3);
    Iterable<Property> _filter = Iterables.<Property>filter(type.getMembers(), Property.class);
    for (final Property property : _filter) {
        document.<Property>format(property);
    }
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) Property(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Property)

Aggregations

IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)34 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)28 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)22 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)22 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)22 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)22 Test (org.junit.Test)22 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)20 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 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)5 FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)4 IHiddenRegionFormatting (org.eclipse.xtext.formatting2.IHiddenRegionFormatting)4 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)4 XExpression (org.eclipse.xtext.xbase.XExpression)4 Extension (org.eclipse.xtext.xbase.lib.Extension)4 Collection (java.util.Collection)3 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)3