Fixing formatting
This commit is contained in:
@@ -57,7 +57,6 @@ import org.springframework.util.ReflectionUtils;
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set of utility operations to interrogate function definitions.
|
* Set of utility operations to interrogate function definitions.
|
||||||
*
|
*
|
||||||
@@ -69,7 +68,7 @@ import org.springframework.util.StringUtils;
|
|||||||
*/
|
*/
|
||||||
public final class FunctionTypeUtils {
|
public final class FunctionTypeUtils {
|
||||||
|
|
||||||
private static Log logger = LogFactory.getLog(FunctionTypeUtils.class);
|
private static Log logger = LogFactory.getLog(FunctionTypeUtils.class);
|
||||||
|
|
||||||
private FunctionTypeUtils() {
|
private FunctionTypeUtils() {
|
||||||
|
|
||||||
@@ -77,17 +76,17 @@ public final class FunctionTypeUtils {
|
|||||||
|
|
||||||
public static Type functionType(Type input, Type output) {
|
public static Type functionType(Type input, Type output) {
|
||||||
return ResolvableType.forClassWithGenerics(Function.class,
|
return ResolvableType.forClassWithGenerics(Function.class,
|
||||||
ResolvableType.forType(input), ResolvableType.forType(output)).getType();
|
ResolvableType.forType(input), ResolvableType.forType(output)).getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type consumerType(Type input) {
|
public static Type consumerType(Type input) {
|
||||||
return ResolvableType.forClassWithGenerics(Consumer.class,
|
return ResolvableType.forClassWithGenerics(Consumer.class,
|
||||||
ResolvableType.forType(input)).getType();
|
ResolvableType.forType(input)).getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type supplierType(Type output) {
|
public static Type supplierType(Type output) {
|
||||||
return ResolvableType.forClassWithGenerics(Supplier.class,
|
return ResolvableType.forClassWithGenerics(Supplier.class,
|
||||||
ResolvableType.forType(output)).getType();
|
ResolvableType.forType(output)).getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,7 +146,7 @@ public final class FunctionTypeUtils {
|
|||||||
*/
|
*/
|
||||||
public static Class<?> getRawType(Type type) {
|
public static Class<?> getRawType(Type type) {
|
||||||
return type != null ? TypeResolver
|
return type != null ? TypeResolver
|
||||||
.resolveRawClass(type instanceof GenericArrayType ? type : TypeResolver.reify(type), null) : null;
|
.resolveRawClass(type instanceof GenericArrayType ? type : TypeResolver.reify(type), null) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,15 +161,15 @@ public final class FunctionTypeUtils {
|
|||||||
public static Method discoverFunctionalMethod(Class<?> pojoFunctionClass) {
|
public static Method discoverFunctionalMethod(Class<?> pojoFunctionClass) {
|
||||||
if (Supplier.class.isAssignableFrom(pojoFunctionClass)) {
|
if (Supplier.class.isAssignableFrom(pojoFunctionClass)) {
|
||||||
return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> !m.isSynthetic()
|
return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> !m.isSynthetic()
|
||||||
&& m.getName().equals("get")).findFirst().get();
|
&& m.getName().equals("get")).findFirst().get();
|
||||||
}
|
}
|
||||||
else if (Consumer.class.isAssignableFrom(pojoFunctionClass) || BiConsumer.class.isAssignableFrom(pojoFunctionClass)) {
|
else if (Consumer.class.isAssignableFrom(pojoFunctionClass) || BiConsumer.class.isAssignableFrom(pojoFunctionClass)) {
|
||||||
return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> !m.isSynthetic()
|
return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> !m.isSynthetic()
|
||||||
&& m.getName().equals("accept")).findFirst().get();
|
&& m.getName().equals("accept")).findFirst().get();
|
||||||
}
|
}
|
||||||
else if (Function.class.isAssignableFrom(pojoFunctionClass) || BiFunction.class.isAssignableFrom(pojoFunctionClass)) {
|
else if (Function.class.isAssignableFrom(pojoFunctionClass) || BiFunction.class.isAssignableFrom(pojoFunctionClass)) {
|
||||||
return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> !m.isSynthetic()
|
return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> !m.isSynthetic()
|
||||||
&& m.getName().equals("apply")).findFirst().get();
|
&& m.getName().equals("apply")).findFirst().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Method> methods = new ArrayList<>();
|
List<Method> methods = new ArrayList<>();
|
||||||
@@ -181,10 +180,10 @@ public final class FunctionTypeUtils {
|
|||||||
|
|
||||||
}, method ->
|
}, method ->
|
||||||
!method.getDeclaringClass().isAssignableFrom(Object.class)
|
!method.getDeclaringClass().isAssignableFrom(Object.class)
|
||||||
&& !method.isSynthetic() && !method.isBridge() && !method.isVarArgs());
|
&& !method.isSynthetic() && !method.isBridge() && !method.isVarArgs());
|
||||||
|
|
||||||
Assert.isTrue(methods.size() == 1, "Discovered " + methods.size() + " methods that would qualify as 'functional' - "
|
Assert.isTrue(methods.size() == 1, "Discovered " + methods.size() + " methods that would qualify as 'functional' - "
|
||||||
+ methods + ".\n Class '" + pojoFunctionClass + "' is not a FunctionalInterface.");
|
+ methods + ".\n Class '" + pojoFunctionClass + "' is not a FunctionalInterface.");
|
||||||
|
|
||||||
return methods.get(0);
|
return methods.get(0);
|
||||||
}
|
}
|
||||||
@@ -207,7 +206,8 @@ public final class FunctionTypeUtils {
|
|||||||
if (Function.class.isAssignableFrom(functionalClass)) {
|
if (Function.class.isAssignableFrom(functionalClass)) {
|
||||||
for (Type superInterface : functionalClass.getGenericInterfaces()) {
|
for (Type superInterface : functionalClass.getGenericInterfaces()) {
|
||||||
if (superInterface != null && !superInterface.equals(Object.class)) {
|
if (superInterface != null && !superInterface.equals(Object.class)) {
|
||||||
if (superInterface.toString().contains("KStream") && ResolvableType.forType(superInterface).getGeneric(1).isArray()) {
|
if (superInterface.toString().contains("KStream") && ResolvableType.forType(superInterface)
|
||||||
|
.getGeneric(1).isArray()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,25 +256,25 @@ public final class FunctionTypeUtils {
|
|||||||
*/
|
*/
|
||||||
public static Type discoverFunctionTypeFromFunctionMethod(Method functionMethod) {
|
public static Type discoverFunctionTypeFromFunctionMethod(Method functionMethod) {
|
||||||
Assert.isTrue(
|
Assert.isTrue(
|
||||||
functionMethod.getName().equals("apply") ||
|
functionMethod.getName().equals("apply") ||
|
||||||
functionMethod.getName().equals("accept") ||
|
functionMethod.getName().equals("accept") ||
|
||||||
functionMethod.getName().equals("get") ||
|
functionMethod.getName().equals("get") ||
|
||||||
functionMethod.getName().equals("invoke"),
|
functionMethod.getName().equals("invoke"),
|
||||||
"Only Supplier, Function or Consumer supported at the moment. Was " + functionMethod.getDeclaringClass());
|
"Only Supplier, Function or Consumer supported at the moment. Was " + functionMethod.getDeclaringClass());
|
||||||
|
|
||||||
if (functionMethod.getName().equals("apply") || functionMethod.getName().equals("invoke")) {
|
if (functionMethod.getName().equals("apply") || functionMethod.getName().equals("invoke")) {
|
||||||
return ResolvableType.forClassWithGenerics(Function.class,
|
return ResolvableType.forClassWithGenerics(Function.class,
|
||||||
ResolvableType.forMethodParameter(functionMethod, 0),
|
ResolvableType.forMethodParameter(functionMethod, 0),
|
||||||
ResolvableType.forMethodReturnType(functionMethod)).getType();
|
ResolvableType.forMethodReturnType(functionMethod)).getType();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (functionMethod.getName().equals("accept")) {
|
else if (functionMethod.getName().equals("accept")) {
|
||||||
return ResolvableType.forClassWithGenerics(Consumer.class,
|
return ResolvableType.forClassWithGenerics(Consumer.class,
|
||||||
ResolvableType.forMethodParameter(functionMethod, 0)).getType();
|
ResolvableType.forMethodParameter(functionMethod, 0)).getType();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return ResolvableType.forClassWithGenerics(Supplier.class,
|
return ResolvableType.forClassWithGenerics(Supplier.class,
|
||||||
ResolvableType.forMethodReturnType(functionMethod)).getType();
|
ResolvableType.forMethodReturnType(functionMethod)).getType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,13 +336,13 @@ public final class FunctionTypeUtils {
|
|||||||
Type inputType;
|
Type inputType;
|
||||||
if (functionType instanceof Class) {
|
if (functionType instanceof Class) {
|
||||||
functionType = Function.class.isAssignableFrom((Class<?>) functionType)
|
functionType = Function.class.isAssignableFrom((Class<?>) functionType)
|
||||||
? TypeResolver.reify(Function.class, (Class<Function<?, ?>>) functionType)
|
? TypeResolver.reify(Function.class, (Class<Function<?, ?>>) functionType)
|
||||||
: TypeResolver.reify(Consumer.class, (Class<Consumer<?>>) functionType);
|
: TypeResolver.reify(Consumer.class, (Class<Consumer<?>>) functionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
inputType = functionType instanceof ParameterizedType
|
inputType = functionType instanceof ParameterizedType
|
||||||
? ((ParameterizedType) functionType).getActualTypeArguments()[0]
|
? ((ParameterizedType) functionType).getActualTypeArguments()[0]
|
||||||
: Object.class;
|
: Object.class;
|
||||||
|
|
||||||
return inputType;
|
return inputType;
|
||||||
}
|
}
|
||||||
@@ -357,7 +357,7 @@ public final class FunctionTypeUtils {
|
|||||||
}
|
}
|
||||||
if (applicationContext.containsBean(functionName + FunctionRegistration.REGISTRATION_NAME_SUFFIX)) { // for Kotlin primarily
|
if (applicationContext.containsBean(functionName + FunctionRegistration.REGISTRATION_NAME_SUFFIX)) { // for Kotlin primarily
|
||||||
FunctionRegistration fr = applicationContext
|
FunctionRegistration fr = applicationContext
|
||||||
.getBean(functionName + FunctionRegistration.REGISTRATION_NAME_SUFFIX, FunctionRegistration.class);
|
.getBean(functionName + FunctionRegistration.REGISTRATION_NAME_SUFFIX, FunctionRegistration.class);
|
||||||
return fr.getType();
|
return fr.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +393,7 @@ public final class FunctionTypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String discoverBeanDefinitionNameByQualifier(ListableBeanFactory beanFactory, String qualifier) {
|
public static String discoverBeanDefinitionNameByQualifier(ListableBeanFactory beanFactory, String qualifier) {
|
||||||
Map<String, Object> beanMap = BeanFactoryAnnotationUtils.qualifiedBeansOfType(beanFactory, Object.class, qualifier);
|
Map<String, Object> beanMap = BeanFactoryAnnotationUtils.qualifiedBeansOfType(beanFactory, Object.class, qualifier);
|
||||||
if (!CollectionUtils.isEmpty(beanMap) && beanMap.size() == 1) {
|
if (!CollectionUtils.isEmpty(beanMap) && beanMap.size() == 1) {
|
||||||
return beanMap.keySet().iterator().next();
|
return beanMap.keySet().iterator().next();
|
||||||
}
|
}
|
||||||
@@ -410,13 +410,13 @@ public final class FunctionTypeUtils {
|
|||||||
Type outputType;
|
Type outputType;
|
||||||
if (functionType instanceof Class) {
|
if (functionType instanceof Class) {
|
||||||
functionType = Function.class.isAssignableFrom((Class<?>) functionType)
|
functionType = Function.class.isAssignableFrom((Class<?>) functionType)
|
||||||
? TypeResolver.reify(Function.class, (Class<Function<?, ?>>) functionType)
|
? TypeResolver.reify(Function.class, (Class<Function<?, ?>>) functionType)
|
||||||
: TypeResolver.reify(Supplier.class, (Class<Supplier<?>>) functionType);
|
: TypeResolver.reify(Supplier.class, (Class<Supplier<?>>) functionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
outputType = functionType instanceof ParameterizedType
|
outputType = functionType instanceof ParameterizedType
|
||||||
? (isSupplier(functionType) ? ((ParameterizedType) functionType).getActualTypeArguments()[0] : ((ParameterizedType) functionType).getActualTypeArguments()[1])
|
? (isSupplier(functionType) ? ((ParameterizedType) functionType).getActualTypeArguments()[0] : ((ParameterizedType) functionType).getActualTypeArguments()[1])
|
||||||
: Object.class;
|
: Object.class;
|
||||||
|
|
||||||
return outputType;
|
return outputType;
|
||||||
}
|
}
|
||||||
@@ -503,18 +503,18 @@ public final class FunctionTypeUtils {
|
|||||||
Type functionType = null;
|
Type functionType = null;
|
||||||
switch (parameterTypes.length) {
|
switch (parameterTypes.length) {
|
||||||
case 0:
|
case 0:
|
||||||
functionType = ResolvableType.forClassWithGenerics(Supplier.class,
|
functionType = ResolvableType.forClassWithGenerics(Supplier.class,
|
||||||
ResolvableType.forMethodReturnType(functionalMethod)).getType();
|
ResolvableType.forMethodReturnType(functionalMethod)).getType();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (Void.class.isAssignableFrom(functionalMethod.getReturnType())) {
|
if (Void.class.isAssignableFrom(functionalMethod.getReturnType())) {
|
||||||
functionType = ResolvableType.forClassWithGenerics(Consumer.class,
|
functionType = ResolvableType.forClassWithGenerics(Consumer.class,
|
||||||
ResolvableType.forMethodParameter(functionalMethod, 0)).getType();
|
ResolvableType.forMethodParameter(functionalMethod, 0)).getType();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
functionType = ResolvableType.forClassWithGenerics(Function.class,
|
functionType = ResolvableType.forClassWithGenerics(Function.class,
|
||||||
ResolvableType.forMethodParameter(functionalMethod, 0),
|
ResolvableType.forMethodParameter(functionalMethod, 0),
|
||||||
ResolvableType.forMethodReturnType(functionalMethod)).getType();
|
ResolvableType.forMethodReturnType(functionalMethod)).getType();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -541,17 +541,18 @@ public final class FunctionTypeUtils {
|
|||||||
if (type instanceof ParameterizedType) {
|
if (type instanceof ParameterizedType) {
|
||||||
type = ((ParameterizedType) type).getRawType();
|
type = ((ParameterizedType) type).getRawType();
|
||||||
Assert.isTrue(type instanceof Class<?>, "Must be one of Supplier, Function, Consumer"
|
Assert.isTrue(type instanceof Class<?>, "Must be one of Supplier, Function, Consumer"
|
||||||
+ " or FunctionRegistration. Was " + type);
|
+ " or FunctionRegistration. Was " + type);
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<?> candidateType = (Class<?>) type;
|
Class<?> candidateType = (Class<?>) type;
|
||||||
|
|
||||||
Assert.isTrue(Supplier.class.isAssignableFrom(candidateType)
|
Assert.isTrue(Supplier.class.isAssignableFrom(candidateType)
|
||||||
|| Function.class.isAssignableFrom(candidateType)
|
|| Function.class.isAssignableFrom(candidateType)
|
||||||
|| Consumer.class.isAssignableFrom(candidateType)
|
|| Consumer.class.isAssignableFrom(candidateType)
|
||||||
|| FunctionRegistration.class.isAssignableFrom(candidateType)
|
|| FunctionRegistration.class.isAssignableFrom(candidateType)
|
||||||
|| type.getTypeName().startsWith("org.springframework.context.annotation.ConfigurationClassEnhancer"), "Must be one of Supplier, Function, Consumer"
|
|| type.getTypeName()
|
||||||
+ " or FunctionRegistration. Was " + type);
|
.startsWith("org.springframework.context.annotation.ConfigurationClassEnhancer"), "Must be one of Supplier, Function, Consumer"
|
||||||
|
+ " or FunctionRegistration. Was " + type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Type extractReactiveType(Type type) {
|
private static Type extractReactiveType(Type type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user