List<FullCase> (@NotNull SwitchStatement statement) { for (Statement caseStatement : statement.getCaseStatements()) { if (caseStatement == null) { return null; } } @NotNull List<List<@Nullable Exprent>> values = statement.getCaseValues(); List<List<Exprent>> sortedCaseValue = new ArrayList<>(); List<List<StatEdge>> sortedEdges = new ArrayList<>(); for (int i = 0; i < values.size(); i++) { List<Exprent> caseValue = statement.getCaseValues().get(i); for (Exprent exprent : caseValue) { if (exprent == null) { continue; } if (!(exprent instanceof ConstExprent constCaseValue)) { return null; } if (!(constCaseValue.getConstType() == VARTYPE_INT || constCaseValue.getConstType() == VARTYPE_BYTECHAR || constCaseValue.getConstType() == VARTYPE_CHAR || constCaseValue.getConstType() == VARTYPE_BYTE)) { return null; } } List<StatEdge> edges = statement.getCaseEdges().get(i); if (edges.size() != caseValue.size()) { return null; } List<CaseValueWithEdge> sorted = IntStream.range(0, edges.size()).mapToObj(ind -> new CaseValueWithEdge(caseValue.get(ind), edges.get(ind))) .sorted( Comparator.<CaseValueWithEdge, Boolean>comparing(o -> o.edge == statement.getDefaultEdge()) .thenComparingLong(o -> o.exprent instanceof ConstExprent c ? c.getIntValue() : Long.MIN_VALUE)) .collect(Collectors.toList()); sortedEdges.add(sorted.stream().map(t -> t.edge).collect(Collectors.toList())); sortedCaseValue.add(sorted.stream().map(t -> t.exprent).collect(Collectors.toList())); } List<FullCase> sortedAll = IntStream.range(0, statement.getCaseValues().size()) .mapToObj(ind -> new FullCase(statement.getCaseStatements().get(ind), sortedCaseValue.get(ind), sortedEdges.get(ind))) .sorted(Comparator.<FullCase, Boolean>comparing( fullCase -> !fullCase.edges().isEmpty() && fullCase.edges().get(fullCase.exprents.size() - 1) == statement.getDefaultEdge()) .thenComparingLong(o -> !o.exprents.isEmpty() && o.exprents.get(o.exprents.size() - 1) instanceof ConstExprent c ? c.getIntValue() : Long.MIN_VALUE)) .collect(Collectors.toList()); for (int i = 0; i < sortedAll.size(); i++) { if (i == sortedAll.size() - 1) { break; } FullCase current = sortedAll.get(i); FullCase next = sortedAll.get(i + 1); if (current.exprents.isEmpty() || next.exprents.isEmpty()) { return null; } Exprent currentFirstExpr = current.exprents.get(0); Exprent nextFirstExpr = next.exprents.get(0); if (currentFirstExpr instanceof ConstExprent constExprent1 && nextFirstExpr instanceof ConstExprent constExprent2) { if (constExprent1.getIntValue() > constExprent2.getIntValue() && constExprent1.getIntValue() != -1 && constExprent2.getIntValue() != -1) { if (statement.getDefaultEdge() != next.edges.get(next.edges.size() - 1)) { return null; } } } List<StatEdge> edges = current.statement.getSuccessorEdges(EdgeType.DIRECT_ALL); if (edges.size() == 1) { StatEdge currentEdge = edges.get(0); if (currentEdge.getType() == EdgeType.REGULAR) { Statement destination = currentEdge.getDestination(); if (destination != next.statement()) { return null; } } } } return sortedAll; }