Search in sources :

Example 1 with ComplexTypeDescriptor

use of com.intellij.xml.impl.schema.ComplexTypeDescriptor in project intellij-community by JetBrains.

the class XmlUtil method getSchemaSimpleContent.

@Nullable
public static XmlTag getSchemaSimpleContent(@NotNull XmlTag tag) {
    XmlElementDescriptor descriptor = tag.getDescriptor();
    if (descriptor instanceof XmlElementDescriptorImpl) {
        final TypeDescriptor type = ((XmlElementDescriptorImpl) descriptor).getType(tag);
        if (type instanceof ComplexTypeDescriptor) {
            final XmlTag[] simpleContent = new XmlTag[1];
            processXmlElements(((ComplexTypeDescriptor) type).getDeclaration(), new PsiElementProcessor() {

                @Override
                public boolean execute(@NotNull final PsiElement element) {
                    if (element instanceof XmlTag) {
                        final XmlTag tag = (XmlTag) element;
                        @NonNls final String s = ((XmlTag) element).getLocalName();
                        if ((s.equals(XSD_SIMPLE_CONTENT_TAG) || s.equals("restriction") && "string".equals(findLocalNameByQualifiedName(tag.getAttributeValue("base")))) && tag.getNamespace().equals(XML_SCHEMA_URI)) {
                            simpleContent[0] = tag;
                            return false;
                        }
                    }
                    return true;
                }
            }, true);
            return simpleContent[0];
        }
    }
    return null;
}
Also used : ComplexTypeDescriptor(com.intellij.xml.impl.schema.ComplexTypeDescriptor) TypeDescriptor(com.intellij.xml.impl.schema.TypeDescriptor) ComplexTypeDescriptor(com.intellij.xml.impl.schema.ComplexTypeDescriptor) XmlElementDescriptorImpl(com.intellij.xml.impl.schema.XmlElementDescriptorImpl) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ComplexTypeDescriptor

use of com.intellij.xml.impl.schema.ComplexTypeDescriptor in project intellij-community by JetBrains.

the class TypeOrElementOrAttributeReference method resolveInner.

private PsiElement resolveInner() {
    final XmlTag tag = PsiTreeUtil.getContextOfType(myElement, XmlTag.class, false);
    if (tag == null)
        return PsiUtilCore.NULL_PSI_ELEMENT;
    String canonicalText = getCanonicalText();
    boolean[] redefined = new boolean[1];
    XmlNSDescriptorImpl nsDescriptor = getDescriptor(tag, canonicalText, redefined);
    if (myType != null && nsDescriptor != null && nsDescriptor.getTag() != null) {
        switch(myType) {
            case GroupReference:
                return nsDescriptor.findGroup(canonicalText);
            case AttributeGroupReference:
                return nsDescriptor.findAttributeGroup(canonicalText);
            case ElementReference:
                {
                    XmlElementDescriptor descriptor = nsDescriptor.getElementDescriptor(XmlUtil.findLocalNameByQualifiedName(canonicalText), getNamespace(tag, canonicalText), new HashSet<>(), true);
                    return descriptor != null ? descriptor.getDeclaration() : PsiUtilCore.NULL_PSI_ELEMENT;
                }
            case AttributeReference:
                {
                    //final String prefixByQualifiedName = XmlUtil.findPrefixByQualifiedName(canonicalText);
                    final String localNameByQualifiedName = XmlUtil.findLocalNameByQualifiedName(canonicalText);
                    XmlAttributeDescriptor descriptor = nsDescriptor.getAttribute(localNameByQualifiedName, getNamespace(tag, canonicalText), tag);
                    if (descriptor != null)
                        return descriptor.getDeclaration();
                    return PsiUtilCore.NULL_PSI_ELEMENT;
                }
            case TypeReference:
                {
                    TypeDescriptor typeDescriptor = redefined[0] ? nsDescriptor.findTypeDescriptor(XmlUtil.findLocalNameByQualifiedName(canonicalText), "") : nsDescriptor.getTypeDescriptor(canonicalText, tag);
                    if (typeDescriptor instanceof ComplexTypeDescriptor) {
                        return typeDescriptor.getDeclaration();
                    } else if (typeDescriptor != null) {
                        return myElement;
                    }
                }
        }
    }
    return PsiUtilCore.NULL_PSI_ELEMENT;
}
Also used : ComplexTypeDescriptor(com.intellij.xml.impl.schema.ComplexTypeDescriptor) TypeDescriptor(com.intellij.xml.impl.schema.TypeDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) ComplexTypeDescriptor(com.intellij.xml.impl.schema.ComplexTypeDescriptor) XmlNSDescriptorImpl(com.intellij.xml.impl.schema.XmlNSDescriptorImpl) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag) HashSet(java.util.HashSet)

Aggregations

ComplexTypeDescriptor (com.intellij.xml.impl.schema.ComplexTypeDescriptor)2 TypeDescriptor (com.intellij.xml.impl.schema.TypeDescriptor)2 PsiElementProcessor (com.intellij.psi.search.PsiElementProcessor)1 XmlTag (com.intellij.psi.xml.XmlTag)1 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)1 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)1 XmlElementDescriptorImpl (com.intellij.xml.impl.schema.XmlElementDescriptorImpl)1 XmlNSDescriptorImpl (com.intellij.xml.impl.schema.XmlNSDescriptorImpl)1 HashSet (java.util.HashSet)1 Nullable (org.jetbrains.annotations.Nullable)1