Search in sources :

Example 46 with IHiddenRegionFormatter

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

the class DomainmodelFormatter method _format.

protected void _format(final Entity entity, @Extension final IFormattableDocument document) {
    final ISemanticRegion open = this.textRegionExtensions.regionFor(entity).keyword("{");
    final ISemanticRegion close = this.textRegionExtensions.regionFor(entity).keyword("}");
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    document.surround(this.textRegionExtensions.regionFor(entity).feature(DomainmodelPackage.Literals.ABSTRACT_ELEMENT__NAME), _function);
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    document.<JvmParameterizedTypeReference>surround(entity.getSuperType(), _function_1);
    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    document.append(open, _function_2);
    final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
        it.indent();
    };
    document.<ISemanticRegion, ISemanticRegion>interior(open, close, _function_3);
    this.format(entity.getSuperType(), document);
    EList<Feature> _features = entity.getFeatures();
    for (final Feature feature : _features) {
        {
            document.<Feature>format(feature);
            final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it) -> {
                it.setNewLines(1, 1, 2);
            };
            document.<Feature>append(feature, _function_4);
        }
    }
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) Feature(org.eclipse.xtext.example.domainmodel.domainmodel.Feature)

Example 47 with IHiddenRegionFormatter

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

the class RuleEngineFormatter method _format.

protected void _format(final Device device, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    document.surround(this.textRegionExtensions.regionFor(device).feature(RuleEnginePackage.Literals.DEVICE__NAME), _function);
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    document.surround(this.textRegionExtensions.regionFor(device).keyword("be"), _function_1);
    EList<State> _states = device.getStates();
    for (final State state : _states) {
        final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
            it.oneSpace();
        };
        document.append(document.prepend(this.textRegionExtensions.immediatelyPreceding(document.<State>format(state)).keyword(","), _function_2), _function_3);
    }
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) State(org.eclipse.xtext.example.homeautomation.ruleEngine.State)

Example 48 with IHiddenRegionFormatter

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

the class RuleEngineFormatter method _format.

protected void _format(final Model model, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.setNewLines(0, 0, 1);
        it.noSpace();
    };
    document.<Model>prepend(model, _function);
    EList<Declaration> _declarations = model.getDeclarations();
    for (final Declaration declaration : _declarations) {
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.setNewLines(1, 1, 2);
        };
        document.<Declaration>append(document.<Declaration>format(declaration), _function_1);
    }
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Model(org.eclipse.xtext.example.homeautomation.ruleEngine.Model) Declaration(org.eclipse.xtext.example.homeautomation.ruleEngine.Declaration) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Example 49 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 XBlockExpression expr, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.indent();
    };
    document.<XBlockExpression>surround(expr, _function);
    EList<XExpression> _expressions = expr.getExpressions();
    for (final XExpression child : _expressions) {
        {
            final ISemanticRegion sem = this.textRegionExtensions.immediatelyFollowing(child).keyword(";");
            if ((sem != null)) {
                final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                    it.noSpace();
                };
                document.prepend(sem, _function_1);
                XExpression _last = IterableExtensions.<XExpression>last(expr.getExpressions());
                boolean _notEquals = (!Objects.equal(child, _last));
                if (_notEquals) {
                    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                        it.newLine();
                    };
                    document.append(sem, _function_2);
                }
            } else {
                XExpression _last_1 = IterableExtensions.<XExpression>last(expr.getExpressions());
                boolean _notEquals_1 = (!Objects.equal(child, _last_1));
                if (_notEquals_1) {
                    final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
                        it.newLine();
                    };
                    document.<XExpression>append(child, _function_3);
                }
            }
            document.<XExpression>format(child);
        }
    }
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XExpression(org.eclipse.xtext.xbase.XExpression) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

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