@Override public void replaceChild(IAstNode child, IAstNode newChild) { if (!hasChild(child)) { throw new ChildDoesNotExistException(child, this); } if (!(newChild instanceof Stmt)) { throw new IllegalArgumentException( "Attempt to replace child of block statement with a non-statement: " + newChild); } for (int i = 0; i < stmts.size(); i++) { if (child == getStmt(i)) { setStmt(i, (Stmt) newChild); return; } } throw new IllegalArgumentException("Should be unreachable."); }
@Override public void replaceNext(Stmt stmt) { assert hasNextStmt(); for (int i = 0; i < blockStmt.getNumStmts(); i++) { if (blockStmt.getStmt(i) == nextStmt) { blockStmt.setStmt(i, stmt); } } }