Search in sources :

Example 1 with AnyXmlElementDescriptor

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

the class HtmlUnknownBooleanAttributeInspectionBase method checkAttribute.

@Override
protected void checkAttribute(@NotNull final XmlAttribute attribute, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    if (attribute.getValueElement() == null) {
        final XmlTag tag = attribute.getParent();
        if (tag instanceof HtmlTag) {
            XmlElementDescriptor elementDescriptor = tag.getDescriptor();
            if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor) {
                return;
            }
            XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor(attribute);
            if (attributeDescriptor != null && !(attributeDescriptor instanceof AnyXmlAttributeDescriptor)) {
                String name = attribute.getName();
                if (!HtmlUtil.isBooleanAttribute(attributeDescriptor, null) && (!isCustomValuesEnabled() || !isCustomValue(name))) {
                    final boolean html5 = HtmlUtil.isHtml5Context(tag);
                    LocalQuickFix[] quickFixes = !html5 ? new LocalQuickFix[] { new AddCustomHtmlElementIntentionAction(BOOLEAN_ATTRIBUTE_KEY, name, XmlBundle.message("add.custom.html.boolean.attribute", name)), XmlQuickFixFactory.getInstance().addAttributeValueFix(attribute), new RemoveAttributeIntentionAction(name) } : new LocalQuickFix[] { XmlQuickFixFactory.getInstance().addAttributeValueFix(attribute) };
                    String error = null;
                    if (html5) {
                        if (attributeDescriptor instanceof XmlEnumerationDescriptor && ((XmlEnumerationDescriptor) attributeDescriptor).getValueDeclaration(attribute, "") == null) {
                            error = XmlErrorMessages.message("wrong.value", "attribute");
                        }
                    } else {
                        error = XmlErrorMessages.message("attribute.is.not.boolean", attribute.getName());
                    }
                    if (error != null) {
                        registerProblemOnAttributeName(attribute, error, holder, quickFixes);
                    }
                }
            }
        }
    }
}
Also used : AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) HtmlTag(com.intellij.psi.html.HtmlTag) XmlEnumerationDescriptor(com.intellij.xml.impl.XmlEnumerationDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 2 with AnyXmlElementDescriptor

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

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

the class XmlHighlightVisitor method checkTag.

private void checkTag(XmlTag tag) {
    if (ourDoJaxpTesting)
        return;
    if (!myHolder.hasErrorResults()) {
        checkTagByDescriptor(tag);
    }
    if (!myHolder.hasErrorResults()) {
        if (!skipValidation(tag)) {
            final XmlElementDescriptor descriptor = tag.getDescriptor();
            if (tag instanceof HtmlTag && (descriptor instanceof AnyXmlElementDescriptor || descriptor == null)) {
                return;
            }
            checkReferences(tag);
        }
    }
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) HtmlTag(com.intellij.psi.html.HtmlTag) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor)

Example 4 with AnyXmlElementDescriptor

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

the class XmlHighlightVisitor method checkAttribute.

private void checkAttribute(XmlAttribute attribute) {
    XmlTag tag = attribute.getParent();
    if (tag == null)
        return;
    final String name = attribute.getName();
    PsiElement prevLeaf = PsiTreeUtil.prevLeaf(attribute);
    if (!(prevLeaf instanceof PsiWhiteSpace)) {
        TextRange textRange = attribute.getTextRange();
        HighlightInfoType type = tag instanceof HtmlTag ? HighlightInfoType.WARNING : HighlightInfoType.ERROR;
        String description = XmlErrorMessages.message("attribute.should.be.preceded.with.space");
        HighlightInfo info = HighlightInfo.newHighlightInfo(type).range(textRange.getStartOffset(), textRange.getStartOffset()).descriptionAndTooltip(description).create();
        addToResults(info);
    }
    if (attribute.isNamespaceDeclaration() || XmlUtil.XML_SCHEMA_INSTANCE_URI.equals(attribute.getNamespace())) {
        //checkReferences(attribute.getValueElement());
        return;
    }
    XmlElementDescriptor elementDescriptor = tag.getDescriptor();
    if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor || ourDoJaxpTesting) {
        return;
    }
    XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor(attribute);
    if (attributeDescriptor == null) {
        if (!XmlUtil.attributeFromTemplateFramework(name, tag)) {
            final String localizedMessage = XmlErrorMessages.message("attribute.is.not.allowed.here", name);
            final HighlightInfo highlightInfo = reportAttributeProblem(tag, name, attribute, localizedMessage);
            if (highlightInfo != null) {
                PsiFile file = tag.getContainingFile();
                if (file != null) {
                    for (XmlUndefinedElementFixProvider fixProvider : Extensions.getExtensions(XmlUndefinedElementFixProvider.EP_NAME)) {
                        IntentionAction[] fixes = fixProvider.createFixes(attribute);
                        if (fixes != null) {
                            for (IntentionAction action : fixes) {
                                QuickFixAction.registerQuickFixAction(highlightInfo, action);
                            }
                            break;
                        }
                    }
                }
            }
        }
    } else {
        checkDuplicateAttribute(tag, attribute);
        // we skip resolve of attribute references since there is separate check when taking attribute descriptors
        PsiReference[] attrRefs = attribute.getReferences();
        doCheckRefs(attribute, attrRefs, !attribute.getNamespacePrefix().isEmpty() ? 2 : 1);
    }
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) TextRange(com.intellij.openapi.util.TextRange) HtmlTag(com.intellij.psi.html.HtmlTag) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor)

Example 5 with AnyXmlElementDescriptor

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

the class TagNameReference method resolve.

@Override
public PsiElement resolve() {
    final XmlTag tag = getTagElement();
    final XmlElementDescriptor descriptor = tag != null ? tag.getDescriptor() : null;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Descriptor for tag " + (tag != null ? tag.getName() : "NULL") + " is " + (descriptor != null ? (descriptor.toString() + ": " + descriptor.getClass().getCanonicalName()) : "NULL"));
    }
    if (descriptor != null) {
        return descriptor instanceof AnyXmlElementDescriptor ? tag : descriptor.getDeclaration();
    }
    return null;
}
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)

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