From 52992d3a476e35a5ed57e81509f2f2bffcfaf734 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Wed, 25 May 2011 16:28:52 +0400 Subject: [PATCH] IDEA-67270: XML: "Unused XML schema declaration" inspection reports false positive for a valid reference to XSD in a sub-directory --- .../XmlUnusedNamespaceInspection.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 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 c32f4289e7d5..27a4823dcef6 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 @@ -24,6 +24,7 @@ import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; +import com.intellij.psi.impl.source.resolve.reference.impl.providers.URLReference; import com.intellij.psi.impl.source.xml.SchemaPrefix; import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlAttributeValue; @@ -135,18 +136,23 @@ public class XmlUnusedNamespaceInspection extends XmlSuppressableInspectionTool XmlAttributeValue value = attribute.getValueElement(); if (value == null) return; PsiReference[] references = value.getReferences(); - for (int i = 0, referencesLength = references.length; i < referencesLength; i+=2) { + for (int i = 0, referencesLength = references.length; i < referencesLength; i++) { PsiReference reference = references[i]; - String ns = getNamespaceFromReference(reference); - if (ArrayUtil.indexOf(attribute.getParent().knownNamespaces(), ns) == -1) { - if (!XmlHighlightVisitor.hasBadResolve(reference, false)) - holder.registerProblemForReference(reference, ProblemHighlightType.LIKE_UNUSED_SYMBOL, NAMESPACE_LOCATION_IS_NEVER_USED, - new RemoveNamespaceLocationFix(ns)); - if (i + 1 < referencesLength) { - PsiReference nextRef = references[i + 1]; - if (!XmlHighlightVisitor.hasBadResolve(nextRef, false)) - holder.registerProblemForReference(nextRef, ProblemHighlightType.LIKE_UNUSED_SYMBOL, NAMESPACE_LOCATION_IS_NEVER_USED, - new RemoveNamespaceLocationFix(ns)); + if (reference instanceof URLReference) { + String ns = getNamespaceFromReference(reference); + if (ArrayUtil.indexOf(attribute.getParent().knownNamespaces(), ns) == -1) { + if (!XmlHighlightVisitor.hasBadResolve(reference, false)) { + holder.registerProblemForReference(reference, ProblemHighlightType.LIKE_UNUSED_SYMBOL, NAMESPACE_LOCATION_IS_NEVER_USED, + new RemoveNamespaceLocationFix(ns)); + } + for (int j = i + 1; j < referencesLength; j++) { + PsiReference nextRef = references[j]; + if (nextRef instanceof URLReference) break; + if (!XmlHighlightVisitor.hasBadResolve(nextRef, false)) { + holder.registerProblemForReference(nextRef, ProblemHighlightType.LIKE_UNUSED_SYMBOL, NAMESPACE_LOCATION_IS_NEVER_USED, + new RemoveNamespaceLocationFix(ns)); + } + } } } }