@Test public void testInsertBefore() { ExprStmt stmt = new ExprStmt(new BoolConstantExpr(true)); BlockStmt b = new BlockStmt(Arrays.asList(stmt), true); assertEquals(1, b.getNumStmts()); b.insertBefore(stmt, new NullStmt()); assertEquals(2, b.getNumStmts()); assertTrue(b.getStmt(0) instanceof NullStmt); assertEquals(stmt, b.getStmt(1)); }
public void insertBefore(Stmt originalStmt, Stmt insertedStmt) { for (int i = 0; i < stmts.size(); i++) { if (getStmt(i) == originalStmt) { insertStmt(i, insertedStmt); return; } } throw new IllegalArgumentException("Should be unreachable."); }
BlockStmt extends Stmt { public void insertBefore(Stmt originalStmt, Stmt insertedStmt) { for (int i = 0; i < stmts.size(); i++) { if (getStmt(i) == originalStmt) { insertStmt(i, insertedStmt); return; } } throw new IllegalArgumentException("Should be unreachable."); } }
BlockStmt extends Stmt { public void insertBefore(Stmt originalStmt, Stmt insertedStmt) { for (int i = 0; i < stmts.size(); i++) { if (getStmt(i) == originalStmt) { insertStmt(i, insertedStmt); return; } } throw new IllegalArgumentException("Should be unreachable."); } BlockStmt(List<Stmt> stmts, boolean introducesNewScope); }
BlockStmt extends Stmt { public void insertBefore(Stmt originalStmt, Stmt insertedStmt) { for (int i = 0; i < stmts.size(); i++) { if (getStmt(i) == originalStmt) { insertStmt(i, 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 insertBefore(Stmt originalStmt, Stmt insertedStmt) { for (int i = 0; i < stmts.size(); i++) { if (getStmt(i) == originalStmt) { insertStmt(i, 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();  }