Search in sources :

Example 6 with XmlAttributeDescriptor

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

the class AbstractDomChildrenDescriptor method getAttributesDescriptors.

@Override
public XmlAttributeDescriptor[] getAttributesDescriptors(@Nullable final XmlTag context) {
    if (context == null)
        return XmlAttributeDescriptor.EMPTY;
    DomElement domElement = myManager.getDomElement(context);
    if (domElement == null)
        return XmlAttributeDescriptor.EMPTY;
    final List<? extends DomAttributeChildDescription> descriptions = domElement.getGenericInfo().getAttributeChildrenDescriptions();
    List<XmlAttributeDescriptor> descriptors = new ArrayList<>();
    for (DomAttributeChildDescription description : descriptions) {
        descriptors.add(new DomAttributeXmlDescriptor(description, myManager.getProject()));
    }
    List<? extends CustomDomChildrenDescription> customs = domElement.getGenericInfo().getCustomNameChildrenDescription();
    for (CustomDomChildrenDescription custom : customs) {
        CustomDomChildrenDescription.AttributeDescriptor descriptor = custom.getCustomAttributeDescriptor();
        if (descriptor != null) {
            for (EvaluatedXmlName variant : descriptor.getCompletionVariants(domElement)) {
                AttributeChildDescriptionImpl childDescription = new AttributeChildDescriptionImpl(variant.getXmlName(), String.class);
                descriptors.add(new DomAttributeXmlDescriptor(childDescription, myManager.getProject()));
            }
        }
    }
    return descriptors.toArray(new XmlAttributeDescriptor[descriptors.size()]);
}
Also used : DomElement(com.intellij.util.xml.DomElement) EvaluatedXmlName(com.intellij.util.xml.EvaluatedXmlName) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) ArrayList(java.util.ArrayList) AttributeChildDescriptionImpl(com.intellij.util.xml.impl.AttributeChildDescriptionImpl)

Example 7 with XmlAttributeDescriptor

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

the class XmlNSDescriptorImpl method getAttributeImpl.

