@Test public void testInsertAfter() { ExprStmt stmt1 = new ExprStmt(new BoolConstantExpr(true)); ExprStmt stmt2 = new ExprStmt(new BoolConstantExpr(false)); BlockStmt b = new BlockStmt(Arrays.asList(stmt1, stmt2), true); assertEquals(2, b.getNumStmts()); b.insertAfter(stmt1, new NullStmt()); assertEquals(3, b.getNumStmts()); b.insertAfter(stmt2, new NullStmt()); assertEquals(4, b.getNumStmts()); assertEquals(stmt1, b.getStmt(0)); assertTrue(b.getStmt(1) instanceof NullStmt); assertEquals(stmt2, b.getStmt(2)); assertTrue(b.getStmt(3) instanceof NullStmt); }
public void insertAfter(Stmt originalStmt, Stmt insertedStmt) { for (int i = 0; i < stmts.size(); i++) { if (getStmt(i) == originalStmt) { insertStmt(i + 1, insertedStmt); return; } } throw new IllegalArgumentException("Should be unreachable."); }
BlockStmt extends Stmt { public void insertAfter(Stmt originalStmt, Stmt insertedStmt) { for (int i = 0; i < stmts.size(); i++) { if (getStmt(i) == originalStmt) { insertStmt(i + 1, insertedStmt); return; } } throw new IllegalArgumentException("Should be unreachable."); } }
BlockStmt extends Stmt { public void insertAfter(Stmt originalStmt, Stmt insertedStmt) { for (int i = 0; i < stmts.size(); i++) { if (getStmt(i) == originalStmt) { insertStmt(i + 1, insertedStmt); return; } } throw new IllegalArgumentException("Should be unreachable."); } BlockStmt(List<Stmt> stmts, boolean introducesNewScope); }
BlockStmt extends Stmt { public void insertAfter(Stmt originalStmt, Stmt insertedStmt) { for (int i = 0; i < stmts.size(); i++) { if (getStmt(i) == originalStmt) { insertStmt(i + 1, insertedStmt); return; } } throw new IllegalArgumentException("Should be unreachable."); } BlockStmt(List<Stmt> stmts, boolean introducesNewScope); List<Stmt> getStmts(); void setStmts(List<Stmt> stmts); int getNumStmts(); Stmt getLastStmt(); boolean introducesNewScope(); void setIntroducesNewScope(boolean introducesNewScope); void insertStmt(int index, Stmt stmt); void setStmt(int index, Stmt stmt); Stmt getStmt(int index); void removeStmt(int index); void removeStmt(Stmt child); @Override void accept(IAstVisitor visitor); @Override void replaceChild(IAstNode child, IAstNode newChild); @Override boolean hasChild(IAstNode candidateChild); void insertAfter(Stmt originalStmt, Stmt insertedStmt); void insertBefore(Stmt originalStmt, Stmt insertedStmt); void addStmt(Stmt stmt); @Override BlockStmt clone(); }
BlockStmt extends Stmt { public void insertAfter(Stmt originalStmt, Stmt insertedStmt) { for (int i = 0; i < stmts.size(); i++) { if (getStmt(i) == originalStmt) { insertStmt(i + 1, insertedStmt); return; } } throw new IllegalArgumentException("Should be unreachable."); } BlockStmt(List<Stmt> stmts, boolean introducesNewScope); List<Stmt> getStmts(); void setStmts(List<Stmt> stmts); int getNumStmts(); Stmt getLastStmt(); boolean introducesNewScope(); void setIntroducesNewScope(boolean introducesNewScope); void insertStmt(int index, Stmt stmt); void setStmt(int index, Stmt stmt); Stmt getStmt(int index); void removeStmt(int index); void removeStmt(Stmt child); @Override void accept(IAstVisitor visitor); @Override void replaceChild(IAstNode child, IAstNode newChild); @Override boolean hasChild(IAstNode candidateChild); void insertAfter(Stmt originalStmt, Stmt insertedStmt); void insertBefore(Stmt originalStmt, Stmt insertedStmt); void addStmt(Stmt stmt); @Override BlockStmt clone();  }