PsiSwitchStatement generate(CommentTracker mainCommentTracker) {
      PsiSwitchBlock switchCopy = (PsiSwitchBlock)mySwitchBlock.copy();
      PsiExpression expression = switchCopy.getExpression();
      if (expression == null) return null;
      PsiCodeBlock body = switchCopy.getBody();
      if (body == null) return null;
      List<PsiSwitchLabeledRuleStatement> rules = ContainerUtil.filterIsInstance(body.getStatements(), PsiSwitchLabeledRuleStatement.class);
      List<CommentTracker> branchTrackers = new ArrayList<>();
      IntList caseCounts = new IntArrayList();
      StringJoiner joiner = new StringJoiner("\n");
      boolean addDefaultBranch = mySwitchBlock instanceof PsiSwitchExpression;
      for (int i = 0; i < rules.size(); i++) {
        PsiSwitchLabeledRuleStatement rule = rules.get(i);
        CommentTracker ct = new CommentTracker();
        branchTrackers.add(ct);
        String generate = collectCommentsBefore(rule, mainCommentTracker);
        generate += generateBranch(rule, ct, switchCopy);
        if (i == rules.size() - 1) {
          generate += collectCommentsBefore(body.getRBrace(), mainCommentTracker);
        }
        PsiCaseLabelElementList labelElementList = rule.getCaseLabelElementList();
        int caseCount = labelElementList == null ? 1 : labelElementList.getElementCount();
        caseCounts.add(caseCount);
        if (joiner.length() != 0 && generate.startsWith("\n")) {
          generate = generate.substring(1);
        }
        joiner.add(generate);
        mainCommentTracker.markUnchanged(rule);
        addDefaultBranch &= !SwitchUtils.isDefaultLabel(rule);

      }
      if (addDefaultBranch) {
        joiner.add("default:throw new java.lang.IllegalArgumentException();");
      }
      String bodyText = joiner.toString();
      String switchText = "switch(" + mainCommentTracker.text(expression) + "){" + bodyText + "}";
      mainCommentTracker.grabComments(switchCopy);
      PsiSwitchStatement newBlock = (PsiSwitchStatement)myFactory.createStatementFromText(switchText, mySwitchBlock);
      PsiCodeBlock newBody = newBlock.getBody();
      assert newBody != null;
      List<PsiSwitchLabelStatement> branches = ContainerUtil.filterIsInstance(newBody.getStatements(), PsiSwitchLabelStatement.class);
      int totalCaseStatements = 0;
      for (int i = 0; i < caseCounts.size(); i++) {
        totalCaseStatements += caseCounts.getInt(i);
      }
      if (branches.size() != totalCaseStatements) return newBlock;
      int firstCaseInChainIndex = 0;
      for (int i = 0; i < branchTrackers.size(); i++) {
        PsiSwitchLabelStatement branch = branches.get(firstCaseInChainIndex);
        branchTrackers.get(i).insertCommentsBefore(branch);
        firstCaseInChainIndex += caseCounts.getInt(i);
      }
      return newBlock;
    }
PsiSwitchStatement generate(CommentTracker mainCommentTracker)