Search in sources :

Example 1 with AnyXmlAttributeDescriptor

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

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()]);
}
Also used : HtmlUtil(com.intellij.xml.util.HtmlUtil) Html5CustomAttributesIndex(com.intellij.html.index.Html5CustomAttributesIndex) XmlAttribute(com.intellij.psi.xml.XmlAttribute) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) XmlAttributeDescriptorsProvider(com.intellij.xml.XmlAttributeDescriptorsProvider) ContainerUtil(com.intellij.util.containers.ContainerUtil) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) ArrayList(java.util.ArrayList) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) List(java.util.List) Project(com.intellij.openapi.project.Project) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) XmlTag(com.intellij.psi.xml.XmlTag) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) XmlAttribute(com.intellij.psi.xml.XmlAttribute) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) Collection(java.util.Collection)

Example 3 with AnyXmlAttributeDescriptor

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()]);
}
Also used : AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) ArrayList(java.util.ArrayList)

Example 4 with AnyXmlAttributeDescriptor

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;
}
Also used : AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) PsiElement(com.intellij.psi.PsiElement)

Example 5 with AnyXmlAttributeDescriptor

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);
}
Also used : AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnyXmlAttributeDescriptor(com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Aggregations

AnyXmlAttributeDescriptor (com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor)6 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)5 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)2 XmlTag (com.intellij.psi.xml.XmlTag)2 ArrayList (java.util.ArrayList)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ByteRange (com.intellij.flex.uiDesigner.io.ByteRange)1 Marker (com.intellij.flex.uiDesigner.io.Marker)1 Html5CustomAttributesIndex (com.intellij.html.index.Html5CustomAttributesIndex)1 JSImplicitElement (com.intellij.lang.javascript.psi.stubs.JSImplicitElement)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 HtmlTag (com.intellij.psi.html.HtmlTag)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 CachedValueProvider (com.intellij.psi.util.CachedValueProvider)1 CachedValuesManager (com.intellij.psi.util.CachedValuesManager)1 PsiModificationTracker (com.intellij.psi.util.PsiModificationTracker)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1