private static void fixTryStatements(final @NotNull PsiMethod method, final CommonProblemDescriptor @NotNull [] problems) {
      final Project project = method.getProject();
      final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);

      final Set<PsiClassType> redundantTypes = getRedundantExceptionTypes(problems, factory);

      final Map<@NotNull PsiFile, @NotNull Set<@NotNull PsiTryStatement>> tryStatementsInFile = getFilesWithTryStatements(method);

      for (Set<PsiTryStatement> tryStatements : tryStatementsInFile.values()) {
        final Map<@NotNull PsiElement, @Nullable PsiElement> mappings = new HashMap<>();

        for (final PsiTryStatement tryStatement : tryStatements) {
          final TryStatementInfo graph = new TryStatementInfo(tryStatement);

          graph.breakConnectionsFromRedundantExceptions(redundantTypes, method);

          for (final PsiCatchSection section : tryStatement.getCatchSections()) {
            final PsiParameter parameter = section.getParameter();
            if (parameter == null) continue;

            final PsiTypeElement catchParamTypeElement = parameter.getTypeElement();
            if (catchParamTypeElement == null) continue;

            final PsiType catchParamType = parameter.getType();

            final List<PsiType> types = graph.getEssentialExceptionsOfCatch(section);

            if (types.isEmpty()) {
              mappings.put(section, null);
            }
            else if (catchParamType instanceof PsiDisjunctionType parameterType) {
              if (parameterType.getDisjunctions().size() == types.size()) continue;
              final PsiType newDisjunctionType = PsiDisjunctionType.createDisjunction(types, method.getManager());

              final PsiTypeElement newDisjunctionTypeElement = factory.createTypeElement(newDisjunctionType);

              mappings.put(catchParamTypeElement, newDisjunctionTypeElement);
            }
          }
        }

        if (mappings.isEmpty()) continue;

        if (!FileModificationService.getInstance().preparePsiElementsForWrite(tryStatements)) return;
        WriteAction.run(() -> {
          final JavaCodeStyleManager instance = JavaCodeStyleManager.getInstance(project);
          for (Map.Entry<PsiElement, PsiElement> mapping : mappings.entrySet()) {
            final PsiElement from = mapping.getKey();
            final PsiElement to = mapping.getValue();
            if (!from.isValid()) continue;
            if (to == null) {
              new CommentTracker().deleteAndRestoreComments(from);
            }
            else if (to.isValid()) {
              final PsiElement element = new CommentTracker().replaceAndRestoreComments(from, to);
              instance.shortenClassReferences(element);
            }
          }

          for (PsiTryStatement tryStatement : tryStatements) {
            if (!tryStatement.isValid()) continue;
            if (tryStatement.getCatchSections().length != 0) continue;
            if (tryStatement.getFinallyBlock() != null) continue;
            if (tryStatement.getResourceList() != null) continue;

            BlockUtils.unwrapTryBlock(tryStatement);
          }
        });
      }
    }
private static void fixTryStatements(final @NotNull PsiMethod method, final CommonProblemDescriptor @NotNull [] problems)