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); } } }
private static void addTextOccurrence( final PsiElement element, final List<UsageInfo> result, final GlobalSearchScope projectScope, final String stringToSearch, final String stringToReplace) { TextOccurrencesUtil.UsageInfoFactory factory = new TextOccurrencesUtil.UsageInfoFactory() { public UsageInfo createUsageInfo( @NotNull PsiElement usage, int startOffset, int endOffset) { TextRange textRange = usage.getTextRange(); int start = textRange == null ? 0 : textRange.getStartOffset(); return NonCodeUsageInfo.create( usage.getContainingFile(), start + startOffset, start + endOffset, element, stringToReplace); } }; TextOccurrencesUtil.addTextOccurences(element, stringToSearch, projectScope, result, 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); } }