BinaryExpr extends Expr { @Override public void setChild(int index, Expr expr) { if (index == 0) { lhs = expr; return; } if (index == 1) { rhs = expr; return; } throw new IndexOutOfBoundsException("Index for BinaryExpr must be 0 or 1"); } BinaryExpr(Expr lhs, Expr rhs, BinOp op); Expr getLhs(); void setLhs(Expr lhs); Expr getRhs(); void setRhs(Expr rhs); BinOp getOp(); @Override void accept(IAstVisitor visitor); @Override BinaryExpr clone(); @Override boolean hasChild(IAstNode candidateChild); @Override Expr getChild(int index); @Override void setChild(int index, Expr expr); @Override int getNumChildren();  }
@Test(expected = IndexOutOfBoundsException.class) public void setChildBad() { new BinaryExpr(new BoolConstantExpr(true), new BoolConstantExpr(false), BinOp.LXOR).setChild(2, new BoolConstantExpr(false)); }