use of com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor 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.schema.AnyXmlAttributeDescriptor in project intellij-community by JetBrains.
the class Html5CustomAttributeDescriptorsProvider method getAttributeDescriptors.
@Override
public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag tag) {
if (tag == null || !HtmlUtil.isHtml5Context(tag)) {
return XmlAttributeDescriptor.EMPTY;
}
final List<String> currentAttrs = new ArrayList<>();
for (XmlAttribute attribute : tag.getAttributes()) {
currentAttrs.add(attribute.getName());
}
final Project project = tag.getProject();
final Collection<String> keys = CachedValuesManager.getManager(project).getCachedValue(project, () -> {
final Collection<String> keys1 = FileBasedIndex.getInstance().getAllKeys(Html5CustomAttributesIndex.INDEX_ID, project);
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
return CachedValueProvider.Result.<Collection<String>>create(ContainerUtil.filter(keys1, key -> !FileBasedIndex.getInstance().processValues(Html5CustomAttributesIndex.INDEX_ID, key, null, (file, value) -> false, scope)), PsiModificationTracker.MODIFICATION_COUNT);
});
if (keys.isEmpty())
return XmlAttributeDescriptor.EMPTY;
final List<XmlAttributeDescriptor> result = new ArrayList<>();
for (String key : keys) {
boolean add = true;
for (String attr : currentAttrs) {
if (attr.startsWith(key)) {
add = false;
}
}
if (add) {
result.add(new AnyXmlAttributeDescriptor(key));
}
}
return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
use of com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor in project intellij-community by JetBrains.
the class MicrodataAttributeDescriptorsProvider method getAttributeDescriptors.
@Override
public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag context) {
if (!HtmlUtil.isHtml5Context(context)) {
return XmlAttributeDescriptor.EMPTY;
}
final String tagName = context.getName();
List<XmlAttributeDescriptor> result = new ArrayList<>();
final boolean goodContextForProps = "div".equalsIgnoreCase(tagName) || "span".equalsIgnoreCase(tagName) || "a".equalsIgnoreCase(tagName);
if (goodContextForProps && hasScopeTag(context)) {
result.add(new MicrodataPropertyAttributeDescriptor(context));
}
if (context.getAttribute(ITEM_SCOPE) == null) {
result.add(new AnyXmlAttributeDescriptor(ITEM_SCOPE));
} else {
result.add(new XmlAttributeDescriptorWithEmptyDefaultValue(ITEM_ID));
result.add(new XmlAttributeDescriptorWithEmptyDefaultValue(ITEM_TYPE));
result.add(new XmlAttributeDescriptorWithEmptyDefaultValue(ITEM_REF));
}
return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
use of com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor in project intellij-plugins by JetBrains.
the class ClassBackedElementDescriptor method getAttributeDescriptor.
@Override
public XmlAttributeDescriptor getAttributeDescriptor(String attributeName, @Nullable final XmlTag context) {
if (isPrivateAttribute(attributeName, context)) {
return new AnyXmlAttributeDescriptor(attributeName);
}
if (context != null && context.getParent() instanceof XmlDocument) {
if (FlexMxmlLanguageAttributeNames.ID.equals(attributeName) || ArrayUtil.contains(attributeName, CodeContext.GUMBO_ATTRIBUTES)) {
// id, includeIn, excludeFrom, itemCreationPolicy, itemDestructionPolicy attributes are not allowed for the root tag
return null;
}
}
PsiElement element = getDeclaration();
if (element == null)
return null;
attributeName = skipStateNamePart(attributeName);
ensureDescriptorsMapsInitialized(element, null);
AnnotationBackedDescriptor descriptor = myDescriptors.get(attributeName);
if (descriptor == null && context != null) {
final String prefix = context.getNamespacePrefix();
if (StringUtil.isNotEmpty(prefix) && attributeName.startsWith(prefix + ":")) {
descriptor = myDescriptors.get(attributeName.substring(prefix.length() + 1));
}
}
if (descriptor == null && context != null && !myPackageToInternalDescriptors.isEmpty()) {
final String contextPackage = JSResolveUtil.getPackageNameFromPlace(context);
final Map<String, AnnotationBackedDescriptor> internalDescriptors = myPackageToInternalDescriptors.get(contextPackage);
if (internalDescriptors != null) {
descriptor = internalDescriptors.get(attributeName);
}
}
if (descriptor == null && myPredefinedDescriptors != null) {
descriptor = myPredefinedDescriptors.get(attributeName);
}
if (descriptor == null) {
if (IMPLEMENTS_ATTR_NAME.equals(attributeName) && context != null) {
final PsiElement parent = context.getParent();
if (parent instanceof XmlDocument || (parent instanceof XmlTag && MxmlLanguageTagsUtil.isComponentTag((XmlTag) parent))) {
descriptor = new AnnotationBackedDescriptorImpl(IMPLEMENTS_ATTR_NAME, this, true, null, null, null);
}
} else if (XmlBackedJSClassImpl.CLASS_NAME_ATTRIBUTE_NAME.equals(attributeName) && MxmlLanguageTagsUtil.isComponentTag(context)) {
descriptor = new ClassNameAttributeDescriptor(this);
} else if (!predefined && !FlexMxmlLanguageAttributeNames.ID.equals(attributeName) && !MxmlLanguageTagsUtil.isXmlOrXmlListTag(context) && isDynamicClass(element)) {
return new AnyXmlAttributeDescriptor(attributeName);
}
}
return descriptor;
}
use of com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor in project intellij-plugins by JetBrains.
the class AngularJSTagDescriptor method getAttributesDescriptors.
@Override
public XmlAttributeDescriptor[] getAttributesDescriptors(@Nullable XmlTag context) {
final JSImplicitElement declaration = getDeclaration();
final String string = declaration.getTypeString();
final String attributes = string.split(";", -1)[3];
final String[] split = attributes.split(",");
final XmlAttributeDescriptor[] result;
if (context != null && AngularIndexUtil.hasAngularJS2(context.getProject())) {
result = AngularAttributeDescriptor.getFieldBasedDescriptors(declaration);
} else if (split.length == 1 && split[0].isEmpty()) {
result = XmlAttributeDescriptor.EMPTY;
} else {
result = new XmlAttributeDescriptor[split.length];
for (int i = 0; i < split.length; i++) {
result[i] = new AnyXmlAttributeDescriptor(DirectiveUtil.getAttributeName(split[i]));
}
}
final XmlAttributeDescriptor[] commonAttributes = HtmlNSDescriptorImpl.getCommonAttributeDescriptors(context);
return ArrayUtil.mergeArrays(result, commonAttributes);
}
Aggregations