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);
}
}
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);
}
}
}
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);
}
}
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;
}
Aggregations