DATACMNS-1779 - Consider kotlin.Unit a simple type.

kotlin.Unit is now considered a simple type to avoid PersistentEntity creation.

ReflectionUtils.isVoid(…) now encapsulates the check so that calling code doesn't need to check if Kotlin is on the class path.
This commit is contained in:
Mark Paluch
2020-07-31 10:49:52 +02:00
parent 837dd0789e
commit bb4d621a32
4 changed files with 36 additions and 3 deletions

View File

@@ -156,7 +156,7 @@ public class SimpleTypeHolder {
String typeName = type.getName();
if (typeName.startsWith("java.lang") || type.getName().startsWith("java.time")) {
if (typeName.startsWith("java.lang") || type.getName().startsWith("java.time") || typeName.equals("kotlin.Unit")) {
return true;
}

View File

@@ -160,7 +160,7 @@ public class MethodInvocationValidator implements MethodInterceptor {
}
private static boolean requiresNoValue(MethodParameter parameter) {
return parameter.getParameterType().equals(Void.class) || parameter.getParameterType().equals(Void.TYPE);
return ReflectionUtils.isVoid(parameter.getParameterType());
}
public boolean[] getNullableParameters() {

View File

@@ -70,6 +70,27 @@ public final class ReflectionUtils {
}
}
/**
* Check whether the given {@code type} represents a void type such as {@code void}, {@link Void} or Kotlin
* {@code Unit}.
*
* @param type must not be {@literal null}.
* @return whether the given the type is a void type.
* @since 2.4
*/
public static boolean isVoid(Class<?> type) {
if (type == Void.class || Void.TYPE == type) {
return true;
}
if (type.getName().equals("kotlin.Unit")) {
return true;
}
return false;
}
/**
* A {@link FieldFilter} that has a description.
*
@@ -399,7 +420,7 @@ public final class ReflectionUtils {
*/
public static boolean isNullable(MethodParameter parameter) {
if (Void.class.equals(parameter.getParameterType()) || Void.TYPE.equals(parameter.getParameterType())) {
if (isVoid(parameter.getParameterType())) {
return true;
}