@Test public void testReplaceChild() throws Exception { final String before = "void main() {" + " switch(0) {" + " case 1:" + " return;" + " default:" + " break;" + " }" + "}"; final String after = "void main() {" + " switch(0) {" + " case 2:" + " return;" + " default:" + " break;" + " }" + "}"; final TranslationUnit tu = ParseHelper.parse(before); new StandardVisitor() { @Override public void visitExprCaseLabel(ExprCaseLabel exprCaseLabel) { super.visitExprCaseLabel(exprCaseLabel); exprCaseLabel.replaceChild(exprCaseLabel.getExpr(), new IntConstantExpr("2")); } }.visit(tu); CompareAstsDuplicate.assertEqualAsts(after, tu); }
@Override public void replaceChild(IAstNode child, IAstNode newChild) { if (child != expr) { throw new ChildDoesNotExistException(child, this); } if (!(newChild instanceof Expr)) { throw new IllegalArgumentException(); } expr = (Expr) newChild; }
ExprCaseLabel extends CaseLabel { @Override public void replaceChild(IAstNode child, IAstNode newChild) { if (child != expr) { throw new ChildDoesNotExistException(child, this); } if (!(newChild instanceof Expr)) { throw new IllegalArgumentException(); } expr = (Expr) newChild; } }
ExprCaseLabel extends CaseLabel { @Override public void replaceChild(IAstNode child, IAstNode newChild) { if (child != expr) { throw new ChildDoesNotExistException(child, this); } if (!(newChild instanceof Expr)) { throw new IllegalArgumentException(); } expr = (Expr) newChild; } ExprCaseLabel(Expr expr); }
ExprCaseLabel extends CaseLabel { @Override public void replaceChild(IAstNode child, IAstNode newChild) { if (child != expr) { throw new ChildDoesNotExistException(child, this); } if (!(newChild instanceof Expr)) { throw new IllegalArgumentException(); } expr = (Expr) newChild; } ExprCaseLabel(Expr expr); Expr getExpr(); @Override void replaceChild(IAstNode child, IAstNode newChild); @Override void accept(IAstVisitor visitor); @Override ExprCaseLabel clone(); }
ExprCaseLabel extends CaseLabel { @Override public void replaceChild(IAstNode child, IAstNode newChild) { if (child != expr) { throw new ChildDoesNotExistException(child, this); } if (!(newChild instanceof Expr)) { throw new IllegalArgumentException(); } expr = (Expr) newChild; } ExprCaseLabel(Expr expr); Expr getExpr(); @Override void replaceChild(IAstNode child, IAstNode newChild); @Override void accept(IAstVisitor visitor); @Override ExprCaseLabel clone();  }