Search in sources :

Example 1 with ManifestPlaceholderConverter

use of org.jetbrains.android.dom.converters.ManifestPlaceholderConverter in project android by JetBrains.

the class AttributeProcessingUtil method registerAttribute.

private static void registerAttribute(@NotNull AttributeDefinition attrDef, @Nullable String parentStyleableName, @Nullable String namespaceKey, @NotNull DomElement element, @NotNull AttributeProcessor callback) {
    String name = attrDef.getName();
    if (!NS_RESOURCES.equals(namespaceKey) && name.startsWith(PREFIX_ANDROID)) {
        // A styleable-definition in the app namespace (user specified or from a library) can include
        // a reference to a platform attribute. In such a case, register it under the android namespace
        // as opposed to the app namespace. See https://code.google.com/p/android/issues/detail?id=171162
        name = name.substring(PREFIX_ANDROID.length());
        namespaceKey = NS_RESOURCES;
    }
    XmlName xmlName = new XmlName(name, namespaceKey);
    final DomExtension extension = callback.processAttribute(xmlName, attrDef, parentStyleableName);
    if (extension == null) {
        return;
    }
    Converter converter = AndroidDomUtil.getSpecificConverter(xmlName, element);
    if (converter == null) {
        if (TOOLS_URI.equals(namespaceKey)) {
            converter = ToolsAttributeUtil.getConverter(attrDef);
        } else {
            converter = AndroidDomUtil.getConverter(attrDef);
            if (converter != null && element.getParentOfType(Manifest.class, true) != null) {
                converter = new ManifestPlaceholderConverter(converter);
            }
        }
    }
    if (converter != null) {
        extension.setConverter(converter, mustBeSoft(converter, attrDef.getFormats()));
    }
    // tag completion. If attribute is not required, no additional action is needed.
    if (element instanceof LayoutElement && isLayoutAttributeRequired(xmlName, element) || element instanceof ManifestElement && AndroidManifestUtils.isRequiredAttribute(xmlName, element)) {
        extension.addCustomAnnotation(new RequiredImpl());
    }
}
Also used : DomExtension(com.intellij.util.xml.reflect.DomExtension) ManifestElement(org.jetbrains.android.dom.manifest.ManifestElement) ManifestPlaceholderConverter(org.jetbrains.android.dom.converters.ManifestPlaceholderConverter) XmlName(com.intellij.util.xml.XmlName) CompositeConverter(org.jetbrains.android.dom.converters.CompositeConverter) Converter(com.intellij.util.xml.Converter) ResourceReferenceConverter(org.jetbrains.android.dom.converters.ResourceReferenceConverter) ManifestPlaceholderConverter(org.jetbrains.android.dom.converters.ManifestPlaceholderConverter) ResolvingConverter(com.intellij.util.xml.ResolvingConverter)

Aggregations

Converter (com.intellij.util.xml.Converter)1 ResolvingConverter (com.intellij.util.xml.ResolvingConverter)1 XmlName (com.intellij.util.xml.XmlName)1 DomExtension (com.intellij.util.xml.reflect.DomExtension)1 CompositeConverter (org.jetbrains.android.dom.converters.CompositeConverter)1 ManifestPlaceholderConverter (org.jetbrains.android.dom.converters.ManifestPlaceholderConverter)1 ResourceReferenceConverter (org.jetbrains.android.dom.converters.ResourceReferenceConverter)1 ManifestElement (org.jetbrains.android.dom.manifest.ManifestElement)1