@Override
  @SuppressWarnings("LoggingSimilarMessage")
  public void codeCleanup(
    @NotNull AnalysisScope scope,
    @NotNull InspectionProfile profile,
    @Nullable String commandName,
    @Nullable Runnable postRunnable,
    boolean modal,
    @NotNull Predicate<? super ProblemDescriptor> shouldApplyFix
  ) {
    @SuppressWarnings("DialogTitleCapitalization") String title = LangBundle.message("progress.title.inspect.code", profile.getName());
    if (LOG.isDebugEnabled()) {
      LOG.debug("Starting code cleanup");
    }
    Runnable retryRunnable = () -> codeCleanup(scope, profile, commandName, postRunnable, modal, shouldApplyFix);

    class TaskDelegate {
      CleanupProblems problems;
      @NlsContexts.NotificationContent String noProblemsMessage;

      void run(@NotNull ProgressIndicator indicator) {
        problems = findProblems(scope, profile, indicator, shouldApplyFix);
        if (problems.files().isEmpty()) {
          noProblemsMessage =
            commandName == null ? null :
            InspectionsBundle.message("inspection.no.problems.message", scope.getFileCount(), scope.getDisplayName());
        }
      }

      void onSuccess() {
        boolean isFinished;
        if (problems.files().isEmpty()) {
          isFinished = reportNoProblemsFound(scope, noProblemsMessage, retryRunnable);
        }
        else {
          isFinished = applyFixes(problems);
        }
        if (isFinished && postRunnable != null) {
          postRunnable.run();
        }
      }
    }

    TaskDelegate delegate = new TaskDelegate();
    Task task = modal ? new Task.Modal(getProject(), title, true) {

      @Override
      public void run(@NotNull ProgressIndicator indicator) {
        delegate.run(indicator);
      }

      @Override
      public void onSuccess() {
        delegate.onSuccess();
      }

      @Override
      public void onThrowable(@NotNull Throwable error) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Code cleanup: an exception during findProblems");
        }
        super.onThrowable(error);
      }

      @Override
      public void onCancel() {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Code cleanup: cancelled");
        }
      }

      @Override
      public void onFinished() {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Code cleanup: finished searching for problems");
        }
      }
    } : new Task.Backgroundable(getProject(), title, true) {

      @Override
      public void run(@NotNull ProgressIndicator indicator) {
        delegate.run(indicator);
      }

      @Override
      public void onSuccess() {
        delegate.onSuccess();
      }

      @Override
      public void onThrowable(@NotNull Throwable error) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Code cleanup: an exception during findProblems");
        }
        super.onThrowable(error);
      }

      @Override
      public void onCancel() {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Code cleanup: cancelled");
        }
      }

      @Override
      public void onFinished() {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Code cleanup: finished searching for problems");
        }
      }
    };
    ProgressManager.getInstance().run(task);
  }
@Override
  @SuppressWarnings("LoggingSimilarMessage")
  public void codeCleanup(
    @NotNull AnalysisScope scope,
    @NotNull InspectionProfile profile,
    @Nullable String commandName,
    @Nullable Runnable postRunnable,
    boolean modal,
    @NotNull Predicate<? super ProblemDescriptor> shouldApplyFix
  )