Search in sources :

Example 51 with XmlElementDescriptor

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

Example 52 with XmlElementDescriptor

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

the class HtmlDocumentationProvider method createNavigationElementHTML.

public PsiElement createNavigationElementHTML(PsiManager psiManager, String text, PsiElement context) {
    String key = text.toLowerCase(Locale.US);
    final HtmlTagDescriptor descriptor = HtmlDescriptorsTable.getTagDescriptor(key);
    if (descriptor != null && !isAttributeContext(context)) {
        try {
            final XmlTag tagFromText = XmlElementFactory.getInstance(psiManager.getProject()).createTagFromText("<" + key + " xmlns=\"" + XmlUtil.XHTML_URI + "\"/>");
            final XmlElementDescriptor tagDescriptor = tagFromText.getDescriptor();
            return tagDescriptor != null ? tagDescriptor.getDeclaration() : null;
        } catch (IncorrectOperationException ignore) {
        }
    } else {
        XmlTag tagContext = findTagContext(context);
        HtmlAttributeDescriptor myAttributeDescriptor = getDescriptor(key, tagContext);
        if (myAttributeDescriptor != null && tagContext != null) {
            XmlElementDescriptor tagDescriptor = tagContext.getDescriptor();
            XmlAttributeDescriptor attributeDescriptor = tagDescriptor != null ? tagDescriptor.getAttributeDescriptor(text, tagContext) : null;
            return (attributeDescriptor != null) ? attributeDescriptor.getDeclaration() : null;
        }
    }
    return null;
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) IncorrectOperationException(com.intellij.util.IncorrectOperationException) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 53 with XmlElementDescriptor

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

the class RngElementDescriptor method getElementsDescriptors.

@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    if (context == null) {
        return EMPTY_ARRAY;
    }
    // TODO: Not sure why this is needed. IDEA sometimes asks us for descriptors with a context that doesn't match our
    // element pattern. At least at namespace boundaries...
    final DElementPattern pattern;
    final XmlElementDescriptor descriptor = myNsDescriptor.getElementDescriptor(context);
    if (descriptor instanceof RngElementDescriptor) {
        final DElementPattern p = ((RngElementDescriptor) descriptor).myElementPattern;
        pattern = p != null ? p : myElementPattern;
    } else {
        pattern = myElementPattern;
    }
    final List<DElementPattern> patterns = ChildElementFinder.find(2, pattern);
    return myNsDescriptor.convertElementDescriptors(patterns);
}
Also used : XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 54 with XmlElementDescriptor

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

the class RngNsDescriptor method findRootDescriptorInner.

private XmlElementDescriptor findRootDescriptorInner(XmlTag tag) {
    final List<DElementPattern> allNamedPatterns = ContainerUtil.findAll(ChildElementFinder.find(-1, myPattern), NamedPatternFilter.INSTANCE);
    XmlElementDescriptor descriptor = findDescriptor(tag, allNamedPatterns);
    return descriptor != null ? descriptor : findDescriptor(tag, ChildElementFinder.find(myPattern));
}
Also used : XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) DElementPattern(org.kohsuke.rngom.digested.DElementPattern)

Example 55 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project android by JetBrains.

the class PropertyTestCase method getDescriptor.

@Nullable
protected XmlAttributeDescriptor getDescriptor(@NotNull NlComponent component, @NotNull String attributeName) {
    XmlElementDescriptor elementDescriptor = myDescriptorProvider.getDescriptor(component.getTag());
    assertThat(elementDescriptor).isNotNull();
    XmlAttributeDescriptor[] descriptors = elementDescriptor.getAttributesDescriptors(component.getTag());
    for (XmlAttributeDescriptor descriptor : descriptors) {
        if (descriptor.getName().equals(attributeName)) {
            return descriptor;
        }
    }
    return null;
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) NamespaceAwareXmlAttributeDescriptor(com.intellij.xml.NamespaceAwareXmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)159 XmlTag (com.intellij.psi.xml.XmlTag)88 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)60 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)54 PsiElement (com.intellij.psi.PsiElement)23 XmlFile (com.intellij.psi.xml.XmlFile)23 Nullable (org.jetbrains.annotations.Nullable)23 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)22 PsiFile (com.intellij.psi.PsiFile)11 ArrayList (java.util.ArrayList)11 XmlAttribute (com.intellij.psi.xml.XmlAttribute)10 NotNull (org.jetbrains.annotations.NotNull)10 ClassBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)7 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)7 Project (com.intellij.openapi.project.Project)7 HtmlTag (com.intellij.psi.html.HtmlTag)7 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)5 XmlDocument (com.intellij.psi.xml.XmlDocument)5 DElementPattern (org.kohsuke.rngom.digested.DElementPattern)5 InvalidPropertyException (com.intellij.flex.uiDesigner.InvalidPropertyException)4