void (@NotNull PsiIfStatement ifStatement, @NotNull List<? extends PsiStatement> tailStatements, CommentTracker ct) { if (!tailStatements.isEmpty()) { for (PsiStatement statement : tailStatements) { ifStatement.getParent().addAfter(statement.copy(), ifStatement); } PsiStatement[] thenStatements = ControlFlowUtils.unwrapBlock(ifStatement.getThenBranch()); PsiStatement[] elseStatements = ControlFlowUtils.unwrapBlock(ifStatement.getElseBranch()); int thenLength = thenStatements.length; int elseLength = elseStatements.length; for (int i = 0; i < tailStatements.size(); i++) { PsiStatement thenStatement = thenStatements[thenLength - 1 - i]; // handling situation, when there is no braces around then branch if (thenStatements.length == 1 && thenStatement.getParent() == ifStatement) { thenStatement.replace(JavaPsiFacade.getElementFactory(thenStatement.getProject()).createCodeBlock()); } else { thenStatement.delete(); } ct.delete(elseStatements[elseLength - 1 - i]); } } }