Search in sources :

Example 1 with XmlHighlightingAwareElementDescriptor

use of com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightingAwareElementDescriptor in project intellij-community by JetBrains.

the class RequiredAttributesInspectionBase method checkTag.

@Override
protected void checkTag(@NotNull XmlTag tag, @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    String name = tag.getName();
    XmlElementDescriptor elementDescriptor = XmlUtil.getDescriptorFromContext(tag);
    if (elementDescriptor instanceof AnyXmlElementDescriptor || elementDescriptor == null) {
        elementDescriptor = tag.getDescriptor();
    }
    if (elementDescriptor == null)
        return;
    if ((elementDescriptor instanceof XmlHighlightingAwareElementDescriptor) && !((XmlHighlightingAwareElementDescriptor) elementDescriptor).shouldCheckRequiredAttributes()) {
        return;
    }
    XmlAttributeDescriptor[] attributeDescriptors = elementDescriptor.getAttributesDescriptors(tag);
    Set<String> requiredAttributes = null;
    for (XmlAttributeDescriptor attribute : attributeDescriptors) {
        if (attribute != null && attribute.isRequired()) {
            if (requiredAttributes == null) {
                requiredAttributes = new HashSet<>();
            }
            requiredAttributes.add(attribute.getName(tag));
        }
    }
    if (requiredAttributes != null) {
        for (final String attrName : requiredAttributes) {
            if (!hasAttribute(tag, attrName) && !XmlExtension.getExtension(tag.getContainingFile()).isRequiredAttributeImplicitlyPresent(tag, attrName)) {
                LocalQuickFix insertRequiredAttributeIntention = XmlQuickFixFactory.getInstance().insertRequiredAttributeFix(tag, attrName);
                final String localizedMessage = XmlErrorMessages.message("element.doesnt.have.required.attribute", name, attrName);
                reportOneTagProblem(tag, attrName, localizedMessage, insertRequiredAttributeIntention, holder, getIntentionAction(attrName));
            }
        }
    }
}
Also used : AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlHighlightingAwareElementDescriptor(com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightingAwareElementDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor)

Aggregations

XmlHighlightingAwareElementDescriptor (com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightingAwareElementDescriptor)1 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)1 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)1 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)1