@Nullable
  @Override
  public Collection<? extends PsiElement> getElementsToSearch(@NotNull PsiElement element,
                                                              @Nullable Module module,
                                                              @NotNull Collection<? extends PsiElement> allElementsToDelete) {
    Project project = element.getProject();
    if (element instanceof PsiPackage && module != null) {
      PsiDirectory[] directories = ((PsiPackage)element).getDirectories(module.getModuleScope());
      if (directories.length == 0) return null;
      return Arrays.asList(directories);
    }
    if (element instanceof PsiMethod) {
      if (ApplicationManager.getApplication().isUnitTestMode()) {
        return Collections.singletonList(element);
      }
      PsiMethod[] methods =
        SuperMethodWarningUtil.checkSuperMethods((PsiMethod)element, allElementsToDelete);
      if (methods.length == 0) return null;
      ArrayList<PsiMethod> psiMethods = new ArrayList<>(Arrays.asList(methods));
      psiMethods.add((PsiMethod)element);
      return psiMethods;
    }
    if (element instanceof PsiParameter param && param.getDeclarationScope() instanceof PsiMethod method) {
      Set<PsiElement> parametersToDelete = new HashSet<>();
      parametersToDelete.add(element);
      int parameterIndex = method.getParameterList().getParameterIndex(param);
      List<PsiMethod> superMethods = new ArrayList<>(Arrays.asList(method.findDeepestSuperMethods()));
      if (superMethods.isEmpty()) {
        superMethods.add(method);
      }
      if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> ReadAction.run(() -> {
        ContainerUtil.addAllNotNull(superMethods, FindSuperElementsHelper.getSiblingInheritedViaSubClass(method));
        for (PsiMethod superMethod : superMethods) {
          parametersToDelete.add(superMethod.getParameterList().getParameters()[parameterIndex]);
          OverridingMethodsSearch.search(superMethod).forEach(overrider -> {
            parametersToDelete.add(overrider.getParameterList().getParameters()[parameterIndex].getNavigationElement());
            return true;
          });
        }
      }), JavaRefactoringBundle.message("progress.title.collect.hierarchy", param.getName()), true, project)) {
        return null;
      }
      

      if (parametersToDelete.size() > 1 && !ApplicationManager.getApplication().isUnitTestMode()) {
        String message = JavaRefactoringBundle.message("0.is.a.part.of.method.hierarchy.do.you.want.to.delete.multiple.parameters", UsageViewUtil.getLongName(method));
        int result = Messages.showYesNoCancelDialog(project, message, SafeDeleteHandler.getRefactoringName(),
                                                    Messages.getQuestionIcon());
        if (result == Messages.CANCEL) return null;
        if (result == Messages.NO) return Collections.singletonList(element);
      }
      return parametersToDelete;
    }
    if (element instanceof PsiTypeParameter) {
      PsiTypeParameterListOwner owner = ((PsiTypeParameter)element).getOwner();
      if (owner instanceof PsiMethod && !owner.hasModifierProperty(PsiModifier.STATIC)) {
        PsiTypeParameterList typeParameterList = owner.getTypeParameterList();
        if (typeParameterList != null) {
          int index = typeParameterList.getTypeParameterIndex((PsiTypeParameter)element);
          if (index >= 0) {
            ArrayList<PsiTypeParameter> overriders = new ArrayList<>();
            overriders.add((PsiTypeParameter)element);
            OverridingMethodsSearch.search((PsiMethod)owner).forEach(overrider -> {
              PsiTypeParameter[] typeParameters = overrider.getTypeParameters();
              if (index < typeParameters.length) {
                overriders.add(typeParameters[index]);
              }
              return true;
            });
            if (overriders.size() > 1 && !ApplicationManager.getApplication().isUnitTestMode()) {
              String message = JavaRefactoringBundle.message("0.is.a.part.of.method.hierarchy.do.you.want.to.delete.multiple.type.parameters", UsageViewUtil.getLongName(owner));
              int result = ApplicationManager.getApplication().isUnitTestMode()
                           ? Messages.YES :Messages.showYesNoCancelDialog(project, message, SafeDeleteHandler.getRefactoringName(), Messages.getQuestionIcon());
              if (result == Messages.CANCEL) return null;
              if (result == Messages.NO) return Collections.singletonList(element);
            }
            return overriders;
          }
        }
      }
    }

    return Collections.singletonList(element);
  }
@Nullable
  @Override
  public Collection<? extends PsiElement> getElementsToSearch(@NotNull PsiElement element,
                                                              @Nullable Module module,
                                                              @NotNull Collection<? extends PsiElement> allElementsToDelete)