Search in sources :

Example 6 with AnyXmlElementDescriptor

use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.

the class TagNameVariantCollector method getTagDescriptors.

public static List<XmlElementDescriptor> getTagDescriptors(final XmlTag element, final Collection<String> namespaces, @Nullable List<String> nsInfo) {
    XmlElementDescriptor elementDescriptor = null;
    String elementNamespace = element.getNamespacePrefix().isEmpty() ? null : element.getNamespace();
    final Map<String, XmlElementDescriptor> descriptorsMap = new HashMap<>();
    PsiElement context = element.getParent();
    PsiElement curElement = element.getParent();
    while (curElement instanceof XmlTag) {
        final XmlTag declarationTag = (XmlTag) curElement;
        final String namespace = declarationTag.getNamespace();
        if (!descriptorsMap.containsKey(namespace)) {
            final XmlElementDescriptor descriptor = declarationTag.getDescriptor();
            if (descriptor != null) {
                descriptorsMap.put(namespace, descriptor);
                if (elementDescriptor == null) {
                    elementDescriptor = descriptor;
                    if (elementNamespace == null) {
                        elementNamespace = namespace;
                    }
                }
            }
        }
        curElement = curElement.getContext();
    }
    final Set<XmlNSDescriptor> visited = new HashSet<>();
    final XmlExtension extension = XmlExtension.getExtension(element.getContainingFile());
    final ArrayList<XmlElementDescriptor> variants = new ArrayList<>();
    for (final String namespace : namespaces) {
        final int initialSize = variants.size();
        processVariantsInNamespace(namespace, element, variants, elementDescriptor, elementNamespace, descriptorsMap, visited, context instanceof XmlTag ? (XmlTag) context : element, extension);
        if (nsInfo != null) {
            for (int i = initialSize; i < variants.size(); i++) {
                XmlElementDescriptor descriptor = variants.get(i);
                nsInfo.add(descriptor instanceof XmlElementDescriptorImpl && !(descriptor instanceof RelaxedHtmlFromSchemaElementDescriptor) ? ((XmlElementDescriptorImpl) descriptor).getNamespaceByContext(element) : namespace);
            }
        }
    }
    final boolean hasPrefix = StringUtil.isNotEmpty(element.getNamespacePrefix());
    return ContainerUtil.filter(variants, descriptor -> {
        if (descriptor instanceof AnyXmlElementDescriptor) {
            return false;
        } else if (hasPrefix && descriptor instanceof XmlElementDescriptorImpl && !namespaces.contains(((XmlElementDescriptorImpl) descriptor).getNamespace())) {
            return false;
        }
        return true;
    });
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlExtension(com.intellij.xml.XmlExtension) RelaxedHtmlFromSchemaElementDescriptor(com.intellij.html.impl.RelaxedHtmlFromSchemaElementDescriptor) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlElementDescriptorImpl(com.intellij.xml.impl.schema.XmlElementDescriptorImpl) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 7 with AnyXmlElementDescriptor

use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-plugins by JetBrains.

the class AngularJSTagDescriptorsProvider method getDescriptor.

@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
    final Project project = xmlTag.getProject();
    if (!(xmlTag instanceof HtmlTag && AngularIndexUtil.hasAngularJS(project)))
        return null;
    final String tagName = xmlTag.getName();
    final String directiveName = DirectiveUtil.normalizeAttributeName(tagName);
    final XmlNSDescriptor nsDescriptor = xmlTag.getNSDescriptor(xmlTag.getNamespace(), false);
    final XmlElementDescriptor descriptor = nsDescriptor != null ? nsDescriptor.getElementDescriptor(xmlTag) : null;
    if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor)) {
        return null;
    }
    if ((NG_CONTAINER.equals(directiveName) || NG_CONTENT.equals(directiveName) || NG_TEMPLATE.equals(directiveName)) && AngularIndexUtil.hasAngularJS2(project)) {
        return new AngularJSTagDescriptor(directiveName, createDirective(xmlTag, directiveName));
    }
    JSImplicitElement directive = DirectiveUtil.getTagDirective(directiveName, project);
    if (DirectiveUtil.isAngular2Directive(directive) && !directive.getName().equals(tagName)) {
        // we've found directive via normalized name for Angular, it should not work
        directive = null;
    }
    if (directive == null && !tagName.equals(directiveName) && AngularIndexUtil.hasAngularJS2(project)) {
        directive = DirectiveUtil.getTagDirective(tagName, project);
        if (!DirectiveUtil.isAngular2Directive(directive))
            directive = null;
    }
    return directive != null ? new AngularJSTagDescriptor(directiveName, directive) : null;
}
Also used : Project(com.intellij.openapi.project.Project) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) HtmlTag(com.intellij.psi.html.HtmlTag) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with AnyXmlElementDescriptor

use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor 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 9 with AnyXmlElementDescriptor

use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.

the class RngNsDescriptor method getElementDescriptor.

@Override
@Nullable
public XmlElementDescriptor getElementDescriptor(@NotNull XmlTag tag) {
    if (myPattern == null) {
        return null;
    }
    XmlTag _tag = tag;
    final LinkedList<XmlTag> chain = new LinkedList<>();
    while (_tag != null) {
        chain.addFirst(_tag);
        _tag = _tag.getParentTag();
    }
    XmlElementDescriptor desc;
    do {
        desc = findRootDescriptor(chain.removeFirst());
    } while (desc == null && chain.size() > 0);
    if (desc != null) {
        for (XmlTag xmlTag : chain) {
            desc = desc.getElementDescriptor(xmlTag, xmlTag.getParentTag());
            if (desc == null) {
                break;
            }
        }
    }
    if (desc == null || desc instanceof AnyXmlElementDescriptor) {
        return findRootDescriptor(tag);
    }
    return desc;
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with AnyXmlElementDescriptor

use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.

the class RelaxedHtmlFromRngNSDescriptor method getElementDescriptor.

@Override
public XmlElementDescriptor getElementDescriptor(@NotNull XmlTag tag) {
    XmlElementDescriptor elementDescriptor = super.getElementDescriptor(tag);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Descriptor from rng for tag " + tag.getName() + " is " + (elementDescriptor != null ? elementDescriptor.getClass().getCanonicalName() : "NULL"));
    }
    String namespace;
    if (elementDescriptor == null && !((namespace = tag.getNamespace()).equals(XmlUtil.XHTML_URI))) {
        return new AnyXmlElementDescriptor(null, XmlUtil.HTML_URI.equals(namespace) ? this : tag.getNSDescriptor(tag.getNamespace(), true));
    }
    return elementDescriptor;
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor)

Aggregations

AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)19 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)15 XmlTag (com.intellij.psi.xml.XmlTag)8 HtmlTag (com.intellij.psi.html.HtmlTag)6 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)3 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)3 Nullable (org.jetbrains.annotations.Nullable)3 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)2 PsiElement (com.intellij.psi.PsiElement)2 XmlExtension (com.intellij.xml.XmlExtension)2 ArrayList (java.util.ArrayList)2 Validator (com.intellij.codeInsight.daemon.Validator)1 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)1 XmlHighlightingAwareElementDescriptor (com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightingAwareElementDescriptor)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 RelaxedHtmlFromSchemaElementDescriptor (com.intellij.html.impl.RelaxedHtmlFromSchemaElementDescriptor)1 JSImplicitElement (com.intellij.lang.javascript.psi.stubs.JSImplicitElement)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1