Search in sources :

Example 6 with XmlDocument

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

the class HtmlFileTreeElement method getChildrenBase.

@Override
@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
    if (isHtml5SectionsMode()) {
        // Html5SectionsNodeProvider will return its structure
        return Collections.emptyList();
    }
    final XmlFile xmlFile = getElement();
    final XmlDocument document = xmlFile == null ? null : xmlFile.getDocument();
    if (document == null) {
        return Collections.emptyList();
    }
    final List<XmlTag> rootTags = new SmartList<>();
    document.processElements(new FilterElementProcessor(XmlTagFilter.INSTANCE, rootTags), document);
    if (rootTags.isEmpty()) {
        return Collections.emptyList();
    } else if (rootTags.size() == 1) {
        final XmlTag rootTag = rootTags.get(0);
        if ("html".equalsIgnoreCase(rootTag.getLocalName())) {
            final XmlTag[] subTags = rootTag.getSubTags();
            if (subTags.length == 1 && ("head".equalsIgnoreCase(subTags[0].getLocalName()) || "body".equalsIgnoreCase(subTags[0].getLocalName()))) {
                return new HtmlTagTreeElement(subTags[0]).getChildrenBase();
            }
            return new HtmlTagTreeElement(rootTag).getChildrenBase();
        }
        return Collections.<StructureViewTreeElement>singletonList(new HtmlTagTreeElement(rootTag));
    } else {
        final Collection<StructureViewTreeElement> result = new ArrayList<>(rootTags.size());
        for (XmlTag tag : rootTags) {
            result.add(new HtmlTagTreeElement(tag));
        }
        return result;
    }
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) FilterElementProcessor(com.intellij.psi.scope.processor.FilterElementProcessor) Collection(java.util.Collection) XmlDocument(com.intellij.psi.xml.XmlDocument) SmartList(com.intellij.util.SmartList) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with XmlDocument

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

the class InclusionProvider method computeInclusion.

