use of org.jetbrains.android.resourceManagers.ResourceManager in project android by JetBrains.
the class AttributeProcessingUtil method processMenuItemAttributes.
private static void processMenuItemAttributes(@NotNull AndroidFacet facet, @NotNull DomElement element, @NotNull Collection<XmlName> skippedAttributes, @NotNull AttributeProcessor callback) {
ResourceManager manager = facet.getSystemResourceManager();
if (manager == null) {
return;
}
AttributeDefinitions styleables = manager.getAttributeDefinitions();
if (styleables == null) {
return;
}
StyleableDefinition styleable = styleables.getStyleableByName("MenuItem");
if (styleable == null) {
getLog().warn("No StyleableDefinition for MenuItem");
return;
}
for (AttributeDefinition attribute : styleable.getAttributes()) {
String name = attribute.getName();
// .lint.checks.AppCompatResourceDetector.
if (name.equals(ATTR_SHOW_AS_ACTION)) {
AndroidModuleModel model = AndroidModuleModel.get(facet);
if (model != null && GradleUtil.dependsOn(model, APPCOMPAT_LIB_ARTIFACT)) {
if (skippedAttributes.add(new XmlName(name, AUTO_URI))) {
registerAttribute(attribute, "MenuItem", AUTO_URI, element, callback);
}
continue;
}
}
if (skippedAttributes.add(new XmlName(name, ANDROID_URI))) {
registerAttribute(attribute, "MenuItem", ANDROID_URI, element, callback);
}
}
}
use of org.jetbrains.android.resourceManagers.ResourceManager in project android by JetBrains.
the class AndroidDomUtil method getAttributeDefinition.
@Nullable
public static AttributeDefinition getAttributeDefinition(@NotNull AndroidFacet facet, @NotNull XmlAttribute attribute) {
String localName = attribute.getLocalName();
String namespace = attribute.getNamespace();
boolean isFramework = namespace.equals(ANDROID_URI);
if (!isFramework && TOOLS_URI.equals(namespace)) {
// Treat tools namespace attributes as aliases for Android namespaces: see https://developer.android.com/studio/write/tool-attributes.html#design-time_view_attributes
isFramework = true;
// However, there are some attributes with other meanings: https://developer.android.com/studio/write/tool-attributes.html
// Filter some of these out such that they are not treated as the (unrelated but identically named) platform attributes
AttributeDefinition toolsAttr = TOOLS_ATTRIBUTE_DEFINITIONS.getAttrDefByName(localName);
if (toolsAttr != null) {
return toolsAttr;
}
}
ResourceManager manager = facet.getResourceManager(isFramework ? SYSTEM_RESOURCE_PACKAGE : null);
if (manager != null) {
AttributeDefinitions attrDefs = manager.getAttributeDefinitions();
if (attrDefs != null) {
return attrDefs.getAttrDefByName(localName);
}
}
return null;
}
use of org.jetbrains.android.resourceManagers.ResourceManager in project android by JetBrains.
the class AttributeProcessingUtil method registerAttributes.
private static void registerAttributes(AndroidFacet facet, DomElement element, @NotNull String styleableName, @Nullable String resPackage, AttributeProcessor callback, Set<XmlName> skipNames) {
ResourceManager manager = facet.getResourceManager(resPackage);
if (manager == null) {
return;
}
AttributeDefinitions attrDefs = manager.getAttributeDefinitions();
if (attrDefs == null) {
return;
}
String namespace = getNamespaceKeyByResourcePackage(facet, resPackage);
StyleableDefinition styleable = attrDefs.getStyleableByName(styleableName);
if (styleable != null) {
registerStyleableAttributes(element, styleable, namespace, callback, skipNames);
}
// It's a good idea to add a warning when styleable not found, to make sure that code doesn't
// try to use attributes that don't exist. However, current AndroidDomExtender code relies on
// a lot of "heuristics" that fail quite a lot (like adding a bunch of suffixes to short class names)
// TODO: add a warning when rest of the code of AndroidDomExtender is cleaned up
}
use of org.jetbrains.android.resourceManagers.ResourceManager in project android by JetBrains.
the class ResourceReferenceConverter method addResourceReferenceValues.
private static void addResourceReferenceValues(AndroidFacet facet, char prefix, ResourceType type, @Nullable String resPackage, Collection<ResourceValue> result, boolean explicitResourceType) {
final ResourceManager manager = facet.getResourceManager(resPackage);
String typeName = type.getName();
if (manager != null) {
for (String name : manager.getResourceNames(type, true)) {
result.add(referenceTo(prefix, typeName, resPackage, name, explicitResourceType));
}
}
}
use of org.jetbrains.android.resourceManagers.ResourceManager in project android by JetBrains.
the class AndroidFindStyleApplicationsAction method resolveStyleRef.
private static PsiElement resolveStyleRef(StyleRefData styleRef, AndroidFacet facet) {
final ResourceManager resourceManager = facet.getResourceManager(styleRef.getStylePackage());
if (resourceManager == null) {
return null;
}
final List<ValueResourceInfoImpl> infos = resourceManager.findValueResourceInfos(ResourceType.STYLE.getName(), styleRef.getStyleName(), true, false);
return infos.size() == 1 ? infos.get(0).computeXmlElement() : null;
}
Aggregations