public void visitIf(If e) { append("if (", e.getCondition(), ") "); if (e.getThenBranch() == null) { append("<null>"); } else { if (e.getThenBranch() instanceof Block) { append(e.getThenBranch()); if (e.getElseBranch() != null) { append(" "); } } else { indent(); append("\n", indent, e.getThenBranch()); deindent(); if (e.getElseBranch() != null) { append("\n", indent); } } } if (e.getElseBranch() != null) { append("else "); if (e.getElseBranch() instanceof Block) { append(e.getElseBranch()); } else { indent(); append("\n", indent, e.getElseBranch()); deindent(); } } }
@Override public boolean replaceChild(Element child, Element by) { if (child == getCondition()) { setCondition((Expression)by); return true; } if (child == getThenBranch()) { setThenBranch((Statement)by); return true; } if (child == getElseBranch()) { setElseBranch((Statement)by); return true; } return super.replaceChild(child, by); } }
@Override public void visitIf(If ifStat) { super.visitIf(ifStat); Expression cond = ifStat.getCondition(); if (!(cond instanceof BinaryOp)) // TODO use typing rather than this hack to detect implicit boolean conversion in if statements (and not only there) { cond.replaceBy(expr(cond, BinaryOperator.IsDifferent, expr(0))); } }
@Override public void visitIf(If ifStat) { super.visitIf(ifStat); Expression cond = ifStat.getCondition(); if (!(cond instanceof BinaryOp)) // TODO use typing rather than this hack to detect implicit boolean conversion in if statements (and not only there) { cond.replaceBy(expr(cond, BinaryOperator.IsDifferent, expr(0))); } }
public void visitIf(If if1) { visitControlStructure(if1); visit(if1.getCondition()); visit(if1.getThenBranch()); visit(if1.getElseBranch()); }