From cba9b5f07920c8f378e2d6ba4ec77b5f9942d77f Mon Sep 17 00:00:00 2001 From: solo Date: Thu, 6 Jul 2023 15:10:48 -0400 Subject: [PATCH] Fix parser registry not properly resolving `TypeToken`s (#454) This change is good for correctness in general but is mostly relevant when using parsers with generic types, which now works as expected. --- .../arguments/parser/StandardParserRegistry.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java index c860d940..efa08c42 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java @@ -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 implements ParserRegistry { }; private final Map>> namedParsers = new HashMap<>(); - private final Map, Function>> parserSuppliers = new HashMap<>(); + private final Map>> parserSuppliers = new AnnotatedTypeMap<>(); private final Map, BiFunction, ParserParameters>> annotationMappers = new HashMap<>(); private final Map, @NonNull String, @NonNull List>> @@ -195,7 +197,7 @@ public final class StandardParserRegistry implements ParserRegistry { final @NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser> supplier ) { - this.parserSuppliers.put(type, supplier); + this.parserSuppliers.put(type.getAnnotatedType(), supplier); } @Override @@ -248,7 +250,7 @@ public final class StandardParserRegistry implements ParserRegistry { } else { actualType = type; } - final Function> producer = this.parserSuppliers.get(actualType); + final Function> producer = this.parserSuppliers.get(actualType.getAnnotatedType()); if (producer == null) { /* Give enums special treatment */ if (GenericTypeReflector.isSuperType(Enum.class, actualType.getType())) {