/** * Find the appropriate discoverer for {@code type}. * * @param type must not be {@literal null}. * @return the appropriate discoverer for {@code type}. */ private static Discoverers findDiscoverer(Class<?> type) { return ReflectionUtils.isSupportedKotlinClass(type) ? KOTLIN : DEFAULT; }
/** * Returns {@literal} whether the given {@link MethodParameter} is nullable. Nullable parameters are reference types * and ones that are defined in Kotlin as such. * * @return {@literal true} if {@link MethodParameter} is nullable. * @since 2.0 */ public static boolean isNullable(MethodParameter parameter) { if (Void.class.equals(parameter.getParameterType()) || Void.TYPE.equals(parameter.getParameterType())) { return true; } if (isSupportedKotlinClass(parameter.getDeclaringClass())) { return KotlinReflectionUtils.isNullable(parameter); } return !parameter.getParameterType().isPrimitive(); }
private static String toString(PreferredConstructor<?, ?> preferredConstructor) { Constructor<?> constructor = preferredConstructor.getConstructor(); if (ReflectionUtils.isSupportedKotlinClass(constructor.getDeclaringClass())) { KFunction<?> kotlinFunction = ReflectJvmMapping.getKotlinFunction(constructor); if (kotlinFunction != null) { return kotlinFunction.toString(); } } return constructor.toString(); }
/** * Returns {@literal true} if the {@code repositoryInterface} is supported by this interceptor. * * @param repositoryInterface the interface class. * @return {@literal true} if the {@code repositoryInterface} is supported by this interceptor. */ public static boolean supports(Class<?> repositoryInterface) { return ReflectionUtils.isSupportedKotlinClass(repositoryInterface) || NullableUtils.isNonNull(repositoryInterface, ElementType.METHOD) || NullableUtils.isNonNull(repositoryInterface, ElementType.PARAMETER); }
private static boolean isNullableParameter(MethodParameter parameter) { return requiresNoValue(parameter) || NullableUtils.isExplicitNullable(parameter) || (ReflectionUtils.isSupportedKotlinClass(parameter.getDeclaringClass()) && ReflectionUtils.isNullable(parameter)); }
/** * Returns whether a {@link PersistentEntity} instance should be created for the given {@link TypeInformation}. By * default this will reject all types considered simple and non-supported Kotlin classes, but it might be necessary to * tweak that in case you have registered custom converters for top level types (which renders them to be considered * simple) but still need meta-information about them. * <p/> * * @param type will never be {@literal null}. * @return */ protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) { if (simpleTypeHolder.isSimpleType(type.getType())) { return false; } return !org.springframework.data.util.ReflectionUtils.isKotlinClass(type.getType()) || org.springframework.data.util.ReflectionUtils.isSupportedKotlinClass(type.getType()); }
@Override protected EntityInstantiator doCreateEntityInstantiator(PersistentEntity<?, ?> entity) { PreferredConstructor<?, ?> constructor = entity.getPersistenceConstructor(); if (ReflectionUtils.isSupportedKotlinClass(entity.getType()) && constructor != null) { PreferredConstructor<?, ?> defaultConstructor = new DefaultingKotlinConstructorResolver(entity) .getDefaultConstructor(); if (defaultConstructor != null) { ObjectInstantiator instantiator = createObjectInstantiator(entity, defaultConstructor); return new DefaultingKotlinClassInstantiatorAdapter(instantiator, constructor); } } return super.doCreateEntityInstantiator(entity); }