final JspFile jspFile = JspPsiUtil.getJspFile(value);
assert jspFile != null;
Project project = jspFile.getProject();
TextRange range = value.getValueTextRange();
Document document = PsiDocumentManager.getInstance(project).getDocument(jspFile);
assert document != null;
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
int start = range.getStartOffset();
int lineStart = document.getLineStartOffset(document.getLineNumber(start));
String linePrefix = document.getCharsSequence().subSequence(lineStart, start).toString();
linePrefix = linePrefix.substring(0, linePrefix.length() - linePrefix.trim().length());
String indent = linePrefix;
while (indent.length() < start - lineStart) indent += " ";
Pair<String, String> tag_var = buildTag(prefix, url, indent, inline, myActionExtension);
String tag = tag_var.getFirst();
String var = tag_var.getSecond();
int end = range.getEndOffset();
int formattingStart;
int formattingEnd;
if (inline) {
document.replaceString(start, end, tag);
formattingStart = start;
formattingEnd = start + tag.length();
}
else {
document.replaceString(start, end, "${" + var + "}");
XmlTag containingTag = PsiTreeUtil.getParentOfType(value, XmlTag.class, false);
assert containingTag != null;
int startOffset = containingTag.getTextRange().getStartOffset();
document.insertString(startOffset, "\n");
document.insertString(startOffset, tag);
formattingStart = startOffset;
formattingEnd = startOffset + tag.length() + 2;
}