@Nullable
private static PsiElement[] computeInclusion(final XmlTag xincludeTag) {
    final XmlFile included = XmlIncludeHandler.resolveXIncludeFile(xincludeTag);
    final XmlDocument document = included != null ? included.getDocument() : null;
    final XmlTag rootTag = document != null ? document.getRootTag() : null;
    if (rootTag != null) {
        final String xpointer = xincludeTag.getAttributeValue("xpointer", XmlPsiUtil.XINCLUDE_URI);
        final XmlTag[] includeTag = extractXpointer(rootTag, xpointer);
        PsiElement[] result = new PsiElement[includeTag.length];
        for (int i = 0; i < includeTag.length; i++) {
            result[i] = new IncludedXmlTag(includeTag[i], xincludeTag.getParentTag());
        }
        return result;
    }
    return null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with XmlDocument

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

the class XmlNSDescriptorImpl method getElementDescriptor.

@Nullable
public XmlElementDescriptor getElementDescriptor(String localName, String namespace, Set<XmlNSDescriptorImpl> visited, boolean reference) {
    if (visited.contains(this))
        return null;
    final QNameKey pair = new QNameKey(namespace, localName);
    final CachedValue<XmlElementDescriptor> descriptor = myDescriptorsMap.get(pair);
    if (descriptor != null) {
        final XmlElementDescriptor value = descriptor.getValue();
        if (value == null || value.getDeclaration().isValid())
            return value;
    }
    final XmlTag rootTag = myTag;
    if (rootTag == null)
        return null;
    XmlTag[] tags = rootTag.getSubTags();
    visited.add(this);
    LOG.assertTrue(rootTag.isValid());
    for (final XmlTag tag : tags) {
        if (equalsToSchemaName(tag, ELEMENT_TAG_NAME)) {
            String name = tag.getAttributeValue("name");
            if (name != null) {
                if (checkElementNameEquivalence(localName, namespace, name, tag)) {
                    final CachedValue<XmlElementDescriptor> cachedValue = CachedValuesManager.getManager(tag.getProject()).createCachedValue(() -> {
                        final String name1 = tag.getAttributeValue("name");
                        if (name1 != null && !name1.equals(pair.second)) {
                            myDescriptorsMap.remove(pair);
                            return new CachedValueProvider.Result<>(null, PsiModificationTracker.MODIFICATION_COUNT);
                        }
                        final XmlElementDescriptor xmlElementDescriptor = createElementDescriptor(tag);
                        return new CachedValueProvider.Result<>(xmlElementDescriptor, xmlElementDescriptor.getDependences());
                    }, false);
                    myDescriptorsMap.put(pair, cachedValue);
                    return cachedValue.getValue();
                }
            }
        } else if (equalsToSchemaName(tag, INCLUDE_TAG_NAME) || (reference && equalsToSchemaName(tag, IMPORT_TAG_NAME) && (namespace.equals(tag.getAttributeValue("namespace")) || namespace.length() == 0 && tag.getAttributeValue("namespace") == null))) {
            final String schemaLocation = tag.getAttributeValue("schemaLocation");
            if (schemaLocation != null) {
                final XmlFile xmlFile = XmlUtil.findNamespace(rootTag.getContainingFile(), schemaLocation);
                if (xmlFile != null) {
                    final XmlDocument includedDocument = xmlFile.getDocument();
                    if (includedDocument != null) {
                        final PsiMetaData data = includedDocument.getMetaData();
                        if (data instanceof XmlNSDescriptorImpl) {
                            final XmlElementDescriptor elementDescriptor = ((XmlNSDescriptorImpl) data).getElementDescriptor(localName, namespace, visited, reference);
                            if (elementDescriptor != null) {
                                return elementDescriptor;
                            }
                        }
                    }
                }
            }
        } else if (equalsToSchemaName(tag, REDEFINE_TAG_NAME)) {
            final XmlNSDescriptorImpl nsDescriptor = getRedefinedElementDescriptor(tag);
            if (nsDescriptor != null) {
                final XmlElementDescriptor xmlElementDescriptor = nsDescriptor.getElementDescriptor(localName, namespace, visited, reference);
                if (xmlElementDescriptor instanceof XmlElementDescriptorImpl) {
                    return new RedefinedElementDescriptor((XmlElementDescriptorImpl) xmlElementDescriptor, this);
                }
            }
        }
    }
    return null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) PsiMetaData(com.intellij.psi.meta.PsiMetaData) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with XmlDocument

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

the class XmlNSDescriptorImpl method getRedefinedElementDescriptor.

public static XmlNSDescriptorImpl getRedefinedElementDescriptor(final XmlTag parentTag) {
    XmlFile file = getRedefinedElementDescriptorFile(parentTag);
    if (file != null) {
        final XmlDocument document = file.getDocument();
        final PsiMetaData metaData = document != null ? document.getMetaData() : null;
        if (metaData instanceof XmlNSDescriptorImpl)
            return (XmlNSDescriptorImpl) metaData;
    }
    return null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) PsiMetaData(com.intellij.psi.meta.PsiMetaData) XmlDocument(com.intellij.psi.xml.XmlDocument)

Example 10 with XmlDocument

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

the class XmlNSDescriptorImpl method findSpecialTag.

@Nullable
private static XmlTag findSpecialTag(@NonNls String name, @NonNls String specialName, XmlTag rootTag, XmlNSDescriptorImpl descriptor, HashSet<XmlTag> visited) {
    XmlNSDescriptorImpl nsDescriptor = getNSDescriptorToSearchIn(rootTag, name, descriptor);
    if (nsDescriptor != descriptor) {
        final XmlDocument document = nsDescriptor.getDescriptorFile() != null ? nsDescriptor.getDescriptorFile().getDocument() : null;
        if (document == null)
            return null;
        return findSpecialTag(XmlUtil.findLocalNameByQualifiedName(name), specialName, document.getRootTag(), nsDescriptor, visited);
    }
    if (visited == null)
        visited = new HashSet<>(1);
    else if (visited.contains(rootTag))
        return null;
    visited.add(rootTag);
    XmlTag[] tags = rootTag.getSubTags();
    return findSpecialTagIn(tags, specialName, name, rootTag, descriptor, visited);
}
Also used : XmlDocument(com.intellij.psi.xml.XmlDocument) THashSet(gnu.trove.THashSet) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

XmlDocument (com.intellij.psi.xml.XmlDocument)57 XmlTag (com.intellij.psi.xml.XmlTag)39 XmlFile (com.intellij.psi.xml.XmlFile)32 PsiElement (com.intellij.psi.PsiElement)13 Nullable (org.jetbrains.annotations.Nullable)11 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)9 PsiFile (com.intellij.psi.PsiFile)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 ArrayList (java.util.ArrayList)6 XmlAttribute (com.intellij.psi.xml.XmlAttribute)5 PsiMetaData (com.intellij.psi.meta.PsiMetaData)4 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 NotNull (org.jetbrains.annotations.NotNull)4 Project (com.intellij.openapi.project.Project)3 XmlText (com.intellij.psi.xml.XmlText)3 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)3 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 Editor (com.intellij.openapi.editor.Editor)2 PsiErrorElement (com.intellij.psi.PsiErrorElement)2 FilterElementProcessor (com.intellij.psi.scope.processor.FilterElementProcessor)2