use of com.taobao.android.builder.extension.annotation.Config in project atlas by alibaba.
the class AtlasConfigHelper method readConfig.
private static void readConfig(Object object, String prefix, List<AtlasConfigField> configFieldList, int groupOrder, String variantName) throws IllegalAccessException {
if (null == object) {
return;
}
for (Field field : getAllFields(object.getClass())) {
field.setAccessible(true);
Config config = field.getAnnotation(Config.class);
if (null != config) {
AtlasConfigField configField = new AtlasConfigField();
configField.name = prefix + "." + field.getName();
configField.order = config.order();
configField.desc = config.message();
Object obj = field.get(object);
configField.value = (null == obj ? null : String.valueOf(obj));
configField.groupOrder = groupOrder;
configField.variantName = variantName;
configField.type = field.getType().getSimpleName();
configField.advanced = config.advance();
configFieldList.add(configField);
continue;
}
ConfigGroup configGroup = field.getAnnotation(ConfigGroup.class);
if (null != configGroup) {
Object nestedValue = field.get(object);
if (nestedValue instanceof NamedDomainObjectContainer) {
readConfig(((NamedDomainObjectContainer) nestedValue).maybeCreate("debug"), prefix + "." + field.getName() + ".debug", configFieldList, configGroup.order(), "debug");
readConfig(((NamedDomainObjectContainer) nestedValue).maybeCreate("release"), prefix + "." + field.getName() + ".release", configFieldList, configGroup.order(), "release");
} else {
readConfig(nestedValue, prefix + "." + field.getName(), configFieldList, configGroup.order(), "");
}
}
}
}
Aggregations