private static void extractTailCommonParts(@NotNull PsiIfStatement ifStatement,
                                               PsiStatement @NotNull [] thenBranch,
                                               PsiStatement @NotNull [] elseBranch,
                                               LocalEquivalenceChecker equivalence,
                                               int thenLen,
                                               int elseLen,
                                               Set<PsiVariable> extractedVariables,
                                               int canBeExtractedFromTail,
                                               List<? super PsiStatement> tailCommonParts,
                                               Set<PsiVariable> differentDeclarationsWithoutInitializers) {
      if (isSimilarTailStatements(thenBranch)) return;
      for (int i = 0; i < canBeExtractedFromTail; i++) {
        PsiStatement thenStmt = thenBranch[thenLen - i - 1];
        PsiStatement elseStmt = elseBranch[elseLen - i - 1];

        // Check that if we put our statement out of if, no var declaration will be uninitialized
        if (!differentDeclarationsWithoutInitializers.isEmpty()) {
          boolean willUseUninitializedVar = StreamEx.of(thenStmt, elseStmt)
            .flatMap(statement -> StreamEx.ofTree((PsiElement)statement, element -> StreamEx.of(element.getChildren())))
            .select(PsiReferenceExpression.class)
            .map(expression -> expression.resolve())
            .select(PsiVariable.class)
            .anyMatch(element -> differentDeclarationsWithoutInitializers.contains(element));
          if (willUseUninitializedVar) break;
        }
        if (!equivalence.statementsAreEquivalent(thenStmt, elseStmt)) break;
        boolean canBeExtractedOutOfIf = VariableAccessUtils.collectUsedVariables(thenStmt).stream()
          .filter(var -> var instanceof PsiLocalVariable)
          .filter(var -> PsiTreeUtil.isAncestor(ifStatement, var, false))
          .allMatch(var -> extractedVariables.contains(var));
        if (!canBeExtractedOutOfIf) break;
        tailCommonParts.add(thenStmt);
      }
    }
private static void extractTailCommonParts(@NotNull PsiIfStatement ifStatement,
                                               PsiStatement @NotNull [] thenBranch,
                                               PsiStatement @NotNull [] elseBranch,
                                               LocalEquivalenceChecker equivalence,
                                               int thenLen,
                                               int elseLen,
                                               Set<PsiVariable> extractedVariables,
                                               int canBeExtractedFromTail,
                                               List<? super PsiStatement> tailCommonParts,
                                               Set<PsiVariable> differentDeclarationsWithoutInitializers)