void (@NotNull PsiElement element, @NotNull TextRange range) { PsiFile file = element.getContainingFile(); Document document = file.getViewProvider().getDocument(); if (document == null) { return; } final int startOffset = range.getStartOffset(); final int replaceStartOffset = element.getTextOffset() + startOffset; int startTag = range.getEndOffset(); @NonNls String text = element.getText(); if (!"<code>".equalsIgnoreCase(text.substring(startOffset, startTag))) { return; } @NonNls final StringBuilder newCommentText = new StringBuilder("{@code"); int endTag = StringUtil.indexOfIgnoreCase(text, "</code>", startTag); while (endTag < 0) { appendElementText(text, startTag, text.length(), newCommentText); element = element.getNextSibling(); if (element == null) return; startTag = 0; text = element.getText(); endTag = StringUtil.indexOfIgnoreCase(text, "</code>", 0); } appendElementText(text, startTag, endTag, newCommentText); newCommentText.append('}'); final int replaceEndOffset = element.getTextOffset() + endTag + 7; final String oldText = document.getText(new TextRange(replaceStartOffset, replaceEndOffset)); if (!StringUtil.startsWithIgnoreCase(oldText, "<code>") || !StringUtil.endsWithIgnoreCase(oldText, "</code>")) { // sanity check return; } document.replaceString(replaceStartOffset, replaceEndOffset, newCommentText); }