Search in sources :

Example 6 with XmlNSDescriptor

use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.

the class XmlElementDescriptorImpl method getNsDescriptorFrom.

@Nullable
private static XmlNSDescriptor getNsDescriptorFrom(final PsiElement elementDecl) {
    final XmlFile file = XmlUtil.getContainingFile(elementDecl);
    if (file == null) {
        return null;
    }
    final XmlDocument document = file.getDocument();
    assert document != null;
    XmlNSDescriptor descriptor = (XmlNSDescriptor) document.getMetaData();
    return descriptor == null ? document.getDefaultNSDescriptor(XmlUtil.EMPTY_URI, false) : descriptor;
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with XmlNSDescriptor

use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.

the class XmlDocumentImpl method getDefaultNSDescriptor.

@Override
public XmlNSDescriptor getDefaultNSDescriptor(final String namespace, final boolean strict) {
    long curExtResourcesModCount = ExternalResourceManagerEx.getInstanceEx().getModificationCount(getProject());
    if (myExtResourcesModCount != curExtResourcesModCount) {
        myDefaultDescriptorsCacheNotStrict.clear();
        myDefaultDescriptorsCacheStrict.clear();
        myExtResourcesModCount = curExtResourcesModCount;
    }
    final ConcurrentMap<String, CachedValue<XmlNSDescriptor>> defaultDescriptorsCache;
    if (strict) {
        defaultDescriptorsCache = myDefaultDescriptorsCacheStrict;
    } else {
        defaultDescriptorsCache = myDefaultDescriptorsCacheNotStrict;
    }
    CachedValue<XmlNSDescriptor> cachedValue = defaultDescriptorsCache.get(namespace);
    if (cachedValue == null) {
        defaultDescriptorsCache.put(namespace, cachedValue = new PsiCachedValueImpl<>(getManager(), () -> {
            final XmlNSDescriptor defaultNSDescriptorInner = getDefaultNSDescriptorInner(namespace, strict);
            if (isGeneratedFromDtd(defaultNSDescriptorInner)) {
                return new CachedValueProvider.Result<>(defaultNSDescriptorInner, this, ExternalResourceManager.getInstance());
            }
            return new CachedValueProvider.Result<>(defaultNSDescriptorInner, defaultNSDescriptorInner != null ? defaultNSDescriptorInner.getDependences() : ExternalResourceManager.getInstance());
        }));
    }
    return cachedValue.getValue();
}
Also used : PsiCachedValueImpl(com.intellij.psi.impl.PsiCachedValueImpl) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) CachedValue(com.intellij.psi.util.CachedValue)

Example 8 with XmlNSDescriptor

use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.

the class XmlCompletionContributor method addEntityRefCompletions.

private static void addEntityRefCompletions(PsiElement context, CompletionResultSet resultSet) {
    XmlFile containingFile = null;
    XmlFile descriptorFile = null;
    final XmlTag tag = PsiTreeUtil.getParentOfType(context, XmlTag.class);
    if (tag != null) {
        containingFile = (XmlFile) tag.getContainingFile();
        descriptorFile = findDescriptorFile(tag, containingFile);
    }
    if (HtmlUtil.isHtml5Context(tag)) {
        descriptorFile = XmlUtil.findXmlFile(containingFile, Html5SchemaProvider.getCharsDtdLocation());
    } else if (tag == null) {
        final XmlDocument document = PsiTreeUtil.getParentOfType(context, XmlDocument.class);
        if (document != null) {
            containingFile = (XmlFile) document.getContainingFile();
            final FileType ft = containingFile.getFileType();
            if (HtmlUtil.isHtml5Document(document)) {
                descriptorFile = XmlUtil.findXmlFile(containingFile, Html5SchemaProvider.getCharsDtdLocation());
            } else if (ft != StdFileTypes.XML) {
                final String namespace = ft == StdFileTypes.XHTML || ft == StdFileTypes.JSPX ? XmlUtil.XHTML_URI : XmlUtil.HTML_URI;
                final XmlNSDescriptor nsDescriptor = document.getDefaultNSDescriptor(namespace, true);
                if (nsDescriptor != null) {
                    descriptorFile = nsDescriptor.getDescriptorFile();
                }
            }
        }
    }
    if (descriptorFile != null && containingFile != null) {
        final boolean acceptSystemEntities = containingFile.getFileType() == StdFileTypes.XML;
        final PsiElementProcessor processor = new PsiElementProcessor() {

            @Override
            public boolean execute(@NotNull final PsiElement element) {
                if (element instanceof XmlEntityDecl) {
                    final XmlEntityDecl xmlEntityDecl = (XmlEntityDecl) element;
                    if (xmlEntityDecl.isInternalReference() || acceptSystemEntities) {
                        final LookupElementBuilder _item = buildEntityLookupItem(xmlEntityDecl);
                        if (_item != null) {
                            resultSet.addElement(_item);
                            resultSet.stopHere();
                        }
                    }
                }
                return true;
            }
        };
        XmlUtil.processXmlElements(descriptorFile, processor, true);
        if (descriptorFile != containingFile && acceptSystemEntities) {
            final XmlProlog element = containingFile.getDocument().getProlog();
            if (element != null)
                XmlUtil.processXmlElements(element, processor, true);
        }
    }
}
Also used : NotNull(org.jetbrains.annotations.NotNull) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) FileType(com.intellij.openapi.fileTypes.FileType) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PsiElement(com.intellij.psi.PsiElement)

