Search in sources :

Example 1 with AttributeStub

use of com.intellij.util.xml.stubs.AttributeStub 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)

Example 2 with AttributeStub

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

the class DomStubBuilderVisitor method visitXmlElement.

void visitXmlElement(XmlElement element, ElementStub parent, int index) {
    DomInvocationHandler handler = myManager.getDomHandler(element);
    if (handler == null || handler.getAnnotation(Stubbed.class) == null && !handler.getChildDescription().isStubbed())
        return;
    AbstractDomChildrenDescription description = handler.getChildDescription();
    String nsKey = description instanceof DomChildrenDescription ? ((DomChildrenDescription) description).getXmlName().getNamespaceKey() : "";
    if (element instanceof XmlTag) {
        XmlTag tag = (XmlTag) element;
        String elementClass = null;
        if (handler.getAnnotation(StubbedOccurrence.class) != null) {
            final Type type = description.getType();
            elementClass = ((Class) type).getName();
        }
        ElementStub stub = new ElementStub(parent, StringRef.fromString(tag.getName()), StringRef.fromNullableString(nsKey), index, description instanceof CustomDomChildrenDescription, elementClass == null ? null : StringRef.fromNullableString(elementClass), tag.getSubTags().length == 0 ? tag.getValue().getTrimmedText() : "");
        for (XmlAttribute attribute : tag.getAttributes()) {
            visitXmlElement(attribute, stub, 0);
        }
        Map<String, Integer> indices = new HashMap<>();
        for (final XmlTag subTag : tag.getSubTags()) {
            String name = subTag.getName();
            Integer i = indices.get(name);
            i = i == null ? 0 : i + 1;
            visitXmlElement(subTag, stub, i);
            indices.put(name, i);
        }
    } else if (element instanceof XmlAttribute) {
        new AttributeStub(parent, StringRef.fromString(((XmlAttribute) element).getLocalName()), StringRef.fromNullableString(nsKey), ((XmlAttribute) element).getValue());
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) Stubbed(com.intellij.util.xml.Stubbed) HashMap(java.util.HashMap) DomInvocationHandler(com.intellij.util.xml.impl.DomInvocationHandler) CustomDomChildrenDescription(com.intellij.util.xml.reflect.CustomDomChildrenDescription) DomChildrenDescription(com.intellij.util.xml.reflect.DomChildrenDescription) AbstractDomChildrenDescription(com.intellij.util.xml.reflect.AbstractDomChildrenDescription) CustomDomChildrenDescription(com.intellij.util.xml.reflect.CustomDomChildrenDescription) Type(java.lang.reflect.Type) AttributeStub(com.intellij.util.xml.stubs.AttributeStub) AbstractDomChildrenDescription(com.intellij.util.xml.reflect.AbstractDomChildrenDescription) ElementStub(com.intellij.util.xml.stubs.ElementStub) XmlTag(com.intellij.psi.xml.XmlTag) StubbedOccurrence(com.intellij.util.xml.StubbedOccurrence)

Aggregations

XmlAttribute (com.intellij.psi.xml.XmlAttribute)2 XmlTag (com.intellij.psi.xml.XmlTag)2 AttributeStub (com.intellij.util.xml.stubs.AttributeStub)2 Stubbed (com.intellij.util.xml.Stubbed)1 StubbedOccurrence (com.intellij.util.xml.StubbedOccurrence)1 DomInvocationHandler (com.intellij.util.xml.impl.DomInvocationHandler)1 AbstractDomChildrenDescription (com.intellij.util.xml.reflect.AbstractDomChildrenDescription)1 CustomDomChildrenDescription (com.intellij.util.xml.reflect.CustomDomChildrenDescription)1 DomChildrenDescription (com.intellij.util.xml.reflect.DomChildrenDescription)1 ElementStub (com.intellij.util.xml.stubs.ElementStub)1 StubParentStrategy (com.intellij.util.xml.stubs.StubParentStrategy)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 NotNull (org.jetbrains.annotations.NotNull)1