Revxrsal / Lamp

A modern annotations-driven commands framework for Java and Kotlin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

default argument type resolvers do not make sense to me.

portlek opened this issue · comments

each default arg type bound like this:
image
but the type does not do anything at all in the bind method:
image
and the parameter's class type hasn't check in the argument resolver too:
image
and looks like it does support nullable too:
image
so i've made the string resolver like this:

public interface CommandFactory {
  @Inject
  @NotNull
  @Provides
  @Singleton
  static BukkitCommandHandler commandManager(@NotNull final Plugin plugin) {
    final var handler = BukkitCommandHandler.create(plugin);
    handler.registerBrigadier();
    handler.enableAdventure();
    handler
      .getBrigadier()
      .orElseThrow()
      .registerArgumentTypeResolver(
        0,
        parameter -> {
          if (parameter.getType() != String.class) {
            return null;
          }
          if (parameter.getType().isAnnotationPresent(Quoted.class)) {
            return StringArgumentType.string();
          }
          if (parameter.consumesAllString()) {
            return StringArgumentType.greedyString();
          }
          return StringArgumentType.word();
        }
      );
    return handler;
  }
}

am i wrong with the returning null if the parameter is not a string? because looks like if it does not find any resolver, returns string already so it should check the parameter type first.

commented

am i wrong with the returning null if the parameter is not a string? because looks like if it does not find any resolver, returns string already so it should check the parameter type first.

Nope, null is perfectly valid to return and it means the resolver is not designed for that type of parameter, in which other resolvers will be tried instead.

I'll correct the behavior of #bind today if I get a chance. Thanks for the heads up!

Nope, null is perfectly valid to return and it means the resolver is not designed for that type of parameter, in which other resolvers will be tried instead.

then all default arg type resolvers should include type check then? like the number type resolver?

commented

Should be fixed in 5cbeef2