void (PsiClass psiClass, PsiElement[] allElementsToDelete, List<? super UsageInfo> usages) { String qualifiedName = psiClass.getQualifiedName(); boolean annotationType = psiClass.isAnnotationType() && qualifiedName != null; PsiElement[] topElementsToDelete = Arrays.stream(allElementsToDelete).map(element -> { if (element instanceof PsiClass) { PsiElement parent = element.getParent(); if (parent instanceof PsiClassOwner) { PsiClass[] classes = ((PsiClassOwner)parent).getClasses(); if (classes.length == 1 && classes[0] == element) { return element.getContainingFile(); } } } return element; }).toArray(PsiElement[]::new); ReferencesSearch.search(psiClass).forEach(reference -> { PsiElement element = reference.getElement(); if (!isInside(element, topElementsToDelete)) { PsiElement parent = element.getParent(); JavaSafeDeleteDelegate safeDeleteDelegate = JavaSafeDeleteDelegate.EP.forLanguage(element.getLanguage()); UsageInfo usageInfo = safeDeleteDelegate != null ? safeDeleteDelegate.createExtendsListUsageInfo(psiClass, reference) : null; if (usageInfo != null) { usages.add(usageInfo); return true; } LOG.assertTrue(element.getTextRange() != null); PsiFile containingFile = psiClass.getContainingFile(); boolean sameFileWithSingleClass = false; if (containingFile instanceof PsiClassOwner) { PsiClass[] classes = ((PsiClassOwner)containingFile).getClasses(); sameFileWithSingleClass = classes.length == 1 && classes[0] == psiClass && element.getContainingFile() == containingFile; } boolean safeDelete = sameFileWithSingleClass || isInNonStaticImport(element); if (annotationType && parent instanceof PsiAnnotation) { usages.add(new SafeDeleteAnnotation((PsiAnnotation)parent, psiClass, safeDelete)); } else { usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(element, psiClass, safeDelete)); } } return true; }); }