Skip to content

Commit

Permalink
ClassUtils: deprecate methods with typos
Browse files Browse the repository at this point in the history
The `ClassUtils.isKotlinFaction0()` and `ClassUtils.isKotlinFaction1()`
are wrong names.

* Deprecate `ClassUtils.isKotlinFaction0()` and `ClassUtils.isKotlinFaction1()`
in favor of newly introduced `isKotlinFunction0()` and `isKotlinFunction1()`

**Cherry-pick to `main`**
  • Loading branch information
artembilan committed Jul 9, 2022
1 parent e0f1379 commit f12248f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,6 @@ private MessageHandler registerHandlerBean(String beanName, Method method, final
return this.beanFactory.getBean(handlerBeanName, MessageHandler.class);
}

private void orderable(Method method, MessageHandler handler) {
if (handler instanceof Orderable) {
Order orderAnnotation = AnnotationUtils.findAnnotation(method, Order.class);
if (orderAnnotation != null) {
((Orderable) handler).setOrder(orderAnnotation.value());
}
}
}

private void producerOrRouter(List<Annotation> annotations, MessageHandler handler) {
if (handler instanceof AbstractMessageProducingHandler || handler instanceof AbstractMessageRouter) {
String sendTimeout = MessagingAnnotationUtils.resolveAttribute(annotations, "sendTimeout", String.class);
Expand Down Expand Up @@ -608,7 +599,7 @@ protected boolean resolveAttributeToBoolean(String attribute) {
@Nullable
protected MessageProcessor<?> buildLambdaMessageProcessorForBeanMethod(Method method, Object target) {
if ((target instanceof Function || target instanceof Consumer) && ClassUtils.isLambda(target.getClass())
|| ClassUtils.isKotlinFaction1(target.getClass())) {
|| ClassUtils.isKotlinFunction1(target.getClass())) {

ResolvableType methodReturnType = ResolvableType.forMethodReturnType(method);
Class<?> expectedPayloadType = methodReturnType.getGeneric(0).toClass();
Expand All @@ -619,6 +610,15 @@ protected MessageProcessor<?> buildLambdaMessageProcessorForBeanMethod(Method me
}
}

private static void orderable(Method method, MessageHandler handler) {
if (handler instanceof Orderable) {
Order orderAnnotation = AnnotationUtils.findAnnotation(method, Order.class);
if (orderAnnotation != null) {
((Orderable) handler).setOrder(orderAnnotation.value());
}
}
}

/**
* Subclasses must implement this method to create the MessageHandler.
* @param bean The bean.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ private MessageSource<?> createMessageSource(Object beanArg, String beanNameArg,
Class<?> targetClass = target.getClass();
Assert.isTrue(MessageSource.class.isAssignableFrom(targetClass) ||
Supplier.class.isAssignableFrom(targetClass) ||
ClassUtils.isKotlinFaction0(targetClass),
ClassUtils.isKotlinFunction0(targetClass),
() -> "The '" + this.annotationType + "' on @Bean method " + "level is allowed only for: " +
MessageSource.class.getName() + " or " + Supplier.class.getName() +
MessageSource.class.getName() + ", or " + Supplier.class.getName() +
(ClassUtils.KOTLIN_FUNCTION_0_CLASS != null
? " or " + ClassUtils.KOTLIN_FUNCTION_0_CLASS.getName()
? ", or " + ClassUtils.KOTLIN_FUNCTION_0_CLASS.getName()
: "") + " beans");
if (target instanceof MessageSource<?>) {
messageSource = (MessageSource<?>) target;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -250,21 +250,46 @@ public static boolean isLambda(Class<?> aClass) {
* @param aClass the {@link Class} to check.
* @return true if class is a {@code kotlin.jvm.functions.Function0} implementation.
* @since 5.2
* @deprecated since 5.5.14 in favor of {@link #isKotlinFunction0(Class)}
*/
@Deprecated
public static boolean isKotlinFaction0(Class<?> aClass) {
return KOTLIN_FUNCTION_0_CLASS != null && KOTLIN_FUNCTION_0_CLASS.isAssignableFrom(aClass);
}

/**
* Check if class is {@code kotlin.jvm.functions.Function0}.
* @param aClass the {@link Class} to check.
* @return true if class is a {@code kotlin.jvm.functions.Function0} implementation.
* @since 5.5.14
*/
public static boolean isKotlinFunction0(Class<?> aClass) {
return KOTLIN_FUNCTION_0_CLASS != null && KOTLIN_FUNCTION_0_CLASS.isAssignableFrom(aClass);
}

/**
* Check if class is {@code kotlin.jvm.functions.Function1}.
* @param aClass the {@link Class} to check.
* @return true if class is a {@code kotlin.jvm.functions.Function1} implementation.
* @since 5.2
* @deprecated since 5.5.14 in favor of {@link #isKotlinFunction1(Class)}
*/
@Deprecated
public static boolean isKotlinFaction1(Class<?> aClass) {
return KOTLIN_FUNCTION_1_CLASS != null && KOTLIN_FUNCTION_1_CLASS.isAssignableFrom(aClass);
}

/**
* Check if class is {@code kotlin.jvm.functions.Function1}.
* @param aClass the {@link Class} to check.
* @return true if class is a {@code kotlin.jvm.functions.Function1} implementation.
* @since 5.5.14
*/
public static boolean isKotlinFunction1(Class<?> aClass) {
return KOTLIN_FUNCTION_1_CLASS != null && KOTLIN_FUNCTION_1_CLASS.isAssignableFrom(aClass);
}


/**
* Check if class is {@code kotlin.Unit}.
* @param aClass the {@link Class} to check.
Expand Down

0 comments on commit f12248f

Please sign in to comment.