Search in sources :

Example 76 with Expression

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

the class GuardFactory method createGuardForTypeof.

private static Guard createGuardForTypeof(EObject topContainer, UnaryExpression ue, boolean negateTree, boolean negateEqe, Expression rhs) {
    if (rhs instanceof StringLiteral) {
        StringLiteral rhsStringLit = (StringLiteral) rhs;
        String lit = rhsStringLit.getValue();
        if (!"undefined".equals(lit)) {
            return null;
        }
    }
    Expression typeofExpr = ue.getExpression();
    if (SymbolFactory.canCreate(typeofExpr)) {
        GuardAssertion asserts = FlowAssertionFactory.getGuard(topContainer, ue.eContainer(), negateTree, negateEqe);
        Guard guard = createIsUndefinedGuard(ue, asserts, typeofExpr);
        return guard;
    }
    return null;
}
Also used : StringLiteral(org.eclipse.n4js.n4JS.StringLiteral) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) RelationalExpression(org.eclipse.n4js.n4JS.RelationalExpression) UnaryExpression(org.eclipse.n4js.n4JS.UnaryExpression) EqualityExpression(org.eclipse.n4js.n4JS.EqualityExpression) ParenExpression(org.eclipse.n4js.n4JS.ParenExpression) Expression(org.eclipse.n4js.n4JS.Expression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression)

Example 77 with Expression

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

the class GuardStructureFactory method getCondition.

/**
 * @return the top {@link Expression} of a {@link GuardStructure}, or null.
 */
private static Expression getCondition(ControlFlowEdge edge) {
    Expression condition = null;
    Node previousNode = edge.start;
    ControlFlowElement previousCFE = previousNode.getControlFlowElement();
    if (previousCFE instanceof ConditionalExpression) {
        ConditionalExpression ce = (ConditionalExpression) previousCFE;
        condition = ce.getExpression();
    } else if (previousCFE instanceof BinaryLogicalExpression) {
        BinaryLogicalExpression ble = (BinaryLogicalExpression) previousCFE;
        condition = ble.getLhs();
    } else if (previousCFE instanceof IfStatement) {
        IfStatement is = (IfStatement) previousCFE;
        condition = is.getExpression();
    } else if (previousCFE instanceof WhileStatement) {
        WhileStatement ws = (WhileStatement) previousCFE;
        condition = ws.getExpression();
    } else if (previousCFE instanceof DoStatement) {
        DoStatement ws = (DoStatement) previousCFE;
        condition = ws.getExpression();
    } else if (previousCFE instanceof ForStatement) {
        ForStatement ws = (ForStatement) previousCFE;
        condition = ws.getExpression();
    }
    return condition;
}
Also used : IfStatement(org.eclipse.n4js.n4JS.IfStatement) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) DoStatement(org.eclipse.n4js.n4JS.DoStatement) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) Expression(org.eclipse.n4js.n4JS.Expression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) Node(org.eclipse.n4js.flowgraphs.model.Node) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) WhileStatement(org.eclipse.n4js.n4JS.WhileStatement) ForStatement(org.eclipse.n4js.n4JS.ForStatement) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 78 with Expression

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

the class NullDereferenceAnalyser method isDereferencing.

private boolean isDereferencing(ControlFlowElement cfe) {
    EObject parent = cfe.eContainer();
    if (parent instanceof ParameterizedPropertyAccessExpression) {
        ParameterizedPropertyAccessExpression ppae = (ParameterizedPropertyAccessExpression) parent;
        Expression target = ppae.getTarget();
        return cfe == target;
    }
    return false;
}
Also used : ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) Expression(org.eclipse.n4js.n4JS.Expression) EObject(org.eclipse.emf.ecore.EObject)

Example 79 with Expression

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

the class GuardStructure method getGuardList.

private List<Guard> getGuardList() {
    LinkedList<Guard> gList = new LinkedList<>();
    List<Expression> allExpressions = EcoreUtil2.getAllContentsOfType(condition, Expression.class);
    allExpressions.add(condition);
    EObject conditionContainer = condition.eContainer();
    for (Expression expr : allExpressions) {
        Guard guard = GuardFactory.create(conditionContainer, expr, negate);
        if (guard != null) {
            gList.add(guard);
        }
    }
    return gList;
}
Also used : BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) Expression(org.eclipse.n4js.n4JS.Expression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) EObject(org.eclipse.emf.ecore.EObject) LinkedList(java.util.LinkedList)

Example 80 with Expression

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

the class PostfixExpressionImpl method basicSetExpression.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetExpression(Expression newExpression, NotificationChain msgs) {
    Expression oldExpression = expression;
    expression = newExpression;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, N4JSPackage.POSTFIX_EXPRESSION__EXPRESSION, oldExpression, newExpression);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : Expression(org.eclipse.n4js.n4JS.Expression) PostfixExpression(org.eclipse.n4js.n4JS.PostfixExpression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

Expression (org.eclipse.n4js.n4JS.Expression)111 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)58 ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)40 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)38 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)37 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)35 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)33 EqualityExpression (org.eclipse.n4js.n4JS.EqualityExpression)31 ParenExpression (org.eclipse.n4js.n4JS.ParenExpression)31 RelationalExpression (org.eclipse.n4js.n4JS.RelationalExpression)31 UnaryExpression (org.eclipse.n4js.n4JS.UnaryExpression)31 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)27 BinaryBitwiseExpression (org.eclipse.n4js.n4JS.BinaryBitwiseExpression)27 IndexedAccessExpression (org.eclipse.n4js.n4JS.IndexedAccessExpression)27 MultiplicativeExpression (org.eclipse.n4js.n4JS.MultiplicativeExpression)27 ShiftExpression (org.eclipse.n4js.n4JS.ShiftExpression)27 AwaitExpression (org.eclipse.n4js.n4JS.AwaitExpression)26 CastExpression (org.eclipse.n4js.n4JS.CastExpression)26 FunctionExpression (org.eclipse.n4js.n4JS.FunctionExpression)26 NewExpression (org.eclipse.n4js.n4JS.NewExpression)26