Search in sources :

Example 1 with StubParentStrategy

use of com.intellij.util.xml.stubs.StubParentStrategy in project intellij-community by JetBrains.

the class DomInvocationHandler method getFixedChild.

@NotNull
final IndexedElementInvocationHandler getFixedChild(final Pair<FixedChildDescriptionImpl, Integer> info) {
    final FixedChildDescriptionImpl description = info.first;
    XmlName xmlName = description.getXmlName();
    final EvaluatedXmlName evaluatedXmlName = createEvaluatedXmlName(xmlName);
    if (myStub != null && description.isStubbed()) {
        List<DomStub> stubs = myStub.getChildrenByName(xmlName.getLocalName(), xmlName.getNamespaceKey());
        DomStub stub = stubs.isEmpty() ? null : stubs.get(0);
        DomParentStrategy strategy = stub == null ? new StubParentStrategy.Empty(myStub) : new StubParentStrategy(stub);
        return new IndexedElementInvocationHandler(evaluatedXmlName, description, 0, strategy, myManager, (ElementStub) stub);
    }
    final XmlTag tag = getXmlTag();
    final int index = info.second;
    if (tag != null) {
        if (!tag.isValid()) {
            throw new PsiInvalidElementAccessException(tag);
        }
        final XmlTag[] subTags = tag.getSubTags();
        for (int i = 0, subTagsLength = subTags.length; i < subTagsLength; i++) {
            XmlTag xmlTag = subTags[i];
            if (!xmlTag.isValid()) {
                throw new PsiInvalidElementAccessException(xmlTag, "invalid children of valid tag: " + tag.getText() + "; subtag=" + xmlTag + "; index=" + i);
            }
        }
        final List<XmlTag> tags = DomImplUtil.findSubTags(subTags, evaluatedXmlName, getFile());
        if (tags.size() > index) {
            final XmlTag child = tags.get(index);
            final IndexedElementInvocationHandler semElement = myManager.getSemService().getSemElement(DomManagerImpl.DOM_INDEXED_HANDLER_KEY, child);
            if (semElement == null) {
                final IndexedElementInvocationHandler take2 = myManager.getSemService().getSemElement(DomManagerImpl.DOM_INDEXED_HANDLER_KEY, child);
                throw new AssertionError("No DOM at XML. Parent=" + tag + "; child=" + child + "; index=" + index + "; second attempt=" + take2);
            }
            return semElement;
        }
    }
    return new IndexedElementInvocationHandler(evaluatedXmlName, description, index, new VirtualDomParentStrategy(this), myManager, null);
}
Also used : PsiInvalidElementAccessException(com.intellij.psi.PsiInvalidElementAccessException) DomStub(com.intellij.util.xml.stubs.DomStub) StubParentStrategy(com.intellij.util.xml.stubs.StubParentStrategy) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with StubParentStrategy

use of com.intellij.util.xml.stubs.StubParentStrategy in project intellij-community by JetBrains.

the class DomInvocationHandler method getAttributeChild.

@NotNull
final AttributeChildInvocationHandler getAttributeChild(final AttributeChildDescriptionImpl description) {
    final EvaluatedXmlName evaluatedXmlName = createEvaluatedXmlName(description.getXmlName());
    if (myStub != null && description.isStubbed()) {
        AttributeStub stub = myStub.getAttributeStub(description.getXmlName());
        StubParentStrategy strategy = StubParentStrategy.createAttributeStrategy(stub, myStub);
        return new AttributeChildInvocationHandler(evaluatedXmlName, description, myManager, strategy, stub);
    }
    final XmlTag tag = getXmlTag();
    if (tag != null) {
        // TODO: this seems ugly
        String ns = evaluatedXmlName.getNamespace(tag, getFile());
        final XmlAttribute attribute = tag.getAttribute(description.getXmlName().getLocalName(), ns.equals(tag.getNamespace()) ? null : ns);
        if (attribute != null) {
            PsiUtilCore.ensureValid(attribute);
            AttributeChildInvocationHandler semElement = myManager.getSemService().getSemElement(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute);
            if (semElement == null) {
                final AttributeChildInvocationHandler take2 = myManager.getSemService().getSemElement(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute);
                throw new AssertionError("No DOM at XML. Parent=" + tag + "; attribute=" + attribute + "; second attempt=" + take2);
            }
            return semElement;
        }
    }
    return new AttributeChildInvocationHandler(evaluatedXmlName, description, myManager, new VirtualDomParentStrategy(this), null);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) AttributeStub(com.intellij.util.xml.stubs.AttributeStub) StubParentStrategy(com.intellij.util.xml.stubs.StubParentStrategy) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlTag (com.intellij.psi.xml.XmlTag)2 StubParentStrategy (com.intellij.util.xml.stubs.StubParentStrategy)2 NotNull (org.jetbrains.annotations.NotNull)2 PsiInvalidElementAccessException (com.intellij.psi.PsiInvalidElementAccessException)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 AttributeStub (com.intellij.util.xml.stubs.AttributeStub)1 DomStub (com.intellij.util.xml.stubs.DomStub)1