void (@NotNull AnActionEvent e) { Document document = PsiDocumentManager.getInstance(myPsiFile.getProject()).getDocument(myPsiFile); if (document == null) { return; } AtomicBoolean moreThanOne = new AtomicBoolean(false); boolean found = new PsiTargetNavigator<>(collector()) .presentationProvider(element -> { String text; @NonNls String containerText; int lineNumber = document.getLineNumber(element.getTextRange().getEndOffset()); if (element instanceof PsiMethod psiMethod) { text = psiMethod.getName(); containerText = getShortName(myMetaInfo.className) + ": " + (lineNumber + 1); } else { PsiExpression expression = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class); PsiElement textElement = expression != null ? expression : element; TextRange textRange = textElement.getTextRange() .intersection(new TextRange(document.getLineStartOffset(lineNumber), document.getLineEndOffset(lineNumber))); if (textRange == null) { textRange = element.getTextRange(); } text = document.getText(textRange).strip(); containerText = getShortName(myMetaInfo.className) + "." + myMetaInfo.methodName + "()" + ": " + (lineNumber + 1); } return TargetPresentation .builder(text) .containerText(containerText) .presentation(); }) .elementsConsumer((elements, navigator) -> { if (elements.isEmpty()) { return; } if (elements.size() > 1) { moreThanOne.set(true); } PsiElement next = elements.iterator().next(); String message; if (next instanceof PsiMethod) { message = JavaBundle.message("action.find.similar.stack.call.methods", getShortName(myMetaInfo.className), myMetaInfo.methodName); } else { message = JavaBundle.message("action.find.similar.stack.call.similar.calls", getShortName(myMetaInfo.className), myMetaInfo.methodName); } navigator.title(message); navigator.tabTitle(message); }) .navigate(myEditor, null, element -> { if (!moreThanOne.get() && element instanceof PsiMethod) { //there is no reason to jump if the caret is already inside int offset = myEditor.getCaretModel().getOffset(); PsiElement caretElement = myPsiFile.findElementAt(offset); if (caretElement != null && PsiTreeUtil.isAncestor(element, caretElement, false)) { showNotFound(JavaBundle.message("action.find.similar.stack.call.location.not.found", getShortName(myMetaInfo.className), myMetaInfo.methodName)); return true; } } return EditSourceUtil.navigateToPsiElement(element); }); if (!found) { showNotFound( JavaBundle.message("action.find.similar.stack.call.methods.not.found", getShortName(myMetaInfo.className), myMetaInfo.methodName)); } }