From 7d8dda9a5ac6b05edb0bbb9d23edf44a3c465554 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 18 Apr 2017 23:25:44 -0400 Subject: [PATCH] Polish reactive type support in Conventions --- .../org/springframework/core/Conventions.java | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/Conventions.java b/spring-core/src/main/java/org/springframework/core/Conventions.java index a1b3c62315..1fbeeae686 100644 --- a/spring-core/src/main/java/org/springframework/core/Conventions.java +++ b/spring-core/src/main/java/org/springframework/core/Conventions.java @@ -36,6 +36,7 @@ import org.springframework.util.ClassUtils; * * @author Rob Harrop * @author Juergen Hoeller + * @author Rossen Stoyanchev * @since 2.0 */ public abstract class Conventions { @@ -108,6 +109,12 @@ public abstract class Conventions { /** * Determine the conventional variable name for the given parameter taking * the generic collection type, if any, into account. + * + *

As of 5.0 this method supports reactive types:
+ * {@code Mono} becomes {@code "productMono"}
+ * {@code Flux} becomes {@code "myProductFlux"}
+ * {@code Observable} becomes {@code "myProductObservable"}
+ * * @param parameter the method or constructor parameter * @return the generated variable name */ @@ -132,10 +139,12 @@ public abstract class Conventions { else { valueClass = parameter.getParameterType(); - ReactiveAdapter adapter = reactiveAdapterRegistry.getAdapter(valueClass); - if (adapter != null && !adapter.getDescriptor().isNoValue()) { - reactiveSuffix = ClassUtils.getShortName(valueClass); - valueClass = parameter.nested().getNestedParameterType(); + if (reactiveAdapterRegistry.hasAdapters()) { + ReactiveAdapter adapter = reactiveAdapterRegistry.getAdapter(valueClass); + if (adapter != null && !adapter.getDescriptor().isNoValue()) { + reactiveSuffix = ClassUtils.getShortName(valueClass); + valueClass = parameter.nested().getNestedParameterType(); + } } } @@ -171,6 +180,12 @@ public abstract class Conventions { * method, taking the generic collection type, if any, into account, falling * back on the given return value if the method declaration is not specific * enough, e.g. {@code Object} return type or untyped collection. + * + *

As of 5.0 this method supports reactive types:
+ * {@code Mono} becomes {@code "productMono"}
+ * {@code Flux} becomes {@code "myProductFlux"}
+ * {@code Observable} becomes {@code "myProductObservable"}
+ * * @param method the method to generate a variable name for * @param resolvedType the resolved return type of the method * @param value the return value (may be {@code null} if not available) @@ -215,10 +230,12 @@ public abstract class Conventions { else { valueClass = resolvedType; - ReactiveAdapter adapter = reactiveAdapterRegistry.getAdapter(valueClass); - if (adapter != null && !adapter.getDescriptor().isNoValue()) { - reactiveSuffix = ClassUtils.getShortName(valueClass); - valueClass = ResolvableType.forMethodReturnType(method).getGeneric(0).resolve(); + if (reactiveAdapterRegistry.hasAdapters()) { + ReactiveAdapter adapter = reactiveAdapterRegistry.getAdapter(valueClass); + if (adapter != null && !adapter.getDescriptor().isNoValue()) { + reactiveSuffix = ClassUtils.getShortName(valueClass); + valueClass = ResolvableType.forMethodReturnType(method).getGeneric(0).resolve(); + } } }