Search in sources :

Example 1 with DestructNode

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

the class AssignmentRelationFactory method findInCorrespondingDestructNodes.

private void findInCorrespondingDestructNodes(Multimap<Symbol, Object> assgns, ControlFlowElement cfe) {
    DestructNode dNode = DestructureUtils.getCorrespondingDestructNode(cfe);
    if (dNode == null) {
        return;
    }
    EObject parentOfDestrNode = DestructureUtils.getTop(cfe);
    if (parentOfDestrNode instanceof ForStatement) {
        ForStatement fs = (ForStatement) parentOfDestrNode;
        Expression fsExpr = fs.getExpression();
        if (fsExpr instanceof ArrayLiteral) {
            ArrayLiteral al = (ArrayLiteral) fsExpr;
            EObject rootOfDestrNode = DestructureUtils.getRoot(cfe);
            for (ArrayElement arrElem : al.getElements()) {
                dNode = DestructNode.unify(rootOfDestrNode, arrElem.getExpression());
                findInDestructNodes(assgns, dNode);
            }
        }
    } else {
        findInDestructNodes(assgns, dNode);
    }
}
Also used : BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) Expression(org.eclipse.n4js.n4JS.Expression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) EObject(org.eclipse.emf.ecore.EObject) DestructNode(org.eclipse.n4js.n4JS.DestructNode) ForStatement(org.eclipse.n4js.n4JS.ForStatement) ArrayLiteral(org.eclipse.n4js.n4JS.ArrayLiteral) ArrayElement(org.eclipse.n4js.n4JS.ArrayElement)

Example 2 with DestructNode

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

the class AssignmentRelationFactory method findInDestructNodes.

private void findInDestructNodes(Multimap<Symbol, Object> assgns, DestructNode dNode) {
    for (Iterator<DestructNode> dnIter = dNode.stream().iterator(); dnIter.hasNext(); ) {
        DestructNode dnChild = dnIter.next();
        ControlFlowElement lhs = dnChild.getVarRef() != null ? dnChild.getVarRef() : dnChild.getVarDecl();
        EObject rhs = DestructureUtilsForSymbols.getValueFromDestructuring(symbolFactory, dnChild);
        if (rhs == null) {
            Symbol undefinedSymbol = symbolFactory.getUndefined();
            createRelation(assgns, lhs, undefinedSymbol, null);
        } else {
            createRelation(assgns, lhs, (Expression) rhs);
        }
    }
}
Also used : Symbol(org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol) EObject(org.eclipse.emf.ecore.EObject) DestructNode(org.eclipse.n4js.n4JS.DestructNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 3 with DestructNode

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

the class AssignmentRelationFactory method findInAllDestructNodes.

private void findInAllDestructNodes(Multimap<Symbol, Object> assgns, ControlFlowElement cfe) {
    EObject top = DestructureUtils.getTop(cfe);
    DestructNode dNode = DestructNode.unify(top);
    if (dNode == null) {
        return;
    }
    if (top instanceof ForStatement) {
        ForStatement fs = (ForStatement) top;
        Expression fsExpr = fs.getExpression();
        if (fsExpr instanceof ArrayLiteral) {
            ArrayLiteral al = (ArrayLiteral) fsExpr;
            EObject rootOfDestrNode = DestructureUtils.getRoot(cfe);
            for (ArrayElement arrElem : al.getElements()) {
                dNode = DestructNode.unify(rootOfDestrNode, arrElem.getExpression());
                findInDestructNodes(assgns, dNode);
            }
        }
    } else {
        findInDestructNodes(assgns, dNode);
    }
}
Also used : BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) Expression(org.eclipse.n4js.n4JS.Expression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) EObject(org.eclipse.emf.ecore.EObject) DestructNode(org.eclipse.n4js.n4JS.DestructNode) ForStatement(org.eclipse.n4js.n4JS.ForStatement) ArrayLiteral(org.eclipse.n4js.n4JS.ArrayLiteral) ArrayElement(org.eclipse.n4js.n4JS.ArrayElement)

Example 4 with DestructNode

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

the class NullUndefinedValidator method isWriteAccess.

private boolean isWriteAccess(EObject reference) {
    EObject parent = reference.eContainer();
    if (parent == null) {
        return false;
    }
    if (parent instanceof AssignmentExpression) {
        AssignmentExpression ae = (AssignmentExpression) parent;
        return ae.getLhs() == reference;
    }
    if (parent instanceof ForStatement) {
        ForStatement fs = (ForStatement) parent;
        return fs.getInitExpr() == reference;
    }
    DestructNode dNode = DestructureUtils.getCorrespondingDestructNode(reference);
    if (dNode != null) {
        dNode = dNode.findNodeForElement(parent);
        return dNode != null;
    }
    return false;
}
Also used : AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) EObject(org.eclipse.emf.ecore.EObject) DestructNode(org.eclipse.n4js.n4JS.DestructNode) ForStatement(org.eclipse.n4js.n4JS.ForStatement)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)4 DestructNode (org.eclipse.n4js.n4JS.DestructNode)4 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)3 ForStatement (org.eclipse.n4js.n4JS.ForStatement)3 ArrayElement (org.eclipse.n4js.n4JS.ArrayElement)2 ArrayLiteral (org.eclipse.n4js.n4JS.ArrayLiteral)2 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)2 ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)2 Expression (org.eclipse.n4js.n4JS.Expression)2 Symbol (org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol)1 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)1