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:
parent
a0c80582d3
commit
cba9b5f079
1 changed files with 5 additions and 3 deletions
|
|
@ -42,9 +42,11 @@ import cloud.commandframework.arguments.standard.StringArgument;
|
||||||
import cloud.commandframework.arguments.standard.StringArrayArgument;
|
import cloud.commandframework.arguments.standard.StringArrayArgument;
|
||||||
import cloud.commandframework.arguments.standard.UUIDArgument;
|
import cloud.commandframework.arguments.standard.UUIDArgument;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import io.leangen.geantyref.AnnotatedTypeMap;
|
||||||
import io.leangen.geantyref.GenericTypeReflector;
|
import io.leangen.geantyref.GenericTypeReflector;
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.AnnotatedType;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
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<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>>
|
private final Map<Class<? extends Annotation>, BiFunction<? extends Annotation, TypeToken<?>, ParserParameters>>
|
||||||
annotationMappers = new HashMap<>();
|
annotationMappers = new HashMap<>();
|
||||||
private final Map<String, BiFunction<@NonNull CommandContext<C>, @NonNull String, @NonNull List<String>>>
|
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,
|
final @NonNull Function<@NonNull ParserParameters,
|
||||||
@NonNull ArgumentParser<C, ?>> supplier
|
@NonNull ArgumentParser<C, ?>> supplier
|
||||||
) {
|
) {
|
||||||
this.parserSuppliers.put(type, supplier);
|
this.parserSuppliers.put(type.getAnnotatedType(), supplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -248,7 +250,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
} else {
|
} else {
|
||||||
actualType = type;
|
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) {
|
if (producer == null) {
|
||||||
/* Give enums special treatment */
|
/* Give enums special treatment */
|
||||||
if (GenericTypeReflector.isSuperType(Enum.class, actualType.getType())) {
|
if (GenericTypeReflector.isSuperType(Enum.class, actualType.getType())) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue