From a9f784ef55bbb7740fd16f92929d8f9ae55f7e28 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 14 Dec 2012 18:06:48 +0400 Subject: [PATCH] IDEA-96597 Find Usages not working [nik]: fixing ParentStrategy for stubbed custom elements --- .../com/intellij/util/xml/stubs/DomStub.java | 4 +++ .../util/xml/stubs/StubParentStrategy.java | 32 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/xml/dom-impl/src/com/intellij/util/xml/stubs/DomStub.java b/xml/dom-impl/src/com/intellij/util/xml/stubs/DomStub.java index 3285ff4d2b12..9b94200b66c9 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/stubs/DomStub.java +++ b/xml/dom-impl/src/com/intellij/util/xml/stubs/DomStub.java @@ -132,4 +132,8 @@ public abstract class DomStub extends ObjectStubBase { public void setHandler(DomInvocationHandler handler) { myHandler = handler; } + + public boolean isCustom() { + return false; + } } diff --git a/xml/dom-impl/src/com/intellij/util/xml/stubs/StubParentStrategy.java b/xml/dom-impl/src/com/intellij/util/xml/stubs/StubParentStrategy.java index 1759fc31799b..392065ef2867 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/stubs/StubParentStrategy.java +++ b/xml/dom-impl/src/com/intellij/util/xml/stubs/StubParentStrategy.java @@ -19,6 +19,7 @@ import com.intellij.psi.xml.XmlElement; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.xml.impl.*; +import com.intellij.xml.util.XmlUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -64,12 +65,33 @@ public class StubParentStrategy implements DomParentStrategy { DomStub parentStub = myStub.getParentStub(); if (parentStub == null) return null; int index = parentStub.getChildIndex(myStub); - DomInvocationHandler handler = parentStub.getHandler(); - XmlTag tag = handler.getXmlTag(); - if (tag == null) return null; - XmlTag[] subTags = tag.findSubTags(myStub.getName()); + if (index < 0) { + return null; + } + XmlTag parentTag = parentStub.getHandler().getXmlTag(); + if (parentTag == null) return null; - return index < 0 || index >= subTags.length ? null : subTags[index]; + // for custom elements, namespace information is lost + // todo: propagate ns info through DomChildDescriptions + XmlTag[] tags = parentTag.getSubTags(); + int i = 0; + String nameToFind = myStub.isCustom() ? XmlUtil.findLocalNameByQualifiedName(myStub.getName()) : myStub.getName(); + assert nameToFind != null; + for (XmlTag xmlTag : tags) { + if (myStub.isCustom()) { + if (nameToFind.equals(xmlTag.getLocalName())) { + if (index == i++) { + return xmlTag; + } + } + } + else if (nameToFind.equals(xmlTag.getName())) { + if (index == i++) { + return xmlTag; + } + } + } + return null; } @NotNull