use of org.jetbrains.android.dom.attrs.AttributeFormat in project android by JetBrains.
the class AndroidDomExtender method registerExtensions.
@Override
public void registerExtensions(@NotNull AndroidDomElement element, @NotNull final DomExtensionsRegistrar registrar) {
final AndroidFacet facet = AndroidFacet.getInstance(element);
if (facet == null) {
return;
}
AttributeProcessingUtil.processAttributes(element, facet, true, (xmlName, attrDef, parentStyleableName) -> {
Set<AttributeFormat> formats = attrDef.getFormats();
Class valueClass = formats.size() == 1 ? getValueClass(formats.iterator().next()) : String.class;
registrar.registerAttributeChildExtension(xmlName, GenericAttributeValue.class);
return registrar.registerGenericAttributeValueChildExtension(xmlName, valueClass);
});
SubtagsProcessingUtil.processSubtags(facet, element, registrar::registerCollectionChildrenExtension);
}
use of org.jetbrains.android.dom.attrs.AttributeFormat in project android by JetBrains.
the class AndroidDomUtil method getResourceReferenceConverter.
@Nullable
public static ResourceReferenceConverter getResourceReferenceConverter(@NotNull AttributeDefinition attr) {
boolean containsReference = false;
boolean containsNotReference = false;
Set<ResourceType> resourceTypes = EnumSet.noneOf(ResourceType.class);
Set<AttributeFormat> formats = attr.getFormats();
for (AttributeFormat format : formats) {
if (format == AttributeFormat.Reference) {
containsReference = true;
} else {
containsNotReference = true;
}
ResourceType type = getResourceType(format);
if (type != null) {
resourceTypes.add(type);
}
}
ResourceType specialResourceType = getSpecialResourceType(attr.getName());
if (specialResourceType != null) {
resourceTypes.add(specialResourceType);
}
if (containsReference) {
if (resourceTypes.contains(ResourceType.COLOR)) {
resourceTypes.add(ResourceType.DRAWABLE);
}
if (resourceTypes.contains(ResourceType.DRAWABLE)) {
resourceTypes.add(ResourceType.MIPMAP);
}
if (resourceTypes.size() == 0) {
resourceTypes.addAll(AndroidResourceUtil.REFERRABLE_RESOURCE_TYPES);
}
}
if (resourceTypes.size() > 0) {
final ResourceReferenceConverter converter = new ResourceReferenceConverter(resourceTypes, attr);
converter.setAllowLiterals(containsNotReference);
return converter;
}
return null;
}
use of org.jetbrains.android.dom.attrs.AttributeFormat in project android by JetBrains.
the class RenderErrorContributor method reportTagResourceFormat.
private void reportTagResourceFormat(@NotNull RenderResult result, @NotNull RenderProblem message) {
Object clientData = message.getClientData();
if (!(clientData instanceof String[])) {
return;
}
String[] strings = (String[]) clientData;
if (strings.length != 2) {
return;
}
RenderTask renderTask = result.getRenderTask();
if (renderTask == null) {
return;
}
IAndroidTarget target = renderTask.getConfiguration().getRealTarget();
if (target == null) {
return;
}
AndroidPlatform platform = renderTask.getPlatform();
if (platform == null) {
return;
}
AndroidTargetData targetData = platform.getSdkData().getTargetData(target);
AttributeDefinitions definitionLookup = targetData.getPublicAttrDefs(result.getFile().getProject());
final String attributeName = strings[0];
final String currentValue = strings[1];
if (definitionLookup == null) {
return;
}
AttributeDefinition definition = definitionLookup.getAttrDefByName(attributeName);
if (definition == null) {
return;
}
Set<AttributeFormat> formats = definition.getFormats();
if (formats.contains(AttributeFormat.Flag) || formats.contains(AttributeFormat.Enum)) {
String[] values = definition.getValues();
if (values.length > 0) {
HtmlBuilder builder = new HtmlBuilder();
builder.add("Change ").add(currentValue).add(" to: ");
boolean first = true;
for (String value : values) {
if (first) {
first = false;
} else {
builder.add(", ");
}
builder.addLink(value, myLinkManager.createReplaceAttributeValueUrl(attributeName, currentValue, value));
}
addRefreshAction(builder);
addIssue().setSummary("Incorrect resource value format").setHtmlContent(builder).build();
}
}
}
use of org.jetbrains.android.dom.attrs.AttributeFormat in project android by JetBrains.
the class ResolutionUtils method getAttrType.
@Nullable
public static /*if we can't work out the type, e.g a 'reference' with a '@null' value or enum*/
ResourceType getAttrType(@NotNull ItemResourceValue item, @NotNull Configuration configuration) {
ResourceResolver resolver = configuration.getResourceResolver();
assert resolver != null;
ResourceValue resolvedValue = resolver.resolveResValue(item);
ResourceType attrType = resolvedValue.getResourceType();
if (attrType != null) {
return attrType;
} else {
AttributeDefinition def = getAttributeDefinition(configuration, item);
if (def != null) {
for (AttributeFormat attrFormat : def.getFormats()) {
attrType = AndroidDomUtil.getResourceType(attrFormat);
if (attrType != null) {
return attrType;
}
}
}
}
// sometimes we won't find the type of the attr, this means it's either a reference that points to @null, or a enum
return null;
}
use of org.jetbrains.android.dom.attrs.AttributeFormat in project android by JetBrains.
the class NlPropertyEditors method getEditorType.
@NotNull
private static EditorType getEditorType(@NotNull NlProperty property) {
AttributeDefinition definition = property.getDefinition();
Set<AttributeFormat> formats = definition != null ? definition.getFormats() : Collections.emptySet();
Boolean isBoolean = null;
for (AttributeFormat format : formats) {
switch(format) {
case Boolean:
if (isBoolean == null) {
isBoolean = Boolean.TRUE;
}
break;
case String:
case Color:
case Dimension:
case Integer:
case Float:
case Fraction:
if (isBoolean == null) {
isBoolean = Boolean.FALSE;
}
break;
case Enum:
return EditorType.COMBO;
case Flag:
return EditorType.FLAG;
default:
break;
}
}
// Do not inline this method. Other classes should not know about EnumSupportFactory.
if (isBoolean == Boolean.TRUE) {
return EditorType.BOOLEAN;
} else if (EnumSupportFactory.supportsProperty(property)) {
if (property.getName().equals(ATTR_STYLE)) {
return EditorType.COMBO_WITH_BROWSE;
}
return EditorType.COMBO;
}
return EditorType.DEFAULT;
}
Aggregations