GotoData (final Editor editor, final PsiFile file) { PsiElement selectedElement = getSelectedElement(editor, file); PsiElement sourceElement = TestFinderHelper.findSourceElement(selectedElement); if (sourceElement == null) return null; List<AdditionalAction> actions = new SmartList<>(); final List<PsiElement> candidates = Collections.synchronizedList(new ArrayList<>()); if (TestFinderHelper.isTest(selectedElement)) { if (!ProgressManager.getInstance().runProcessWithProgressSynchronously( () -> { Collection<PsiElement> classes = ReadAction.compute(() -> TestFinderHelper.findClassesForTest(selectedElement)); candidates.addAll(classes); }, TestFinderHelper.getSearchingForClassesForTestProgressTitle(selectedElement), true, file.getProject())) { return null; } } else { final Ref<Boolean> navigateToTestImmediatelyRef = new Ref<>(false); if (!ProgressManager.getInstance().runProcessWithProgressSynchronously( () -> { Collection<PsiElement> tests = ReadAction.compute(() -> TestFinderHelper.findTestsForClass(selectedElement)); candidates.addAll(tests); navigateToTestImmediatelyRef.set(candidates.size() == 1 && TestFinderHelper.navigateToTestImmediately(candidates.get(0))); }, TestFinderHelper.getSearchingForTestsForClassProgressTitle(selectedElement), true, file.getProject())) { return null; } if (!navigateToTestImmediatelyRef.get()) { for (TestCreator creator : LanguageTestCreators.INSTANCE.allForLanguage(file.getLanguage())) { if (!creator.isAvailable(file.getProject(), editor, file)) continue; actions.add(new AdditionalAction() { @NotNull @Override public String getText() { String text = creator instanceof ItemPresentation ? ((ItemPresentation)creator).getPresentableText() : null; return ObjectUtils.notNull(text, LangBundle.message("action.create.new.test.text")); } @Override public Icon getIcon() { Icon icon = creator instanceof ItemPresentation ? ((ItemPresentation)creator).getIcon(false) : null; return ObjectUtils.notNull(icon, AllIcons.Actions.IntentionBulb); } @Override public void execute() { creator.createTest(file.getProject(), editor, file); } }); } } } return new GotoData(sourceElement, PsiUtilCore.toPsiElementArray(candidates), actions); }