Example 9 with XmlNSDescriptor

use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.

the class DtdResolveUtil method getNsDescriptor.

@Nullable
static XmlNSDescriptor getNsDescriptor(XmlElement element) {
    final XmlElement parentThatProvidesMetaData = PsiTreeUtil.getParentOfType(CompletionUtilCoreImpl.getOriginalElement(element), XmlDocument.class, XmlMarkupDecl.class);
    if (parentThatProvidesMetaData instanceof XmlDocument) {
        final XmlDocument document = (XmlDocument) parentThatProvidesMetaData;
        XmlNSDescriptor rootTagNSDescriptor = document.getRootTagNSDescriptor();
        if (rootTagNSDescriptor == null)
            rootTagNSDescriptor = (XmlNSDescriptor) document.getMetaData();
        return rootTagNSDescriptor;
    } else if (parentThatProvidesMetaData instanceof XmlMarkupDecl) {
        final XmlMarkupDecl markupDecl = (XmlMarkupDecl) parentThatProvidesMetaData;
        final PsiMetaData psiMetaData = markupDecl.getMetaData();
        if (psiMetaData instanceof XmlNSDescriptor) {
            return (XmlNSDescriptor) psiMetaData;
        }
    }
    return null;
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) PsiMetaData(com.intellij.psi.meta.PsiMetaData) XmlElement(com.intellij.psi.xml.XmlElement) XmlMarkupDecl(com.intellij.psi.xml.XmlMarkupDecl) XmlDocument(com.intellij.psi.xml.XmlDocument) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with XmlNSDescriptor

use of com.intellij.xml.XmlNSDescriptor 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)

Aggregations

XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)87 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)60 XmlTag (com.intellij.psi.xml.XmlTag)52 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)32 XmlFile (com.intellij.psi.xml.XmlFile)21 Nullable (org.jetbrains.annotations.Nullable)11 XmlDocument (com.intellij.psi.xml.XmlDocument)10 PsiElement (com.intellij.psi.PsiElement)5 XmlAttribute (com.intellij.psi.xml.XmlAttribute)5 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)5 XmlNSDescriptorImpl (com.intellij.xml.impl.schema.XmlNSDescriptorImpl)5 CachedValue (com.intellij.psi.util.CachedValue)3 NotNull (org.jetbrains.annotations.NotNull)3 FlexMxmlNSDescriptor (com.intellij.javascript.flex.mxml.schema.FlexMxmlNSDescriptor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 HtmlTag (com.intellij.psi.html.HtmlTag)2 PsiMetaData (com.intellij.psi.meta.PsiMetaData)2 PsiElementProcessor (com.intellij.psi.search.PsiElementProcessor)2 XmlElementDescriptorImpl (com.intellij.xml.impl.schema.XmlElementDescriptorImpl)2