Search in sources :

Example 1 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion 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 2 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion 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 3 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion 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 4 with ISemanticRegion

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

the class RegionAccessBuilderTest method assertToStringDoesNotCrash.

private void assertToStringDoesNotCrash(final ITextRegionAccess access) {
    IHiddenRegion _previousHiddenRegion = access.regionForRootEObject().getPreviousHiddenRegion();
    ISequentialRegion current = ((ISequentialRegion) _previousHiddenRegion);
    while ((current != null)) {
        {
            Assert.assertNotNull(current.toString());
            boolean _matched = false;
            if (current instanceof IHiddenRegion) {
                _matched = true;
                current = ((IHiddenRegion) current).getNextSemanticRegion();
            }
            if (!_matched) {
                if (current instanceof ISemanticRegion) {
                    _matched = true;
                    Assert.assertNotNull(((ISemanticRegion) current).getEObjectRegion().toString());
                    current = ((ISemanticRegion) current).getNextHiddenRegion();
                }
            }
        }
    }
}
Also used : ISequentialRegion(org.eclipse.xtext.formatting2.regionaccess.ISequentialRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 5 with ISemanticRegion

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

the class XtendFormatter method _format.

protected void _format(final XtendEnum enumeration, @Extension final IFormattableDocument format) {
    this.formatAnnotations(enumeration, format, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations);
    this.formatModifiers(enumeration, format);
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    format.append(this.textRegionExtensions.regionFor(enumeration).keyword("enum"), _function);
    final ISemanticRegion open = this.textRegionExtensions.regionFor(enumeration).keyword("{");
    final ISemanticRegion close = this.textRegionExtensions.regionFor(enumeration).keyword("}");
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.indent();
    };
    format.<ISemanticRegion, ISemanticRegion>interior(open, close, _function_1);
    format.prepend(open, XbaseFormatterPreferenceKeys.bracesInNewLine);
    boolean _isEmpty = enumeration.getMembers().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        format.append(open, XtendFormatterPreferenceKeys.blankLinesBeforeFirstMember);
        int _size = enumeration.getMembers().size();
        int _minus = (_size - 1);
        IntegerRange _upTo = new IntegerRange(0, _minus);
        for (final Integer i : _upTo) {
            {
                final XtendMember current = enumeration.getMembers().get((i).intValue());
                format.<XtendMember>format(current);
                int _size_1 = enumeration.getMembers().size();
                int _minus_1 = (_size_1 - 1);
                boolean _lessThan = ((i).intValue() < _minus_1);
                if (_lessThan) {
                    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                        it.noSpace();
                    };
                    format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(current).keyword(","), _function_2), XtendFormatterPreferenceKeys.blankLinesBetweenEnumLiterals);
                } else {
                    format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesAfterLastMember);
                }
            }
        }
    } else {
        final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
            it.newLine();
        };
        format.append(open, _function_2);
    }
}
Also used : IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Aggregations

ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)59 Test (org.junit.Test)30 ISemanticRegionsFinder (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder)18 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)15 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)14 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)13 Mixed (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed)12 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)9 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)7 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)7 EObject (org.eclipse.emf.ecore.EObject)4 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)4 AssignedAction (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.AssignedAction)4 XExpression (org.eclipse.xtext.xbase.XExpression)4 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)3 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)3 ValueList (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList)3 LinkedList (java.util.LinkedList)2 EReference (org.eclipse.emf.ecore.EReference)2 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2