SpecialFirstIterationLoop (boolean firstIterationThen, int index, @NotNull List<? extends PsiStatement> thenStatements, @NotNull List<? extends PsiStatement> elseStatements, @NotNull List<? extends PsiStatement> statements, @NotNull PsiLocalVariable checkVar) { PsiStatement statement = statements.get(index); PsiIfStatement ifStatement = tryCast(statement, PsiIfStatement.class); if (ifStatement == null) return null; List<? extends PsiStatement> beforeStatements = statements.subList(0, index); List<? extends PsiStatement> afterStatements = statements.subList(index + 1, statements.size()); ArrayList<PsiStatement> firstIteration = new ArrayList<>(beforeStatements); ArrayList<PsiStatement> otherIterations = new ArrayList<>(beforeStatements); firstIteration.addAll(firstIterationThen ? thenStatements : elseStatements); firstIteration.addAll(afterStatements); otherIterations.addAll(firstIterationThen ? elseStatements : thenStatements); otherIterations.addAll(afterStatements); return new SpecialFirstIterationLoop(firstIteration, otherIterations, checkVar); }