From 50c3584fe64eb2f37e5d2d5e4c387817b3fe5481 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Tue, 7 Feb 2012 16:24:10 +0400 Subject: [PATCH] IDEA-80841: "Organize import" deletes xsi:schemeLocation mark as unsed because xmlns redefine for element --- .../impl/analysis/XmlUnusedNamespaceInspection.java | 8 +++++--- .../src/com/intellij/xml/util/XmlRefCountHolder.java | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlUnusedNamespaceInspection.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlUnusedNamespaceInspection.java index c49be1b8653f..ca59bb366f21 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlUnusedNamespaceInspection.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlUnusedNamespaceInspection.java @@ -127,9 +127,11 @@ public class XmlUnusedNamespaceInspection extends XmlSuppressableInspectionTool private static void checkUnusedLocations(XmlAttribute attribute, ProblemsHolder holder) { if (XmlUtil.XML_SCHEMA_INSTANCE_URI.equals(attribute.getNamespace())) { + XmlRefCountHolder refCountHolder = XmlRefCountHolder.getRefCountHolder(attribute); + if (refCountHolder == null) return; + if (XmlUtil.NO_NAMESPACE_SCHEMA_LOCATION_ATT.equals(attribute.getLocalName())) { - XmlRefCountHolder refCountHolder = XmlRefCountHolder.getRefCountHolder(attribute); - if (refCountHolder == null || refCountHolder.isInUse("")) return; + if (refCountHolder.isInUse("")) return; holder.registerProblem(attribute, NAMESPACE_LOCATION_IS_NEVER_USED, ProblemHighlightType.LIKE_UNUSED_SYMBOL, new RemoveNamespaceLocationFix("")); } @@ -141,7 +143,7 @@ public class XmlUnusedNamespaceInspection extends XmlSuppressableInspectionTool PsiReference reference = references[i]; if (reference instanceof URLReference) { String ns = getNamespaceFromReference(reference); - if (ArrayUtil.indexOf(attribute.getParent().knownNamespaces(), ns) == -1) { + if (ArrayUtil.indexOf(attribute.getParent().knownNamespaces(), ns) == -1 && !refCountHolder.isUsedNamespace(ns)) { if (!XmlHighlightVisitor.hasBadResolve(reference, false)) { holder.registerProblemForReference(reference, ProblemHighlightType.LIKE_UNUSED_SYMBOL, NAMESPACE_LOCATION_IS_NEVER_USED, new RemoveNamespaceLocationFix(ns)); diff --git a/xml/impl/src/com/intellij/xml/util/XmlRefCountHolder.java b/xml/impl/src/com/intellij/xml/util/XmlRefCountHolder.java index abc213158bb1..0a43ad190e36 100644 --- a/xml/impl/src/com/intellij/xml/util/XmlRefCountHolder.java +++ b/xml/impl/src/com/intellij/xml/util/XmlRefCountHolder.java @@ -68,6 +68,7 @@ public class XmlRefCountHolder { private final Set myAdditionallyDeclaredIds = new HashSet(); private final Set myDoNotValidateParentsList = new HashSet(); private final Set myUsedPrefixes = new HashSet(); + private final Set myUsedNamespaces = new HashSet(); @Nullable public static XmlRefCountHolder getRefCountHolder(final XmlElement element) { @@ -140,6 +141,10 @@ public class XmlRefCountHolder { return myUsedPrefixes.contains(prefix); } + public boolean isUsedNamespace(String ns) { + return myUsedNamespaces.contains(ns); + } + private static class IdGatheringRecursiveVisitor extends XmlRecursiveElementVisitor { private final XmlRefCountHolder myHolder; @@ -192,6 +197,7 @@ public class XmlRefCountHolder { @Override public void visitXmlTag(XmlTag tag) { myHolder.addUsedPrefix(tag.getNamespacePrefix()); + myHolder.addUsedNamespace(tag.getNamespace()); String text = tag.getValue().getTrimmedText(); detectPrefix(text); super.visitXmlTag(tag); @@ -202,6 +208,7 @@ public class XmlRefCountHolder { if (!attribute.isNamespaceDeclaration()) { myHolder.addUsedPrefix(attribute.getNamespacePrefix()); } + myHolder.addUsedNamespace(attribute.getNamespace()); super.visitXmlAttribute(attribute); } @@ -269,4 +276,8 @@ public class XmlRefCountHolder { private void addUsedPrefix(String prefix) { myUsedPrefixes.add(prefix); } + + private void addUsedNamespace(String ns) { + myUsedNamespaces.add(ns); + } }