@NotNull
    private SwitchPatternHelper.PatternContainer collectGuards(@NotNull Map<Statement, List<PatternVariableCandidate>> candidates,
                                                               @NotNull Exprent typeVar,
                                                               @Nullable Statement doParentStatement,
                                                               @NotNull Set<AssignmentExprent> usedAssignments) {
      PatternContainer container = new PatternContainer();
      @NotNull List<Statement> statements = myRootSwitchStatement.getCaseStatements();
      for (int i = 0; i < statements.size(); i++) {
        Statement previousValueStatement = statements.get(i);
        Statement caseStatement = statements.get(i);
        List<PatternVariableCandidate> variableCandidates = candidates.get(caseStatement);
        if (variableCandidates != null) {
          for (PatternVariableCandidate variableCandidate : variableCandidates) {
            container.addPattern(previousValueStatement, variableCandidate.getGuards(), variableCandidate.getNextStatement(),
                                 variableCandidate.getVarExprent());
          }
          //java 21, only one pattern can be with guard
          //todo check with unnamed patterns and variables
          if (variableCandidates.size() != 1) {
            continue;
          }
          caseStatement = variableCandidates.get(0).getNextStatement();
        }
        if (caseStatement.getStats().size() < 2) {
          continue;
        }
        if (doParentStatement == null) {
          continue;
        }
        List<@Nullable Exprent> exprents = myRootSwitchStatement.getCaseValues().get(i);
        OptionalInt maxCaseValue = exprents.stream().filter(t -> t instanceof ConstExprent)
          .mapToInt(t -> ((ConstExprent)t).getIntValue())
          .max();
        if (maxCaseValue.isEmpty()) {
          continue;
        }
        boolean guardIsNegated = false;

        if (!(caseStatement.getStats().get(0) instanceof IfStatement ifStatement &&
              ifStatement.getIfstat() != null &&
              ifStatement.getElsestat() == null &&
              ifStatement.iftype == IFTYPE_IF)) {
          continue;
        }
        AssignmentExprent assignmentExprent = null;

        if (ifStatement.getIfstat().getExprents() != null &&
            ifStatement.getIfstat().getExprents().size() == 1 &&
            ifStatement.getIfstat().getExprents().get(0) instanceof AssignmentExprent expectedAssignmentExprent &&
            expectedAssignmentExprent.getLeft() != typeVar && expectedAssignmentExprent.getRight() instanceof ConstExprent constExprent &&
            constExprent.getValue() instanceof Integer index && index > maxCaseValue.getAsInt()) {
          assignmentExprent = expectedAssignmentExprent;
          guardIsNegated = true;
        }

        if (!guardIsNegated) {
          Statement breakStatement = caseStatement.getStats().get(1);
          Statement expectedBreakStatement = caseStatement.getStats().get(caseStatement.getStats().size() - 1);
          List<StatEdge> successorEdges = expectedBreakStatement.getSuccessorEdges(EdgeType.DIRECT_ALL);
          if (successorEdges.size() != 1) {
            continue;
          }
          StatEdge breakEdge = successorEdges.get(0);
          if (breakEdge.getType() == EdgeType.REGULAR) {
            continue;
          }
          if (breakEdge.getDestination() != doParentStatement) {
            continue;
          }
          if (!(breakStatement.getExprents() != null &&
                breakStatement.getExprents().size() == 1 &&
                breakStatement.getExprents().get(0) instanceof AssignmentExprent expectedAssignmentExprent &&
                expectedAssignmentExprent.getLeft() != typeVar &&
                expectedAssignmentExprent.getRight() instanceof ConstExprent constExprent &&
                constExprent.getValue() instanceof Integer index &&
                index > maxCaseValue.getAsInt())) {
            continue;
          }
          assignmentExprent = expectedAssignmentExprent;
          Statement ifstat = ifStatement.getIfstat();
          List<StatEdge> edges = ifstat.getSuccessorEdges(EdgeType.DIRECT_ALL);
          if (!edges.isEmpty() && (edges.size() != 1 || edges.get(0).getType() == EdgeType.REGULAR)) {
            continue;
          }
        }

        if (!(ifStatement.getHeadexprentList().size() == 1 &&
              ifStatement.getHeadexprent() != null &&
              ifStatement.getHeadexprent().getCondition() != null &&
              ifStatement.getIfstat() != null)) {
          continue;
        }

        IfExprent ifExprent = ifStatement.getHeadexprent();
        Statement newCaseStatement = ifStatement.getIfstat();
        if (guardIsNegated) {
          ifExprent = ifExprent.negateIf();
          newCaseStatement = new SequenceStatement(caseStatement.getStats().subList(1, caseStatement.getStats().size()));
        }
        Exprent nameAssignment = Optional.ofNullable(ifStatement.getStats())
          .map(stats -> !stats.isEmpty() ? stats.get(0).getExprents() : null)
          .map(exprs -> exprs.size() == 1 ? exprs.get(0) : null)
          .orElse(null);

        usedAssignments.add(assignmentExprent);
        VarExprent nextValue = null;
        if (nameAssignment instanceof AssignmentExprent nameAssignmentExprent &&
            nameAssignmentExprent.getLeft() instanceof VarExprent varExprent) {
          myTempVarAssignments.add(new TempVarAssignmentItem(varExprent, ifStatement));
          nextValue = varExprent;
        }

        if (variableCandidates != null && variableCandidates.size() == 1) {
          nextValue = variableCandidates.get(0).getVarExprent();
        }
        container.replacePattern(previousValueStatement, ifExprent.getCondition(), newCaseStatement, nextValue);
      }
      return container;
    }
@NotNull
    private SwitchPatternHelper.PatternContainer collectGuards(@NotNull Map<Statement, List<PatternVariableCandidate>> candidates,
                                                               @NotNull Exprent typeVar,
                                                               @Nullable Statement doParentStatement,
                                                               @NotNull Set<AssignmentExprent> usedAssignments)