Search in sources :

Example 6 with XmlAttribute

use of com.intellij.psi.xml.XmlAttribute 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 7 with XmlAttribute

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

the class IdRefReference method getIdValueElement.

@Nullable
protected PsiElement getIdValueElement(PsiElement element) {
    if (element instanceof XmlTag) {
        final XmlTag tag = (XmlTag) element;
        XmlAttribute attribute = tag.getAttribute(IdReferenceProvider.ID_ATTR_NAME, null);
        if (!myIdAttrsOnly) {
            if (attribute == null) {
                attribute = tag.getAttribute(IdReferenceProvider.NAME_ATTR_NAME, null);
            }
            if (attribute == null) {
                attribute = tag.getAttribute(IdReferenceProvider.STYLE_ID_ATTR_NAME, null);
            }
        }
        return attribute != null ? attribute.getValueElement() : getImplicitIdRefValueElement(tag);
    } else {
        return element;
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with XmlAttribute

use of com.intellij.psi.xml.XmlAttribute 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 9 with XmlAttribute

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

the class DomAnchorImpl method diagnoseNegativeIndex2.

private static <T extends DomElement> void diagnoseNegativeIndex2(T t, DomElement parent, AbstractDomChildrenDescription description, List<? extends DomElement> values) {
    final XmlTag parentTag = parent.getXmlTag();
    StringBuilder diag = new StringBuilder("Index<0: description=" + description + "\nparent=" + parent + "\nt=" + t + "\nvalues=" + values + "\n");
    for (int i = 0, size = values.size(); i < size; i++) {
        DomElement value = values.get(i);
        if (value.toString().equals(t.toString())) {
            final XmlElement tElement = t.getXmlElement();
            final XmlElement valElement = value.getXmlElement();
            diag.append(" hasSame, i=" + i + "; same=" + (value == t) + ", equal=" + value.equals(t) + ", equal2=" + t.equals(value) + ", t.physical=" + (tElement == null ? "null" : String.valueOf(tElement.isPhysical())) + ", value.physical=" + (valElement == null ? "null" : String.valueOf(valElement.isPhysical())) + ", sameElements=" + (tElement == value.getXmlElement()) + "\n");
            if (tElement != null && valElement != null) {
                diag.append("  sameFile=" + (tElement.getContainingFile() == valElement.getContainingFile()) + ", sameParent=" + (tElement.getParent() == valElement.getParent()) + "\n");
            }
        }
    }
    if (parentTag != null) {
        diag.append("Parent tag: ").append(parentTag.getName()).append("\n");
        if (t instanceof GenericAttributeValue) {
            for (XmlAttribute attribute : parentTag.getAttributes()) {
                diag.append(", attr: ").append(attribute.getName());
            }
            diag.append("\n");
        } else {
            for (XmlTag tag : parentTag.getSubTags()) {
                diag.append("\n subtag: ").append(tag.getName());
            }
            diag.append("\n");
        }
    }
    diag.append("Child name: ").append(t.getXmlElementName()).append(";").append(t.getXmlElementNamespaceKey());
    LOG.error(diag);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlElement(com.intellij.psi.xml.XmlElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 10 with XmlAttribute

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

the class DomCompletionContributor method domKnowsBetter.

private boolean domKnowsBetter(final CompletionParameters parameters, final CompletionResultSet result) {
    final XmlAttributeValue element = PsiTreeUtil.getParentOfType(parameters.getPosition(), XmlAttributeValue.class);
    if (element == null) {
        return false;
    }
    if (isSchemaEnumerated(element)) {
        return false;
    }
    final PsiElement parent = element.getParent();
    if (parent instanceof XmlAttribute) {
        XmlAttributeDescriptor descriptor = ((XmlAttribute) parent).getDescriptor();
        if (descriptor != null && descriptor.getDefaultValue() != null) {
            final PsiReference[] references = myProvider.getReferencesByElement(element, new ProcessingContext());
            if (references.length > 0) {
                return LegacyCompletionContributor.completeReference(parameters, result);
            }
        }
    }
    return false;
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) 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)

Aggregations

XmlAttribute (com.intellij.psi.xml.XmlAttribute)220 XmlTag (com.intellij.psi.xml.XmlTag)116 PsiElement (com.intellij.psi.PsiElement)60 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)57 NotNull (org.jetbrains.annotations.NotNull)44 XmlFile (com.intellij.psi.xml.XmlFile)37 Nullable (org.jetbrains.annotations.Nullable)27 Project (com.intellij.openapi.project.Project)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)20 TextRange (com.intellij.openapi.util.TextRange)18 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)18 ArrayList (java.util.ArrayList)18 PsiFile (com.intellij.psi.PsiFile)17 PsiReference (com.intellij.psi.PsiReference)17 IncorrectOperationException (com.intellij.util.IncorrectOperationException)10 DomElement (com.intellij.util.xml.DomElement)10 Result (com.intellij.openapi.application.Result)9 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)9 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)8 XmlElement (com.intellij.psi.xml.XmlElement)6