Search in sources :

Example 1 with AndroidAnyAttributeDescriptor

use of org.jetbrains.android.dom.AndroidAnyAttributeDescriptor in project android by JetBrains.

the class NlProperties method getPropertiesWithReadLock.

@NotNull
private Table<String, String, NlPropertyItem> getPropertiesWithReadLock(@NotNull AndroidFacet facet, @NotNull List<NlComponent> components, @NotNull GradleDependencyManager dependencyManager) {
    ResourceManager localResourceManager = facet.getLocalResourceManager();
    ResourceManager systemResourceManager = facet.getSystemResourceManager();
    if (systemResourceManager == null) {
        Logger.getInstance(NlProperties.class).error("No system resource manager for module: " + facet.getModule().getName());
        return ImmutableTable.of();
    }
    AttributeDefinitions localAttrDefs = localResourceManager.getAttributeDefinitions();
    AttributeDefinitions systemAttrDefs = systemResourceManager.getAttributeDefinitions();
    Table<String, String, NlPropertyItem> combinedProperties = null;
    for (NlComponent component : components) {
        XmlTag tag = component.getTag();
        if (!tag.isValid()) {
            return ImmutableTable.of();
        }
        XmlElementDescriptor elementDescriptor = myDescriptorProvider.getDescriptor(tag);
        if (elementDescriptor == null) {
            return ImmutableTable.of();
        }
        XmlAttributeDescriptor[] descriptors = elementDescriptor.getAttributesDescriptors(tag);
        Table<String, String, NlPropertyItem> properties = HashBasedTable.create(3, descriptors.length);
        for (XmlAttributeDescriptor desc : descriptors) {
            String namespace = getNamespace(desc, tag);
            AttributeDefinitions attrDefs = NS_RESOURCES.equals(namespace) ? systemAttrDefs : localAttrDefs;
            AttributeDefinition attrDef = attrDefs == null ? null : attrDefs.getAttrDefByName(desc.getName());
            NlPropertyItem property = NlPropertyItem.create(components, desc, namespace, attrDef);
            properties.put(StringUtil.notNullize(namespace), property.getName(), property);
        }
        // Exceptions:
        switch(tag.getName()) {
            case AUTO_COMPLETE_TEXT_VIEW:
                // An AutoCompleteTextView has a popup that is created at runtime.
                // Properties for this popup can be added to the AutoCompleteTextView tag.
                properties.put(ANDROID_URI, ATTR_POPUP_BACKGROUND, NlPropertyItem.create(components, new AndroidAnyAttributeDescriptor(ATTR_POPUP_BACKGROUND), ANDROID_URI, systemAttrDefs != null ? systemAttrDefs.getAttrDefByName(ATTR_POPUP_BACKGROUND) : null));
                break;
        }
        combinedProperties = combine(properties, combinedProperties);
    }
    // The following properties are deprecated in the support library and can be ignored by tools:
    assert combinedProperties != null;
    combinedProperties.remove(AUTO_URI, ATTR_PADDING_START);
    combinedProperties.remove(AUTO_URI, ATTR_PADDING_END);
    combinedProperties.remove(AUTO_URI, ATTR_THEME);
    setUpDesignProperties(combinedProperties);
    setUpSrcCompat(combinedProperties, facet, components, dependencyManager);
    initStarState(combinedProperties);
    //noinspection ConstantConditions
    return combinedProperties;
}
Also used : AndroidAnyAttributeDescriptor(org.jetbrains.android.dom.AndroidAnyAttributeDescriptor) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) ResourceManager(org.jetbrains.android.resourceManagers.ResourceManager) AttributeDefinitions(org.jetbrains.android.dom.attrs.AttributeDefinitions) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) NamespaceAwareXmlAttributeDescriptor(com.intellij.xml.NamespaceAwareXmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 XmlTag (com.intellij.psi.xml.XmlTag)1 NamespaceAwareXmlAttributeDescriptor (com.intellij.xml.NamespaceAwareXmlAttributeDescriptor)1 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)1 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)1 AndroidAnyAttributeDescriptor (org.jetbrains.android.dom.AndroidAnyAttributeDescriptor)1 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)1 AttributeDefinitions (org.jetbrains.android.dom.attrs.AttributeDefinitions)1 ResourceManager (org.jetbrains.android.resourceManagers.ResourceManager)1 NotNull (org.jetbrains.annotations.NotNull)1