private void checkDuplicateAttribute(XmlTag tag, final XmlAttribute attribute) { if (skipValidation(tag)) { return; } final XmlAttribute[] attributes = tag.getAttributes(); final PsiFile containingFile = tag.getContainingFile(); final XmlExtension extension = containingFile instanceof XmlFile ? XmlExtension.getExtension(containingFile) : XmlExtension.DEFAULT_EXTENSION; for (XmlAttribute tagAttribute : attributes) { ProgressManager.checkCanceled(); if (attribute != tagAttribute && Comparing.strEqual(attribute.getName(), tagAttribute.getName())) { final String localName = attribute.getLocalName(); if (extension.canBeDuplicated(tagAttribute)) continue; // multiple import attributes are allowed in jsp directive HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo( getTagProblemInfoType(tag), XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild( SourceTreeToPsiMap.psiElementToTree(attribute)), XmlErrorMessages.message("duplicate.attribute", localName)); addToResults(highlightInfo); IntentionAction intentionAction = new RemoveAttributeIntentionFix(localName, attribute); QuickFixAction.registerQuickFixAction(highlightInfo, intentionAction); } } }
@NotNull public Map<String, String> getLocalNamespaceDeclarations() { Map<String, String> namespaces = new THashMap<String, String>(); for (final XmlAttribute attribute : getAttributes()) { if (!attribute.isNamespaceDeclaration() || attribute.getValue() == null) continue; // xmlns -> "", xmlns:a -> a final String localName = attribute.getLocalName(); namespaces.put(localName.equals(attribute.getName()) ? "" : localName, attribute.getValue()); } return namespaces; }
private static boolean canBeExtracted(@NotNull XmlAttribute attribute) { if (!(SdkConstants.NS_RESOURCES.equals(attribute.getNamespace()))) { return false; } final String name = attribute.getLocalName(); if (ArrayUtil.find(NON_EXTRACTABLE_ATTRIBUTES, name) >= 0) { return false; } if (name.startsWith(AndroidDomUtil.ATTR_STYLE)) { return false; } return true; }
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); }