Search in sources :

Example 66 with ISemanticRegion

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

the class StatemachineFormatter method format.

protected void format(State s, IFormattableDocument doc) {
    // indent the state elements between the name of the state and the 'end' keyword
    ISemanticRegion begin = regionFor(s).feature(STATE__NAME);
    ISemanticRegion end = regionFor(s).keyword(ga.getStateAccess().getEndKeyword_4());
    doc.append(begin, it -> it.newLine());
    doc.interior(begin, end, it -> it.indent());
    formatActions(s, doc);
    for (Transition transition : s.getTransitions()) {
        format(transition, doc);
    }
    if (isLastState(s)) {
        doc.append(s, it -> it.newLine());
    } else {
        doc.append(s, it -> it.setNewLines(2));
    }
}
Also used : Transition(org.eclipse.xtext.example.fowlerdsl.statemachine.Transition) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 67 with ISemanticRegion

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

ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)63 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