private static boolean processUsages(
    @NotNull PsiElement element,
    @NotNull RenamePsiElementProcessorBase elementProcessor,
    String newName,
    @NotNull SearchScope searchScope,
    boolean searchInCode,
    boolean searchInStringsAndComments,
    boolean searchForTextOccurrences,
    @NotNull Processor<? super UsageInfo> processor
  ) {
    SearchScope useScope = PsiSearchHelper.getInstance(element.getProject()).getUseScope(element);
    if (!(useScope instanceof LocalSearchScope)) {
      useScope = searchScope.intersectWith(useScope);
    }

    if (searchInCode) {
      Collection<PsiReference> refs = elementProcessor.findReferences(element, useScope, searchInStringsAndComments);
      for (final PsiReference ref : refs) {
        if (ref == null) {
          LOG.error("null reference from processor " + elementProcessor);
          continue;
        }
        PsiElement referenceElement = ref.getElement();
        if (!processor.process(elementProcessor.createUsageInfo(element, ref, referenceElement))) return false;
      }
    }

    final PsiElement searchForInComments = elementProcessor.getElementToSearchInStringsAndComments(element);

    if (searchInStringsAndComments && searchForInComments != null) {
      String stringToSearch = ElementDescriptionUtil.getElementDescription(searchForInComments, NonCodeSearchDescriptionLocation.STRINGS_AND_COMMENTS);
      if (stringToSearch.length() > 0) {
        final String stringToReplace = getStringToReplace(element, newName, false, elementProcessor);
        UsageInfoFactory factory = new NonCodeUsageInfoFactory(searchForInComments, stringToReplace);
        if (!TextOccurrencesUtilBase.processUsagesInStringsAndComments(processor, searchForInComments,
                                                                       searchScope, stringToSearch, factory)) return false;
      }
    }

    if (searchForTextOccurrences && searchForInComments != null) {
      String stringToSearch = ElementDescriptionUtil.getElementDescription(searchForInComments, NonCodeSearchDescriptionLocation.NON_JAVA);
      if (stringToSearch.length() > 0) {
        final String stringToReplace = getStringToReplace(element, newName, true, elementProcessor);
        if (!processTextOccurrences(searchForInComments, searchScope, stringToSearch, stringToReplace, processor)) return false;
      }

      final Pair<String, String> additionalStringToSearch = elementProcessor.getTextOccurrenceSearchStrings(searchForInComments, newName);
      if (additionalStringToSearch != null && additionalStringToSearch.first.length() > 0) {
        if (!processTextOccurrences(searchForInComments, searchScope, additionalStringToSearch.first, additionalStringToSearch.second,
                                    processor
        )) return false;
      }
    }

    return true;
  }
private static boolean processUsages(
    @NotNull PsiElement element,
    @NotNull RenamePsiElementProcessorBase elementProcessor,
    String newName,
    @NotNull SearchScope searchScope,
    boolean searchInCode,
    boolean searchInStringsAndComments,
    boolean searchForTextOccurrences,
    @NotNull Processor<? super UsageInfo> processor
  )