public static void invoke(@NotNull Project project, PsiElement @NotNull [] elements, @Nullable Module module, boolean checkDelegates,
                            @Nullable Runnable successRunnable, @Nullable Runnable afterRefactoring, boolean silent) {
    for (PsiElement element : elements) {
      if (!SafeDeleteProcessor.validElement(element)) {
        return;
      }
    }

    if (elements.length == 1) {
      SafeDeleteTarget target = SafeDeleteTargetProvider.Companion.createSafeDeleteTarget(elements[0]);
      if (target != null) {
        safeDelete(project, target.createPointer());
        return;
      }
    }

    PsiElement[] tempToDelete = PsiTreeUtil.filterAncestors(elements);
    Set<PsiElement> elementsSet = Set.of(tempToDelete);
    Set<PsiElement> fullElementsSet = new LinkedHashSet<>();

    if (checkDelegates) {
      for (PsiElement element : tempToDelete) {
        boolean found = false;
        for(SafeDeleteProcessorDelegate delegate: SafeDeleteProcessorDelegate.EP_NAME.getExtensionList()) {
          if (delegate.handlesElement(element)) {
            found = true;
            Collection<? extends PsiElement> addElements = delegate instanceof SafeDeleteProcessorDelegateBase
                                                           ? ((SafeDeleteProcessorDelegateBase)delegate).getElementsToSearch(element, module, elementsSet)
                                                           : delegate.getElementsToSearch(element, elementsSet);
            if (addElements == null) return;
            fullElementsSet.addAll(addElements);
            break;
          }
        }
        if (!found) {
          fullElementsSet.add(element);
        }
      }
    } else {
      ContainerUtil.addAll(fullElementsSet, tempToDelete);
    }

    if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, fullElementsSet, true)) return;

    PsiElement[] elementsToDelete = PsiUtilCore.toPsiElementArray(fullElementsSet);

    if (ApplicationManager.getApplication().isUnitTestMode() || silent) {
      RefactoringSettings settings = RefactoringSettings.getInstance();
      SafeDeleteProcessor processor =
        SafeDeleteProcessor.createInstance(project, null, elementsToDelete, settings.SAFE_DELETE_SEARCH_IN_COMMENTS,
                                           settings.SAFE_DELETE_SEARCH_IN_NON_JAVA, true);
      if (afterRefactoring != null) processor.setAfterRefactoringCallback(afterRefactoring);
      processor.run();
      if (successRunnable != null) successRunnable.run();
    }
    else {
      SafeDeleteDialog.Callback callback = dialog -> {
        SafeDeleteProcessor processor = SafeDeleteProcessor.createInstance(project, () -> {
          if (successRunnable != null) {
            successRunnable.run();
          }
          dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
        }, elementsToDelete, dialog.isSearchInComments(), dialog.isSearchForTextOccurences(), true);
        if (afterRefactoring != null) processor.setAfterRefactoringCallback(afterRefactoring);
        processor.run();
      };

      SafeDeleteDialog dialog = new SafeDeleteDialog(project, elementsToDelete, callback);
      dialog.show();
    }
  }
public static void invoke(@NotNull Project project, PsiElement @NotNull [] elements, @Nullable Module module, boolean checkDelegates,
                            @Nullable Runnable successRunnable, @Nullable Runnable afterRefactoring, boolean silent)