feat(core): add InteractionProcessors and InteractionExecutors and improve Autocomplete Interaction
This commit is contained in:
@@ -11,7 +11,6 @@ import org.slf4j.Logger;
|
||||
|
||||
import io.leangen.geantyref.GenericTypeReflector;
|
||||
import net.tomatentum.marinara.interaction.ident.InteractionIdentifier;
|
||||
import net.tomatentum.marinara.registry.InteractionRegistry;
|
||||
import net.tomatentum.marinara.util.LoggerUtil;
|
||||
import net.tomatentum.marinara.util.ReflectionUtil;
|
||||
|
||||
@@ -30,30 +29,30 @@ public class IdentifierProvider {
|
||||
if (conv.getClass().getName().contains("$$Lambda"))
|
||||
throw new IllegalArgumentException("Lambdas cannot be used for IdentifierConverter because of Type erasure.");
|
||||
Type type = GenericTypeReflector.getExactSuperType(conv.getClass(), Converter.class);
|
||||
Type parameterType = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0];
|
||||
Type parameterType = ((ParameterizedType) type).getActualTypeArguments()[0];
|
||||
if (!(parameterType instanceof Class))
|
||||
throw new IllegalArgumentException("Only full Class types are supported by IdentiferConverters");
|
||||
this.converter.put((Class<?>) parameterType, conv);
|
||||
}
|
||||
}
|
||||
|
||||
public InteractionIdentifier provide(Object context, InteractionRegistry registry) {
|
||||
public InteractionIdentifier provide(Object context) {
|
||||
Type type = ReflectionUtil.getMostSpecificClass(
|
||||
converter.keySet().stream().filter(x -> x.isAssignableFrom(context.getClass())).toArray(Class<?>[]::new),
|
||||
context.getClass());
|
||||
|
||||
if (type == null)
|
||||
logger.debug("No Identifier converter found for context {}", context.getClass().toString());
|
||||
logger.debug("No Identifier converter found for context {}", context.getClass());
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Converter<Object> conv = (Converter<Object>) converter.get(type);
|
||||
|
||||
return conv.convert(context, registry);
|
||||
return conv.convert(context);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Converter<T extends Object> {
|
||||
InteractionIdentifier convert(T context, InteractionRegistry registry);
|
||||
InteractionIdentifier convert(T context);
|
||||
}
|
||||
|
||||
public static class LambdaWrapper<T extends Object> implements Converter<T> {
|
||||
@@ -65,8 +64,8 @@ public class IdentifierProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionIdentifier convert(T context, InteractionRegistry registry) {
|
||||
return this.converter.convert(context, registry);
|
||||
public InteractionIdentifier convert(T context) {
|
||||
return this.converter.convert(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user