@Test(expected = IllegalArgumentException.class) public void replaceChildBad2() throws Exception { VariableIdentifierExpr v = new VariableIdentifierExpr("v"); Expr pe = new ParenExpr(v); pe.replaceChild(v, new NullStmt()); }
@Override public void replaceChild(IAstNode child, IAstNode newChild) { if (!(child instanceof Expr && newChild instanceof Expr)) { throw new IllegalArgumentException(); } for (int i = 0; i < getNumChildren(); i++) { if (getChild(i) == child) { setChild(i, (Expr) newChild); return; } } throw new ChildDoesNotExistException(child, this); }
Expr implements IAstNode { @Override public void replaceChild(IAstNode child, IAstNode newChild) { if (!(child instanceof Expr && newChild instanceof Expr)) { throw new IllegalArgumentException(); } for (int i = 0; i < getNumChildren(); i++) { if (getChild(i) == child) { setChild(i, (Expr) newChild); return; } } throw new ChildDoesNotExistException(child, this); } }
Expr implements IAstNode { @Override public void replaceChild(IAstNode child, IAstNode newChild) { if (!(child instanceof Expr && newChild instanceof Expr)) { throw new IllegalArgumentException(); } for (int i = 0; i < getNumChildren(); i++) { if (getChild(i) == child) { setChild(i, (Expr) newChild); return; } } throw new ChildDoesNotExistException(child, this); }  }
Expr implements IAstNode { @Override public void replaceChild(IAstNode child, IAstNode newChild) { if (!(child instanceof Expr && newChild instanceof Expr)) { throw new IllegalArgumentException(); } for (int i = 0; i < getNumChildren(); i++) { if (getChild(i) == child) { setChild(i, (Expr) newChild); return; } } throw new ChildDoesNotExistException(child, this); }  @Override abstract Expr clone(); abstract Expr getChild(int index); abstract void setChild(int index, Expr expr); abstract int getNumChildren(); @Override void replaceChild(IAstNode child, IAstNode newChild); abstract boolean hasChild(IAstNode child); static void checkNoTopLevelCommaExpression(List<Expr> args); }
Expr implements IAstNode { @Override public void replaceChild(IAstNode child, IAstNode newChild) { if (!(child instanceof Expr && newChild instanceof Expr)) { throw new IllegalArgumentException(); } for (int i = 0; i < getNumChildren(); i++) { if (getChild(i) == child) { setChild(i, (Expr) newChild); return; } } throw new ChildDoesNotExistException(child, this); }  @Override abstract Expr clone(); abstract Expr getChild(int index); abstract void setChild(int index, Expr expr); abstract int getNumChildren(); @Override void replaceChild(IAstNode child, IAstNode newChild); abstract boolean hasChild(IAstNode child); static void checkNoTopLevelCommaExpression(List<Expr> args);  }