diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/StorageData.java b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/StorageData.java index 7a59717665f7..6f928f020348 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/StorageData.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/StorageData.java @@ -144,16 +144,24 @@ public class StorageData { void setState(@NotNull final String componentName, final Element element) { element.setName(COMPONENT); - //componentName should be first! - final List attributes = new ArrayList(element.getAttributes()); - for (Attribute attribute : attributes) { - element.removeAttribute(attribute); + // componentName should be first + List elementAttributes = element.getAttributes(); + if (elementAttributes.isEmpty()) { + element.setAttribute(NAME, componentName); } - - element.setAttribute(NAME, componentName); - - for (Attribute attribute : attributes) { - element.setAttribute(attribute.getName(), attribute.getValue()); + else { + Attribute nameAttribute = element.getAttribute(NAME); + if (nameAttribute == null) { + nameAttribute = new Attribute(NAME, componentName); + elementAttributes.add(0, nameAttribute); + } + else { + nameAttribute.setValue(componentName); + if (elementAttributes.get(0) != nameAttribute) { + elementAttributes.remove(nameAttribute); + elementAttributes.add(0, nameAttribute); + } + } } myComponentStates.put(componentName, element);