private static void inlineSingleTag( XmlTag includeTag, XmlTag includeParentTag, XmlTag layoutRootTag) { final Map<String, String> attributesToAdd = new HashMap<String, String>(); for (XmlAttribute attribute : includeTag.getAttributes()) { final String namespace = attribute.getNamespace(); if (SdkConstants.NS_RESOURCES.equals(namespace)) { attributesToAdd.put(attribute.getLocalName(), attribute.getValue()); } } final XmlTag newTag = (XmlTag) includeTag.replace(layoutRootTag.copy()); final List<XmlAttribute> toDelete = new ArrayList<XmlAttribute>(); for (XmlAttribute attribute : newTag.getAttributes()) { if (attribute.isNamespaceDeclaration()) { final String localName = attribute.getLocalName(); final String prefix = localName.equals(attribute.getName()) ? "" : localName; final String namespace = attribute.getValue(); if (includeParentTag != null && namespace.equals(includeParentTag.getNamespaceByPrefix(prefix))) { toDelete.add(attribute); } } } for (XmlAttribute attribute : toDelete) { attribute.delete(); } for (Map.Entry<String, String> entry : attributesToAdd.entrySet()) { final String localName = entry.getKey(); final String value = entry.getValue(); newTag.setAttribute(localName, SdkConstants.NS_RESOURCES, value); } CodeStyleManager.getInstance(newTag.getManager()).reformat(newTag); }
private static void generateRaw(final @NotNull XmlTag newTag) { XmlElementDescriptor selected = newTag.getDescriptor(); if (selected == null) return; switch (selected.getContentType()) { case XmlElementDescriptor.CONTENT_TYPE_EMPTY: newTag.collapseIfEmpty(); ASTNode node = newTag.getNode(); assert node != null; ASTNode elementEnd = node.findChildByType(XmlTokenType.XML_EMPTY_ELEMENT_END); if (elementEnd == null) { LeafElement emptyTagEnd = Factory.createSingleLeafElement( XmlTokenType.XML_EMPTY_ELEMENT_END, "/>", 0, 2, null, newTag.getManager()); node.addChild(emptyTagEnd); } break; case XmlElementDescriptor.CONTENT_TYPE_MIXED: newTag.getValue().setText(""); } for (XmlAttributeDescriptor descriptor : selected.getAttributesDescriptors(newTag)) { if (descriptor.isRequired()) { newTag.setAttribute(descriptor.getName(), ""); } } List<XmlElementDescriptor> tags = getRequiredSubTags(selected); for (XmlElementDescriptor descriptor : tags) { if (descriptor == null) { XmlTag tag = XmlElementFactory.getInstance(newTag.getProject()) .createTagFromText("<", newTag.getLanguage()); newTag.addSubTag(tag, false); } else { XmlTag subTag = newTag.addSubTag(createTag(newTag, descriptor), false); generateRaw(subTag); } } }