boolean (final RefEntity @NotNull [] refElements) { if (!super.applyFix(refElements)) return false; //filter only elements applicable to be deleted (exclude entry points) List<RefElement> list = new ArrayList<>(); for (RefEntity entry : refElements) { if (entry instanceof RefJavaElement && getFilter().accepts((RefJavaElement)entry)) { list.add((RefElement)entry); } } RefElement[] filteredRefElements = list.toArray(new RefElement[0]); ApplicationManager.getApplication().invokeLater(() -> { final Project project = getContext().getProject(); if (isDisposed() || project.isDisposed()) return; Set<RefEntity> classes = Arrays.stream(filteredRefElements) .filter(refElement -> refElement instanceof RefClass) .collect(Collectors.toSet()); //filter out elements inside classes to be deleted PsiElement[] elements = Arrays.stream(filteredRefElements).filter(e -> { RefEntity owner = e.getOwner(); return owner == null || !classes.contains(owner); }).map(e -> e.getPsiElement()) .filter(e -> e != null) .toArray(PsiElement[]::new); SafeDeleteHandler.invoke(project, elements, false, () -> { removeElements(filteredRefElements, project, myToolWrapper); for (RefEntity ref : filteredRefElements) { myFixedElements.put(ref, UnusedDeclarationHint.DELETE); } }); }); return false; //refresh after safe delete dialog is closed }