public boolean isUsed(@NotNull PsiElement element, @NotNull FindUsagesOptions findUsagesOptions) { FindUsagesHandler handler = getFindUsagesHandler(element, true); if (handler == null) return false; UsageInfoToUsageConverter.TargetElementsDescriptor descriptor = new UsageInfoToUsageConverter.TargetElementsDescriptor(element); UsageSearcher usageSearcher = createUsageSearcher(descriptor, handler, findUsagesOptions, null); final AtomicBoolean used = new AtomicBoolean(); usageSearcher.generate( new Processor<Usage>() { @Override public boolean process(final Usage usage) { used.set(true); return false; } }); return used.get(); }
private static Usage findSiblingUsage( @NotNull final UsageSearcher usageSearcher, FileSearchScope dir, final FileEditorLocation currentLocation, @NotNull final boolean[] usagesWereFound, @NotNull FileEditor fileEditor) { if (fileEditor.getUserData(KEY_START_USAGE_AGAIN) != null) { dir = dir == FileSearchScope.AFTER_CARET ? FileSearchScope.FROM_START : FileSearchScope.FROM_END; } final FileSearchScope direction = dir; final Usage[] foundUsage = {null}; usageSearcher.generate( new Processor<Usage>() { @Override public boolean process(Usage usage) { usagesWereFound[0] = true; if (direction == FileSearchScope.FROM_START) { foundUsage[0] = usage; return false; } if (direction == FileSearchScope.FROM_END) { foundUsage[0] = usage; } else if (direction == FileSearchScope.AFTER_CARET) { if (Comparing.compare(usage.getLocation(), currentLocation) > 0) { foundUsage[0] = usage; return false; } } else if (direction == FileSearchScope.BEFORE_CARET) { if (Comparing.compare(usage.getLocation(), currentLocation) < 0) { if (foundUsage[0] != null) { if (foundUsage[0].getLocation().compareTo(usage.getLocation()) < 0) { foundUsage[0] = usage; } } else { foundUsage[0] = usage; } } else { return false; } } return true; } }); fileEditor.putUserData(KEY_START_USAGE_AGAIN, null); return foundUsage[0]; }
private static Usage findSiblingUsage( @NotNull final UsageSearcher usageSearcher, @NotNull FileSearchScope dir, final FileEditorLocation currentLocation, @NotNull final AtomicBoolean usagesWereFound, @NotNull FileEditor fileEditor) { if (fileEditor.getUserData(KEY_START_USAGE_AGAIN) != null) { dir = dir == FileSearchScope.AFTER_CARET ? FileSearchScope.FROM_START : FileSearchScope.FROM_END; } final FileSearchScope direction = dir; final AtomicReference<Usage> foundUsage = new AtomicReference<Usage>(); usageSearcher.generate( new Processor<Usage>() { @Override public boolean process(Usage usage) { usagesWereFound.set(true); if (direction == FileSearchScope.FROM_START) { foundUsage.compareAndSet(null, usage); return false; } if (direction == FileSearchScope.FROM_END) { foundUsage.set(usage); } else if (direction == FileSearchScope.AFTER_CARET) { if (Comparing.compare(usage.getLocation(), currentLocation) > 0) { foundUsage.set(usage); return false; } } else if (direction == FileSearchScope.BEFORE_CARET) { if (Comparing.compare(usage.getLocation(), currentLocation) >= 0) { return false; } while (true) { Usage found = foundUsage.get(); if (found == null) { if (foundUsage.compareAndSet(null, usage)) break; } else { if (Comparing.compare(found.getLocation(), usage.getLocation()) < 0 && foundUsage.compareAndSet(found, usage)) break; } } } return true; } }); fileEditor.putUserData(KEY_START_USAGE_AGAIN, null); return foundUsage.get(); }