@Nullable
private XmlAttributeDescriptor getAttributeImpl(String localName, String namespace, @Nullable Set<XmlTag> visited) {
    if (myTag == null)
        return null;
    XmlNSDescriptor nsDescriptor = myTag.getNSDescriptor(namespace, true);
    if (nsDescriptor != this && nsDescriptor instanceof XmlNSDescriptorImpl) {
        return ((XmlNSDescriptorImpl) nsDescriptor).getAttributeImpl(localName, namespace, visited);
    }
    if (visited == null)
        visited = new HashSet<>(1);
    else if (visited.contains(myTag))
        return null;
    visited.add(myTag);
    XmlTag[] tags = myTag.getSubTags();
    for (XmlTag tag : tags) {
        if (equalsToSchemaName(tag, ATTRIBUTE_TAG_NAME)) {
            String name = tag.getAttributeValue("name");
            if (name != null) {
                if (checkElementNameEquivalence(localName, namespace, name, tag)) {
                    return createAttributeDescriptor(tag);
                }
            }
        } else if (equalsToSchemaName(tag, INCLUDE_TAG_NAME) || (equalsToSchemaName(tag, IMPORT_TAG_NAME) && namespace.equals(tag.getAttributeValue("namespace")))) {
            final String schemaLocation = tag.getAttributeValue("schemaLocation");
            if (schemaLocation != null) {
                final XmlFile xmlFile = XmlUtil.findNamespace(myTag.getContainingFile(), schemaLocation);
                if (xmlFile != null) {
                    final XmlDocument includedDocument = xmlFile.getDocument();
                    if (includedDocument != null) {
                        final PsiMetaData data = includedDocument.getMetaData();
                        if (data instanceof XmlNSDescriptorImpl) {
                            final XmlAttributeDescriptor attributeDescriptor = ((XmlNSDescriptorImpl) data).getAttributeImpl(localName, namespace, visited);
                            if (attributeDescriptor != null) {
                                final CachedValue<XmlAttributeDescriptor> value = CachedValuesManager.getManager(includedDocument.getProject()).createCachedValue(() -> {
                                    Object[] deps = attributeDescriptor.getDependences();
                                    if (deps.length == 0) {
                                        LOG.error(attributeDescriptor + " (" + attributeDescriptor.getClass() + ") returned no dependencies");
                                    }
                                    return new CachedValueProvider.Result<>(attributeDescriptor, deps);
                                }, false);
                                return value.getValue();
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : CachedValueProvider(com.intellij.psi.util.CachedValueProvider) XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) CachedValue(com.intellij.psi.util.CachedValue) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) PsiMetaData(com.intellij.psi.meta.PsiMetaData) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) THashSet(gnu.trove.THashSet) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with XmlAttributeDescriptor

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

the class XmlElementDescriptorImpl method collectAttributeDescriptorsMap.

// Read-only calculation
@Override
protected HashMap<String, XmlAttributeDescriptor> collectAttributeDescriptorsMap(final XmlTag context) {
    final HashMap<String, XmlAttributeDescriptor> localADM;
    final XmlAttributeDescriptor[] xmlAttributeDescriptors = getAttributesDescriptors(context);
    localADM = new HashMap<>(xmlAttributeDescriptors.length);
    for (final XmlAttributeDescriptor xmlAttributeDescriptor : xmlAttributeDescriptors) {
        localADM.put(xmlAttributeDescriptor.getName(), xmlAttributeDescriptor);
    }
    return localADM;
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor)

Example 9 with XmlAttributeDescriptor

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

the class XsltContextProviderBase method processElementDescriptors.

private static void processElementDescriptors(XmlElementDescriptor descriptor, XmlTag tag, ElementNames names, Set<XmlElementDescriptor> history, int depth) throws StopProcessingException {
    if (!history.add(descriptor) || ++depth == 200) {
        if (depth == 200) {
            throw new StopProcessingException();
        }
        return;
    }
    final String namespace = descriptor instanceof XmlElementDescriptorImpl ? ((XmlElementDescriptorImpl) descriptor).getNamespace() : tag.getNamespace();
    names.elementNames.add(new QName(namespace, descriptor.getName()));
    final XmlAttributeDescriptor[] attributesDescriptors = descriptor.getAttributesDescriptors(null);
    for (XmlAttributeDescriptor attributesDescriptor : attributesDescriptors) {
        final String localPart = attributesDescriptor.getName();
        if (!"xmlns".equals(localPart))
            names.attributeNames.add(new QName(localPart));
    }
    final XmlElementDescriptor[] descriptors = descriptor.getElementsDescriptors(tag);
    for (XmlElementDescriptor elem : descriptors) {
        processElementDescriptors(elem, tag, names, history, depth);
    }
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) QName(javax.xml.namespace.QName) XmlElementDescriptorImpl(com.intellij.xml.impl.schema.XmlElementDescriptorImpl) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 10 with XmlAttributeDescriptor

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

the class XmlParameterInfoHandler method updateElementDescriptor.

public static void updateElementDescriptor(XmlElementDescriptor descriptor, ParameterInfoUIContext context, Function<String, Boolean> attributePresentFun) {
    final XmlAttributeDescriptor[] attributes = descriptor != null ? getSortedDescriptors(descriptor) : XmlAttributeDescriptor.EMPTY;
    StringBuilder buffer = new StringBuilder();
    int highlightStartOffset = -1;
    int highlightEndOffset = -1;
    if (attributes.length == 0) {
        buffer.append(CodeInsightBundle.message("xml.tag.info.no.attributes"));
    } else {
        StringBuilder text1 = new StringBuilder(" ");
        StringBuilder text2 = new StringBuilder(" ");
        StringBuilder text3 = new StringBuilder(" ");
        for (XmlAttributeDescriptor attribute : attributes) {
            if (Boolean.TRUE.equals(attributePresentFun.fun(attribute.getName()))) {
                if (!(text1.toString().equals(" "))) {
                    text1.append(", ");
                }
                text1.append(attribute.getName());
            } else if (attribute.isRequired()) {
                if (!(text2.toString().equals(" "))) {
                    text2.append(", ");
                }
                text2.append(attribute.getName());
            } else {
                if (!(text3.toString().equals(" "))) {
                    text3.append(", ");
                }
                text3.append(attribute.getName());
            }
        }
        if (!text1.toString().equals(" ") && !text2.toString().equals(" ")) {
            text1.append(", ");
        }
        if (!text2.toString().equals(" ") && !text3.toString().equals(" ")) {
            text2.append(", ");
        }
        if (!text1.toString().equals(" ") && !text3.toString().equals(" ") && text2.toString().equals(" ")) {
            text1.append(", ");
        }
        buffer.append(text1);
        highlightStartOffset = buffer.length();
        buffer.append(text2);
        highlightEndOffset = buffer.length();
        buffer.append(text3);
    }
    context.setupUIComponentPresentation(buffer.toString(), highlightStartOffset, highlightEndOffset, false, false, true, context.getDefaultParameterColor());
}
Also used : XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor)

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