Search in sources :

Example 1 with RngXmlAttributeDescriptor

use of org.intellij.plugins.relaxNG.model.descriptors.RngXmlAttributeDescriptor in project intellij-community by JetBrains.

the class RngDocumentationProvider method generateDoc.

@Override
@Nullable
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
    final XmlElement c = PsiTreeUtil.getParentOfType(originalElement, XmlTag.class, XmlAttribute.class);
    if (c != null && c.getManager() == null) {
        LOG.warn("Invalid context element passed to generateDoc()", new Throwable("<stack trace>"));
        return null;
    }
    if (c instanceof XmlTag) {
        final XmlTag xmlElement = (XmlTag) c;
        final XmlElementDescriptor descriptor = xmlElement.getDescriptor();
        if (descriptor instanceof CompositeDescriptor) {
            final StringBuilder sb = new StringBuilder();
            final CompositeDescriptor d = (CompositeDescriptor) descriptor;
            final DElementPattern[] patterns = d.getElementPatterns();
            final THashSet<PsiElement> elements = ContainerUtil.newIdentityTroveSet();
            for (DElementPattern pattern : patterns) {
                final PsiElement psiElement = d.getDeclaration(pattern.getLocation());
                if (psiElement instanceof XmlTag && elements.add(psiElement)) {
                    if (sb.length() > 0) {
                        sb.append("<hr>");
                    }
                    sb.append(getDocumentationFromTag((XmlTag) psiElement, xmlElement.getLocalName(), "Element"));
                }
            }
            return makeDocumentation(sb);
        } else if (descriptor instanceof RngElementDescriptor) {
            final RngElementDescriptor d = (RngElementDescriptor) descriptor;
            final PsiElement declaration = d.getDeclaration();
            if (declaration instanceof XmlTag) {
                return makeDocumentation(getDocumentationFromTag((XmlTag) declaration, xmlElement.getLocalName(), "Element"));
            }
        }
    } else if (c instanceof XmlAttribute) {
        final XmlAttribute attribute = (XmlAttribute) c;
        final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
        if (descriptor instanceof RngXmlAttributeDescriptor) {
            final RngXmlAttributeDescriptor d = (RngXmlAttributeDescriptor) descriptor;
            final StringBuilder sb = new StringBuilder();
            final Collection<PsiElement> declaration = ContainerUtil.newIdentityTroveSet(d.getDeclarations());
            for (PsiElement psiElement : declaration) {
                if (psiElement instanceof XmlTag) {
                    if (sb.length() > 0) {
                        sb.append("<hr>");
                    }
                    sb.append(getDocumentationFromTag((XmlTag) psiElement, d.getName(), "Attribute"));
                }
            }
            return makeDocumentation(sb);
        }
    } else if (element instanceof XmlTag) {
        return makeDocumentation(getDocumentationFromTag((XmlTag) element, ((XmlTag) element).getLocalName(), "Element"));
    }
    return null;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) RngXmlAttributeDescriptor(org.intellij.plugins.relaxNG.model.descriptors.RngXmlAttributeDescriptor) RngElementDescriptor(org.intellij.plugins.relaxNG.model.descriptors.RngElementDescriptor) RngXmlAttributeDescriptor(org.intellij.plugins.relaxNG.model.descriptors.RngXmlAttributeDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElement(com.intellij.psi.xml.XmlElement) CompositeDescriptor(org.intellij.plugins.relaxNG.model.descriptors.CompositeDescriptor) Collection(java.util.Collection) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) DElementPattern(org.kohsuke.rngom.digested.DElementPattern) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlElement (com.intellij.psi.xml.XmlElement)1 XmlTag (com.intellij.psi.xml.XmlTag)1 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)1 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)1 Collection (java.util.Collection)1 CompositeDescriptor (org.intellij.plugins.relaxNG.model.descriptors.CompositeDescriptor)1 RngElementDescriptor (org.intellij.plugins.relaxNG.model.descriptors.RngElementDescriptor)1 RngXmlAttributeDescriptor (org.intellij.plugins.relaxNG.model.descriptors.RngXmlAttributeDescriptor)1 Nullable (org.jetbrains.annotations.Nullable)1 DElementPattern (org.kohsuke.rngom.digested.DElementPattern)1