Search in sources :

Example 1 with XmlNSDescriptorImpl

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

the class MavenDomElementDescriptorHolder method getDescriptor.

@Nullable
public XmlElementDescriptor getDescriptor(@NotNull XmlTag tag) {
    FileKind kind = getFileKind(tag.getContainingFile());
    if (kind == null)
        return null;
    XmlNSDescriptorImpl desc;
    synchronized (this) {
        desc = tryGetOrCreateDescriptor(kind);
        if (desc == null)
            return null;
    }
    LOG.assertTrue(tag.isValid());
    LOG.assertTrue(desc.isValid());
    return desc.getElementDescriptor(tag.getName(), desc.getDefaultNamespace());
}
Also used : XmlNSDescriptorImpl(com.intellij.xml.impl.schema.XmlNSDescriptorImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with XmlNSDescriptorImpl

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

the class CreateXmlElementIntentionAction method isAvailable.

@Override
public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) {
    if (!myIsAvailableEvaluated) {
        final XmlTag tag = PsiTreeUtil.getParentOfType(myRef.getElement(), XmlTag.class);
        if (tag != null) {
            final XmlNSDescriptorImpl descriptor = myRef.getDescriptor(tag, myRef.getCanonicalText(), new boolean[1]);
            if (descriptor != null && descriptor.getDescriptorFile() != null && descriptor.getDescriptorFile().isWritable()) {
                myTargetFile = descriptor.getDescriptorFile();
            }
        }
        myIsAvailableEvaluated = true;
    }
    return myTargetFile != null;
}
Also used : XmlNSDescriptorImpl(com.intellij.xml.impl.schema.XmlNSDescriptorImpl) XmlTag(com.intellij.psi.xml.XmlTag)

Example 3 with XmlNSDescriptorImpl

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

the class Xsd2InstanceUtils method addVariantsFromRootTag.

public static List<String> addVariantsFromRootTag(XmlTag rootTag) {
    PsiMetaData metaData = rootTag.getMetaData();
    if (metaData instanceof XmlNSDescriptorImpl) {
        XmlNSDescriptorImpl nsDescriptor = (XmlNSDescriptorImpl) metaData;
        List<String> elementDescriptors = new ArrayList<>();
        XmlElementDescriptor[] rootElementsDescriptors = nsDescriptor.getRootElementsDescriptors(PsiTreeUtil.getParentOfType(rootTag, XmlDocument.class));
        for (XmlElementDescriptor e : rootElementsDescriptors) {
            elementDescriptors.add(e.getName());
        }
        return elementDescriptors;
    }
    return Collections.emptyList();
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlNSDescriptorImpl(com.intellij.xml.impl.schema.XmlNSDescriptorImpl) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 4 with XmlNSDescriptorImpl

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

the class TypeOrElementOrAttributeReference method getVariants.

public static Object[] getVariants(XmlTag tag, ReferenceType type, String prefix) {
    String[] tagNames = null;
    switch(type) {
        case GroupReference:
            tagNames = new String[] { SchemaReferencesProvider.GROUP_TAG_NAME };
            break;
        case AttributeGroupReference:
            tagNames = new String[] { SchemaReferencesProvider.ATTRIBUTE_GROUP_TAG_NAME };
            break;
        case AttributeReference:
            tagNames = new String[] { SchemaReferencesProvider.ATTRIBUTE_TAG_NAME };
            break;
        case ElementReference:
            tagNames = new String[] { SchemaReferencesProvider.ELEMENT_TAG_NAME };
            break;
        case TypeReference:
            tagNames = new String[] { SchemaReferencesProvider.SIMPLE_TYPE_TAG_NAME, SchemaReferencesProvider.COMPLEX_TYPE_TAG_NAME };
            break;
    }
    final XmlDocument document = ((XmlFile) tag.getContainingFile()).getDocument();
    if (document == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final XmlTag rootTag = document.getRootTag();
    String ourNamespace = rootTag != null ? rootTag.getAttributeValue(TARGET_NAMESPACE) : "";
    if (ourNamespace == null)
        ourNamespace = "";
    CompletionProcessor processor = new CompletionProcessor(tag, prefix);
    for (String namespace : tag.knownNamespaces()) {
        if (ourNamespace.equals(namespace))
            continue;
        final XmlNSDescriptor nsDescriptor = tag.getNSDescriptor(namespace, true);
        if (nsDescriptor instanceof XmlNSDescriptorImpl) {
            processNamespace(namespace, processor, (XmlNSDescriptorImpl) nsDescriptor, tagNames);
        }
    }
    XmlNSDescriptor nsDescriptor = (XmlNSDescriptor) document.getMetaData();
    if (nsDescriptor instanceof XmlNSDescriptorImpl) {
        processNamespace(ourNamespace, processor, (XmlNSDescriptorImpl) nsDescriptor, tagNames);
    }
    return ArrayUtil.toStringArray(processor.myElements);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlNSDescriptorImpl(com.intellij.xml.impl.schema.XmlNSDescriptorImpl) XmlTag(com.intellij.psi.xml.XmlTag)

Example 5 with XmlNSDescriptorImpl

use of com.intellij.xml.impl.schema.XmlNSDescriptorImpl 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

XmlNSDescriptorImpl (com.intellij.xml.impl.schema.XmlNSDescriptorImpl)12 XmlTag (com.intellij.psi.xml.XmlTag)5 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)5 XmlFile (com.intellij.psi.xml.XmlFile)4 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)4 PsiFile (com.intellij.psi.PsiFile)3 XmlDocument (com.intellij.psi.xml.XmlDocument)3 Nullable (org.jetbrains.annotations.Nullable)3 PsiMetaData (com.intellij.psi.meta.PsiMetaData)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 ExternalResourceManager (com.intellij.javaee.ExternalResourceManager)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 ComplexTypeDescriptor (com.intellij.xml.impl.schema.ComplexTypeDescriptor)1 TypeDescriptor (com.intellij.xml.impl.schema.TypeDescriptor)1 THashSet (gnu.trove.THashSet)1 MalformedURLException (java.net.MalformedURLException)1