public IfThenElseNode handleIfStatement(Expression condition, List<SequentialNode> then_part, List<SequentialNode> else_part) { IfThenElseNode ifthenelse = new IfThenElseNode(graph, condition); addNode(ifthenelse); rewireNodes(then_part, ifthenelse); rewireNodes(else_part, ifthenelse); ifthenelse.setPositive(then_part.get(0)); ifthenelse.setNegative((else_part != null && else_part.size() > 0) ? else_part.get(0) : new BlockEndNode(graph, lastNode)); return ifthenelse; }
/** * Handles an if statement. The statement consists of a condition expression, a mandatory then part (block) and an * optional else part. * * @param condition condition expression * @param then_part list of statements belonging to then part * @param else_part optional list of statements belonging to else part (empty list in case of no else part) * @return new {@link IfThenElseNode} representing this statement. */ public IfThenElseNode handleIfStatement(Expression condition, List<SequentialNode> then_part, List<SequentialNode> else_part) { IfThenElseNode ifthenelse = new IfThenElseNode(graph, condition); addNode(ifthenelse); rewireNodes(then_part, ifthenelse); rewireNodes(else_part, ifthenelse); ifthenelse.setPositive(then_part.get(0)); ifthenelse.setNegative((else_part != null && else_part.size() > 0) ? else_part.get(0) : new BlockEndNode(graph, ifthenelse)); return ifthenelse; }
@Override public IfThenElseNode copyElements() { IfThenElseNode copy = new IfThenElseNode(getGraph(), condition.copy()); copy.elseif = elseif; SequentialNode newPositive = positive.copy(); newPositive.removePredecessor(this); newPositive.addPredecessor(copy); copy.setPositive(newPositive); copySubtree(newPositive, copy); SequentialNode newNegative = negative.copy(); newNegative.removePredecessor(this); newNegative.addPredecessor(copy); copy.setNegative(newNegative); copySubtree(newNegative, copy); return copy; }