Skip to content

Commit cba9b5f

Browse files
solonovamaxjpenilla
authored andcommitted
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.
1 parent a0c8058 commit cba9b5f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

cloud-core/src/main/java/cloud/commandframework/arguments/parser/StandardParserRegistry.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242
import cloud.commandframework.arguments.standard.StringArrayArgument;
4343
import cloud.commandframework.arguments.standard.UUIDArgument;
4444
import cloud.commandframework.context.CommandContext;
45+
import io.leangen.geantyref.AnnotatedTypeMap;
4546
import io.leangen.geantyref.GenericTypeReflector;
4647
import io.leangen.geantyref.TypeToken;
4748
import java.lang.annotation.Annotation;
49+
import java.lang.reflect.AnnotatedType;
4850
import java.time.Duration;
4951
import java.util.Arrays;
5052
import java.util.Collection;
@@ -85,7 +87,7 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
8587
};
8688

8789
private final Map<String, Function<ParserParameters, ArgumentParser<C, ?>>> namedParsers = new HashMap<>();
88-
private final Map<TypeToken<?>, Function<ParserParameters, ArgumentParser<C, ?>>> parserSuppliers = new HashMap<>();
90+
private final Map<AnnotatedType, Function<ParserParameters, ArgumentParser<C, ?>>> parserSuppliers = new AnnotatedTypeMap<>();
8991
private final Map<Class<? extends Annotation>, BiFunction<? extends Annotation, TypeToken<?>, ParserParameters>>
9092
annotationMappers = new HashMap<>();
9193
private final Map<String, BiFunction<@NonNull CommandContext<C>, @NonNull String, @NonNull List<String>>>
@@ -195,7 +197,7 @@ public <T> void registerParserSupplier(
195197
final @NonNull Function<@NonNull ParserParameters,
196198
@NonNull ArgumentParser<C, ?>> supplier
197199
) {
198-
this.parserSuppliers.put(type, supplier);
200+
this.parserSuppliers.put(type.getAnnotatedType(), supplier);
199201
}
200202

201203
@Override
@@ -248,7 +250,7 @@ public <A extends Annotation, T> void registerAnnotationMapper(
248250
} else {
249251
actualType = type;
250252
}
251-
final Function<ParserParameters, ArgumentParser<C, ?>> producer = this.parserSuppliers.get(actualType);
253+
final Function<ParserParameters, ArgumentParser<C, ?>> producer = this.parserSuppliers.get(actualType.getAnnotatedType());
252254
if (producer == null) {
253255
/* Give enums special treatment */
254256
if (GenericTypeReflector.isSuperType(Enum.class, actualType.getType())) {

0 commit comments

Comments
 (0)