Search in sources :

Example 1 with XmlAttributeDescriptor

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

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

the class RequiredAttributesInspectionBase method hasAttribute.

private static boolean hasAttribute(XmlTag tag, String attrName) {
    final XmlAttribute attribute = tag.getAttribute(attrName);
    if (attribute == null)
        return false;
    if (attribute.getValueElement() != null)
        return true;
    if (!(tag instanceof HtmlTag))
        return false;
    final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
    return descriptor != null && HtmlUtil.isBooleanAttribute(descriptor, tag);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) HtmlTag(com.intellij.psi.html.HtmlTag)

Example 3 with XmlAttributeDescriptor

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

the class IdReferenceProvider method getReferencesByElement.

@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
    if (element instanceof XmlAttributeValue) {
        final XmlExtension extension = XmlExtension.getExtensionByElement(element);
        if (extension != null && extension.hasDynamicComponents(element)) {
            return PsiReference.EMPTY_ARRAY;
        }
        final PsiElement parentElement = element.getParent();
        if (!(parentElement instanceof XmlAttribute))
            return PsiReference.EMPTY_ARRAY;
        final String name = ((XmlAttribute) parentElement).getName();
        final String ns = ((XmlAttribute) parentElement).getParent().getNamespace();
        final boolean jsfNs = Arrays.asList(XmlUtil.JSF_CORE_URIS).contains(ns) || Arrays.asList(XmlUtil.JSF_HTML_URIS).contains(ns);
        if (FOR_ATTR_NAME.equals(name)) {
            return new PsiReference[] { jsfNs && element.getText().indexOf(':') == -1 ? new IdRefReference(element) : new IdRefReference(element) {

                @Override
                public boolean isSoft() {
                    final XmlAttributeDescriptor descriptor = ((XmlAttribute) parentElement).getDescriptor();
                    return descriptor != null && !descriptor.hasIdRefType();
                }
            } };
        } else {
            final boolean allowReferences = !ourNamespacesWithoutNameReference.contains(ns);
            if (ID_ATTR_NAME.equals(name) && allowReferences || STYLE_ID_ATTR_NAME.equals(name) || NAME_ATTR_NAME.equals(name) && allowReferences) {
                final AttributeValueSelfReference attributeValueSelfReference;
                if (jsfNs) {
                    attributeValueSelfReference = new AttributeValueSelfReference(element);
                } else {
                    if (hasOuterLanguageElement(element))
                        return PsiReference.EMPTY_ARRAY;
                    attributeValueSelfReference = new GlobalAttributeValueSelfReference(element, true);
                }
                return new PsiReference[] { attributeValueSelfReference };
            }
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
Also used : XmlExtension(com.intellij.xml.XmlExtension) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) PsiReference(com.intellij.psi.PsiReference) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with XmlAttributeDescriptor

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

the class XmlHighlightingTest method testAnyAttributeNavigation.

public void testAnyAttributeNavigation() throws Exception {
    configureByFiles(null, getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xml"), getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xsd"), getVirtualFile(BASE_PATH + "AnyAttributeNavigation/library.xsd"));
    PsiReference at = getFile().findReferenceAt(getEditor().getCaretModel().getOffset());
    XmlTag tag = PsiTreeUtil.getParentOfType(at.getElement(), XmlTag.class);
    XmlElementDescriptorImpl descriptor = (XmlElementDescriptorImpl) tag.getDescriptor();
    XmlAttributeDescriptor[] descriptors = descriptor.getAttributesDescriptors(tag);
    System.out.println(Arrays.asList(descriptors));
    doDoTest(true, false);
    PsiElement resolve = at.resolve();
    assertTrue(resolve instanceof XmlTag);
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptorImpl(com.intellij.xml.impl.schema.XmlElementDescriptorImpl)

Example 5 with XmlAttributeDescriptor

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

the class PsiDocumentNavigator method getElementById.

public Object getElementById(Object object, final String elementId) {
    final XmlTag rootTag = ((XmlFile) ((XmlElement) object).getContainingFile()).getRootTag();
    if (rootTag == null) {
        return null;
    }
    final Ref<XmlTag> ref = new Ref<>();
    rootTag.accept(new XmlRecursiveElementVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (ref.get() == null) {
                super.visitElement(element);
            }
        }

        @Override
        public void visitXmlAttribute(XmlAttribute attribute) {
            final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
            final String value = attribute.getValue();
            if ((value != null && (descriptor != null && descriptor.hasIdType()))) {
                if (elementId.equals(value)) {
                    ref.set(attribute.getParent());
                }
            }
        }
    });
    return ref.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlRecursiveElementVisitor(com.intellij.psi.XmlRecursiveElementVisitor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)89 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)54 XmlTag (com.intellij.psi.xml.XmlTag)46 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)32 XmlAttribute (com.intellij.psi.xml.XmlAttribute)18 NotNull (org.jetbrains.annotations.NotNull)11 PsiElement (com.intellij.psi.PsiElement)10 ArrayList (java.util.ArrayList)8 XmlFile (com.intellij.psi.xml.XmlFile)7 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)6 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)6 Nullable (org.jetbrains.annotations.Nullable)6 Project (com.intellij.openapi.project.Project)5 HtmlTag (com.intellij.psi.html.HtmlTag)5 NamespaceAwareXmlAttributeDescriptor (com.intellij.xml.NamespaceAwareXmlAttributeDescriptor)5 AnyXmlAttributeDescriptor (com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor)5 JavaFxPropertyAttributeDescriptor (org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyAttributeDescriptor)5 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)3 PsiReference (com.intellij.psi.PsiReference)3 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)2