Commit 14816a6b authored by Phillip Webb's avatar Phillip Webb

Support @Name meta-annotations with Kotlin binding

Update `ValueObjectBinder` Kotlin support to meta-annotations of
`@Named`.

See gh-24379
parent 32e1289b
...@@ -190,6 +190,8 @@ class ValueObjectBinder implements DataObjectBinder { ...@@ -190,6 +190,8 @@ class ValueObjectBinder implements DataObjectBinder {
*/ */
private static final class KotlinValueObject<T> extends ValueObject<T> { private static final class KotlinValueObject<T> extends ValueObject<T> {
private static final Annotation[] ANNOTATION_ARRAY = new Annotation[0];
private final List<ConstructorParameter> constructorParameters; private final List<ConstructorParameter> constructorParameters;
private KotlinValueObject(Constructor<T> primaryConstructor, KFunction<T> kotlinConstructor, private KotlinValueObject(Constructor<T> primaryConstructor, KFunction<T> kotlinConstructor,
...@@ -206,15 +208,15 @@ class ValueObjectBinder implements DataObjectBinder { ...@@ -206,15 +208,15 @@ class ValueObjectBinder implements DataObjectBinder {
String name = getParameterName(parameter); String name = getParameterName(parameter);
ResolvableType parameterType = ResolvableType ResolvableType parameterType = ResolvableType
.forType(ReflectJvmMapping.getJavaType(parameter.getType()), type); .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)); result.add(new ConstructorParameter(name, parameterType, annotations));
} }
return Collections.unmodifiableList(result); return Collections.unmodifiableList(result);
} }
private String getParameterName(KParameter parameter) { private String getParameterName(KParameter parameter) {
return parameter.getAnnotations().stream().filter(Name.class::isInstance).findFirst().map(Name.class::cast) return MergedAnnotations.from(parameter, parameter.getAnnotations().toArray(ANNOTATION_ARRAY))
.map(Name::value).orElse(parameter.getName()); .get(Name.class).getValue(MergedAnnotation.VALUE, String.class).orElseGet(parameter::getName);
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment