void (@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); if (!(element instanceof XmlToken)) { return; } final PsiElement parent = element.getParent(); if (!(parent instanceof XmlTag)) { return; } String text = parent.getText(); if (text.contains("\n")) { int cutoff = -1; for (int i = text.length() - 1; i > 0; i--) { final char c = text.charAt(i); if (c == ' ' || c == '\t') continue; if (c == '\n') cutoff = i; else break; } if (cutoff > 0) { text = text.substring(0, cutoff); } } final String replacementText = text + "</" + element.getText() + ">"; final XmlElementFactory factory = XmlElementFactory.getInstance(project); final XmlTag newTag = factory.createHTMLTagFromText(replacementText); final PsiElement child = parent.getLastChild().copy(); CodeStyleManager.getInstance(project).performActionWithFormatterDisabled((Runnable)() -> { final PsiElement replacement = parent.replace(newTag); if (child instanceof XmlText) { final PsiElement grandChild = child.getLastChild(); if (grandChild instanceof PsiWhiteSpace) { final XmlTag dummyTag = factory.createHTMLTagFromText("<dummy>" + grandChild.getText() + "</dummy>"); final XmlText whitespace = PsiTreeUtil.getChildOfType(dummyTag, XmlText.class); assert whitespace != null; replacement.getParent().addAfter(whitespace, replacement); } } }); }