protected static int getNumberOfOccurrences(PsiNameIdentifierOwner nameIdentifierOwner,
                                              Predicate<? super PsiReference> ignoreOccurrence,
                                              Function<? super GlobalSearchScope, ? extends Query<PsiReference>> searcher) {
    final PsiSearchHelper searchHelper = PsiSearchHelper.getInstance(nameIdentifierOwner.getProject());
    final GlobalSearchScope scope = GlobalSearchScope.projectScope(nameIdentifierOwner.getProject());
    final String name = nameIdentifierOwner.getName();
    final boolean isCheapToSearch =
     name != null && searchHelper.isCheapEnoughToSearch(name, scope, null) != PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
    return isCheapToSearch ? (int)searcher.apply(scope).findAll().stream().filter(ignoreOccurrence).count() : - 1;
  }
protected static int getNumberOfOccurrences(PsiNameIdentifierOwner nameIdentifierOwner,
                                              Predicate<? super PsiReference> ignoreOccurrence,
                                              Function<? super GlobalSearchScope, ? extends Query<PsiReference>> searcher)