Skip to content

Commit 8c0a64d

Browse files
authored
3542 iterable configuration option (helidon-io#3600)
* Added `Iterable` to the allowed types. * Added Null check for argument type. * Switched operands in null check. * `allowedValues` method should just check for enum or return an empty list.
1 parent 5aee7c0 commit 8c0a64d

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

config/metadata-processor/src/main/java/io/helidon/config/metadata/processor/ConfigMetadataHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ConfigMetadataHandler {
8989
private TypeMirror builderType;
9090
private TypeMirror configType;
9191
private TypeMirror erasedListType;
92+
private TypeMirror erasedIterableType;
9293
private TypeMirror erasedSetType;
9394
private TypeMirror erasedMapType;
9495

@@ -111,6 +112,7 @@ synchronized void init(ProcessingEnvironment processingEnv) {
111112
configType = elementUtils.getTypeElement("io.helidon.config.Config").asType();
112113
erasedListType = typeUtils.erasure(elementUtils.getTypeElement(List.class.getName()).asType());
113114
erasedSetType = typeUtils.erasure(elementUtils.getTypeElement(Set.class.getName()).asType());
115+
erasedIterableType = typeUtils.erasure(elementUtils.getTypeElement(Iterable.class.getName()).asType());
114116
erasedMapType = typeUtils.erasure(elementUtils.getTypeElement(Map.class.getName()).asType());
115117
}
116118

@@ -570,7 +572,8 @@ private OptionType type(ConfiguredOptionData annotation, ExecutableElement eleme
570572
TypeMirror paramType = parameter.asType();
571573
TypeMirror erasedType = typeUtils.erasure(paramType);
572574

573-
if (typeUtils.isSameType(erasedType, erasedListType) || typeUtils.isSameType(erasedType, erasedSetType)) {
575+
if (typeUtils.isSameType(erasedType, erasedListType) || typeUtils.isSameType(erasedType, erasedSetType)
576+
|| typeUtils.isSameType(erasedType, erasedIterableType)) {
574577
DeclaredType type = (DeclaredType) paramType;
575578
TypeMirror genericType = type.getTypeArguments().get(0);
576579
return new OptionType(genericType.toString(), "LIST");
@@ -697,7 +700,7 @@ String toConfigKey(String methodName) {
697700
}
698701

699702
static List<AllowedValue> allowedValues(Elements elementUtils, TypeElement typeElement) {
700-
if (typeElement.getKind() == ElementKind.ENUM) {
703+
if (typeElement != null && typeElement.getKind() == ElementKind.ENUM) {
701704
return typeElement.getEnclosedElements()
702705
.stream()
703706
.filter(element -> element.getKind().equals(ElementKind.ENUM_CONSTANT))

config/metadata/src/main/java/io/helidon/config/metadata/ConfiguredOption.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@
104104
/**
105105
* Kind of this option.
106106
* Defaults to {@link Kind#VALUE},
107-
* autodetects {@link Kind#LIST} if the parameter is an actual {@link java.util.List} or {@link java.util.Set}.
107+
* autodetects {@link Kind#LIST} if the parameter is an actual {@link java.util.List}, {@link java.util.Set}
108+
* or {@link java.lang.Iterable}.
108109
* {@link Kind#MAP} is detected as well, though the type must be a String to a primitive or string
109110
*
110111
* @return kind of configuration option

0 commit comments

Comments
 (0)