@Nullable
  private static List<PsiExpression> extractBranches(PsiSwitchBlock block) {
    PsiCodeBlock body = block.getBody();
    if (body == null) return null;
    PsiStatement[] statements = body.getStatements();
    if (statements.length < 2) return null;
    List<PsiExpression> result = new ArrayList<>();
    for (PsiStatement statement : statements) {
      if (!(statement instanceof PsiSwitchLabeledRuleStatement rule)) return null;
      PsiStatement ruleBody = rule.getBody();
      if (ruleBody instanceof PsiThrowStatement) continue;
      if (ruleBody instanceof PsiBlockStatement blockStatement) {
        if (!(block instanceof PsiSwitchExpression)) return null;
        if (ControlFlowUtils.codeBlockMayCompleteNormally(blockStatement.getCodeBlock())) return null;
        Collection<PsiYieldStatement> yields = PsiTreeUtil.findChildrenOfType(blockStatement, PsiYieldStatement.class);
        List<PsiYieldStatement> myYields = ContainerUtil.filter(yields, st -> st.findEnclosingExpression() == block);
        for (PsiYieldStatement yield : myYields) {
          PsiExpression expression = yield.getExpression();
          if (expression == null) return null;
          result.add(expression);
        }
        continue;
      }
      if (ruleBody instanceof PsiExpressionStatement expr) {
        result.add(expr.getExpression());
        continue;
      }
      return null;
    }
    if (result.size() < 2) return null;
    return result;
  }
@Nullable
  private static List<PsiExpression> extractBranches(PsiSwitchBlock block)