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);
}
}
}
}
}
}
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;
}
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;
}
Aggregations