stat = new Statement.If(ifTest.expr, thn, els);
classGetter.addModifiers(ModifierType.Public, ModifierType.Static); classGetter.setBody(new Block( new Statement.If( expr( varRef(classInstanceName),
new Statement.If( expr(instRef, Expression.BinaryOperator.IsEqual, nullExpr()), initStats.size() == 1 ? initStats.get(0) : new Statement.Block(initStats),
classGetter.addModifiers(ModifierType.Public, ModifierType.Static); classGetter.setBody(new Block( new Statement.If( expr( varRef(classInstanceName),
new Statement.If( expr(instRef, Expression.BinaryOperator.IsEqual, nullExpr()), initStats.size() == 1 ? initStats.get(0) : new Statement.Block(initStats),
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); } }
public void setThenBranch(Statement thenBranch) { this.thenBranch = changeValue(this, this.thenBranch, thenBranch); } public Statement getElseBranch() {
Statement throwIfArraySizeDifferent(String varAndFieldName) { return new Statement.If( expr( memberRef(varRef(varAndFieldName), MemberRefStyle.Dot, "length"), BinaryOperator.IsDifferent, memberRef(memberRef(thisRef(), MemberRefStyle.Dot, varAndFieldName), MemberRefStyle.Dot, "length")), new Statement.Throw(new Expression.New(typeRef(IllegalArgumentException.class), expr("Wrong array size !"))), null); }
public void setCondition(Expression condition) { this.condition = changeValue(this, this.condition, condition); } public void setThenBranch(Statement thenBranch) {
@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 setElseBranch(Statement elseBranch) { this.elseBranch = changeValue(this, this.elseBranch, elseBranch); } public void setCondition(Expression condition) {
@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))); } }
Statement throwIfArraySizeDifferent(String varAndFieldName) { return new Statement.If( expr( memberRef(varRef(varAndFieldName), MemberRefStyle.Dot, "length"), BinaryOperator.IsDifferent, memberRef(memberRef(thisRef(), MemberRefStyle.Dot, varAndFieldName), MemberRefStyle.Dot, "length")), new Statement.Throw(new Expression.New(typeRef(IllegalArgumentException.class), expr("Wrong array size !"))), null); }
public If(Expression condition, Statement thenBranch, Statement elseBranch) { setCondition(condition); setThenBranch(thenBranch); setElseBranch(elseBranch); } Expression condition;
public void visitIf(If if1) { visitControlStructure(if1); visit(if1.getCondition()); visit(if1.getThenBranch()); visit(if1.getElseBranch()); }