Polish Coroutines detection
This commit is contained in:
@@ -16,13 +16,10 @@
|
||||
|
||||
package org.springframework.messaging.handler.invocation.reactive;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import kotlin.reflect.KFunction;
|
||||
import kotlin.reflect.jvm.ReflectJvmMapping;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.reactivestreams.Publisher;
|
||||
@@ -135,9 +132,7 @@ public abstract class AbstractEncoderMethodReturnValueHandler implements Handler
|
||||
ResolvableType elementType;
|
||||
if (adapter != null) {
|
||||
publisher = adapter.toPublisher(content);
|
||||
boolean isUnwrapped = KotlinDetector.isKotlinReflectPresent() &&
|
||||
KotlinDetector.isKotlinType(returnType.getContainingClass()) &&
|
||||
KotlinDelegate.isSuspend(returnType.getMethod()) &&
|
||||
boolean isUnwrapped = KotlinDetector.isSuspendingFunction(returnType.getMethod()) &&
|
||||
!COROUTINES_FLOW_CLASS_NAME.equals(returnValueType.toClass().getName());
|
||||
ResolvableType genericType = isUnwrapped ? returnValueType : returnValueType.getGeneric();
|
||||
elementType = getElementType(adapter, genericType);
|
||||
@@ -218,19 +213,4 @@ public abstract class AbstractEncoderMethodReturnValueHandler implements Handler
|
||||
*/
|
||||
protected abstract Mono<Void> handleNoContent(MethodParameter returnType, Message<?> message);
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on Kotlin at runtime.
|
||||
*/
|
||||
private static class KotlinDelegate {
|
||||
|
||||
private static boolean isSuspend(@Nullable Method method) {
|
||||
if (method == null) {
|
||||
return false;
|
||||
}
|
||||
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
|
||||
return (function != null && function.isSuspend());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,13 +16,10 @@
|
||||
|
||||
package org.springframework.web.reactive.result.method.annotation;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import kotlin.reflect.KFunction;
|
||||
import kotlin.reflect.jvm.ReflectJvmMapping;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -131,9 +128,7 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa
|
||||
ResolvableType actualElementType;
|
||||
if (adapter != null) {
|
||||
publisher = adapter.toPublisher(body);
|
||||
boolean isUnwrapped = KotlinDetector.isKotlinReflectPresent() &&
|
||||
KotlinDetector.isKotlinType(bodyParameter.getContainingClass()) &&
|
||||
KotlinDelegate.isSuspend(bodyParameter.getMethod()) &&
|
||||
boolean isUnwrapped = KotlinDetector.isSuspendingFunction(bodyParameter.getMethod()) &&
|
||||
!COROUTINES_FLOW_CLASS_NAME.equals(bodyType.toClass().getName());
|
||||
ResolvableType genericType = isUnwrapped ? bodyType : bodyType.getGeneric();
|
||||
elementType = getElementType(adapter, genericType);
|
||||
@@ -203,16 +198,4 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa
|
||||
return writableMediaTypes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on Kotlin at runtime.
|
||||
*/
|
||||
private static class KotlinDelegate {
|
||||
|
||||
private static boolean isSuspend(Method method) {
|
||||
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
|
||||
return function != null && function.isSuspend();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user