Search in sources :

Example 1 with XmlEnumerationDescriptor

use of com.intellij.xml.impl.XmlEnumerationDescriptor 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 XmlEnumerationDescriptor

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

the class XmlAttributeValueGetter method getEnumeratedValues.

@NotNull
public static String[] getEnumeratedValues(XmlAttribute attribute) {
    final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
    if (descriptor == null) {
        return ArrayUtil.EMPTY_STRING_ARRAY;
    }
    String[] result;
    if (descriptor instanceof BasicXmlAttributeDescriptor) {
        result = ((BasicXmlAttributeDescriptor) descriptor).getEnumeratedValues(attribute);
    } else if (descriptor instanceof XmlEnumerationDescriptor) {
        result = ((XmlEnumerationDescriptor) descriptor).getValuesForCompletion();
    } else {
        result = descriptor.getEnumeratedValues();
    }
    return result != null ? StringUtil.filterEmptyStrings(result) : ArrayUtil.EMPTY_STRING_ARRAY;
}
Also used : XmlEnumerationDescriptor(com.intellij.xml.impl.XmlEnumerationDescriptor) BasicXmlAttributeDescriptor(com.intellij.xml.impl.BasicXmlAttributeDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) BasicXmlAttributeDescriptor(com.intellij.xml.impl.BasicXmlAttributeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with XmlEnumerationDescriptor

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

the class XmlEnumeratedValueReferenceProvider method getReferencesByElement.

@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    if (XmlSchemaTagsProcessor.PROCESSING_FLAG.get() != null || context.get(SUPPRESS) != null) {
        return PsiReference.EMPTY_ARRAY;
    }
    @SuppressWarnings("unchecked") PsiElement host = getHost((T) element);
    if (host instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost) host)) {
        return PsiReference.EMPTY_ARRAY;
    }
    if (XmlHighlightVisitor.skipValidation(element)) {
        return PsiReference.EMPTY_ARRAY;
    }
    String unquotedValue = ElementManipulators.getValueText(element);
    if (!XmlUtil.isSimpleValue(unquotedValue, element)) {
        return PsiReference.EMPTY_ARRAY;
    }
    @SuppressWarnings("unchecked") final Object descriptor = getDescriptor((T) element);
    if (descriptor instanceof XmlEnumerationDescriptor) {
        XmlEnumerationDescriptor enumerationDescriptor = (XmlEnumerationDescriptor) descriptor;
        if (enumerationDescriptor.isFixed() || enumerationDescriptor.isEnumerated((XmlElement) element)) {
            //noinspection unchecked
            return enumerationDescriptor.getValueReferences((XmlElement) element, unquotedValue);
        } else if (unquotedValue.equals(enumerationDescriptor.getDefaultValue())) {
            // todo case insensitive
            return ContainerUtil.map2Array(enumerationDescriptor.getValueReferences((XmlElement) element, unquotedValue), PsiReference.class, reference -> PsiDelegateReference.createSoft(reference, true));
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) ArrayUtil(com.intellij.util.ArrayUtil) XmlAttribute(com.intellij.psi.xml.XmlAttribute) Key(com.intellij.openapi.util.Key) ContainerUtil(com.intellij.util.containers.ContainerUtil) XmlHighlightVisitor(com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor) PsiDelegateReference(com.intellij.psi.impl.source.resolve.reference.impl.PsiDelegateReference) XmlSchemaTagsProcessor(com.intellij.xml.impl.schema.XmlSchemaTagsProcessor) XmlText(com.intellij.psi.xml.XmlText) XmlEnumerationDescriptor(com.intellij.xml.impl.XmlEnumerationDescriptor) XmlElement(com.intellij.psi.xml.XmlElement) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) XmlTag(com.intellij.psi.xml.XmlTag) XmlEnumerationDescriptor(com.intellij.xml.impl.XmlEnumerationDescriptor) XmlElement(com.intellij.psi.xml.XmlElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlEnumerationDescriptor (com.intellij.xml.impl.XmlEnumerationDescriptor)3 XmlTag (com.intellij.psi.xml.XmlTag)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 NotNull (org.jetbrains.annotations.NotNull)2 XmlHighlightVisitor (com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 Key (com.intellij.openapi.util.Key)1 com.intellij.psi (com.intellij.psi)1 HtmlTag (com.intellij.psi.html.HtmlTag)1 PsiDelegateReference (com.intellij.psi.impl.source.resolve.reference.impl.PsiDelegateReference)1 InjectedLanguageUtil (com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlElement (com.intellij.psi.xml.XmlElement)1 XmlText (com.intellij.psi.xml.XmlText)1 ArrayUtil (com.intellij.util.ArrayUtil)1 ProcessingContext (com.intellij.util.ProcessingContext)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)1 BasicXmlAttributeDescriptor (com.intellij.xml.impl.BasicXmlAttributeDescriptor)1 AnyXmlAttributeDescriptor (com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor)1