Fix parser registry not properly resolving TypeTokens (#454)

This change is good for correctness in general but is mostly relevant when using parsers with generic types, which now works as expected.
This commit is contained in:
solo 2023-07-06 15:10:48 -04:00 committed by Jason
parent a0c80582d3
commit cba9b5f079

View file

@ -42,9 +42,11 @@ import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.arguments.standard.StringArrayArgument;
import cloud.commandframework.arguments.standard.UUIDArgument;
import cloud.commandframework.context.CommandContext;
import io.leangen.geantyref.AnnotatedTypeMap;
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedType;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collection;
@ -85,7 +87,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
};
private final Map<String, Function<ParserParameters, ArgumentParser<C, ?>>> namedParsers = new HashMap<>();
private final Map<TypeToken<?>, Function<ParserParameters, ArgumentParser<C, ?>>> parserSuppliers = new HashMap<>();
private final Map<AnnotatedType, Function<ParserParameters, ArgumentParser<C, ?>>> parserSuppliers = new AnnotatedTypeMap<>();
private final Map<Class<? extends Annotation>, BiFunction<? extends Annotation, TypeToken<?>, ParserParameters>>
annotationMappers = new HashMap<>();
private final Map<String, BiFunction<@NonNull CommandContext<C>, @NonNull String, @NonNull List<String>>>
@ -195,7 +197,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
final @NonNull Function<@NonNull ParserParameters,
@NonNull ArgumentParser<C, ?>> supplier
) {
this.parserSuppliers.put(type, supplier);
this.parserSuppliers.put(type.getAnnotatedType(), supplier);
}
@Override
@ -248,7 +250,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
} else {
actualType = type;
}
final Function<ParserParameters, ArgumentParser<C, ?>> producer = this.parserSuppliers.get(actualType);
final Function<ParserParameters, ArgumentParser<C, ?>> producer = this.parserSuppliers.get(actualType.getAnnotatedType());
if (producer == null) {
/* Give enums special treatment */
if (GenericTypeReflector.isSuperType(Enum.class, actualType.getType())) {