@Test public void replaceChild() { final ExprStmt init = new ExprStmt(new IntConstantExpr("0")); final IntConstantExpr condition = new IntConstantExpr("1"); final IntConstantExpr increment = new IntConstantExpr("2"); final BlockStmt body = new BlockStmt(new ArrayList<>(), false); final ForStmt forStmt = new ForStmt( init, condition, increment, body); final ExprStmt newInit = new ExprStmt(new IntConstantExpr("3")); final IntConstantExpr newCondition = new IntConstantExpr("4"); final IntConstantExpr newIncrement = new IntConstantExpr("5"); final BlockStmt newBody = new BlockStmt(new ArrayList<>(), false); forStmt.replaceChild(init, newInit); forStmt.replaceChild(condition, newCondition); forStmt.replaceChild(increment, newIncrement); forStmt.replaceChild(body, newBody); assertTrue(newInit == forStmt.getInit()); assertTrue(newCondition == forStmt.getCondition()); assertTrue(newIncrement == forStmt.getIncrement()); assertTrue(newBody == forStmt.getBody()); }
@Override public void replaceChild(IAstNode child, IAstNode newChild) { if (child == init) { init = (Stmt) newChild; } else if (child == increment) { increment = (Expr) newChild; } else { super.replaceChild(child, newChild); } }
ForStmt extends LoopStmt { @Override public void replaceChild(IAstNode child, IAstNode newChild) { if (child == init) { init = (Stmt) newChild; } else if (child == increment) { increment = (Expr) newChild; } else { super.replaceChild(child, newChild); } } }
ForStmt extends LoopStmt { @Override public void replaceChild(IAstNode child, IAstNode newChild) { if (child == init) { init = (Stmt) newChild; } else if (child == increment) { increment = (Expr) newChild; } else { super.replaceChild(child, newChild); } } ForStmt(Stmt init, Expr condition, Expr increment, Stmt body); }
ForStmt extends LoopStmt { @Override public void replaceChild(IAstNode child, IAstNode newChild) { if (child == init) { init = (Stmt) newChild; } else if (child == increment) { increment = (Expr) newChild; } else { super.replaceChild(child, newChild); } } ForStmt(Stmt init, Expr condition, Expr increment, Stmt body); @Override boolean hasCondition(); boolean hasIncrement(); Stmt getInit(); Expr getIncrement(); @Override void accept(IAstVisitor visitor); @Override ForStmt clone(); @Override void replaceChild(IAstNode child, IAstNode newChild); @Override boolean hasChild(IAstNode candidateChild); }
ForStmt extends LoopStmt { @Override public void replaceChild(IAstNode child, IAstNode newChild) { if (child == init) { init = (Stmt) newChild; } else if (child == increment) { increment = (Expr) newChild; } else { super.replaceChild(child, newChild); } } ForStmt(Stmt init, Expr condition, Expr increment, Stmt body); @Override boolean hasCondition(); boolean hasIncrement(); Stmt getInit(); Expr getIncrement(); @Override void accept(IAstVisitor visitor); @Override ForStmt clone(); @Override void replaceChild(IAstNode child, IAstNode newChild); @Override boolean hasChild(IAstNode candidateChild);  }