use of org.jetbrains.android.dom.attrs.AttributeFormat in project android by JetBrains.
the class EnumSupportFactory method supportsProperty.
public static boolean supportsProperty(@NotNull NlProperty property) {
switch(property.getName()) {
case ATTR_FONT_FAMILY:
case ATTR_TYPEFACE:
case ATTR_TEXT_SIZE:
case ATTR_LINE_SPACING_EXTRA:
case ATTR_TEXT_APPEARANCE:
case ATTR_LAYOUT_HEIGHT:
case ATTR_LAYOUT_WIDTH:
case ATTR_DROPDOWN_HEIGHT:
case ATTR_DROPDOWN_WIDTH:
case ATTR_ON_CLICK:
return true;
case ATTR_ID:
return false;
case ATTR_STYLE:
String tagName = property.getTagName();
return tagName != null && StyleFilter.hasWidgetStyles(property.getModel().getProject(), property.getResolver(), tagName);
default:
if (property.getName().endsWith(TEXT_APPEARANCE_SUFFIX)) {
return true;
}
if (AndroidDomUtil.SPECIAL_RESOURCE_TYPES.get(property.getName()) == ResourceType.ID) {
return true;
}
AttributeDefinition definition = property.getDefinition();
Set<AttributeFormat> formats = definition != null ? definition.getFormats() : Collections.emptySet();
return formats.contains(AttributeFormat.Enum);
}
}
use of org.jetbrains.android.dom.attrs.AttributeFormat in project android by JetBrains.
the class NlPropertyRenderers method get.
@NotNull
public static TableCellRenderer get(@NotNull NlProperty p) {
AttributeDefinition definition = p.getDefinition();
if (definition == null) {
return getDefaultRenderer();
}
Set<AttributeFormat> formats = definition.getFormats();
if (formats.size() == 1 && formats.contains(AttributeFormat.Boolean)) {
NlBooleanRenderer renderer = getBooleanRenderer();
if (renderer.canRender(p, formats)) {
return renderer;
}
}
if (formats.contains(AttributeFormat.Flag)) {
NlFlagRenderer renderer = getFlagRenderer();
if (renderer.canRender(p, formats)) {
return renderer;
}
}
return getDefaultRenderer();
}
use of org.jetbrains.android.dom.attrs.AttributeFormat in project android by JetBrains.
the class AndroidDomUtil method getConverter.
@Nullable
public static ResolvingConverter getConverter(@NotNull AttributeDefinition attr) {
Set<AttributeFormat> formats = attr.getFormats();
CompositeConverter.Builder compositeBuilder = new CompositeConverter.Builder();
String[] values = attr.getValues();
boolean containsUnsupportedFormats = false;
if ("fontFamily".equals(attr.getName())) {
compositeBuilder.addConverter(new StaticEnumConverter(AVAILABLE_FAMILIES).setContainsAllValues(false));
}
for (AttributeFormat format : formats) {
ResolvingConverter<String> converter = getStringConverter(format, values);
if (converter != null) {
compositeBuilder.addConverter(converter);
} else {
containsUnsupportedFormats = true;
}
}
ResourceReferenceConverter resConverter = getResourceReferenceConverter(attr);
if (formats.contains(AttributeFormat.Flag)) {
return new FlagConverter(compositeBuilder.build(), values);
}
if (resConverter == null && formats.contains(AttributeFormat.Enum)) {
resConverter = new ResourceReferenceConverter(EnumSet.of(ResourceType.INTEGER), attr);
resConverter.setQuiet(true);
}
ResolvingConverter<String> stringConverter = compositeBuilder.build();
if (resConverter != null) {
resConverter.setAdditionalConverter(stringConverter, containsUnsupportedFormats);
return resConverter;
}
return stringConverter;
}
use of org.jetbrains.android.dom.attrs.AttributeFormat in project android by JetBrains.
the class AndroidXmlDocumentationProvider method generateDocForXmlAttribute.
private static String generateDocForXmlAttribute(@NotNull AttributeDefinition definition, @Nullable String parentStyleable) {
final StringBuilder builder = new StringBuilder("<html><body>");
final Set<AttributeFormat> formats = definition.getFormats();
if (formats.size() > 0) {
builder.append("Formats: ");
final List<String> formatLabels = new ArrayList<>(formats.size());
for (AttributeFormat format : formats) {
formatLabels.add(format.name().toLowerCase(Locale.US));
}
Collections.sort(formatLabels);
for (int i = 0, n = formatLabels.size(); i < n; i++) {
builder.append(formatLabels.get(i));
if (i < n - 1) {
builder.append(", ");
}
}
}
final String[] values = definition.getValues();
if (values.length > 0) {
if (builder.length() > 0) {
builder.append("<br>");
}
builder.append("Values: ");
final String[] sortedValues = new String[values.length];
System.arraycopy(values, 0, sortedValues, 0, values.length);
Arrays.sort(sortedValues);
for (int i = 0; i < sortedValues.length; i++) {
builder.append(sortedValues[i]);
if (i < sortedValues.length - 1) {
builder.append(", ");
}
}
}
final String docValue = definition.getDocValue(parentStyleable);
if (docValue != null && docValue.length() > 0) {
if (builder.length() > 0) {
builder.append("<br><br>");
}
builder.append(docValue);
}
builder.append("</body></html>");
return builder.toString();
}
use of org.jetbrains.android.dom.attrs.AttributeFormat in project android by JetBrains.
the class BrowsePanel method getResourceTypes.
@NotNull
public static EnumSet<ResourceType> getResourceTypes(@NotNull String propertyName, @Nullable AttributeDefinition definition) {
Set<AttributeFormat> formats = definition != null ? definition.getFormats() : EnumSet.allOf(AttributeFormat.class);
// for some special known properties, we can narrow down the possible types (rather than the all encompassing reference type)
ResourceType type = AndroidDomUtil.SPECIAL_RESOURCE_TYPES.get(propertyName);
return type == null ? AttributeFormat.convertTypes(formats) : EnumSet.of(type);
}
Aggregations