Search in sources :

Example 1 with RichStringElseIf

use of org.eclipse.xtend.core.xtend.RichStringElseIf in project xtext-xtend by eclipse.

the class ParserTest method testRichStringIF_00.

@Test
public void testRichStringIF_00() throws Exception {
    XtendFunction function = function("def foo() ''' foo �IF true� wurst �ELSEIF null==3� brot �ELSE� machine �ENDIF� bar '''");
    final RichString richString = (RichString) function.getExpression();
    assertTrue(richString.getExpressions().get(0) instanceof RichStringLiteral);
    final RichStringIf rsIf = (RichStringIf) richString.getExpressions().get(1);
    assertTrue(rsIf.getIf() instanceof XBooleanLiteral);
    assertTrue(rsIf.getThen() instanceof RichString);
    assertEquals(1, rsIf.getElseIfs().size());
    RichStringElseIf elseIf = rsIf.getElseIfs().get(0);
    assertTrue(elseIf.getIf() instanceof XBinaryOperation);
    assertTrue(elseIf.getThen() instanceof RichString);
    assertTrue(rsIf.getElse() instanceof RichString);
    assertTrue(richString.getExpressions().get(2) instanceof RichStringLiteral);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBooleanLiteral(org.eclipse.xtext.xbase.XBooleanLiteral) RichString(org.eclipse.xtend.core.xtend.RichString) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) RichStringIf(org.eclipse.xtend.core.xtend.RichStringIf) XBinaryOperation(org.eclipse.xtext.xbase.XBinaryOperation) RichStringElseIf(org.eclipse.xtend.core.xtend.RichStringElseIf) Test(org.junit.Test)

Example 2 with RichStringElseIf

use of org.eclipse.xtend.core.xtend.RichStringElseIf in project xtext-xtend by eclipse.

the class XtendTypeComputer method _computeTypes.

protected void _computeTypes(RichStringIf object, ITypeComputationState state) {
    LightweightTypeReference charSequence = getRawTypeForName(CharSequence.class, state);
    LightweightTypeReference booleanType = getRawTypeForName(Boolean.TYPE, state);
    ITypeComputationState conditionExpectation = state.withExpectation(booleanType);
    XExpression condition = object.getIf();
    conditionExpectation.computeTypes(condition);
    XExpression thenExpression = object.getThen();
    ITypeComputationState thenState = reassignCheckedType(condition, thenExpression, state);
    thenState.withExpectation(charSequence).computeTypes(thenExpression);
    for (RichStringElseIf elseIf : object.getElseIfs()) {
        state.withExpectation(booleanType).computeTypes(elseIf.getIf());
        ITypeComputationState elseState = reassignCheckedType(elseIf.getIf(), elseIf.getThen(), state);
        elseState.withExpectation(charSequence).computeTypes(elseIf.getThen());
    }
    state.withExpectation(charSequence).computeTypes(object.getElse());
    state.acceptActualType(charSequence);
}
Also used : ITypeComputationState(org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XExpression(org.eclipse.xtext.xbase.XExpression) RichStringElseIf(org.eclipse.xtend.core.xtend.RichStringElseIf)

Example 3 with RichStringElseIf

use of org.eclipse.xtend.core.xtend.RichStringElseIf in project xtext-xtend by eclipse.

the class RichStringFormatter method _format.

protected void _format(final RichStringIf expr, @Extension final IFormattableDocument doc) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    doc.append(doc.prepend(this._iTextRegionExtensions.regionFor(expr).keyword("IF"), _function), _function_1);
    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    doc.<RichStringElseIf>append(IterableExtensions.<RichStringElseIf>last(expr.getElseIfs()), _function_2);
    this.formatIntoSingleLine(doc, expr.getIf());
    this.format(expr.getThen(), doc);
    EList<RichStringElseIf> _elseIfs = expr.getElseIfs();
    for (final RichStringElseIf elseif : _elseIfs) {
        this.format(elseif, doc);
    }
    final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    doc.surround(this._iTextRegionExtensions.regionFor(expr).keyword("ELSE"), _function_3);
    this.format(expr.getElse(), doc);
    final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    doc.surround(this._iTextRegionExtensions.regionFor(expr).keyword("ENDIF"), _function_4);
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) RichStringElseIf(org.eclipse.xtend.core.xtend.RichStringElseIf)

Example 4 with RichStringElseIf

use of org.eclipse.xtend.core.xtend.RichStringElseIf in project xtext-xtend by eclipse.

the class ElseIfConditionImpl method setRichStringElseIf.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setRichStringElseIf(RichStringElseIf newRichStringElseIf) {
    RichStringElseIf oldRichStringElseIf = richStringElseIf;
    richStringElseIf = newRichStringElseIf;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ProcessedRichStringPackage.ELSE_IF_CONDITION__RICH_STRING_ELSE_IF, oldRichStringElseIf, richStringElseIf));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) RichStringElseIf(org.eclipse.xtend.core.xtend.RichStringElseIf)

Aggregations

RichStringElseIf (org.eclipse.xtend.core.xtend.RichStringElseIf)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 RichString (org.eclipse.xtend.core.xtend.RichString)1 RichStringIf (org.eclipse.xtend.core.xtend.RichStringIf)1 RichStringLiteral (org.eclipse.xtend.core.xtend.RichStringLiteral)1 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)1 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)1 XBinaryOperation (org.eclipse.xtext.xbase.XBinaryOperation)1 XBooleanLiteral (org.eclipse.xtext.xbase.XBooleanLiteral)1 XExpression (org.eclipse.xtext.xbase.XExpression)1 ITypeComputationState (org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState)1 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)1 Test (org.junit.Test)1