Merge pull request #3 from embeddedt/master

Add support for string list configs
This commit is contained in:
FalsePattern authored and GitHub committed 2022-06-10 12:27:20 +02:00
commit 971dafaaf7
2 files changed
+10

No files matched your search

@@ -91,6 +91,12 @@ public @interface Config {
String value();
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface DefaultStringList {
String[] value();
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface Name {
@@ -155,6 +155,10 @@ public class ConfigurationManager {
configClass.getName() + "! Using default value of " + defaultValue + "!");
field.set(null, defaultValue);
}
} else if (fieldClass.isArray() && fieldClass.getComponentType().equals(String.class)) {
val defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultStringList.class)).map(Config.DefaultStringList::value).orElse((String[])field.get(null));
var value = rawConfig.getStringList(name, category, defaultValue, comment, null, langKey);
field.set(null, value);
} else {
throw new ConfigException("Illegal config field: " + field.getName() + " in " + configClass.getName() +
": Unsupported type " + fieldClass.getName() +