void (Project project, final Document document, TextRange selection) { final CharSequence sequence = document.getCharsSequence(); final StringBuilder sb = new StringBuilder(); Pattern pattern = Pattern.compile("<(/?(?:error|warning|EOLError|EOLWarning|info|weak_warning))((?:\\s|=|\\w+|\"(?:[^\"]|\\\\\")*?\")*?)>(.*?)"); Matcher matcher = pattern.matcher(sequence); if (matcher.find(selection.getStartOffset())) { boolean compactMode = false; int pos = 0; do { if (matcher.start(0) >= selection.getEndOffset()) break; String tag = matcher.group(1); if (!tag.startsWith("/")) { boolean hasDescription = matcher.start(2) < matcher.end(2); if (hasDescription) { if (!compactMode) { sb.setLength(pos = 0); // restart in compact mode from the first description compactMode = true; } sb.append(sequence, pos, matcher.start(2)); pos = matcher.end(2); } else if (!compactMode) { sb.append(sequence, pos, matcher.start()); pos = matcher.end(); } } else if (!compactMode) { sb.append(sequence, pos, matcher.start()); pos = matcher.end(); } } while (matcher.find(matcher.end())); sb.append(sequence, pos, sequence.length()); } else { final int[] offset = {0}; final ArrayList<HighlightInfo> infos = new ArrayList<>(); DaemonCodeAnalyzerEx.processHighlights( document, project, HighlightSeverity.WARNING, 0, sequence.length(), info -> { if (info.getSeverity() != HighlightSeverity.WARNING && info.getSeverity() != HighlightSeverity.ERROR) return true; if (info.getStartOffset() >= selection.getEndOffset()) return false; if (info.getEndOffset() > selection.getStartOffset()) { offset[0] = appendInfo(info, sb, sequence, offset[0], infos); } return true; }); offset[0] = appendInfo(null, sb, sequence, offset[0], infos); sb.append(sequence.subSequence(offset[0], sequence.length())); } document.setText(sb); }