Search in sources :

Example 1 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData 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 2 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.

the class HtmlDocumentationProvider method findDocumentationDescriptor.

private static EntityDescriptor findDocumentationDescriptor(PsiElement element, XmlTag context) {
    boolean isTag = true;
    PsiElement nameElement = null;
    String key = null;
    if (element instanceof XmlElementDecl) {
        nameElement = ((XmlElementDecl) element).getNameElement();
    } else if (element instanceof XmlAttributeDecl) {
        nameElement = ((XmlAttributeDecl) element).getNameElement();
        isTag = false;
    } else if (element instanceof XmlTag) {
        final XmlTag xmlTag = ((XmlTag) element);
        final PsiMetaData metaData = xmlTag.getMetaData();
        key = (metaData != null) ? metaData.getName() : null;
        isTag = xmlTag.getLocalName().equals(ELEMENT_ELEMENT_NAME);
    } else if (element.getParent() instanceof XmlAttributeValue) {
        isTag = false;
        key = ((XmlAttribute) element.getParent().getParent()).getName();
    } else if (element instanceof XmlAttributeValue) {
        isTag = false;
        final XmlAttribute xmlAttribute = (XmlAttribute) element.getParent();
        key = xmlAttribute.getName();
    } else if (element instanceof XmlAttribute) {
        final XmlAttribute xmlAttribute = (XmlAttribute) element;
        isTag = false;
        key = xmlAttribute.getName();
    } else if (element instanceof XmlElement) {
        nameElement = element;
        isTag = !(element.getParent() instanceof XmlAttribute);
    } else {
        nameElement = element;
        if (context != null) {
            String text = element.getText();
            isTag = text != null && text.startsWith(context.getName());
        }
    }
    if (nameElement != null) {
        key = nameElement.getText();
    }
    key = StringUtil.notNullize(key).toLowerCase(Locale.US);
    int dotIndex = key.indexOf('.');
    if (dotIndex > 0) {
        key = key.substring(0, dotIndex);
    }
    if (isTag) {
        return HtmlDescriptorsTable.getTagDescriptor(key);
    } else {
        return getDescriptor(key, context);
    }
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiElement(com.intellij.psi.PsiElement)

Example 3 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData 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 4 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData 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 5 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.

the class XmlNSDescriptorImpl method getAttributeImpl.

@Nullable
private XmlAttributeDescriptor getAttributeImpl(String localName, String namespace, @Nullable Set<XmlTag> visited) {
    if (myTag == null)
        return null;
    XmlNSDescriptor nsDescriptor = myTag.getNSDescriptor(namespace, true);
    if (nsDescriptor != this && nsDescriptor instanceof XmlNSDescriptorImpl) {
        return ((XmlNSDescriptorImpl) nsDescriptor).getAttributeImpl(localName, namespace, visited);
    }
    if (visited == null)
        visited = new HashSet<>(1);
    else if (visited.contains(myTag))
        return null;
    visited.add(myTag);
    XmlTag[] tags = myTag.getSubTags();
    for (XmlTag tag : tags) {
        if (equalsToSchemaName(tag, ATTRIBUTE_TAG_NAME)) {
            String name = tag.getAttributeValue("name");
            if (name != null) {
                if (checkElementNameEquivalence(localName, namespace, name, tag)) {
                    return createAttributeDescriptor(tag);
                }
            }
        } else if (equalsToSchemaName(tag, INCLUDE_TAG_NAME) || (equalsToSchemaName(tag, IMPORT_TAG_NAME) && namespace.equals(tag.getAttributeValue("namespace")))) {
            final String schemaLocation = tag.getAttributeValue("schemaLocation");
            if (schemaLocation != null) {
                final XmlFile xmlFile = XmlUtil.findNamespace(myTag.getContainingFile(), schemaLocation);
                if (xmlFile != null) {
                    final XmlDocument includedDocument = xmlFile.getDocument();
                    if (includedDocument != null) {
                        final PsiMetaData data = includedDocument.getMetaData();
                        if (data instanceof XmlNSDescriptorImpl) {
                            final XmlAttributeDescriptor attributeDescriptor = ((XmlNSDescriptorImpl) data).getAttributeImpl(localName, namespace, visited);
                            if (attributeDescriptor != null) {
                                final CachedValue<XmlAttributeDescriptor> value = CachedValuesManager.getManager(includedDocument.getProject()).createCachedValue(() -> {
                                    Object[] deps = attributeDescriptor.getDependences();
                                    if (deps.length == 0) {
                                        LOG.error(attributeDescriptor + " (" + attributeDescriptor.getClass() + ") returned no dependencies");
                                    }
                                    return new CachedValueProvider.Result<>(attributeDescriptor, deps);
                                }, false);
                                return value.getValue();
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : CachedValueProvider(com.intellij.psi.util.CachedValueProvider) XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) CachedValue(com.intellij.psi.util.CachedValue) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) PsiMetaData(com.intellij.psi.meta.PsiMetaData) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) THashSet(gnu.trove.THashSet) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiMetaData (com.intellij.psi.meta.PsiMetaData)24 PsiMetaOwner (com.intellij.psi.meta.PsiMetaOwner)10 XmlDocument (com.intellij.psi.xml.XmlDocument)5 NotNull (org.jetbrains.annotations.NotNull)5 PsiElement (com.intellij.psi.PsiElement)4 XmlFile (com.intellij.psi.xml.XmlFile)3 XmlTag (com.intellij.psi.xml.XmlTag)3 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)3 Nullable (org.jetbrains.annotations.Nullable)3 TailType (com.intellij.codeInsight.TailType)2 Template (com.intellij.codeInsight.template.Template)2 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 PsiNamedElement (com.intellij.psi.PsiNamedElement)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)2 XmlNSDescriptorImpl (com.intellij.xml.impl.schema.XmlNSDescriptorImpl)2 JavaMethodCallElement (com.intellij.codeInsight.completion.JavaMethodCallElement)1