Search in sources :

Example 6 with Statement

use of org.eclipse.n4js.n4JS.Statement in project n4js by eclipse.

the class BinaryLogicalExpressionFactory method isTopJumpCatcher.

/**
 * Short circuit evaluation of a {@link BinaryLogicalExpression} <i>ble</i> causes jumps that start at a lhs
 * condition and jump e.g. directly into the then or else block. However, sometimes this jump does not target such a
 * then or else block, for instance when <i>ble</i> is not used as a condition. In this case, the <i>ble</i> itself
 * or one of its parents will catch the short circuit jump.
 * <p>
 * This method returns true if the given {@link BinaryLogicalExpression} is catching a jump that is caused by a
 * short circuit evaluation. It returns false, if there is a parent element that will catch the jump instead.
 */
private static boolean isTopJumpCatcher(BinaryLogicalExpression ble) {
    EObject child, parent = ble;
    do {
        // skip parentheses
        child = parent;
        parent = parent.eContainer();
    } while (parent instanceof ParenExpression);
    if (parent instanceof BinaryLogicalExpression) {
        return false;
    }
    if (parent instanceof ConditionalExpression) {
        ConditionalExpression isParent = (ConditionalExpression) parent;
        return isParent.getExpression() != child;
    }
    if (parent instanceof Statement) {
        if (parent instanceof IfStatement) {
            IfStatement isParent = (IfStatement) parent;
            return isParent.getExpression() != child;
        }
        if (parent instanceof ForStatement) {
            ForStatement isParent = (ForStatement) parent;
            return isParent.getExpression() != child || !isParent.isForPlain();
        }
        if (parent instanceof WhileStatement) {
            WhileStatement isParent = (WhileStatement) parent;
            return isParent.getExpression() != child;
        }
        if (parent instanceof DoStatement) {
            DoStatement isParent = (DoStatement) parent;
            return isParent.getExpression() != child;
        }
    }
    return true;
}
Also used : IfStatement(org.eclipse.n4js.n4JS.IfStatement) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) DoStatement(org.eclipse.n4js.n4JS.DoStatement) ForStatement(org.eclipse.n4js.n4JS.ForStatement) IfStatement(org.eclipse.n4js.n4JS.IfStatement) Statement(org.eclipse.n4js.n4JS.Statement) WhileStatement(org.eclipse.n4js.n4JS.WhileStatement) DoStatement(org.eclipse.n4js.n4JS.DoStatement) EObject(org.eclipse.emf.ecore.EObject) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) ParenExpression(org.eclipse.n4js.n4JS.ParenExpression) WhileStatement(org.eclipse.n4js.n4JS.WhileStatement) ForStatement(org.eclipse.n4js.n4JS.ForStatement)

Example 7 with Statement

use of org.eclipse.n4js.n4JS.Statement in project n4js by eclipse.

the class WithStatementImpl method basicSetStatement.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetStatement(Statement newStatement, NotificationChain msgs) {
    Statement oldStatement = statement;
    statement = newStatement;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, N4JSPackage.WITH_STATEMENT__STATEMENT, oldStatement, newStatement);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : Statement(org.eclipse.n4js.n4JS.Statement) WithStatement(org.eclipse.n4js.n4JS.WithStatement) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 8 with Statement

use of org.eclipse.n4js.n4JS.Statement in project n4js by eclipse.

the class IfStatementImpl method basicSetElseStmt.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetElseStmt(Statement newElseStmt, NotificationChain msgs) {
    Statement oldElseStmt = elseStmt;
    elseStmt = newElseStmt;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, N4JSPackage.IF_STATEMENT__ELSE_STMT, oldElseStmt, newElseStmt);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : Statement(org.eclipse.n4js.n4JS.Statement) IfStatement(org.eclipse.n4js.n4JS.IfStatement) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 9 with Statement

use of org.eclipse.n4js.n4JS.Statement in project n4js by eclipse.

the class ForStatementImpl method basicSetStatement.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetStatement(Statement newStatement, NotificationChain msgs) {
    Statement oldStatement = statement;
    statement = newStatement;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, N4JSPackage.FOR_STATEMENT__STATEMENT, oldStatement, newStatement);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ForStatement(org.eclipse.n4js.n4JS.ForStatement) Statement(org.eclipse.n4js.n4JS.Statement) IterationStatement(org.eclipse.n4js.n4JS.IterationStatement) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 10 with Statement

use of org.eclipse.n4js.n4JS.Statement in project n4js by eclipse.

the class PrettyPrinterSwitch method caseIfStatement.

@Override
public Boolean caseIfStatement(IfStatement original) {
    write("if (");
    process(original.getExpression());
    write(") ");
    final Statement ifStmnt = original.getIfStmt();
    processInBlock(ifStmnt);
    final Statement elseStmnt = original.getElseStmt();
    if (elseStmnt != null) {
        write(" else ");
        if (elseStmnt instanceof IfStatement) {
            // don't enforce block in this case to better support "else if"
            process(elseStmnt);
        } else {
            processInBlock(elseStmnt);
        }
    }
    return DONE;
}
Also used : IfStatement(org.eclipse.n4js.n4JS.IfStatement) IfStatement(org.eclipse.n4js.n4JS.IfStatement) Statement(org.eclipse.n4js.n4JS.Statement) ContinueStatement(org.eclipse.n4js.n4JS.ContinueStatement) ReturnStatement(org.eclipse.n4js.n4JS.ReturnStatement) DoStatement(org.eclipse.n4js.n4JS.DoStatement) DebuggerStatement(org.eclipse.n4js.n4JS.DebuggerStatement) WhileStatement(org.eclipse.n4js.n4JS.WhileStatement) BreakStatement(org.eclipse.n4js.n4JS.BreakStatement) ExpressionStatement(org.eclipse.n4js.n4JS.ExpressionStatement) VariableStatement(org.eclipse.n4js.n4JS.VariableStatement) EmptyStatement(org.eclipse.n4js.n4JS.EmptyStatement) WithStatement(org.eclipse.n4js.n4JS.WithStatement) SwitchStatement(org.eclipse.n4js.n4JS.SwitchStatement) ThrowStatement(org.eclipse.n4js.n4JS.ThrowStatement) ExportedVariableStatement(org.eclipse.n4js.n4JS.ExportedVariableStatement) ForStatement(org.eclipse.n4js.n4JS.ForStatement) TryStatement(org.eclipse.n4js.n4JS.TryStatement) LabelledStatement(org.eclipse.n4js.n4JS.LabelledStatement)

Aggregations

Statement (org.eclipse.n4js.n4JS.Statement)16 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)6 ExpressionStatement (org.eclipse.n4js.n4JS.ExpressionStatement)6 Expression (org.eclipse.n4js.n4JS.Expression)4 IfStatement (org.eclipse.n4js.n4JS.IfStatement)4 EObject (org.eclipse.emf.ecore.EObject)3 ForStatement (org.eclipse.n4js.n4JS.ForStatement)3 LabelledStatement (org.eclipse.n4js.n4JS.LabelledStatement)3 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)3 SuperLiteral (org.eclipse.n4js.n4JS.SuperLiteral)3 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)3 LinkedList (java.util.LinkedList)2 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)2 HelperNode (org.eclipse.n4js.flowgraphs.model.HelperNode)2 Node (org.eclipse.n4js.flowgraphs.model.Node)2 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)2 ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)2 DoStatement (org.eclipse.n4js.n4JS.DoStatement)2 IterationStatement (org.eclipse.n4js.n4JS.IterationStatement)2 ParenExpression (org.eclipse.n4js.n4JS.ParenExpression)2