private static boolean usedOnlyIn(@NotNull PsiElement explored, @NotNull PsiMember place) {
    if (explored instanceof PsiNamedElement namedElement) {
      final String name = namedElement.getName();
      if (name != null &&
          PsiSearchHelper.getInstance(explored.getProject())
            .isCheapEnoughToSearch(name, GlobalSearchScope.projectScope(explored.getProject()), null) ==
          PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) {
        return false;
      }
    }
    if (explored instanceof PsiClassOwner classOwner) {
      for (PsiClass aClass : classOwner.getClasses()) {
        if (!usedOnlyIn(aClass, place)) return false;
      }
      return true;
    }
    if (UnusedDeclarationInspectionBase.isDeclaredAsEntryPoint(explored)) return false;
    CommonProcessors.FindProcessor<PsiReference> findProcessor = new CommonProcessors.FindProcessor<>() {
      @Override
      protected boolean accept(PsiReference reference) {
        final PsiElement element = reference.getElement();
        return !PsiTreeUtil.isAncestor(place, element, true) &&
               !PsiTreeUtil.isAncestor(explored, element, true);
      }
    };
    return ReferencesSearch.search(explored).forEach(findProcessor);
  }
private static boolean usedOnlyIn(@NotNull PsiElement explored, @NotNull PsiMember place)