Collection<Tag> (@NotNull PsiElement element) { Bookmark bookmark = BookmarkManager.getInstance(myProject).findElementBookmark(element); if (bookmark == null) return Collections.emptySet(); String desc = bookmark.getDescription(); if (desc.indexOf('#') == -1 || desc.indexOf(' ') == -1) { String text = StringUtil.isNotEmpty(desc) && desc.indexOf(' ') == -1 ? (desc.indexOf('#') == -1 ? "#" + desc : desc) : ""; return Collections.singleton(new Tag(text, JBColor.RED, bookmark.getIcon())); } Matcher matcher = Pattern.compile("#\\w[\\w_\\-#]*").matcher(desc); TreeSet<Tag> result = new TreeSet<>(Comparator.comparing(o -> o.text)); int offset=0; while (matcher.find(offset)) { String text = desc.substring(matcher.start(), matcher.end()); result.add(new Tag(text, JBColor.RED, bookmark.getIcon())); offset = matcher.end(); } return result; }