Bookmark (@NotNull PsiElement element) { if (!(element instanceof PsiNameIdentifierOwner) || !element.isValid()) return null; if (element instanceof PsiCompiledElement) return null; VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element); PsiElement nameIdentifier = virtualFile == null ? null : ((PsiNameIdentifierOwner)element).getNameIdentifier(); TextRange nameRange = nameIdentifier == null ? null : nameIdentifier.getTextRange(); Document document = nameRange == null ? null : FileDocumentManager.getInstance().getDocument(virtualFile); Collection<Bookmark> bookmarks = document == null ? Collections.emptyList() : getFileBookmarks(virtualFile); for (Bookmark bookmark : bookmarks) { int line = bookmark.getLine(); if (line == -1) continue; if (nameRange.intersects(document.getLineStartOffset(line), document.getLineEndOffset(line))) { return bookmark; } } return null; }