void (@NotNull final Project project, @NotNull final PsiElement tag) { final ASTNode child = XmlChildRole.START_TAG_END_FINDER.findChild(tag.getNode()); if (child == null) return; final int offset = child.getTextRange().getStartOffset(); final Document document = tag.getContainingFile().getViewProvider().getDocument(); assert document != null; document.replaceString(offset, tag.getTextRange().getEndOffset(), "/>"); SmartPsiElementPointer<PsiElement> pointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(tag); PsiDocumentManager.getInstance(project).commitDocument(document); PsiElement restored = pointer.getElement(); if (restored != null) { CodeStyleManager.getInstance(project).reformat(restored); } }