public static void findNonCodeUsages(
      PsiElement element,
      String stringToSearch,
      boolean searchInStringsAndComments,
      boolean searchInNonJavaFiles,
      String newQName,
      Collection<UsageInfo> results) {
    if (searchInStringsAndComments || searchInNonJavaFiles) {
      UsageInfoFactory factory = createUsageInfoFactory(element, newQName);

      if (searchInStringsAndComments) {
        addUsagesInStringsAndComments(element, stringToSearch, results, factory);
      }

      if (searchInNonJavaFiles) {
        GlobalSearchScope projectScope = GlobalSearchScope.projectScope(element.getProject());
        addTextOccurences(element, stringToSearch, projectScope, results, factory);
      }
    }
  }
 public static void addNonCodeUsages(
     final PsiElement element,
     List<UsageInfo> usages,
     @Nullable final Condition<PsiElement> insideElements,
     boolean searchNonJava,
     boolean searchInCommentsAndStrings) {
   UsageInfoFactory nonCodeUsageFactory =
       new UsageInfoFactory() {
         @Override
         public UsageInfo createUsageInfo(
             @NotNull PsiElement usage, int startOffset, int endOffset) {
           if (insideElements != null && insideElements.value(usage)) {
             return null;
           }
           return new SafeDeleteReferenceSimpleDeleteUsageInfo(
               usage, element, startOffset, endOffset, true, false);
         }
       };
   if (searchInCommentsAndStrings) {
     String stringToSearch =
         ElementDescriptionUtil.getElementDescription(
             element, NonCodeSearchDescriptionLocation.STRINGS_AND_COMMENTS);
     TextOccurrencesUtil.addUsagesInStringsAndComments(
         element, stringToSearch, usages, nonCodeUsageFactory);
   }
   if (searchNonJava) {
     String stringToSearch =
         ElementDescriptionUtil.getElementDescription(
             element, NonCodeSearchDescriptionLocation.NON_JAVA);
     TextOccurrencesUtil.addTextOccurences(
         element,
         stringToSearch,
         GlobalSearchScope.projectScope(element.getProject()),
         usages,
         nonCodeUsageFactory);
   }
 }
  @NotNull
  public static UsageInfo[] findUsages(
      final PsiElement element,
      final String newName,
      boolean searchInStringsAndComments,
      boolean searchForTextOccurrences,
      Map<? extends PsiElement, String> allRenames) {
    final List<UsageInfo> result = Collections.synchronizedList(new ArrayList<UsageInfo>());

    PsiManager manager = element.getManager();
    GlobalSearchScope projectScope = GlobalSearchScope.projectScope(manager.getProject());
    RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(element);

    Collection<PsiReference> refs = processor.findReferences(element, searchInStringsAndComments);
    for (final PsiReference ref : refs) {
      if (ref == null) {
        LOG.error("null reference from processor " + processor);
        continue;
      }
      PsiElement referenceElement = ref.getElement();
      result.add(
          new MoveRenameUsageInfo(
              referenceElement,
              ref,
              ref.getRangeInElement().getStartOffset(),
              ref.getRangeInElement().getEndOffset(),
              element,
              ref.resolve() == null));
    }

    processor.findCollisions(element, newName, allRenames, result);

    final PsiElement searchForInComments =
        processor.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, processor);
        TextOccurrencesUtil.UsageInfoFactory factory =
            new NonCodeUsageInfoFactory(searchForInComments, stringToReplace);
        TextOccurrencesUtil.addUsagesInStringsAndComments(
            searchForInComments, stringToSearch, result, factory);
      }
    }

    if (searchForTextOccurrences && searchForInComments != null) {
      String stringToSearch =
          ElementDescriptionUtil.getElementDescription(
              searchForInComments, NonCodeSearchDescriptionLocation.NON_JAVA);
      if (stringToSearch.length() > 0) {
        final String stringToReplace = getStringToReplace(element, newName, true, processor);
        addTextOccurrence(
            searchForInComments, result, projectScope, stringToSearch, stringToReplace);
      }

      final Pair<String, String> additionalStringToSearch =
          processor.getTextOccurrenceSearchStrings(searchForInComments, newName);
      if (additionalStringToSearch != null && additionalStringToSearch.first.length() > 0) {
        addTextOccurrence(
            searchForInComments,
            result,
            projectScope,
            additionalStringToSearch.first,
            additionalStringToSearch.second);
      }
    }

    return result.toArray(new UsageInfo[result.size()]);
  }