use of kotlin.reflect.KParameter in project spring-framework by spring-projects.
the class KotlinReflectionParameterNameDiscoverer method getParameterNames.
@Nullable
private String[] getParameterNames(List<KParameter> parameters) {
List<KParameter> filteredParameters = parameters.stream().filter(p -> KParameter.Kind.VALUE.equals(p.getKind()) || KParameter.Kind.EXTENSION_RECEIVER.equals(p.getKind())).collect(Collectors.toList());
String[] parameterNames = new String[filteredParameters.size()];
for (int i = 0; i < filteredParameters.size(); i++) {
KParameter parameter = filteredParameters.get(i);
// extension receivers are not explicitly named, but require a name for Java interoperability
// $receiver is not a valid Kotlin identifier, but valid in Java, so it can be used here
String name = KParameter.Kind.EXTENSION_RECEIVER.equals(parameter.getKind()) ? "$receiver" : parameter.getName();
if (name == null) {
return null;
}
parameterNames[i] = name;
}
return parameterNames;
}
Aggregations