Skip to content

Commit

Permalink
Support @name meta-annotations with Kotlin binding
Browse files Browse the repository at this point in the history
Update `ValueObjectBinder` Kotlin support to meta-annotations of
`@Named`.

See gh-24379
  • Loading branch information
philwebb committed Dec 10, 2020
1 parent 32e1289 commit 14816a6
Showing 1 changed file with 5 additions and 3 deletions.
Expand Up @@ -190,6 +190,8 @@ static <T> ValueObject<T> get(Bindable<T> bindable, BindConstructorProvider cons
*/
private static final class KotlinValueObject<T> extends ValueObject<T> {

private static final Annotation[] ANNOTATION_ARRAY = new Annotation[0];

private final List<ConstructorParameter> constructorParameters;

private KotlinValueObject(Constructor<T> primaryConstructor, KFunction<T> kotlinConstructor,
Expand All @@ -206,15 +208,15 @@ private List<ConstructorParameter> parseConstructorParameters(KFunction<T> kotli
String name = getParameterName(parameter);
ResolvableType parameterType = ResolvableType
.forType(ReflectJvmMapping.getJavaType(parameter.getType()), type);
Annotation[] annotations = parameter.getAnnotations().toArray(new Annotation[0]);
Annotation[] annotations = parameter.getAnnotations().toArray(ANNOTATION_ARRAY);
result.add(new ConstructorParameter(name, parameterType, annotations));
}
return Collections.unmodifiableList(result);
}

private String getParameterName(KParameter parameter) {
return parameter.getAnnotations().stream().filter(Name.class::isInstance).findFirst().map(Name.class::cast)
.map(Name::value).orElse(parameter.getName());
return MergedAnnotations.from(parameter, parameter.getAnnotations().toArray(ANNOTATION_ARRAY))
.get(Name.class).getValue(MergedAnnotation.VALUE, String.class).orElseGet(parameter::getName);
}

@Override
Expand Down

0 comments on commit 14816a6

Please sign in to comment.