ShowUsagesActionHandler (@NotNull FindUsagesHandlerBase handler, @NotNull FindUsagesOptions options) { // show super method warning dialogs before starting finding usages PsiElement[] primaryElements = handler.getPrimaryElements(); PsiElement[] secondaryElements = handler.getSecondaryElements(); String title = getUsagesTitle(handler.getPsiElement()); String optionsString = options.generateUsagesString(); return new ShowUsagesActionHandler() { @Override public boolean isValid() { return handler.getPsiElement().isValid(); } @Override public @NotNull UsageSearchPresentation getPresentation() { return new UsageSearchPresentation() { @Override public @Nls @NotNull String getSearchTargetString() { return title; } @Override public @Nls @NotNull String getOptionsString() { return optionsString; } }; } @Override public @NotNull UsageSearcher createUsageSearcher() { return FindUsagesManager.createUsageSearcher(handler, primaryElements, secondaryElements, options); } @Override public @NotNull SearchScope getSelectedScope() { return options.searchScope; } @Override public @NotNull GlobalSearchScope getMaximalScope() { return FindUsagesManager.getMaximalScope(handler); } @Override public ShowUsagesActionHandler showDialog() { FindUsagesOptions newOptions = ShowUsagesAction.showDialog(handler); if (newOptions == null) { return null; } else { return createActionHandler(handler, newOptions); } } @Override public void findUsages() { Project project = handler.getProject(); FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager(); findUsagesManager.findUsages( handler.getPrimaryElements(), handler.getSecondaryElements(), handler, options, FindSettings.getInstance().isSkipResultsWithOneUsage() ); } @Override public @NotNull ShowUsagesActionHandler withScope(@NotNull SearchScope searchScope) { FindUsagesOptions newOptions = options.clone(); newOptions.searchScope = searchScope; return createActionHandler(handler, newOptions); } @Override public @Nullable ShowUsagesParameters moreUsages(@NotNull ShowUsagesParameters parameters) { return parameters.moreUsages(); } @Override public Language getTargetLanguage() { return handler.getPsiElement().getLanguage(); } @Override public @NotNull Class<?> getTargetClass() { return handler.getPsiElement().getClass(); } @Override public @NotNull List<EventPair<?>> getEventData() { List<EventPair<?>> eventData = new ArrayList<>(); PsiElement target = handler.getPsiElement(); final ObjectEventData targetElementData = UsageViewStatisticsCollector.calculateElementData(target); if (targetElementData != null) { eventData.add(UsageViewStatisticsCollector.TARGET_ELEMENT_DATA.with(targetElementData)); } eventData.add(UsageViewStatisticsCollector.NUMBER_OF_TARGETS.with(primaryElements.length + secondaryElements.length)); return eventData; } @Override public @NotNull List<EventPair<?>> buildFinishEventData(@Nullable UsageInfo selectedUsage) { List<EventPair<?>> eventData = getEventData(); PsiElement target = handler.getPsiElement(); PsiElement selectedUsagesElement = selectedUsage != null ? selectedUsage.getElement() : null; if (selectedUsagesElement != null) { PsiFile containingFile = selectedUsagesElement.getContainingFile(); PsiManager manager = selectedUsagesElement.getManager(); eventData.add(UsageViewStatisticsCollector.IS_THE_SAME_FILE.with( manager != null && manager.areElementsEquivalent(target.getContainingFile(), containingFile))); ObjectEventData usageElementData = UsageViewStatisticsCollector.calculateElementData(selectedUsagesElement); if (usageElementData != null) { eventData.add(UsageViewStatisticsCollector.SELECTED_ELEMENT_DATA.with(usageElementData)); } eventData.add(UsageViewStatisticsCollector.IS_SELECTED_ELEMENT_AMONG_RECENT_FILES.with( ContainerUtil.exists(ContainerUtil.reverse(EditorHistoryManager.getInstance(target.getProject()).getFileList()), e -> e.equals(containingFile.getVirtualFile())))); } return eventData; } @Override public void beforeClose(String reason) { } }; }