ThrowableRunnable<RuntimeException> (final @NotNull XmlTag tag, final @NotNull PsiFile file, final @Nullable String newTagName, final @NotNull Collection<String> classes, final @NotNull Map<String, String> attributes) { return () -> { if (tag.isValid()) { if (!ReadonlyStatusHandler.getInstance(file.getProject()).ensureFilesWritable(Collections.singletonList(file.getVirtualFile())) .hasReadonlyFiles()) { tag.setAttribute(HtmlUtil.CLASS_ATTRIBUTE_NAME, StringUtil.join(classes, " ").trim()); for (Map.Entry<String, String> attribute : attributes.entrySet()) { final String attributeName = attribute.getKey(); if (StringUtil.startsWithChar(attributeName, '+')) { final XmlAttribute existingAttribute = tag.getAttribute(attributeName.substring(1)); if (existingAttribute != null) { existingAttribute.setValue(StringUtil.notNullize(existingAttribute.getValue() + attribute.getValue())); } else { tag.setAttribute(attributeName.substring(1), attribute.getValue()); } } else if (StringUtil.startsWithChar(attributeName, '-')) { final XmlAttribute existingAttribute = tag.getAttribute(attributeName.substring(1)); if (existingAttribute != null) { existingAttribute.delete(); } } else { tag.setAttribute(attributeName, attribute.getValue()); } } if (newTagName != null) { tag.setName(newTagName); } } } }; }