private static void unwrapStatement(@NotNull PsiSwitchLabelStatementBase labelStatement, @NotNull PsiCaseLabelElement label,
                                      @NotNull PsiSwitchStatement switchStatement) {
    PsiCodeBlock block = switchStatement.getBody();
    PsiStatement body = labelStatement instanceof PsiSwitchLabeledRuleStatement ruleStatement ? ruleStatement.getBody() : null;
    List<PsiLocalVariable> variables;
    if (body == null) {
      variables = block != null ? collectVariables(label, switchStatement) : Collections.emptyList();
      new CommentTracker().deleteAndRestoreComments(labelStatement);
    }
    else if (body instanceof PsiBlockStatement blockStatement) {
      variables = collectVariables(label, switchStatement);
      block = blockStatement.getCodeBlock();
    }
    else {
      variables = collectVariables(label, switchStatement);
      new CommentTracker().replaceAndRestoreComments(labelStatement, body);
    }
    PsiCodeBlock parent = ObjectUtils.tryCast(switchStatement.getParent(), PsiCodeBlock.class);
    CommentTracker ct = new CommentTracker();
    if (parent != null && !BlockUtils.containsConflictingDeclarations(Objects.requireNonNull(block), parent)) {
      ct.grabComments(switchStatement);
      ct.markUnchanged(block);
      ct.insertCommentsBefore(switchStatement);
      PsiElement firstElementAdded = BlockUtils.inlineCodeBlock(switchStatement, block);
      if (firstElementAdded != null) {
        variables.replaceAll(variable -> addVariable(variable, firstElementAdded, parent));
        inline(variables, parent);
      }
    }
    else if (block != null) {
      PsiBlockStatement element = (PsiBlockStatement)ct.replaceAndRestoreComments(switchStatement, ct.text(block));
      if (!variables.isEmpty()) {
        PsiStatement firstStatement = ArrayUtil.getFirstElement(element.getCodeBlock().getStatements());
        if (firstStatement != null) {
          PsiCodeBlock variableParent = element.getCodeBlock();
          variables.replaceAll(variable -> addVariable(variable, firstStatement, variableParent));
          inline(variables, variableParent);
        }
      }
    }
    else {
      ct.deleteAndRestoreComments(switchStatement);
    }
  }
private static void unwrapStatement(@NotNull PsiSwitchLabelStatementBase labelStatement, @NotNull PsiCaseLabelElement label,
                                      @NotNull PsiSwitchStatement switchStatement)