Search in sources :

Example 1 with Validator

use of com.intellij.codeInsight.daemon.Validator in project intellij-community by JetBrains.

the class XmlHighlightVisitor method checkTagByDescriptor.

private void checkTagByDescriptor(final XmlTag tag) {
    String name = tag.getName();
    XmlElementDescriptor elementDescriptor;
    final PsiElement parent = tag.getParent();
    if (parent instanceof XmlTag) {
        XmlTag parentTag = (XmlTag) parent;
        elementDescriptor = XmlUtil.getDescriptorFromContext(tag);
        final XmlElementDescriptor parentDescriptor = parentTag.getDescriptor();
        if (parentDescriptor != null && elementDescriptor == null && shouldBeValidated(tag)) {
            if (tag instanceof HtmlTag) {
                //if (inspection != null /*&& isAdditionallyDeclared(inspection.getAdditionalEntries(XmlEntitiesInspection.UNKNOWN_TAG), name)*/) {
                return;
            //}
            }
            addElementsForTag(tag, XmlErrorMessages.message("element.is.not.allowed.here", name), getTagProblemInfoType(tag));
            return;
        }
        if (elementDescriptor instanceof AnyXmlElementDescriptor || elementDescriptor == null) {
            elementDescriptor = tag.getDescriptor();
        }
        if (elementDescriptor == null)
            return;
    } else {
        //root tag
        elementDescriptor = tag.getDescriptor();
        if (elementDescriptor == null) {
            addElementsForTag(tag, XmlErrorMessages.message("element.must.be.declared", name), HighlightInfoType.WRONG_REF);
            return;
        }
    }
    if (elementDescriptor instanceof Validator) {
        //noinspection unchecked
        ((Validator<XmlTag>) elementDescriptor).validate(tag, this);
    }
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) HtmlTag(com.intellij.psi.html.HtmlTag) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) Validator(com.intellij.codeInsight.daemon.Validator)

Example 2 with Validator

use of com.intellij.codeInsight.daemon.Validator in project intellij-community by JetBrains.

the class XMLExternalAnnotator method collectInformation.

@Nullable
@Override
public MyHost collectInformation(@NotNull PsiFile file) {
    if (!(file instanceof XmlFile))
        return null;
    final XmlDocument document = ((XmlFile) file).getDocument();
    if (document == null)
        return null;
    XmlTag rootTag = document.getRootTag();
    XmlNSDescriptor nsDescriptor = rootTag == null ? null : rootTag.getNSDescriptor(rootTag.getNamespace(), false);
    if (nsDescriptor instanceof Validator) {
        //noinspection unchecked
        MyHost host = new MyHost();
        ((Validator<XmlDocument>) nsDescriptor).validate(document, host);
        return host;
    }
    return null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlDocument(com.intellij.psi.xml.XmlDocument) Validator(com.intellij.codeInsight.daemon.Validator) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Validator (com.intellij.codeInsight.daemon.Validator)2 HtmlTag (com.intellij.psi.html.HtmlTag)1 XmlDocument (com.intellij.psi.xml.XmlDocument)1 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlTag (com.intellij.psi.xml.XmlTag)1 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)1 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)1 Nullable (org.jetbrains.annotations.Nullable)1