Search in sources :

Example 6 with IHiddenRegionFormatter

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

the class XtendFormatter method _format.

protected void _format(final XtendClass clazz, @Extension final IFormattableDocument format) {
    this.formatAnnotations(clazz, format, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations);
    this.formatModifiers(clazz, format);
    this.formatTypeParameters(clazz, clazz.getTypeParameters(), format);
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    format.append(this.textRegionExtensions.regionFor(clazz).keyword("class"), _function);
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    format.surround(this.textRegionExtensions.regionFor(clazz).keyword("extends"), _function_1);
    format.<JvmTypeReference>format(clazz.getExtends());
    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    format.surround(this.textRegionExtensions.regionFor(clazz).keyword("implements"), _function_2);
    EList<JvmTypeReference> _implements = clazz.getImplements();
    for (final JvmTypeReference imp : _implements) {
        {
            final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it) -> {
                it.oneSpace();
            };
            format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(imp).keyword(","), _function_3), _function_4);
            format.<JvmTypeReference>format(imp);
        }
    }
    this.formatBody(clazz, format);
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1)

Example 7 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)

Example 8 with IHiddenRegionFormatter

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

the class PartialSerializationTestLanguageFormatter method _format.

protected void _format(final Node obj, @Extension final IFormattableDocument document) {
    List<ISemanticRegion> _keywords = this.textRegionExtensions.regionFor(obj).keywords(";");
    for (final ISemanticRegion r : _keywords) {
        final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.oneSpace();
        };
        document.append(document.prepend(r, _function), _function_1);
    }
    EList<Node> _children = obj.getChildren();
    for (final Node child : _children) {
        document.<Node>format(child);
    }
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Node(org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 9 with IHiddenRegionFormatter

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

the class FormattableDocument method set.

@Override
public Pair<IHiddenRegion, IHiddenRegion> set(IHiddenRegion first, IHiddenRegion second, Procedure1<? super IHiddenRegionFormatter> init) {
    if (first != null && second != null) {
        AbstractFormatter2 formatter = getFormatter();
        IHiddenRegionFormatting f1 = formatter.createHiddenRegionFormatting();
        IHiddenRegionFormatting f2 = formatter.createHiddenRegionFormatting();
        init.apply(formatter.createHiddenRegionFormatter(f1, f2));
        ITextReplacer replacer1 = formatter.createHiddenRegionReplacer(first, f1);
        ITextReplacer replacer2 = formatter.createHiddenRegionReplacer(second, f2);
        addReplacer(replacer1);
        addReplacer(replacer2);
    }
    return Pair.of(first, second);
}
Also used : IHiddenRegionFormatting(org.eclipse.xtext.formatting2.IHiddenRegionFormatting) ITextReplacer(org.eclipse.xtext.formatting2.ITextReplacer) AbstractFormatter2(org.eclipse.xtext.formatting2.AbstractFormatter2)

Example 10 with IHiddenRegionFormatter

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

the class FormattableDocument method append.

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

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