Search in sources :

Example 1 with XmlAttributeDescriptorImpl

use of com.intellij.xml.impl.schema.XmlAttributeDescriptorImpl in project intellij-community by JetBrains.

the class HtmlUtil method getCustomAttributeDescriptors.

public static XmlAttributeDescriptor[] getCustomAttributeDescriptors(XmlElement context) {
    String entitiesString = getEntitiesString(context, XmlEntitiesInspection.ATTRIBUTE_SHORT_NAME);
    if (entitiesString == null)
        return XmlAttributeDescriptor.EMPTY;
    StringTokenizer tokenizer = new StringTokenizer(entitiesString, ",");
    XmlAttributeDescriptor[] descriptors = new XmlAttributeDescriptor[tokenizer.countTokens()];
    int index = 0;
    while (tokenizer.hasMoreElements()) {
        final String customName = tokenizer.nextToken();
        if (customName.length() == 0)
            continue;
        descriptors[index++] = new XmlAttributeDescriptorImpl() {

            @Override
            public String getName(PsiElement context) {
                return customName;
            }

            @Override
            public String getName() {
                return customName;
            }
        };
    }
    return descriptors;
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlAttributeDescriptorImpl(com.intellij.xml.impl.schema.XmlAttributeDescriptorImpl) PsiElement(com.intellij.psi.PsiElement)

Example 2 with XmlAttributeDescriptorImpl

use of com.intellij.xml.impl.schema.XmlAttributeDescriptorImpl in project intellij-community by JetBrains.

the class XmlPrefixReferenceProvider method getReferencesByElement.

@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    XmlAttributeValue attributeValue = (XmlAttributeValue) element;
    String value = attributeValue.getValue();
    if (value == null)
        return PsiReference.EMPTY_ARRAY;
    int i = value.indexOf(':');
    if (i <= 0)
        return PsiReference.EMPTY_ARRAY;
    PsiElement parent = attributeValue.getParent();
    if (parent instanceof XmlAttribute) {
        XmlTag tag = ((XmlAttribute) parent).getParent();
        if (tag != null && !XmlNSDescriptorImpl.checkSchemaNamespace(tag)) {
            XmlAttributeDescriptor descriptor = ((XmlAttribute) parent).getDescriptor();
            if (descriptor instanceof XmlAttributeDescriptorImpl) {
                String type = ((XmlAttributeDescriptorImpl) descriptor).getType();
                if (type != null && type.endsWith(":QName")) {
                    String prefix = XmlUtil.findPrefixByQualifiedName(type);
                    String ns = ((XmlTag) descriptor.getDeclaration()).getNamespaceByPrefix(prefix);
                    if (XmlNSDescriptorImpl.checkSchemaNamespace(ns)) {
                        return new PsiReference[] { new SchemaPrefixReference(attributeValue, TextRange.from(1, i), value.substring(0, i), null) };
                    }
                }
            }
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) PsiReference(com.intellij.psi.PsiReference) XmlAttributeDescriptorImpl(com.intellij.xml.impl.schema.XmlAttributeDescriptorImpl) SchemaPrefixReference(com.intellij.psi.impl.source.xml.SchemaPrefixReference) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiElement (com.intellij.psi.PsiElement)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 XmlAttributeDescriptorImpl (com.intellij.xml.impl.schema.XmlAttributeDescriptorImpl)2 PsiReference (com.intellij.psi.PsiReference)1 SchemaPrefixReference (com.intellij.psi.impl.source.xml.SchemaPrefixReference)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 XmlTag (com.intellij.psi.xml.XmlTag)1 NotNull (org.jetbrains.annotations.NotNull)1