Search in sources :

Example 6 with AttributeDefinitions

use of org.jetbrains.android.dom.attrs.AttributeDefinitions in project android by JetBrains.

the class AndroidCompletionContributor method isFrameworkAttributeDeprecated.

private static boolean isFrameworkAttributeDeprecated(AndroidFacet facet, XmlAttribute attribute, String attributeName) {
    final ResourceManager manager = facet.getResourceManager(AndroidUtils.SYSTEM_RESOURCE_PACKAGE, attribute.getParent());
    if (manager == null) {
        return false;
    }
    final AttributeDefinitions attributes = manager.getAttributeDefinitions();
    if (attributes == null) {
        return false;
    }
    final AttributeDefinition attributeDefinition = attributes.getAttrDefByName(attributeName);
    return attributeDefinition != null && attributeDefinition.isAttributeDeprecated();
}
Also used : AttributeDefinitions(org.jetbrains.android.dom.attrs.AttributeDefinitions) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) ResourceManager(org.jetbrains.android.resourceManagers.ResourceManager)

Example 7 with AttributeDefinitions

use of org.jetbrains.android.dom.attrs.AttributeDefinitions in project android by JetBrains.

the class ResolutionUtils method getAttributeDefinition.

@Nullable
public static AttributeDefinition getAttributeDefinition(@NotNull Module module, @Nullable Configuration configuration, @NotNull String name) {
    AttributeDefinitions definitions;
    if (name.startsWith(ANDROID_NS_NAME_PREFIX)) {
        IAndroidTarget target;
        if (configuration == null) {
            AndroidFacet facet = AndroidFacet.getInstance(module);
            assert facet != null;
            // same as getHighestApiTarget();
            target = facet.getConfigurationManager().getDefaultTarget();
        } else {
            target = configuration.getRealTarget();
        }
        assert target != null;
        AndroidTargetData androidTargetData = AndroidTargetData.getTargetData(target, module);
        assert androidTargetData != null;
        definitions = androidTargetData.getAllAttrDefs(module.getProject());
    } else {
        AndroidFacet facet = AndroidFacet.getInstance(module);
        assert facet != null : String.format("Module %s is not an Android module", module.getName());
        definitions = facet.getLocalResourceManager().getAttributeDefinitions();
    }
    if (definitions == null) {
        return null;
    }
    return definitions.getAttrDefByName(getNameFromQualifiedName(name));
}
Also used : AttributeDefinitions(org.jetbrains.android.dom.attrs.AttributeDefinitions) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with AttributeDefinitions

use of org.jetbrains.android.dom.attrs.AttributeDefinitions 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)

Example 9 with AttributeDefinitions

use of org.jetbrains.android.dom.attrs.AttributeDefinitions in project android by JetBrains.

the class PropertyTestCase method getDefinition.

@Nullable
protected static AttributeDefinition getDefinition(@NotNull NlComponent component, @NotNull XmlAttributeDescriptor descriptor) {
    AndroidFacet facet = component.getModel().getFacet();
    ResourceManager localResourceManager = facet.getLocalResourceManager();
    ResourceManager systemResourceManager = facet.getSystemResourceManager();
    assertThat(systemResourceManager).isNotNull();
    AttributeDefinitions localAttrDefs = localResourceManager.getAttributeDefinitions();
    AttributeDefinitions systemAttrDefs = systemResourceManager.getAttributeDefinitions();
    AttributeDefinitions attrDefs = NS_RESOURCES.equals(getNamespace(component, descriptor)) ? systemAttrDefs : localAttrDefs;
    return attrDefs == null ? null : attrDefs.getAttrDefByName(descriptor.getName());
}
Also used : AttributeDefinitions(org.jetbrains.android.dom.attrs.AttributeDefinitions) ResourceManager(org.jetbrains.android.resourceManagers.ResourceManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AttributeDefinitions (org.jetbrains.android.dom.attrs.AttributeDefinitions)9 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)6 ResourceManager (org.jetbrains.android.resourceManagers.ResourceManager)5 Nullable (org.jetbrains.annotations.Nullable)5 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)4 IAndroidTarget (com.android.sdklib.IAndroidTarget)2 XmlTag (com.intellij.psi.xml.XmlTag)2 SystemResourceManager (org.jetbrains.android.resourceManagers.SystemResourceManager)2 AndroidTargetData (org.jetbrains.android.sdk.AndroidTargetData)2 NotNull (org.jetbrains.annotations.NotNull)2 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)1 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)1 ResourceItem (com.android.ide.common.res2.ResourceItem)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 HtmlBuilder (com.android.utils.HtmlBuilder)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