Search in sources :

Example 96 with XmlElementDescriptor

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

the class MavenPropertyPsiReference method processSchema.

@Nullable
private <T> T processSchema(String schema, SchemaProcessor<T> processor) {
    VirtualFile file = MavenSchemaProvider.getSchemaFile(schema);
    PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
    if (!(psiFile instanceof XmlFile))
        return null;
    XmlFile xmlFile = (XmlFile) psiFile;
    XmlDocument document = xmlFile.getDocument();
    XmlNSDescriptor desc = (XmlNSDescriptor) document.getMetaData();
    XmlElementDescriptor[] descriptors = desc.getRootElementsDescriptors(document);
    return doProcessSchema(descriptors, null, processor, new THashSet<>());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 97 with XmlElementDescriptor

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

the class BaseDomElementNode method doGetChildren.

protected final SimpleNode[] doGetChildren(final DomElement element) {
    if (!element.isValid())
        return NO_CHILDREN;
    List<SimpleNode> children = new ArrayList<>();
    final XmlTag tag = element.getXmlTag();
    if (tag != null && !(tag.getContainingFile() instanceof XmlFile))
        return NO_CHILDREN;
    final XmlElementDescriptor xmlElementDescriptor = tag == null ? null : tag.getDescriptor();
    final XmlElementDescriptor[] xmlDescriptors = xmlElementDescriptor == null ? null : xmlElementDescriptor.getElementsDescriptors(tag);
    for (DomFixedChildDescription description : element.getGenericInfo().getFixedChildrenDescriptions()) {
        String childName = description.getXmlElementName();
        if (xmlDescriptors != null) {
            if (findDescriptor(xmlDescriptors, childName) == -1)
                continue;
        }
        final List<? extends DomElement> values = description.getStableValues(element);
        if (shouldBeShown(description.getType())) {
            if (DomUtil.isGenericValueType(description.getType())) {
                for (DomElement value : values) {
                    children.add(new GenericValueNode((GenericDomValue) value, this));
                }
            } else {
                for (DomElement domElement : values) {
                    children.add(new BaseDomElementNode(domElement, myRootDomElement, this));
                }
            }
        }
    }
    for (DomCollectionChildDescription description : element.getGenericInfo().getCollectionChildrenDescriptions()) {
        if (shouldBeShown(description.getType())) {
            DomElementsGroupNode groupNode = new DomElementsGroupNode(element, description, this, myRootDomElement);
            if (isMarkedType(description.getType(), CONSOLIDATED_NODES_KEY)) {
                Collections.addAll(children, groupNode.getChildren());
            } else {
                children.add(groupNode);
            }
        }
    }
    AbstractDomElementNode[] childrenNodes = children.toArray(new AbstractDomElementNode[children.size()]);
    Comparator<AbstractDomElementNode> comparator = DomUtil.getFile(myDomElement).getUserData(COMPARATOR_KEY);
    if (comparator == null) {
        comparator = getDefaultComparator(element);
    }
    if (comparator != null) {
        Arrays.sort(childrenNodes, comparator);
    }
    return childrenNodes;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) SimpleNode(com.intellij.ui.treeStructure.SimpleNode) DomCollectionChildDescription(com.intellij.util.xml.reflect.DomCollectionChildDescription) DomFixedChildDescription(com.intellij.util.xml.reflect.DomFixedChildDescription) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 98 with XmlElementDescriptor

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

the class AbstractDomChildrenDescriptor method getElementsDescriptors.

@Override
public XmlElementDescriptor[] getElementsDescriptors(final XmlTag context) {
    final DomElement domElement = myManager.getDomElement(context);
    if (domElement == null)
        return EMPTY_ARRAY;
    List<XmlElementDescriptor> xmlElementDescriptors = new ArrayList<>();
    for (DomCollectionChildDescription childrenDescription : domElement.getGenericInfo().getCollectionChildrenDescriptions()) {
        xmlElementDescriptors.add(new DomElementXmlDescriptor(childrenDescription, myManager));
    }
    for (DomFixedChildDescription childrenDescription : domElement.getGenericInfo().getFixedChildrenDescriptions()) {
        xmlElementDescriptors.add(new DomElementXmlDescriptor(childrenDescription, myManager));
    }
    final List<? extends CustomDomChildrenDescription> customs = domElement.getGenericInfo().getCustomNameChildrenDescription();
    for (final CustomDomChildrenDescription custom : customs) {
        final CustomDomChildrenDescription.TagNameDescriptor tagNameDescriptor = custom.getTagNameDescriptor();
        if (tagNameDescriptor == null)
            continue;
        final XmlTag xmlTag = domElement.getXmlTag();
        for (final EvaluatedXmlName name : tagNameDescriptor.getCompletionVariants(domElement)) {
            AbstractDomChildrenDescriptor descriptor = new AbstractDomChildrenDescriptor(myManager) {

                @Override
                public String getDefaultName() {
                    final String ns = xmlTag != null ? name.getNamespace(xmlTag, (XmlFile) xmlTag.getContainingFile()) : null;
                    if (ns != null) {
                        final String prefix = xmlTag.getPrefixByNamespace(ns);
                        if (prefix != null) {
                            return prefix + ":" + name.getXmlName().getLocalName();
                        }
                    }
                    return name.getXmlName().getLocalName();
                }

                @Override
                @Nullable
                public PsiElement getDeclaration() {
                    final PomTarget target = tagNameDescriptor.findDeclaration(domElement, name);
                    return target == null ? null : PomService.convertToPsi(context.getProject(), target);
                }
            };
            xmlElementDescriptors.add(descriptor);
        }
        xmlElementDescriptors.add(new AnyXmlElementDescriptor(this, getNSDescriptor()));
    }
    return xmlElementDescriptors.toArray(new XmlElementDescriptor[xmlElementDescriptors.size()]);
}
Also used : EvaluatedXmlName(com.intellij.util.xml.EvaluatedXmlName) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) PomTarget(com.intellij.pom.PomTarget) DomElement(com.intellij.util.xml.DomElement) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 99 with XmlElementDescriptor

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

the class CompositeDescriptor method findElementDescriptor.

@Override
protected XmlElementDescriptor findElementDescriptor(XmlTag childTag) {
    final List<DElementPattern> patterns = new ArrayList<>();
    for (DElementPattern pattern : myPatterns) {
        patterns.addAll(ChildElementFinder.find(2, pattern));
    }
    // TODO: filter out impossible variants:
    /*
      while this needs both variants of <choice>-children
      <element><choice><caret>

      this does not, because <choice> inside <choice> is unambiguous:
      <element><choice><data type="string" /><choice><caret>
     */
    final XmlElementDescriptor d = myNsDescriptor.findDescriptor(childTag, patterns);
    if (d != null) {
        return d;
    }
    return NULL;
}
Also used : ArrayList(java.util.ArrayList) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) DElementPattern(org.kohsuke.rngom.digested.DElementPattern)

Example 100 with XmlElementDescriptor

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

the class CompositeDescriptor method getElementsDescriptors.

@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    final List<XmlElementDescriptor> descriptors = new ArrayList<>(Arrays.asList(super.getElementsDescriptors(context)));
    for (DElementPattern pattern : myPatterns) {
        final List<DElementPattern> list = ChildElementFinder.find(2, pattern);
        descriptors.addAll(Arrays.asList(myNsDescriptor.convertElementDescriptors(list)));
    }
    return descriptors.toArray(new XmlElementDescriptor[descriptors.size()]);
}
Also used : ArrayList(java.util.ArrayList) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) DElementPattern(org.kohsuke.rngom.digested.DElementPattern)

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