Collection<PsiElement> (@NotNull final PsiElement element, final @NotNull Collection<? extends PsiElement> allElementsToDelete, final boolean askUser) { if (!askUser || !(element instanceof PsiFile)) return Collections.emptyList(); final VirtualFile file = ((PsiFile)element).getVirtualFile(); if (file == null) return Collections.emptyList(); final Collection<NestingTreeStructureProvider.ChildFileInfo> relatedFileInfos = NestingTreeStructureProvider.getFilesShownAsChildrenInProjectView(element.getProject(), file); final Collection<PsiElement> psiFiles = new ArrayList<>(relatedFileInfos.size()); for (NestingTreeStructureProvider.ChildFileInfo info : relatedFileInfos) { final PsiFile psiFile = element.getManager().findFile(info.file()); if (psiFile != null && !allElementsToDelete.contains(psiFile)) { psiFiles.add(psiFile); } } if (!psiFiles.isEmpty()) { final String message = psiFiles.size() == 1 ? RefactoringBundle.message("ask.to.delete.related.file", ((PsiFile)psiFiles.iterator().next()).getName()) : RefactoringBundle.message("ask.to.delete.related.files", StringUtil.join(psiFiles, (psiFile) -> ((PsiFile)psiFile).getName(), ", ")); final int ok = Messages.showYesNoDialog(element.getProject(), message, RefactoringBundle.message("delete.title"), Messages.getQuestionIcon()); if (ok == Messages.YES) { return psiFiles; } } return Collections.emptyList(); }