Search in sources :

Example 11 with Expression

use of org.eclipse.xtext.example.arithmetics.arithmetics.Expression in project xtext-eclipse by eclipse.

the class DivImpl method basicSetLeft.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetLeft(Expression newLeft, NotificationChain msgs) {
    Expression oldLeft = left;
    left = newLeft;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ArithmeticsPackage.DIV__LEFT, oldLeft, newLeft);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : Expression(org.eclipse.xtext.example.arithmetics.arithmetics.Expression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 12 with Expression

use of org.eclipse.xtext.example.arithmetics.arithmetics.Expression in project xtext-eclipse by eclipse.

the class CalculatorTest method evaluatesTo.

private void evaluatesTo(CharSequence content, double expected) throws Exception {
    Module module = parseHelper.parse("module test " + content);
    Statement firstStatement = module.getStatements().get(0);
    Iterable<Expression> expressions = Iterables.filter(firstStatement.eContents(), Expression.class);
    Expression expression = Iterables.getFirst(expressions, null);
    BigDecimal result = calculator.evaluate(expression);
    Assert.assertEquals(expected, result.doubleValue(), 0.0001);
}
Also used : Expression(org.eclipse.xtext.example.arithmetics.arithmetics.Expression) Statement(org.eclipse.xtext.example.arithmetics.arithmetics.Statement) Module(org.eclipse.xtext.example.arithmetics.arithmetics.Module) BigDecimal(java.math.BigDecimal)

Aggregations

Expression (org.eclipse.xtext.example.arithmetics.arithmetics.Expression)12 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)10 BigDecimal (java.math.BigDecimal)2 Statement (org.eclipse.xtext.example.arithmetics.arithmetics.Statement)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 Module (org.eclipse.xtext.example.arithmetics.arithmetics.Module)1