@Override public void insertIfStatement(IfStatement ifStmt, Block thenBlock) { // when stmt declares a local variable (see RearrangeStrategy.create(..)) we need to move all // subsequent statements into the then-block to ensure that the existing declared local is visible: List<ASTNode> blockStmts= this.block.statements(); int stmtIdx= blockStmts.indexOf(this.origStmt); int lastIdx= blockStmts.size()-1; if (stmtIdx != -1 && stmtIdx < lastIdx) { thenBlock.statements() .add(this.blockRewrite.createMoveTarget(blockStmts.get(stmtIdx+1), blockStmts.get(lastIdx), null, this.group)); } super.insertIfStatement(ifStmt, thenBlock); } }
@Override public void insertIfStatement(IfStatement ifStmt, Block thenBlock) { // when stmt declares a local variable (see RearrangeStrategy.create(..)) we need to move all // subsequent statements into the then-block to ensure that the existing declared local is visible: List<ASTNode> blockStmts= this.block.statements(); int stmtIdx= blockStmts.indexOf(this.origStmt); int lastIdx= blockStmts.size()-1; if (stmtIdx != -1 && stmtIdx < lastIdx) { thenBlock.statements() .add(this.blockRewrite.createMoveTarget(blockStmts.get(stmtIdx+1), blockStmts.get(lastIdx), null, this.group)); } super.insertIfStatement(ifStmt, thenBlock); } }
public static RearrangeStrategy create(Statement origStmt, ASTRewrite rewrite, TextEditGroup group) { ASTNode parent = origStmt.getParent(); if (parent instanceof Block) { Block block= (Block)parent; if (origStmt instanceof VariableDeclarationStatement) return new ModifyBlockWithLocalDecl(origStmt, block, rewrite, group); else return new ModifyBlock(origStmt, block, rewrite, group); } else { return new ReplaceStatement(origStmt, rewrite, group); } }
public static RearrangeStrategy create(Statement origStmt, ASTRewrite rewrite, TextEditGroup group) { ASTNode parent = origStmt.getParent(); if (parent instanceof Block) { Block block= (Block)parent; if (origStmt instanceof VariableDeclarationStatement) return new ModifyBlockWithLocalDecl(origStmt, block, rewrite, group); else return new ModifyBlock(origStmt, block, rewrite, group); } else { return new ReplaceStatement(origStmt, rewrite, group); } }