Search in sources :

Example 11 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)

Example 12 with AnyXmlElementDescriptor

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

the class TagNameVariantCollector method couldContainDescriptor.

static boolean couldContainDescriptor(final XmlTag parentTag, final XmlElementDescriptor parentDescriptor, final XmlElementDescriptor childDescriptor, String childNamespace, boolean strict) {
    if (XmlUtil.nsFromTemplateFramework(childNamespace))
        return true;
    if (parentTag == null)
        return true;
    if (parentDescriptor == null)
        return false;
    final XmlTag childTag = parentTag.createChildTag(childDescriptor.getName(), childNamespace, null, false);
    childTag.putUserData(XmlElement.INCLUDING_ELEMENT, parentTag);
    XmlElementDescriptor descriptor = parentDescriptor.getElementDescriptor(childTag, parentTag);
    return descriptor != null && (!strict || !(descriptor instanceof AnyXmlElementDescriptor));
}
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)

Example 13 with AnyXmlElementDescriptor

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

the class XmlTagImpl method computeElementDescriptor.

@Nullable
protected XmlElementDescriptor computeElementDescriptor() {
    for (XmlElementDescriptorProvider provider : Extensions.getExtensions(XmlElementDescriptorProvider.EP_NAME)) {
        XmlElementDescriptor elementDescriptor = provider.getDescriptor(this);
        if (elementDescriptor != null) {
            return elementDescriptor;
        }
    }
    final String namespace = getNamespace();
    if (XmlUtil.EMPTY_URI.equals(namespace)) {
        //nonqualified items
        final XmlTag parent = getParentTag();
        if (parent != null) {
            final XmlElementDescriptor descriptor = parent.getDescriptor();
            if (descriptor != null) {
                XmlElementDescriptor fromParent = descriptor.getElementDescriptor(this, parent);
                if (fromParent != null && !(fromParent instanceof AnyXmlElementDescriptor)) {
                    return fromParent;
                }
            }
        }
    }
    XmlElementDescriptor elementDescriptor = null;
    final XmlNSDescriptor nsDescriptor = getNSDescriptor(namespace, false);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Descriptor for namespace " + namespace + " is " + (nsDescriptor != null ? nsDescriptor.getClass().getCanonicalName() : "NULL"));
    }
    if (nsDescriptor != null) {
        if (!DumbService.getInstance(getProject()).isDumb() || DumbService.isDumbAware(nsDescriptor)) {
            elementDescriptor = nsDescriptor.getElementDescriptor(this);
        }
    }
    if (elementDescriptor == null) {
        return XmlUtil.findXmlDescriptorByType(this);
    }
    return elementDescriptor;
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with AnyXmlElementDescriptor

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

the class XmlEntityRefImpl method doResolveEntity.

private static CachedValueProvider.Result<XmlEntityDecl> doResolveEntity(final PsiElement targetElement, final String entityName, final PsiFile contextFile) {
    return RecursionManager.doPreventingRecursion(targetElement, true, new Computable<CachedValueProvider.Result<XmlEntityDecl>>() {

        @Override
        public CachedValueProvider.Result<XmlEntityDecl> compute() {
            final List<PsiElement> deps = new ArrayList<>();
            final XmlEntityDecl[] result = { null };
            PsiElementProcessor processor = new PsiElementProcessor() {

                @Override
                public boolean execute(@NotNull PsiElement element) {
                    if (element instanceof XmlDoctype) {
                        XmlDoctype xmlDoctype = (XmlDoctype) element;
                        final String dtdUri = getDtdForEntity(xmlDoctype);
                        if (dtdUri != null) {
                            XmlFile file = XmlUtil.getContainingFile(element);
                            if (file == null)
                                return true;
                            final XmlFile xmlFile = XmlUtil.findNamespace(file, dtdUri);
                            if (xmlFile != null) {
                                if (xmlFile != targetElement) {
                                    deps.add(xmlFile);
                                    if (!XmlUtil.processXmlElements(xmlFile, this, true))
                                        return false;
                                }
                            }
                        }
                        final XmlMarkupDecl markupDecl = xmlDoctype.getMarkupDecl();
                        if (markupDecl != null) {
                            if (!XmlUtil.processXmlElements(markupDecl, this, true))
                                return false;
                        }
                    } else if (element instanceof XmlEntityDecl) {
                        XmlEntityDecl entityDecl = (XmlEntityDecl) element;
                        final String declName = entityDecl.getName();
                        if (StringUtil.equals(declName, entityName)) {
                            result[0] = entityDecl;
                            return false;
                        }
                    }
                    return true;
                }
            };
            FileViewProvider provider = targetElement.getContainingFile().getViewProvider();
            deps.add(provider.getPsi(provider.getBaseLanguage()));
            boolean notfound = PsiTreeUtil.processElements(targetElement, processor);
            if (notfound) {
                if (contextFile != targetElement && contextFile != null && contextFile.isValid()) {
                    notfound = PsiTreeUtil.processElements(contextFile, processor);
                }
            }
            if (// no dtd ref at all
            notfound && targetElement instanceof XmlFile && deps.size() == 1 && ((XmlFile) targetElement).getFileType() != DTDFileType.INSTANCE) {
                XmlDocument document = ((XmlFile) targetElement).getDocument();
                final XmlTag rootTag = document != null ? document.getRootTag() : null;
                XmlFile descriptorFile = null;
                if (HtmlUtil.isHtml5Document(document)) {
                    descriptorFile = XmlUtil.findXmlFile((XmlFile) targetElement, Html5SchemaProvider.getCharsDtdLocation());
                } else if (rootTag != null && document.getUserData(DISABLE_ENTITY_EXPAND) == null) {
                    final XmlElementDescriptor descriptor = rootTag.getDescriptor();
                    if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor)) {
                        PsiElement element = descriptor.getDeclaration();
                        final PsiFile containingFile = element != null ? element.getContainingFile() : null;
                        descriptorFile = containingFile instanceof XmlFile ? (XmlFile) containingFile : null;
                    }
                }
                if (descriptorFile != null && !descriptorFile.getName().equals(((XmlFile) targetElement).getName() + ".dtd")) {
                    deps.add(descriptorFile);
                    XmlUtil.processXmlElements(descriptorFile, processor, true);
                }
            }
            return new CachedValueProvider.Result<>(result[0], ArrayUtil.toObjectArray(deps));
        }
    });
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) ArrayList(java.util.ArrayList) List(java.util.List) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor)

Example 15 with AnyXmlElementDescriptor

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

the class ExtendedTagInsertHandler method isNamespaceBound.

protected boolean isNamespaceBound(PsiElement psiElement) {
    PsiElement parent = psiElement.getParent();
    if (!(parent instanceof XmlTag))
        return false;
    final XmlTag tag = (XmlTag) parent;
    final XmlElementDescriptor tagDescriptor = tag.getDescriptor();
    final String tagNamespace = tag.getNamespace();
    assert myNamespace != null;
    return tagDescriptor != null && !(tagDescriptor instanceof AnyXmlElementDescriptor) && myNamespace.equals(tagNamespace);
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

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