Re-order type discovery and function wrapping
Otherwise the explicit types from the function registration are not used.
This commit is contained in:
@@ -39,7 +39,7 @@ public class FunctionRegistration<T> {
|
||||
|
||||
private final Map<String, String> properties = new LinkedHashMap<>();
|
||||
|
||||
private Type type;
|
||||
private FunctionType type;
|
||||
|
||||
public FunctionRegistration(T target) {
|
||||
this.target = target;
|
||||
@@ -53,7 +53,7 @@ public class FunctionRegistration<T> {
|
||||
return names;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
public FunctionType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class FunctionRegistration<T> {
|
||||
}
|
||||
|
||||
public FunctionRegistration<T> type(Type type) {
|
||||
this.type = type;
|
||||
this.type = FunctionType.of(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,10 @@ public class FunctionType {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Class<?> getInputWrapper() {
|
||||
return findType(ParamType.INPUT_WRAPPER);
|
||||
}
|
||||
@@ -79,6 +83,10 @@ public class FunctionType {
|
||||
|| Mono.class.equals(type) || Optional.class.equals(type);
|
||||
}
|
||||
|
||||
public static FunctionType of(Type function) {
|
||||
return new FunctionType(function);
|
||||
}
|
||||
|
||||
public static FunctionType from(Class<?> input) {
|
||||
return new FunctionType(ResolvableType
|
||||
.forClassWithGenerics(Function.class, input, Object.class).getType());
|
||||
|
||||
@@ -439,10 +439,15 @@ public class ContextFunctionCatalogAutoConfiguration {
|
||||
private void wrap(FunctionRegistration<Object> registration, String key) {
|
||||
Object target = registration.getTarget();
|
||||
this.registrations.put(target, key);
|
||||
if (registration.getType() != null) {
|
||||
this.types.put(key, registration.getType());
|
||||
}
|
||||
else {
|
||||
findType(target);
|
||||
}
|
||||
Class<?> type;
|
||||
if (target instanceof Supplier) {
|
||||
type = Supplier.class;
|
||||
findType(target);
|
||||
registration.target(target((Supplier<?>) target, key));
|
||||
for (String name : registration.getNames()) {
|
||||
this.suppliers.put(name, registration.getTarget());
|
||||
@@ -450,7 +455,6 @@ public class ContextFunctionCatalogAutoConfiguration {
|
||||
}
|
||||
else if (target instanceof Consumer) {
|
||||
type = Consumer.class;
|
||||
findType(target);
|
||||
registration.target(target((Consumer<?>) target, key));
|
||||
for (String name : registration.getNames()) {
|
||||
this.consumers.put(name, registration.getTarget());
|
||||
@@ -458,7 +462,6 @@ public class ContextFunctionCatalogAutoConfiguration {
|
||||
}
|
||||
else if (target instanceof Function) {
|
||||
type = Function.class;
|
||||
findType(target);
|
||||
registration.target(target((Function<?, ?>) target, key));
|
||||
for (String name : registration.getNames()) {
|
||||
this.functions.put(name, registration.getTarget());
|
||||
@@ -467,7 +470,7 @@ public class ContextFunctionCatalogAutoConfiguration {
|
||||
else {
|
||||
return;
|
||||
}
|
||||
registrations.remove(target);
|
||||
this.registrations.remove(target);
|
||||
this.registrations.put(registration.getTarget(), key);
|
||||
if (publisher != null) {
|
||||
publisher.publishEvent(new FunctionRegistrationEvent(
|
||||
|
||||
Reference in New Issue
Block a user