From 3e9d16e82de607e2a33fbee2c653ece9dfc90cc2 Mon Sep 17 00:00:00 2001 From: Mazen Date: Sun, 6 Oct 2024 11:57:41 +0300 Subject: [PATCH] New system replacing Value Resolvers --- .../imperat/adventure/AdventureProvider.java | 2 +- .../velix/imperat/ArgumentTypeResolver.java | 20 +-- .../velix/imperat/BaseBrigadierManager.java | 4 +- .../dev/velix/imperat/BrigadierManager.java | 16 +-- .../java/dev/velix/imperat/BukkitImperat.java | 4 +- .../java/dev/velix/imperat/BukkitSource.java | 2 +- .../brigadier/DefaultArgTypeResolvers.java | 8 +- .../brigadier/MinecraftArgumentType.java | 36 ++--- .../main/java/dev/velix/imperat/Imperat.java | 12 +- .../dev/velix/imperat/ResolverRegistrar.java | 70 +++++----- .../java/dev/velix/imperat/SourceWrapper.java | 10 +- .../dev/velix/imperat/ThrowableHandler.java | 12 +- .../annotations/base/AnnotationFactory.java | 18 +-- .../annotations/base/AnnotationHelper.java | 2 +- .../annotations/base/AnnotationParser.java | 34 ++--- .../base/AnnotationParserImpl.java | 26 ++-- .../annotations/base/AnnotationReplacer.java | 2 +- .../base/element/ParseElement.java | 8 +- .../base/element/RootCommandClass.java | 2 +- .../element/SimpleCommandClassVisitor.java | 9 +- .../element/selector/ElementSelector.java | 2 +- .../base/element/selector/MethodRules.java | 2 +- .../parameters/AnnotatedParameter.java | 6 +- .../AnnotationParameterDecorator.java | 6 +- .../velix/imperat/command/BaseImperat.java | 42 +++--- .../dev/velix/imperat/command/Command.java | 4 +- .../imperat/command/CommandExecution.java | 2 +- .../velix/imperat/command/CommandUsage.java | 6 +- .../imperat/command/CommandUsageImpl.java | 8 +- .../command/ContextResolverFactory.java | 2 +- .../command/cooldown/CooldownHandler.java | 2 +- .../command/parameters/CommandParameter.java | 62 +++++---- .../command/parameters/FlagBuilder.java | 8 +- .../command/parameters/FlagParameter.java | 4 +- .../command/parameters/InputParameter.java | 26 ++-- .../parameters/NormalCommandParameter.java | 4 +- .../command/parameters/ParameterBuilder.java | 22 +-- .../parameters/type/BaseParameterType.java | 45 +++++++ .../parameters/type/ParameterBoolean.java | 66 +++++++++ .../parameters/type/ParameterFlag.java | 41 ++++++ .../parameters/type/ParameterNumber.java | 126 ++++++++++++++++++ .../parameters/type/ParameterString.java | 59 ++++++++ .../parameters/type/ParameterType.java | 42 ++++++ .../parameters/type/ParameterTypes.java | 59 ++++++++ .../parameters/type/ParameterWord.java | 59 ++++++++ .../parameters/types/ParameterType.java | 11 -- .../parameters/types/ParameterTypes.java | 108 --------------- .../processors/CommandPostProcessor.java | 2 +- .../processors/CommandPreProcessor.java | 2 +- .../command/suggestions/AutoCompleter.java | 2 +- .../SuggestionResolverRegistry.java | 2 +- .../imperat/command/tree/ArgumentNode.java | 7 +- .../imperat/command/tree/CommandTree.java | 2 +- .../velix/imperat/context/ArgumentQueue.java | 10 +- .../imperat/context/ArgumentQueueImpl.java | 1 + .../velix/imperat/context/CommandFlag.java | 2 +- .../velix/imperat/context/CommandSwitch.java | 4 +- .../dev/velix/imperat/context/Context.java | 2 +- .../imperat/context/ExecutionContext.java | 12 +- .../imperat/context/ResolvedContext.java | 2 +- .../dev/velix/imperat/context/Source.java | 2 +- .../imperat/context/StringTokenizer.java | 90 ------------- .../context/ValueResolverRegistry.java | 2 +- .../context/internal/ResolvedContextImpl.java | 18 +-- .../internal/sur/CommandInputStream.java | 47 +++++++ .../internal/sur/SmartUsageResolve.java | 4 +- .../exception/SelfHandledException.java | 2 +- .../dev/velix/imperat/help/HelpProvider.java | 2 +- .../velix/imperat/help/UsageFormatter.java | 2 +- .../imperat/resolvers/ContextResolver.java | 2 +- .../imperat/resolvers/SuggestionResolver.java | 8 +- .../resolvers/TypeSuggestionResolver.java | 6 +- .../imperat/resolvers/ValueResolver.java | 4 +- .../supplier/OptionalValueSupplier.java | 2 +- .../defaults/BooleanValueSupplier.java | 2 +- .../dev/velix/imperat/util/StringUtils.java | 18 +++ .../dev/velix/imperat/util/TypeVisitor.java | 4 +- .../java/dev/velix/imperat/util/TypeWrap.java | 2 +- .../util/reflection/FieldAccessor.java | 2 +- .../imperat/util/reflection/Reflections.java | 28 ++-- .../verification/TypeTolerantVerifier.java | 6 +- .../java/dev/velix/imperat/TestImperat.java | 4 +- .../dev/velix/imperat/MinestomImperat.java | 6 +- .../dev/velix/imperat/MinestomSource.java | 2 +- .../dev/velix/imperat/SyntaxDataLoader.java | 8 +- 85 files changed, 900 insertions(+), 544 deletions(-) create mode 100644 core/src/main/java/dev/velix/imperat/command/parameters/type/BaseParameterType.java create mode 100644 core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterBoolean.java create mode 100644 core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterFlag.java create mode 100644 core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterNumber.java create mode 100644 core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterString.java create mode 100644 core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterType.java create mode 100644 core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterTypes.java create mode 100644 core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterWord.java delete mode 100644 core/src/main/java/dev/velix/imperat/command/parameters/types/ParameterType.java delete mode 100644 core/src/main/java/dev/velix/imperat/command/parameters/types/ParameterTypes.java delete mode 100644 core/src/main/java/dev/velix/imperat/context/StringTokenizer.java create mode 100644 core/src/main/java/dev/velix/imperat/context/internal/sur/CommandInputStream.java diff --git a/adventure/src/main/java/dev/velix/imperat/adventure/AdventureProvider.java b/adventure/src/main/java/dev/velix/imperat/adventure/AdventureProvider.java index 782098c0..b6892e5a 100644 --- a/adventure/src/main/java/dev/velix/imperat/adventure/AdventureProvider.java +++ b/adventure/src/main/java/dev/velix/imperat/adventure/AdventureProvider.java @@ -11,7 +11,7 @@ * within the application, typically in a context like a game server or * chat system where audiences are dynamically determined. * - * @param the type of the source from which the {@link Audience} can be derived + * @param the valueType of the source from which the {@link Audience} can be derived */ @SuppressWarnings("unchecked") public interface AdventureProvider { diff --git a/brigadier/src/main/java/dev/velix/imperat/ArgumentTypeResolver.java b/brigadier/src/main/java/dev/velix/imperat/ArgumentTypeResolver.java index cfffb96f..6f030003 100644 --- a/brigadier/src/main/java/dev/velix/imperat/ArgumentTypeResolver.java +++ b/brigadier/src/main/java/dev/velix/imperat/ArgumentTypeResolver.java @@ -8,45 +8,45 @@ /** * A resolver that specifies {@link ArgumentType} - * for each parameter depending on the parameter's type. + * for each parameter depending on the parameter's valueType. */ @FunctionalInterface public interface ArgumentTypeResolver { /** * Creates a {@link ArgumentTypeResolver} that will return the same - * argument type for all parameters that match a specific type + * argument valueType for all parameters that match a specific valueType * * @param type Type to check for - * @param argumentType The argument type to return + * @param argumentType The argument valueType to return * @return The resolver factory */ static @NotNull ArgumentTypeResolver forType(Class type, ArgumentType argumentType) { - return parameter -> parameter.type() == type ? argumentType : null; + return parameter -> parameter.valueType() == type ? argumentType : null; } /** * Creates a {@link ArgumentTypeResolver} that will return the same - * argument type for all parameters that match or extend a specific type + * argument valueType for all parameters that match or extend a specific valueType * * @param type Type to check for - * @param argumentType The argument type to return + * @param argumentType The argument valueType to return * @return The resolver factory */ static @NotNull ArgumentTypeResolver forHierarchyType(Class type, ArgumentType argumentType) { return parameter -> { - var token = TypeWrap.of(parameter.type()); + var token = TypeWrap.of(parameter.valueType()); var token2 = TypeWrap.of(type); - return parameter.type() == type || token.isSupertypeOf(token2) ? argumentType : null; + return parameter.valueType() == type || token.isSupertypeOf(token2) ? argumentType : null; }; } /** - * Returns the argument type for the given parameter. + * Returns the argument valueType for the given parameter. * If unknown, it returns null * * @param parameter Parameter to create for - * @return The argument type + * @return The argument valueType */ @Nullable ArgumentType resolveArgType(@NotNull CommandParameter parameter); diff --git a/brigadier/src/main/java/dev/velix/imperat/BaseBrigadierManager.java b/brigadier/src/main/java/dev/velix/imperat/BaseBrigadierManager.java index e09315e0..612b8cd2 100644 --- a/brigadier/src/main/java/dev/velix/imperat/BaseBrigadierManager.java +++ b/brigadier/src/main/java/dev/velix/imperat/BaseBrigadierManager.java @@ -179,10 +179,10 @@ public void registerArgumentResolver( return argumentTypeResolver.resolveArgType(flagParameter); } - return param.type() == flagParameter.flagData().inputType() + return param.valueType() == flagParameter.flagData().inputType() ? argumentTypeResolver.resolveArgType(param) : null; } - return TypeUtility.matches(param.type(), type) ? argumentTypeResolver.resolveArgType(param) : null; + return TypeUtility.matches(param.valueType(), type) ? argumentTypeResolver.resolveArgType(param) : null; }); } diff --git a/brigadier/src/main/java/dev/velix/imperat/BrigadierManager.java b/brigadier/src/main/java/dev/velix/imperat/BrigadierManager.java index 16a21d92..fa134cbc 100644 --- a/brigadier/src/main/java/dev/velix/imperat/BrigadierManager.java +++ b/brigadier/src/main/java/dev/velix/imperat/BrigadierManager.java @@ -12,7 +12,7 @@ * A class that manages parsing {@link Command} * into brigadier {@link CommandNode} * - * @param the command-source type + * @param the command-source valueType */ public sealed interface BrigadierManager permits BaseBrigadierManager { @@ -26,24 +26,24 @@ public sealed interface BrigadierManager permits BaseBrigadier S wrapCommandSource(Object commandSource); /** - * Registers the argument type to its class type + * Registers the argument valueType to its class valueType * - * @param type the type to register to the value-type obj - * @param argumentTypeResolver the value type resolver - * @param the type parameter for the type. + * @param type the valueType to register to the value-valueType obj + * @param argumentTypeResolver the value valueType resolver + * @param the valueType parameter for the valueType. */ void registerArgumentResolver(Class type, ArgumentTypeResolver argumentTypeResolver); /** - * Registers the argument type resolver + * Registers the argument valueType resolver * - * @param argumentTypeResolver the value type resolver + * @param argumentTypeResolver the value valueType resolver */ void registerArgumentResolver(ArgumentTypeResolver argumentTypeResolver); /** - * Fetches the argument type from the parameter + * Fetches the argument valueType from the parameter * * @param parameter the parameter * @return the {@link ArgumentType} for the {@link CommandParameter} diff --git a/bukkit/src/main/java/dev/velix/imperat/BukkitImperat.java b/bukkit/src/main/java/dev/velix/imperat/BukkitImperat.java index 478d2f99..925ee60b 100644 --- a/bukkit/src/main/java/dev/velix/imperat/BukkitImperat.java +++ b/bukkit/src/main/java/dev/velix/imperat/BukkitImperat.java @@ -134,10 +134,10 @@ public static Class getSelectedEntity(@NotNull Type selectorTy } /** - * Wraps the sender into a built-in command-sender type + * Wraps the sender into a built-in command-sender valueType * * @param sender the sender's actual value - * @return the wrapped command-sender type + * @return the wrapped command-sender valueType */ @Override public BukkitSource wrapSender(Object sender) { diff --git a/bukkit/src/main/java/dev/velix/imperat/BukkitSource.java b/bukkit/src/main/java/dev/velix/imperat/BukkitSource.java index cd866ab2..7bb77c5b 100644 --- a/bukkit/src/main/java/dev/velix/imperat/BukkitSource.java +++ b/bukkit/src/main/java/dev/velix/imperat/BukkitSource.java @@ -29,7 +29,7 @@ public String name() { } /** - * @return The original command sender type instance + * @return The original command sender valueType instance */ @Override public CommandSender origin() { diff --git a/bukkit/src/main/java/dev/velix/imperat/brigadier/DefaultArgTypeResolvers.java b/bukkit/src/main/java/dev/velix/imperat/brigadier/DefaultArgTypeResolvers.java index 6df99927..d3c24825 100644 --- a/bukkit/src/main/java/dev/velix/imperat/brigadier/DefaultArgTypeResolvers.java +++ b/bukkit/src/main/java/dev/velix/imperat/brigadier/DefaultArgTypeResolvers.java @@ -21,7 +21,7 @@ class DefaultArgTypeResolvers { if (parameter.isNumeric()) { NumericRange range = parameter.asNumeric().getRange(); - return numeric(parameter.type(), range); + return numeric(parameter.valueType(), range); } return null; @@ -34,8 +34,8 @@ class DefaultArgTypeResolvers { //TODO add entity selector /*public static final ArgumentTypeResolver ENTITY_SELECTOR = parameter -> { - Class type = BukkitImperat.getSelectedEntity(parameter.getType()); - if (Player.class.isAssignableFrom(type)) // EntitySelector + Class valueType = BukkitImperat.getSelectedEntity(parameter.getType()); + if (Player.class.isAssignableFrom(valueType)) // EntitySelector return MULTI_PLAYER; return MULTI_ENTITY; };*/ @@ -52,7 +52,7 @@ private static ArgumentType numeric( } else if (TypeUtility.matches(type, double.class)) { return DoubleArgumentType.doubleArg(getMin(range), getMax(range)); } else { - throw new IllegalArgumentException("Unsupported numeric type: " + type); + throw new IllegalArgumentException("Unsupported numeric valueType: " + type); } } diff --git a/bukkit/src/main/java/dev/velix/imperat/brigadier/MinecraftArgumentType.java b/bukkit/src/main/java/dev/velix/imperat/brigadier/MinecraftArgumentType.java index fdc083f5..e3ff6d1e 100644 --- a/bukkit/src/main/java/dev/velix/imperat/brigadier/MinecraftArgumentType.java +++ b/bukkit/src/main/java/dev/velix/imperat/brigadier/MinecraftArgumentType.java @@ -281,7 +281,7 @@ public static void ensureSetup() { } /** - * Checks if this argument type is supported in this Minecraft version + * Checks if this argument valueType is supported in this Minecraft version * * @return If this is supported */ @@ -290,7 +290,7 @@ public boolean isSupported() { } /** - * Checks if this argument type requires parameters + * Checks if this argument valueType requires parameters * * @return If this requires parameters */ @@ -299,34 +299,34 @@ public boolean requiresParameters() { } /** - * Returns the argument type represented by this enum value, otherwise + * Returns the argument valueType represented by this enum value, otherwise * throws an exception * - * @param The argument type - * @return The argument type + * @param The argument valueType + * @return The argument valueType * @throws IllegalArgumentException if not supported in this version * @throws IllegalArgumentException if this argument requires arguments. See {@link #create(Object...)} */ public @NotNull ArgumentType get() { if (argumentConstructor == null) - throw new IllegalArgumentException("Argument type '" + name().toLowerCase() + "' is not available on this version."); + throw new IllegalArgumentException("Argument valueType '" + name().toLowerCase() + "' is not available on this version."); if (argumentType != null) return (ArgumentType) argumentType; - throw new IllegalArgumentException("This argument type requires " + parameters.length + " parameter(s) of type(s) " + + throw new IllegalArgumentException("This argument valueType requires " + parameters.length + " parameter(s) of valueType(s) " + Arrays.stream(parameters).map(Class::getName).collect(Collectors.joining(", ")) + ". Use #create() instead."); } /** - * Creates an instance of this argument type + * Creates an instance of this argument valueType * - * @param arguments Arguments to construct the argument type with + * @param arguments Arguments to construct the argument valueType with * @param The argument ttype - * @return The created argument type. + * @return The created argument valueType. * @throws IllegalArgumentException if not supported in this version */ public @NotNull ArgumentType create(Object... arguments) { if (argumentConstructor == null) { - throw new IllegalArgumentException("Argument type '" + name().toLowerCase() + "' is not available on this version."); + throw new IllegalArgumentException("Argument valueType '" + name().toLowerCase() + "' is not available on this version."); } if (argumentType != null && arguments.length == 0) { @@ -341,11 +341,11 @@ public boolean requiresParameters() { } /** - * Returns the argument type represented by this enum value, wrapped + * Returns the argument valueType represented by this enum value, wrapped * inside an {@link Optional} * - * @param The argument type - * @return The argument type optional + * @param The argument valueType + * @return The argument valueType optional * @throws IllegalArgumentException if this argument requires arguments. See {@link #createIfPresent(Object...)} */ public @NotNull Optional> getIfPresent() { @@ -353,16 +353,16 @@ public boolean requiresParameters() { return Optional.empty(); if (argumentType != null) return Optional.of((ArgumentType) argumentType); - throw new IllegalArgumentException("This argument type requires " + parameters.length + " parameter(s) of type(s) " + + throw new IllegalArgumentException("This argument valueType requires " + parameters.length + " parameter(s) of valueType(s) " + Arrays.stream(parameters).map(Class::getName).collect(Collectors.joining(", ")) + ". Use #create() instead."); } /** - * Creates an instance of this argument type, wrapped in an optional. + * Creates an instance of this argument valueType, wrapped in an optional. * - * @param arguments Arguments to construct the argument type with + * @param arguments Arguments to construct the argument valueType with * @param The argument ttype - * @return The created argument type optional. + * @return The created argument valueType optional. */ public @NotNull Optional> createIfPresent(Object... arguments) { if (argumentConstructor == null) { diff --git a/core/src/main/java/dev/velix/imperat/Imperat.java b/core/src/main/java/dev/velix/imperat/Imperat.java index 43450ce4..3a403de7 100644 --- a/core/src/main/java/dev/velix/imperat/Imperat.java +++ b/core/src/main/java/dev/velix/imperat/Imperat.java @@ -25,7 +25,7 @@ * It also caches the settings that the user can * change or modify in the api. * - * @param the command sender type + * @param the command sender valueType */ @ApiStatus.AvailableSince("1.0.0") public non-sealed interface Imperat extends @@ -71,21 +71,21 @@ public non-sealed interface Imperat extends void setAnnotationParser(AnnotationParser parser); /** - * Registers a type of annotations so that it can be - * detected by {@link AnnotationReader} , it's useful as it allows that type of annotation + * Registers a valueType of annotations so that it can be + * detected by {@link AnnotationReader} , it's useful as it allows that valueType of annotation * to be recognized as a true Imperat-related annotation to be used in something like checking if a * {@link CommandParameter} is annotated and checks for the annotations it has. * - * @param type the type of annotation + * @param type the valueType of annotation */ void registerAnnotations(Class... type); /** * Registers annotation replacer * - * @param type the type to replace the annotation by + * @param type the valueType to replace the annotation by * @param replacer the replacer - * @param the type of annotation to replace + * @param the valueType of annotation to replace */ void registerAnnotationReplacer( final Class type, diff --git a/core/src/main/java/dev/velix/imperat/ResolverRegistrar.java b/core/src/main/java/dev/velix/imperat/ResolverRegistrar.java index ece63757..7566baa2 100644 --- a/core/src/main/java/dev/velix/imperat/ResolverRegistrar.java +++ b/core/src/main/java/dev/velix/imperat/ResolverRegistrar.java @@ -31,17 +31,17 @@ public sealed interface ResolverRegistrar permits Imperat { void registerContextResolverFactory(Type type, ContextResolverFactory factory); /** - * Checks whether the type has + * Checks whether the valueType has * a registered context-resolver * - * @param type the type - * @return whether the type has + * @param type the valueType + * @return whether the valueType has * a context-resolver */ boolean hasContextResolver(Type type); /** - * @param resolvingContextType the type the factory is registered to + * @param resolvingContextType the valueType the factory is registered to * @return returns the factory for creation of * {@link ContextResolver} */ @@ -49,10 +49,10 @@ public sealed interface ResolverRegistrar permits Imperat { ContextResolverFactory getContextResolverFactory(Type resolvingContextType); /** - * Fetches {@link ContextResolver} for a certain type + * Fetches {@link ContextResolver} for a certain valueType * - * @param resolvingContextType the type for this resolver - * @param the type of class + * @param resolvingContextType the valueType for this resolver + * @param the valueType of class * @return the context resolver */ @Nullable @@ -62,7 +62,7 @@ public sealed interface ResolverRegistrar permits Imperat { * Fetches the context resolver for {@link ParameterElement} of a method * * @param element the element - * @param the type of value this parameter should be resolved into + * @param the valueType of value this parameter should be resolved into * @return the {@link ContextResolver} for this element */ @Nullable @@ -72,19 +72,19 @@ public sealed interface ResolverRegistrar permits Imperat { * Fetches the {@link ContextResolver} suitable for the {@link CommandParameter} * * @param commandParameter the parameter of a command's usage - * @param the type of value that will be resolved by {@link ValueResolver} - * @return the context resolver for this parameter's value type + * @param the valueType of value that will be resolved by {@link ValueResolver} + * @return the context resolver for this parameter's value valueType */ default ContextResolver getContextResolver(CommandParameter commandParameter) { - return getContextResolver(commandParameter.type()); + return getContextResolver(commandParameter.valueType()); } /** * Registers {@link ContextResolver} * - * @param type the class-type of value being resolved from context + * @param type the class-valueType of value being resolved from context * @param resolver the resolver for this value - * @param the type of value being resolved from context + * @param the valueType of value being resolved from context */ void registerContextResolver(Type type, @NotNull ContextResolver resolver); @@ -92,7 +92,7 @@ default ContextResolver getContextResolver(CommandParameter command * Fetches {@link ValueResolver} for a certain value * * @param resolvingValueType the value that the resolver ends providing it from the context - * @return the value resolver of a certain type + * @return the value resolver of a certain valueType */ @Nullable ValueResolver getValueResolver(Type resolvingValueType); @@ -101,18 +101,18 @@ default ContextResolver getContextResolver(CommandParameter command * Fetches the {@link ValueResolver} suitable for the {@link CommandParameter} * * @param commandParameter the parameter of a command's usage - * @return the value resolver for this parameter's value type + * @return the value resolver for this parameter's value valueType */ default ValueResolver getValueResolver(CommandParameter commandParameter) { - return getValueResolver(commandParameter.type()); + return getValueResolver(commandParameter.valueType()); } /** * Registers {@link ValueResolver} * - * @param type the class-type of value being resolved from context + * @param type the class-valueType of value being resolved from context * @param resolver the resolver for this value - * @param the type of value being resolved from context + * @param the valueType of value being resolved from context */ void registerValueResolver(Type type, @NotNull ValueResolver resolver); @@ -122,17 +122,17 @@ default ContextResolver getContextResolver(CommandParameter command Collection> getRegisteredValueResolvers(); /** - * Fetches the suggestion provider/resolver for a specific type of + * Fetches the suggestion provider/resolver for a specific valueType of * argument or parameter. * - * @param parameter the parameter symbolizing the type and argument name - * @return the {@link SuggestionResolver} instance for that type + * @param parameter the parameter symbolizing the valueType and argument name + * @return the {@link SuggestionResolver} instance for that valueType */ @SuppressWarnings("uncecked") default @NotNull SuggestionResolver getParameterSuggestionResolver(CommandParameter parameter) { SuggestionResolver parameterSpecificResolver = parameter.getSuggestionResolver(); if (parameterSpecificResolver == null) { - var resolverByType = getSuggestionResolverByType(parameter.type()); + var resolverByType = getSuggestionResolverByType(parameter.valueType()); if (resolverByType != null) return resolverByType; else return SuggestionResolver.type(String.class, Collections.singletonList(parameter.format())); } else @@ -140,11 +140,11 @@ default ContextResolver getContextResolver(CommandParameter command } /** - * Fetches the suggestion provider/resolver for a specific type of + * Fetches the suggestion provider/resolver for a specific valueType of * argument or parameter. * - * @param type the type - * @return the {@link SuggestionResolver} instance for that type + * @param type the valueType + * @return the {@link SuggestionResolver} instance for that valueType */ @Nullable SuggestionResolver getSuggestionResolverByType(Type type); @@ -162,14 +162,14 @@ default ContextResolver getContextResolver(CommandParameter command * Registers a suggestion resolver * * @param suggestionResolver the suggestion resolver to register - * @param the type of value that the suggestion resolver will work with. + * @param the valueType of value that the suggestion resolver will work with. */ void registerSuggestionResolver(TypeSuggestionResolver suggestionResolver); /** - * Registers a suggestion resolver to a type + * Registers a suggestion resolver to a valueType * - * @param type the type + * @param type the valueType * @param suggestionResolver the suggestion resolver. */ void registerSuggestionResolver(Type type, SuggestionResolver suggestionResolver); @@ -185,18 +185,18 @@ default ContextResolver getContextResolver(CommandParameter command /** * Fetches the {@link SourceResolver} from an internal registry. * - * @param type the target source type - * @param the new source type parameter - * @return the {@link SourceResolver} for specific type + * @param type the target source valueType + * @param the new source valueType parameter + * @return the {@link SourceResolver} for specific valueType */ @Nullable SourceResolver getSourceResolver(Type type); /** * Registers the {@link SourceResolver} into an internal registry * - * @param type the target source type + * @param type the target source valueType * @param sourceResolver the source resolver to register - * @param the new source type parameter + * @param the new source valueType parameter */ default void registerSourceResolver(TypeWrap type, SourceResolver sourceResolver) { registerSourceResolver(type.getType(), sourceResolver); @@ -205,9 +205,9 @@ default void registerSourceResolver(TypeWrap type, SourceResolver s /** * Registers the {@link SourceResolver} into an internal registry * - * @param type the target source type + * @param type the target source valueType * @param sourceResolver the source resolver to register - * @param the new source type parameter + * @param the new source valueType parameter */ void registerSourceResolver(Type type, SourceResolver sourceResolver); diff --git a/core/src/main/java/dev/velix/imperat/SourceWrapper.java b/core/src/main/java/dev/velix/imperat/SourceWrapper.java index 09022df4..3afa5dd8 100644 --- a/core/src/main/java/dev/velix/imperat/SourceWrapper.java +++ b/core/src/main/java/dev/velix/imperat/SourceWrapper.java @@ -6,18 +6,18 @@ public sealed interface SourceWrapper permits Imperat { /** - * Wraps the sender into a built-in command-sender type + * Wraps the sender into a built-in command-sender valueType * * @param sender the sender's actual value - * @return the wrapped command-sender type + * @return the wrapped command-sender valueType */ S wrapSender(Object sender); /** - * Checks whether the type can be a command sender + * Checks whether the valueType can be a command sender * - * @param type the type - * @return whether the type can be a command sender + * @param type the valueType + * @return whether the valueType can be a command sender */ boolean canBeSender(Type type); } diff --git a/core/src/main/java/dev/velix/imperat/ThrowableHandler.java b/core/src/main/java/dev/velix/imperat/ThrowableHandler.java index 2a0fb50d..d59e2de9 100644 --- a/core/src/main/java/dev/velix/imperat/ThrowableHandler.java +++ b/core/src/main/java/dev/velix/imperat/ThrowableHandler.java @@ -8,24 +8,24 @@ public sealed interface ThrowableHandler permits Imperat { /** - * Retrieves the {@link ThrowableResolver} responsible for handling the specified type + * Retrieves the {@link ThrowableResolver} responsible for handling the specified valueType * of throwable. If no specific resolver is found, it may return null or a default resolver. * * @param exception The class of the throwable to get the resolver for. - * @param The type of the throwable. - * @return The {@link ThrowableResolver} capable of handling the throwable of the specified type, + * @param The valueType of the throwable. + * @return The {@link ThrowableResolver} capable of handling the throwable of the specified valueType, * or null if no specific resolver is registered. */ @Nullable ThrowableResolver getThrowableResolver(final Class exception); /** - * Registers a new {@link ThrowableResolver} for the specified type of throwable. + * Registers a new {@link ThrowableResolver} for the specified valueType of throwable. * This allows customizing the handling of specific throwable types within the application. * * @param exception The class of the throwable to set the resolver for. - * @param handler The {@link ThrowableResolver} to be registered for the specified throwable type. - * @param The type of the throwable. + * @param handler The {@link ThrowableResolver} to be registered for the specified throwable valueType. + * @param The valueType of the throwable. */ void setThrowableResolver( final Class exception, diff --git a/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationFactory.java b/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationFactory.java index 5954e42b..b9189365 100644 --- a/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationFactory.java +++ b/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationFactory.java @@ -23,8 +23,8 @@ public final class AnnotationFactory { * Creates a new annotation with no values. Any default values will * automatically be used. * - * @param type The annotation type - * @param Annotation type + * @param type The annotation valueType + * @param Annotation valueType * @return The newly created annotation */ public static @NotNull T create(@NotNull Class type) { @@ -38,9 +38,9 @@ public final class AnnotationFactory { * Note that the map may also use {@link Supplier}s instead of direct * values. * - * @param type The annotation type + * @param type The annotation valueType * @param members The annotation members - * @param Annotation type + * @param Annotation valueType * @return The newly created annotation */ public static @NotNull T create(@NotNull Class type, @@ -61,8 +61,8 @@ public final class AnnotationFactory { * Note that the map may also use {@link Supplier}s instead of direct * values. * - * @param type The annotation type - * @param Annotation type + * @param type The annotation valueType + * @param Annotation valueType * @return The newly created annotation */ public static @NotNull T create(@NotNull Class type, @@ -87,7 +87,7 @@ public final class AnnotationFactory { /** * Implementation of {@link Annotation#hashCode()}. * - * @param type The annotation type + * @param type The annotation valueType * @param members The annotation members * @return The annotation's hashcode. */ @@ -104,7 +104,7 @@ private static int hashCode(Class type, Map type, Map valueSupplier = (OptionalValueSupplier) emptyConstructor.newInstance(); if (!TypeUtility.matches(valueSupplier.reflectionType(), parameter.getType())) { - throw new IllegalArgumentException("Optional supplier of value-type '" + valueSupplier.reflectionType().getTypeName() + "' doesn't match the optional value type '" + parameter.getType().getName() + "'"); + throw new IllegalArgumentException("Optional supplier of value-valueType '" + valueSupplier.reflectionType().getTypeName() + "' doesn't match the optional value valueType '" + parameter.getType().getName() + "'"); } return valueSupplier; diff --git a/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationParser.java b/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationParser.java index bf105cd2..1fc6cc43 100644 --- a/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationParser.java +++ b/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationParser.java @@ -16,7 +16,7 @@ * parsing annotated command classes and translating/converting them * into {@link Command} POJOs then registering them using {@link Imperat} * - * @param the command-sender type + * @param the command-sender valueType */ public abstract class AnnotationParser { @@ -33,55 +33,55 @@ public static AnnotationParser defaultParser( } /** - * Parses annotated command class of type {@linkplain T} + * Parses annotated command class of valueType {@linkplain T} * into {@link Command} then register it using {@link Imperat} * * @param instance the instance of the command class - * @param the type of annotated command class to parse + * @param the valueType of annotated command class to parse */ public abstract void parseCommandClass(T instance); /** - * Registers a type of annotations so that it can be - * detected by {@link AnnotationReader} , it's useful as it allows that type of annotation + * Registers a valueType of annotations so that it can be + * detected by {@link AnnotationReader} , it's useful as it allows that valueType of annotation * to be recognized as a true Imperat-related annotation to be used in something like checking if a * {@link CommandParameter} is annotated and checks for the annotations it has. * - * @param types the type of annotation + * @param types the valueType of annotation */ public abstract void registerAnnotations(Class... types); /** * Registers {@link AnnotationReplacer} * - * @param type the type to replace the annotation by + * @param type the valueType to replace the annotation by * @param replacer the replacer */ public abstract void registerAnnotationReplacer(Class type, AnnotationReplacer replacer); /** - * Checks the internal registry whether the type of annotation entered is known/registered or not. + * Checks the internal registry whether the valueType of annotation entered is known/registered or not. * - * @param annotationType the type of annotation to enter - * @return whether the type of annotation entered is known/registered or not. + * @param annotationType the valueType of annotation to enter + * @return whether the valueType of annotation entered is known/registered or not. */ public abstract boolean isKnownAnnotation(Class annotationType); /** - * Checks if the specific type of annotation entered has a {@link AnnotationReplacer} + * Checks if the specific valueType of annotation entered has a {@link AnnotationReplacer} * for it in the internal registry for replacers * - * @param type the type of annotation entered - * @return Whether the there's an annotation replacer for the type entered. + * @param type the valueType of annotation entered + * @return Whether the there's an annotation replacer for the valueType entered. */ public abstract boolean hasAnnotationReplacerFor(Class type); /** - * Fetches the {@link AnnotationReplacer} mapped to the entered annotation type. + * Fetches the {@link AnnotationReplacer} mapped to the entered annotation valueType. * - * @param type the type of annotation - * @param the annotation type parameter - * @return the {@link AnnotationReplacer} mapped to the entered annotation type. + * @param type the valueType of annotation + * @param the annotation valueType parameter + * @return the {@link AnnotationReplacer} mapped to the entered annotation valueType. */ public abstract @Nullable AnnotationReplacer getAnnotationReplacer(Class type); diff --git a/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationParserImpl.java b/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationParserImpl.java index cc2c9a8a..aef84cfc 100644 --- a/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationParserImpl.java +++ b/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationParserImpl.java @@ -39,12 +39,12 @@ public void parseCommandClass(T instance) { } /** - * Registers a type of annotations so that it can be - * detected by {@link AnnotationReader} , it's useful as it allows that type of annotation + * Registers a valueType of annotations so that it can be + * detected by {@link AnnotationReader} , it's useful as it allows that valueType of annotation * to be recognized as a true Imperat-related annotation to be used in something like checking if a * {@link CommandParameter} is annotated and checks for the annotations it has. * - * @param type the type of annotation + * @param type the valueType of annotation */ @SafeVarargs @Override @@ -56,7 +56,7 @@ public final void registerAnnotations(Class... type) { /** * Registers {@link AnnotationReplacer} * - * @param type the type to replace the annotation by + * @param type the valueType to replace the annotation by * @param replacer the replacer */ @Override @@ -65,10 +65,10 @@ public void registerAnnotationReplacer(Class type, Ann } /** - * Checks the internal registry whether the type of annotation entered is known/registered or not. + * Checks the internal registry whether the valueType of annotation entered is known/registered or not. * - * @param annotationType the type of annotation to enter - * @return whether the type of annotation entered is known/registered or not. + * @param annotationType the valueType of annotation to enter + * @return whether the valueType of annotation entered is known/registered or not. */ @Override public boolean isKnownAnnotation(Class annotationType) { @@ -76,11 +76,11 @@ public boolean isKnownAnnotation(Class annotationType) { } /** - * Checks if the specific type of annotation entered has a {@link AnnotationReplacer} + * Checks if the specific valueType of annotation entered has a {@link AnnotationReplacer} * for it in the internal registry for replacers * - * @param type the type of annotation entered - * @return Whether the there's an annotation replacer for the type entered. + * @param type the valueType of annotation entered + * @return Whether the there's an annotation replacer for the valueType entered. */ @Override public boolean hasAnnotationReplacerFor(Class type) { @@ -88,10 +88,10 @@ public boolean hasAnnotationReplacerFor(Class type) { } /** - * Fetches the {@link AnnotationReplacer} mapped to the entered annotation type. + * Fetches the {@link AnnotationReplacer} mapped to the entered annotation valueType. * - * @param type the type of annotation - * @return the {@link AnnotationReplacer} mapped to the entered annotation type. + * @param type the valueType of annotation + * @return the {@link AnnotationReplacer} mapped to the entered annotation valueType. */ @Override public @Nullable AnnotationReplacer getAnnotationReplacer(Class type) { diff --git a/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationReplacer.java b/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationReplacer.java index 5cfb6ef7..519f6141 100644 --- a/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationReplacer.java +++ b/core/src/main/java/dev/velix/imperat/annotations/base/AnnotationReplacer.java @@ -11,7 +11,7 @@ * Replaces a custom annotation made by the user, with annotations * made from the basic pre-made annotations such as {@link Command} * - * @param the type of annotation to replace with other annotations + * @param the valueType of annotation to replace with other annotations */ @ApiStatus.AvailableSince("1.0.0") public interface AnnotationReplacer { diff --git a/core/src/main/java/dev/velix/imperat/annotations/base/element/ParseElement.java b/core/src/main/java/dev/velix/imperat/annotations/base/element/ParseElement.java index 128b8481..626b6ad4 100644 --- a/core/src/main/java/dev/velix/imperat/annotations/base/element/ParseElement.java +++ b/core/src/main/java/dev/velix/imperat/annotations/base/element/ParseElement.java @@ -52,12 +52,12 @@ private void load(@NotNull AnnotationPa } /** - * Returns this element's annotation for the specified type if + * Returns this element's annotation for the specified valueType if * such an annotation is present, else null. * * @param annotationClass the Class object corresponding to the - * annotation type - * @return this element's annotation for the specified annotation type if + * annotation valueType + * @return this element's annotation for the specified annotation valueType if * present on this element, else null * @throws NullPointerException if the given annotation class is null * @since 1.5 @@ -105,7 +105,7 @@ public Annotation[] getDeclaredAnnotations() { /** - * Returns an iterator over elements of type {@code T}. + * Returns an iterator over elements of valueType {@code T}. * * @return an Iterator. */ diff --git a/core/src/main/java/dev/velix/imperat/annotations/base/element/RootCommandClass.java b/core/src/main/java/dev/velix/imperat/annotations/base/element/RootCommandClass.java index 6a35c89e..067d6b5b 100644 --- a/core/src/main/java/dev/velix/imperat/annotations/base/element/RootCommandClass.java +++ b/core/src/main/java/dev/velix/imperat/annotations/base/element/RootCommandClass.java @@ -9,7 +9,7 @@ /** * Represents a root command class information * - * @param the command source type + * @param the command source valueType */ public final class RootCommandClass { diff --git a/core/src/main/java/dev/velix/imperat/annotations/base/element/SimpleCommandClassVisitor.java b/core/src/main/java/dev/velix/imperat/annotations/base/element/SimpleCommandClassVisitor.java index e7731337..f2ad6764 100644 --- a/core/src/main/java/dev/velix/imperat/annotations/base/element/SimpleCommandClassVisitor.java +++ b/core/src/main/java/dev/velix/imperat/annotations/base/element/SimpleCommandClassVisitor.java @@ -15,6 +15,7 @@ import dev.velix.imperat.command.parameters.CommandParameter; import dev.velix.imperat.command.parameters.NumericRange; import dev.velix.imperat.command.parameters.StrictParameterList; +import dev.velix.imperat.command.parameters.type.ParameterTypes; import dev.velix.imperat.command.processors.CommandPostProcessor; import dev.velix.imperat.command.processors.CommandPreProcessor; import dev.velix.imperat.context.Source; @@ -448,7 +449,7 @@ private CommandParameter loadParameter( suggestionResolverName ); if (namedResolver != null && !(namedResolver instanceof TypeSuggestionResolver)) - throw new UnsupportedOperationException("Named suggestion resolvers must be of type `TypeSuggestionResolver` and make sure the type matches that of the parameter's"); + throw new UnsupportedOperationException("Named suggestion resolvers must be of valueType `TypeSuggestionResolver` and make sure the valueType matches that of the parameter's"); else if (namedResolver != null) suggestionResolver = (TypeSuggestionResolver) namedResolver; else { @@ -459,7 +460,7 @@ else if (namedResolver != null) boolean greedy = parameter.getAnnotation(Greedy.class) != null; if (greedy && parameter.getType() != String.class) { - throw new IllegalArgumentException("Argument '" + parameter.getName() + "' is greedy while having a non-greedy type '" + parameter.getType().getName() + "'"); + throw new IllegalArgumentException("Argument '" + parameter.getName() + "' is greedy while having a non-greedy valueType '" + parameter.getType().getName() + "'"); } dev.velix.imperat.command.Description desc = dev.velix.imperat.command.Description.EMPTY; @@ -515,12 +516,12 @@ else if (namedResolver != null) CommandParameter param = AnnotationParameterDecorator.decorate( CommandParameter.of( - name, parameterType, permission, desc, + name, ParameterTypes.from(parameterType), permission, desc, optional, greedy, optionalValueSupplier, suggestionResolver ), element ); - if (TypeUtility.isNumericType(TypeWrap.of(param.type())) + if (TypeUtility.isNumericType(TypeWrap.of(param.valueType())) && element.isAnnotationPresent(Range.class)) { Range range = element.getAnnotation(Range.class); assert range != null; diff --git a/core/src/main/java/dev/velix/imperat/annotations/base/element/selector/ElementSelector.java b/core/src/main/java/dev/velix/imperat/annotations/base/element/selector/ElementSelector.java index 1b892dd8..e7d3e796 100644 --- a/core/src/main/java/dev/velix/imperat/annotations/base/element/selector/ElementSelector.java +++ b/core/src/main/java/dev/velix/imperat/annotations/base/element/selector/ElementSelector.java @@ -10,7 +10,7 @@ /** * Selects a {@link ParseElement} based on specific list of {@link Rule} * - * @param the type of {@link ParseElement} to select + * @param the valueType of {@link ParseElement} to select */ public sealed interface ElementSelector> permits SimpleElementSelector { diff --git a/core/src/main/java/dev/velix/imperat/annotations/base/element/selector/MethodRules.java b/core/src/main/java/dev/velix/imperat/annotations/base/element/selector/MethodRules.java index 7f2a5666..b13246e7 100644 --- a/core/src/main/java/dev/velix/imperat/annotations/base/element/selector/MethodRules.java +++ b/core/src/main/java/dev/velix/imperat/annotations/base/element/selector/MethodRules.java @@ -38,7 +38,7 @@ public interface MethodRules { if (parameterElement == null) { msg = "Method '" + method.getName() + "' has no parameters"; } else { - msg = "First parameter of type '" + parameterElement.getType().getTypeName() + "' is not a sub-type of `" + Source.class.getName() + "'"; + msg = "First parameter of valueType '" + parameterElement.getType().getTypeName() + "' is not a sub-valueType of `" + Source.class.getName() + "'"; } throw methodError(method, msg); }) diff --git a/core/src/main/java/dev/velix/imperat/annotations/parameters/AnnotatedParameter.java b/core/src/main/java/dev/velix/imperat/annotations/parameters/AnnotatedParameter.java index 3260ee7d..ba7126b6 100644 --- a/core/src/main/java/dev/velix/imperat/annotations/parameters/AnnotatedParameter.java +++ b/core/src/main/java/dev/velix/imperat/annotations/parameters/AnnotatedParameter.java @@ -18,9 +18,9 @@ public interface AnnotatedParameter extends CommandParameter the type of the annotation - * @return the specific instance of an annotation of a certain type {@linkplain A} + * @param clazz the valueType of annotation + * @param the valueType of the annotation + * @return the specific instance of an annotation of a certain valueType {@linkplain A} */ @Nullable A getAnnotation(Class clazz); diff --git a/core/src/main/java/dev/velix/imperat/annotations/parameters/AnnotationParameterDecorator.java b/core/src/main/java/dev/velix/imperat/annotations/parameters/AnnotationParameterDecorator.java index 40aca7d7..bce3eeae 100644 --- a/core/src/main/java/dev/velix/imperat/annotations/parameters/AnnotationParameterDecorator.java +++ b/core/src/main/java/dev/velix/imperat/annotations/parameters/AnnotationParameterDecorator.java @@ -19,7 +19,7 @@ public final class AnnotationParameterDecorator extends InputP AnnotationParameterDecorator(CommandParameter parameter, ParameterElement element) { super( - parameter.name(), parameter.wrappedType(), parameter.permission(), + parameter.name(), parameter.type(), parameter.permission(), parameter.description(), parameter.isOptional(), parameter.isFlag(), parameter.isGreedy(), parameter.getDefaultValueSupplier(), parameter.getSuggestionResolver() @@ -38,8 +38,8 @@ public static AnnotationParameterDecorator decorate( /** * Get the instance of specific annotation * - * @param clazz the type of annotation - * @return the specific instance of an annotation of a certain type {@linkplain A} + * @param clazz the valueType of annotation + * @return the specific instance of an annotation of a certain valueType {@linkplain A} */ @Override public @Nullable A getAnnotation(Class clazz) { diff --git a/core/src/main/java/dev/velix/imperat/command/BaseImperat.java b/core/src/main/java/dev/velix/imperat/command/BaseImperat.java index 134f9971..1f96f85e 100644 --- a/core/src/main/java/dev/velix/imperat/command/BaseImperat.java +++ b/core/src/main/java/dev/velix/imperat/command/BaseImperat.java @@ -81,7 +81,7 @@ private void registerProcessors() { private void regDefThrowableResolvers() { this.setThrowableResolver(InvalidSourceException.class, (exception, imperat, context) -> { - throw new UnsupportedOperationException("Couldn't find any source resolver for type `" + throw new UnsupportedOperationException("Couldn't find any source resolver for valueType `" + exception.getTargetType().getType().getTypeName() + "'"); }); @@ -261,12 +261,12 @@ public void setAnnotationParser(AnnotationParser parser) { } /** - * Registers a type of annotations so that it can be - * detected by {@link AnnotationReader} , it's useful as it allows that type of annotation + * Registers a valueType of annotations so that it can be + * detected by {@link AnnotationReader} , it's useful as it allows that valueType of annotation * to be recognized as a true Imperat-related annotation to be used in something like checking if a * {@link CommandParameter} is annotated and checks for the annotations it has. * - * @param type the type of annotation + * @param type the valueType of annotation */ @SafeVarargs @Override @@ -277,7 +277,7 @@ public final void registerAnnotations(Class... type) { /** * Registers {@link AnnotationReplacer} * - * @param type the type to replace the annotation by + * @param type the valueType to replace the annotation by * @param replacer the replacer */ @Override @@ -323,11 +323,11 @@ public void setContextFactory(@NotNull ContextFactory contextFactory) { } /** - * Checks whether the type has + * Checks whether the valueType has * a registered context-resolver * - * @param type the type - * @return whether the type has + * @param type the valueType + * @return whether the valueType has * a context-resolver */ @Override @@ -355,9 +355,9 @@ public void registerContextResolverFactory(Type type, ContextResolverFactory } /** - * Fetches {@link ContextResolver} for a certain type + * Fetches {@link ContextResolver} for a certain valueType * - * @param resolvingContextType the type for this resolver + * @param resolvingContextType the valueType for this resolver * @return the context resolver */ @Override @@ -380,7 +380,7 @@ public void registerContextResolverFactory(Type type, ContextResolverFactory /** * Registers {@link ContextResolver} * - * @param type the class-type of value being resolved from context + * @param type the class-valueType of value being resolved from context * @param resolver the resolver for this value */ @Override @@ -392,7 +392,7 @@ public void registerContextResolver(Type type, /** * Registers {@link ValueResolver} * - * @param type the class-type of value being resolved from context + * @param type the class-valueType of value being resolved from context * @param resolver the resolver for this value */ @Override @@ -412,7 +412,7 @@ public void registerValueResolver(Type type, @NotNull ValueResolver re * Fetches {@link ValueResolver} for a certain value * * @param resolvingValueType the value that the resolver ends providing it from the context - * @return the context resolver of a certain type + * @return the context resolver of a certain valueType */ @Override public @Nullable ValueResolver getValueResolver(Type resolvingValueType) { @@ -420,11 +420,11 @@ public void registerValueResolver(Type type, @NotNull ValueResolver re } /** - * Fetches the suggestion provider/resolver for a specific type of + * Fetches the suggestion provider/resolver for a specific valueType of * argument or parameter. * - * @param type the type - * @return the {@link SuggestionResolver} instance for that type + * @param type the valueType + * @return the {@link SuggestionResolver} instance for that valueType */ @Override public @Nullable SuggestionResolver getSuggestionResolverByType(Type type) { @@ -432,10 +432,10 @@ public void registerValueResolver(Type type, @NotNull ValueResolver re } /** - * Checks whether the type can be a command sender + * Checks whether the valueType can be a command sender * - * @param type the type - * @return whether the type can be a command sender + * @param type the valueType + * @return whether the valueType can be a command sender */ @Override public boolean canBeSender(Type type) { @@ -453,9 +453,9 @@ public void registerSuggestionResolver(TypeSuggestionResolver suggesti } /** - * Registers a suggestion resolver to a type + * Registers a suggestion resolver to a valueType * - * @param type the type + * @param type the valueType * @param suggestionResolver the suggestion resolver. */ @Override diff --git a/core/src/main/java/dev/velix/imperat/command/Command.java b/core/src/main/java/dev/velix/imperat/command/Command.java index bf9021fe..56a01c3e 100644 --- a/core/src/main/java/dev/velix/imperat/command/Command.java +++ b/core/src/main/java/dev/velix/imperat/command/Command.java @@ -28,7 +28,7 @@ /** * Represents a wrapper for the actual command's data * - * @param the command sender type + * @param the command sender valueType */ @ApiStatus.AvailableSince("1.0.0") public interface Command extends CommandParameter { @@ -309,7 +309,7 @@ default boolean isSubCommand() { } /** - * @return the value type of this parameter + * @return the value valueType of this parameter */ @Override default TypeWrap wrappedType() { diff --git a/core/src/main/java/dev/velix/imperat/command/CommandExecution.java b/core/src/main/java/dev/velix/imperat/command/CommandExecution.java index 46dee591..c08a0bf1 100644 --- a/core/src/main/java/dev/velix/imperat/command/CommandExecution.java +++ b/core/src/main/java/dev/velix/imperat/command/CommandExecution.java @@ -9,7 +9,7 @@ * This class represents the execution/action of this command that's triggered when * the sender asks for this command to be executed. * - * @param the command sender type + * @param the command sender valueType */ @ApiStatus.AvailableSince("1.0.0") public interface CommandExecution { diff --git a/core/src/main/java/dev/velix/imperat/command/CommandUsage.java b/core/src/main/java/dev/velix/imperat/command/CommandUsage.java index e8ad5c47..80bcd5db 100644 --- a/core/src/main/java/dev/velix/imperat/command/CommandUsage.java +++ b/core/src/main/java/dev/velix/imperat/command/CommandUsage.java @@ -135,8 +135,8 @@ default CommandUsage mergeWithCommand(Command subCommand, CommandUsage } /** - * @param clazz the type of the parameter to check upon - * @return Whether the usage has a specific type of parameter + * @param clazz the valueType of the parameter to check upon + * @return Whether the usage has a specific valueType of parameter */ boolean hasParamType(Class clazz); @@ -155,7 +155,7 @@ default CommandUsage mergeWithCommand(Command subCommand, CommandUsage int getMaxLength(); /** - * Searches for a parameter with specific type + * Searches for a parameter with specific valueType * * @param parameterPredicate the parameter condition * @return whether this usage has atLeast on {@link CommandParameter} with specific condition diff --git a/core/src/main/java/dev/velix/imperat/command/CommandUsageImpl.java b/core/src/main/java/dev/velix/imperat/command/CommandUsageImpl.java index 20fd2d6d..6c83437e 100644 --- a/core/src/main/java/dev/velix/imperat/command/CommandUsageImpl.java +++ b/core/src/main/java/dev/velix/imperat/command/CommandUsageImpl.java @@ -176,14 +176,14 @@ public List> getParametersWithoutFlags() { } /** - * @param clazz the type of the parameter to check upon - * @return Whether the usage has a specific type of parameter + * @param clazz the valueType of the parameter to check upon + * @return Whether the usage has a specific valueType of parameter */ @Override public boolean hasParamType(Class clazz) { return getParameters() .stream() - .anyMatch((param) -> param.type().equals(clazz)); + .anyMatch((param) -> param.valueType().equals(clazz)); } /** @@ -210,7 +210,7 @@ public int getMaxLength() { } /** - * Searches for a parameter with specific type + * Searches for a parameter with specific valueType * * @param parameterPredicate the parameter condition * @return whether this usage has atLeast on {@link CommandParameter} with specific condition diff --git a/core/src/main/java/dev/velix/imperat/command/ContextResolverFactory.java b/core/src/main/java/dev/velix/imperat/command/ContextResolverFactory.java index c6057f69..9e580770 100644 --- a/core/src/main/java/dev/velix/imperat/command/ContextResolverFactory.java +++ b/core/src/main/java/dev/velix/imperat/command/ContextResolverFactory.java @@ -11,7 +11,7 @@ * Represents a context resolver factory * that is responsible for creating {@link ContextResolver} * - * @param the command-sender type + * @param the command-sender valueType */ public interface ContextResolverFactory { diff --git a/core/src/main/java/dev/velix/imperat/command/cooldown/CooldownHandler.java b/core/src/main/java/dev/velix/imperat/command/cooldown/CooldownHandler.java index d34a6d06..deb0c9f3 100644 --- a/core/src/main/java/dev/velix/imperat/command/cooldown/CooldownHandler.java +++ b/core/src/main/java/dev/velix/imperat/command/cooldown/CooldownHandler.java @@ -10,7 +10,7 @@ * Cool-down checker and handler for the command usages * {@link CommandUsage} * - * @param the sender-type + * @param the sender-valueType */ @ApiStatus.AvailableSince("1.0.0") public interface CooldownHandler { diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/CommandParameter.java b/core/src/main/java/dev/velix/imperat/command/parameters/CommandParameter.java index cf157ba8..7d6ac055 100644 --- a/core/src/main/java/dev/velix/imperat/command/parameters/CommandParameter.java +++ b/core/src/main/java/dev/velix/imperat/command/parameters/CommandParameter.java @@ -5,12 +5,13 @@ import dev.velix.imperat.command.Description; import dev.velix.imperat.command.DescriptionHolder; import dev.velix.imperat.command.PermissionHolder; +import dev.velix.imperat.command.parameters.type.ParameterType; +import dev.velix.imperat.command.parameters.type.ParameterTypes; import dev.velix.imperat.context.Source; import dev.velix.imperat.resolvers.SuggestionResolver; import dev.velix.imperat.resolvers.TypeSuggestionResolver; import dev.velix.imperat.supplier.OptionalValueSupplier; import dev.velix.imperat.util.Preconditions; -import dev.velix.imperat.util.TypeUtility; import dev.velix.imperat.util.TypeWrap; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -27,7 +28,7 @@ public interface CommandParameter extends PermissionHolder, De static CommandParameter of( String name, - TypeWrap type, + ParameterType type, @Nullable String permission, Description description, boolean optional, @@ -37,7 +38,7 @@ static CommandParameter of( ) { Preconditions.notNull(name, "name"); Preconditions.notNull(type, "type"); - Preconditions.checkArgument(!TypeUtility.matches(type.getType(), Object.class), "Type cannot be `Object`"); + Preconditions.checkArgument(!type.equalsExactly(Object.class), "Type cannot be `Object`"); return new NormalCommandParameter<>( name, type, permission, description, optional, @@ -45,76 +46,71 @@ static CommandParameter of( ); } - static ParameterBuilder required(String name, TypeWrap type) { + static ParameterBuilder required(String name, ParameterType type) { return new ParameterBuilder<>(name, type, false); } - static ParameterBuilder required(String name, Class type) { - return required(name, TypeWrap.of(type)); - } - static ParameterBuilder requiredInt(String name) { - return required(name, Integer.class); + return required(name, ParameterTypes.numeric(Integer.class)); } static ParameterBuilder requiredLong(String name) { - return required(name, Long.class); + return required(name, ParameterTypes.numeric(Long.class)); } static ParameterBuilder requiredDouble(String name) { - return required(name, Double.class); + return required(name, ParameterTypes.numeric(Double.class)); } static ParameterBuilder requiredFloat(String name) { - return required(name, Float.class); + return required(name, ParameterTypes.numeric(Float.class)); } static ParameterBuilder requiredBoolean(String name) { - return required(name, Boolean.class); + return required(name, ParameterTypes.bool()); } static ParameterBuilder requiredText(String name) { - return required(name, String.class); + return required(name, ParameterTypes.string()); } + //TODO REPLACE GREEDY SYSTEM WITH PARAMETER TYPE SYSTEM static ParameterBuilder requiredGreedy(String name) { - return new ParameterBuilder<>(name, String.class, false, true); + return new ParameterBuilder<>(name, ParameterTypes.string(), false, true); } - static ParameterBuilder optional(String name, TypeWrap token) { + static ParameterBuilder optional(String name, ParameterType token) { return new ParameterBuilder<>(name, token, true); } - static ParameterBuilder optional(String name, Class type) { - return optional(name, TypeWrap.of(type)); - } static ParameterBuilder optionalInt(String name) { - return optional(name, Integer.class); + return optional(name, ParameterTypes.numeric(Integer.class)); } static ParameterBuilder optionalLong(String name) { - return optional(name, Long.class); + return optional(name, ParameterTypes.numeric(Long.class)); } static ParameterBuilder optionalDouble(String name) { - return optional(name, Double.class); + return optional(name, ParameterTypes.numeric(Double.class)); } static ParameterBuilder optionalFloat(String name) { - return optional(name, Float.class); + return optional(name, ParameterTypes.numeric(Float.class)); } static ParameterBuilder optionalBoolean(String name) { - return optional(name, Boolean.class); + return optional(name, ParameterTypes.bool()); } static ParameterBuilder optionalText(String name) { - return optional(name, String.class); + return optional(name, ParameterTypes.string()); } + //TODO REPLACE GREEDY SYSTEM WITH PARAMETER TYPE SYSTEM static ParameterBuilder optionalGreedy(String name) { - return new ParameterBuilder<>(name, String.class, true, true); + return new ParameterBuilder<>(name, ParameterTypes.string(), true, true); } static FlagBuilder flag( @@ -161,17 +157,19 @@ static FlagBuilder flagSwitch(String name) { void position(int position); /** - * @return the value type-token of this parameter + * @return the value valueType-token of this parameter */ TypeWrap wrappedType(); /** - * @return the value type of this parameter + * @return the value valueType of this parameter */ - default Type type() { + default Type valueType() { return wrappedType().getType(); } + @NotNull ParameterType type(); + /** * @return the default value if it's input is not present * in case of the parameter being optional @@ -238,7 +236,7 @@ default AnnotatedParameter asAnnotated() { * Fetches the suggestion resolver linked to this * command parameter. * - * @param the type of value to be resolved + * @param the valueType of value to be resolved * @return the {@link SuggestionResolver} for a resolving suggestion */ @Nullable @@ -260,13 +258,13 @@ default NumericParameter asNumeric() { } /** - * Checks if this parameter has same name and type to the other {@link CommandParameter} + * Checks if this parameter has same name and valueType to the other {@link CommandParameter} * unlike `CommandParameter#equals(Object)`, * if both parameters are only different in their parent {@link Command}, * it would still return true * * @param parameter the parameter to compare to - * @return Whether this parameter has same name and type to the other {@link CommandParameter} or not + * @return Whether this parameter has same name and valueType to the other {@link CommandParameter} or not */ boolean similarTo(CommandParameter parameter); diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/FlagBuilder.java b/core/src/main/java/dev/velix/imperat/command/parameters/FlagBuilder.java index 6b3393d1..b8352f41 100644 --- a/core/src/main/java/dev/velix/imperat/command/parameters/FlagBuilder.java +++ b/core/src/main/java/dev/velix/imperat/command/parameters/FlagBuilder.java @@ -1,5 +1,6 @@ package dev.velix.imperat.command.parameters; +import dev.velix.imperat.command.parameters.type.ParameterTypes; import dev.velix.imperat.context.CommandFlag; import dev.velix.imperat.context.CommandSwitch; import dev.velix.imperat.context.Source; @@ -8,6 +9,7 @@ import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public final class FlagBuilder extends ParameterBuilder { @@ -18,7 +20,7 @@ public final class FlagBuilder extends ParameterBuilder suggestionResolver; private FlagBuilder(String name, Class inputType) { - super(name, CommandFlag.class, true, false); + super(name, ParameterTypes.flag(CommandFlag.create(name, Collections.emptyList(), inputType)), true, false); this.inputType = inputType; } @@ -47,7 +49,7 @@ public FlagBuilder aliases(String... aliases) { public FlagBuilder flagDefaultInputValue(OptionalValueSupplier valueSupplier) { if (inputType == null) { - throw new IllegalArgumentException("Flag of type switches, cannot have a default value supplier !"); + throw new IllegalArgumentException("Flag of valueType switches, cannot have a default value supplier !"); } this.defaultValueSupplier = valueSupplier; return this; @@ -55,7 +57,7 @@ public FlagBuilder flagDefaultInputValue(OptionalValueSupplier valueSup public FlagBuilder suggestForInputValue(TypeSuggestionResolver suggestionResolver) { if (inputType == null) { - throw new IllegalArgumentException("Flag of type switches, cannot have a default value supplier !"); + throw new IllegalArgumentException("Flag of valueType switches, cannot have a default value supplier !"); } this.suggestionResolver = suggestionResolver; return this; diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/FlagParameter.java b/core/src/main/java/dev/velix/imperat/command/parameters/FlagParameter.java index 7f1fa0be..cf018b20 100644 --- a/core/src/main/java/dev/velix/imperat/command/parameters/FlagParameter.java +++ b/core/src/main/java/dev/velix/imperat/command/parameters/FlagParameter.java @@ -18,14 +18,14 @@ public interface FlagParameter extends CommandParameter { CommandFlag flagData(); /** - * @return The type of input value + * @return The valueType of input value */ default Type inputValueType() { return flagData().inputType(); } /** - * @param the type of flag input value + * @param the valueType of flag input value * @return the {@link TypeSuggestionResolver} for input value of this flag * null if the flag is {@link CommandSwitch}, check using {@link FlagParameter#isSwitch()} */ diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/InputParameter.java b/core/src/main/java/dev/velix/imperat/command/parameters/InputParameter.java index 7d6bea75..64539590 100644 --- a/core/src/main/java/dev/velix/imperat/command/parameters/InputParameter.java +++ b/core/src/main/java/dev/velix/imperat/command/parameters/InputParameter.java @@ -2,11 +2,11 @@ import dev.velix.imperat.command.Command; import dev.velix.imperat.command.Description; +import dev.velix.imperat.command.parameters.type.ParameterType; import dev.velix.imperat.context.Source; import dev.velix.imperat.resolvers.SuggestionResolver; import dev.velix.imperat.resolvers.TypeSuggestionResolver; import dev.velix.imperat.supplier.OptionalValueSupplier; -import dev.velix.imperat.util.TypeUtility; import dev.velix.imperat.util.TypeWrap; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -19,7 +19,7 @@ public abstract class InputParameter implements CommandParamet protected Command parentCommand; protected final String name; - protected final TypeWrap typeWrap; + protected final ParameterType type; protected final boolean optional, flag, greedy; protected final OptionalValueSupplier optionalValueSupplier; protected final TypeSuggestionResolver suggestionResolver; @@ -29,7 +29,8 @@ public abstract class InputParameter implements CommandParamet protected InputParameter( - String name, TypeWrap typeWrap, + String name, + @NotNull ParameterType type, @Nullable String permission, Description description, boolean optional, boolean flag, boolean greedy, @@ -37,7 +38,7 @@ protected InputParameter( @Nullable TypeSuggestionResolver suggestionResolver ) { this.name = name; - this.typeWrap = typeWrap; + this.type = type; this.permission = permission; this.description = description; this.optional = optional; @@ -86,9 +87,14 @@ public void position(int position) { this.index = position; } + @Override + public @NotNull ParameterType type() { + return type; + } + @Override public TypeWrap wrappedType() { - return typeWrap; + return type.wrappedType(); } /** @@ -149,9 +155,9 @@ public FlagParameter asFlagParameter() { */ @Override public boolean isGreedy() { - if (this.typeWrap.getType() != String.class && greedy) { + if (this.type.type() != String.class && greedy) { throw new IllegalStateException( - String.format("Usage parameter '%s' cannot be greedy while having value-type '%s'", name, type().getTypeName()) + String.format("Usage parameter '%s' cannot be greedy while having value-valueType '%s'", name, valueType().getTypeName()) ); } return greedy; @@ -188,7 +194,7 @@ public void describe(final Description description) { @Override public boolean similarTo(CommandParameter parameter) { return this.name.equalsIgnoreCase(parameter.name()) - && TypeUtility.matches(typeWrap.getType(), parameter.wrappedType().getType()); + && type.isRelatedToType(parameter.wrappedType().getType()); } @Override @@ -197,12 +203,12 @@ public boolean equals(Object o) { if (!(o instanceof InputParameter that)) return false; return Objects.equals(parentCommand, that.parentCommand) && Objects.equals(name, that.name) - && Objects.equals(typeWrap, that.typeWrap); + && Objects.equals(type, that.type); } @Override public int hashCode() { - return Objects.hash(name, typeWrap); + return Objects.hash(name, type); } @Override diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/NormalCommandParameter.java b/core/src/main/java/dev/velix/imperat/command/parameters/NormalCommandParameter.java index 5e3f42f1..71ade00d 100644 --- a/core/src/main/java/dev/velix/imperat/command/parameters/NormalCommandParameter.java +++ b/core/src/main/java/dev/velix/imperat/command/parameters/NormalCommandParameter.java @@ -1,18 +1,18 @@ package dev.velix.imperat.command.parameters; import dev.velix.imperat.command.Description; +import dev.velix.imperat.command.parameters.type.ParameterType; import dev.velix.imperat.context.Source; import dev.velix.imperat.resolvers.TypeSuggestionResolver; import dev.velix.imperat.supplier.OptionalValueSupplier; import dev.velix.imperat.util.StringUtils; -import dev.velix.imperat.util.TypeWrap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; class NormalCommandParameter extends InputParameter { NormalCommandParameter(String name, - TypeWrap type, + ParameterType type, @Nullable String permission, Description description, boolean optional, diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/ParameterBuilder.java b/core/src/main/java/dev/velix/imperat/command/parameters/ParameterBuilder.java index 236132ad..4c1dc7f2 100644 --- a/core/src/main/java/dev/velix/imperat/command/parameters/ParameterBuilder.java +++ b/core/src/main/java/dev/velix/imperat/command/parameters/ParameterBuilder.java @@ -1,19 +1,19 @@ package dev.velix.imperat.command.parameters; import dev.velix.imperat.command.Description; +import dev.velix.imperat.command.parameters.type.ParameterType; import dev.velix.imperat.context.Source; import dev.velix.imperat.resolvers.SuggestionResolver; import dev.velix.imperat.resolvers.TypeSuggestionResolver; import dev.velix.imperat.supplier.OptionalValueSupplier; import dev.velix.imperat.util.Preconditions; -import dev.velix.imperat.util.TypeWrap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public sealed class ParameterBuilder permits FlagBuilder { protected final String name; - private final TypeWrap type; + private final ParameterType type; private final boolean optional; private final boolean greedy; @@ -22,26 +22,18 @@ public sealed class ParameterBuilder permits FlagBuilder { private @NotNull OptionalValueSupplier valueSupplier; private TypeSuggestionResolver suggestionResolver = null; - ParameterBuilder(String name, TypeWrap type, boolean optional, boolean greedy) { + ParameterBuilder(String name, ParameterType type, boolean optional, boolean greedy) { this.name = name; this.type = type; this.optional = optional; this.greedy = greedy; - this.valueSupplier = OptionalValueSupplier.empty(type); + this.valueSupplier = OptionalValueSupplier.empty(type.wrappedType()); } - ParameterBuilder(String name, TypeWrap type, boolean optional) { + ParameterBuilder(String name, ParameterType type, boolean optional) { this(name, type, optional, false); } - ParameterBuilder(String name, Class type, boolean optional, boolean greedy) { - this(name, TypeWrap.of(type), optional, greedy); - } - - - ParameterBuilder(String name, Class type, boolean optional) { - this(name, type, optional, false); - } public ParameterBuilder permission(@Nullable String permission) { this.permission = permission; @@ -64,7 +56,7 @@ public ParameterBuilder defaultValue(@NotNull OptionalValueSupplier def } public ParameterBuilder defaultValue(@Nullable T value) { - return defaultValue(value == null ? OptionalValueSupplier.empty(this.type) : OptionalValueSupplier.of(value)); + return defaultValue(value == null ? OptionalValueSupplier.empty(this.type.wrappedType()) : OptionalValueSupplier.of(value)); } public ParameterBuilder suggest(TypeSuggestionResolver suggestionResolver) { @@ -73,7 +65,7 @@ public ParameterBuilder suggest(TypeSuggestionResolver suggestionRes } public ParameterBuilder suggest(String... suggestions) { - return suggest(SuggestionResolver.type(type, suggestions)); + return suggest(SuggestionResolver.type(type.wrappedType(), suggestions)); } public CommandParameter build() { diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/type/BaseParameterType.java b/core/src/main/java/dev/velix/imperat/command/parameters/type/BaseParameterType.java new file mode 100644 index 00000000..bbeecf6d --- /dev/null +++ b/core/src/main/java/dev/velix/imperat/command/parameters/type/BaseParameterType.java @@ -0,0 +1,45 @@ +package dev.velix.imperat.command.parameters.type; + +import dev.velix.imperat.context.Source; +import dev.velix.imperat.resolvers.SuggestionResolver; +import dev.velix.imperat.resolvers.TypeSuggestionResolver; +import dev.velix.imperat.util.TypeWrap; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public abstract class BaseParameterType implements ParameterType { + + protected final TypeWrap typeWrap; + protected final List suggestions = new ArrayList<>(); + protected final TypeSuggestionResolver suggestionResolver; + + protected BaseParameterType(TypeWrap typeWrap) { + this.typeWrap = typeWrap; + this.suggestionResolver = SuggestionResolver.type(typeWrap, suggestions()); + } + + @Override + public Type type() { + return typeWrap.getType(); + } + + @Override + public Collection suggestions() { + return suggestions; + } + + @Override + public TypeSuggestionResolver getSuggestionResolver() { + return suggestionResolver; + } + + @Override + public @NotNull ParameterType withSuggestions(String... suggestions) { + this.suggestions.addAll(List.of(suggestions)); + return this; + } +} diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterBoolean.java b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterBoolean.java new file mode 100644 index 00000000..09712f7e --- /dev/null +++ b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterBoolean.java @@ -0,0 +1,66 @@ +package dev.velix.imperat.command.parameters.type; + +import dev.velix.imperat.context.ResolvedContext; +import dev.velix.imperat.context.Source; +import dev.velix.imperat.context.internal.sur.CommandInputStream; +import dev.velix.imperat.exception.ImperatException; +import dev.velix.imperat.exception.SourceException; +import dev.velix.imperat.util.TypeWrap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Locale; +import java.util.Map; + +public final class ParameterBoolean extends BaseParameterType { + + private final static Map VARIANTS = Map.of( + "t", true, "f", false, + "yes", true, "no", false, + "y", true, "n", false, + "on", true, "off", false, + "enabled", true, "disabled", false + ); + + private boolean allowVariants = false; + + ParameterBoolean() { + super(TypeWrap.of(Boolean.class)); + } + + @Override + public @Nullable Boolean resolve(ResolvedContext context, @NotNull CommandInputStream commandInputStream) throws ImperatException { + + var raw = commandInputStream.currentRaw(); + if (raw.equalsIgnoreCase("true") || raw.equalsIgnoreCase("false")) { + return Boolean.parseBoolean(raw); + } + + if (allowVariants) { + return VARIANTS.get(raw.toLowerCase()); + } else { + throw new SourceException("Invalid boolean '%s'", raw); + } + } + + @Override + public boolean matchesInput(String input) { + + if (!allowVariants && (input.equalsIgnoreCase("true") || input.equalsIgnoreCase("false"))) + return true; + else if (allowVariants) { + return VARIANTS.get(input.toLowerCase(Locale.ENGLISH)) != null; + } + + return Boolean.parseBoolean(input); + } + + public ParameterBoolean setAllowVariants(boolean allowVariants) { + this.allowVariants = allowVariants; + return this; + } + + public ParameterBoolean allowVariants() { + return setAllowVariants(true); + } +} diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterFlag.java b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterFlag.java new file mode 100644 index 00000000..b9fe0943 --- /dev/null +++ b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterFlag.java @@ -0,0 +1,41 @@ +package dev.velix.imperat.command.parameters.type; + +import dev.velix.imperat.context.CommandFlag; +import dev.velix.imperat.context.ResolvedContext; +import dev.velix.imperat.context.Source; +import dev.velix.imperat.context.internal.sur.CommandInputStream; +import dev.velix.imperat.exception.ImperatException; +import dev.velix.imperat.util.Patterns; +import dev.velix.imperat.util.TypeWrap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ParameterFlag extends BaseParameterType { + private final CommandFlag flag; + + protected ParameterFlag(CommandFlag flag) { + super(TypeWrap.of(CommandFlag.class)); + this.flag = flag; + } + + + //TODO fix fucked up flags structure next week + @Override + public @Nullable CommandFlag resolve(ResolvedContext context, @NotNull CommandInputStream commandInputStream) throws ImperatException { + return null; + } + + @Override + public boolean matchesInput(String input) { + int subStringIndex; + if (Patterns.SINGLE_FLAG.matcher(input).matches()) { + subStringIndex = 1; + } else if (Patterns.DOUBLE_FLAG.matcher(input).matches()) { + subStringIndex = 2; + } else { + subStringIndex = 0; + } + String flagInput = input.substring(subStringIndex); + return flag.acceptsInput(flagInput); + } +} diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterNumber.java b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterNumber.java new file mode 100644 index 00000000..b3f289ef --- /dev/null +++ b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterNumber.java @@ -0,0 +1,126 @@ +package dev.velix.imperat.command.parameters.type; + +import dev.velix.imperat.context.ResolvedContext; +import dev.velix.imperat.context.Source; +import dev.velix.imperat.context.internal.sur.CommandInputStream; +import dev.velix.imperat.exception.ImperatException; +import dev.velix.imperat.exception.SourceException; +import dev.velix.imperat.util.TypeUtility; +import dev.velix.imperat.util.TypeWrap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public abstract class ParameterNumber extends BaseParameterType { + + protected ParameterNumber(TypeWrap typeWrap) { + super(typeWrap); + } + + @SuppressWarnings("unchecked") + static ParameterNumber from(Class numType) { + if (TypeUtility.matches(numType, Integer.class)) { + return (ParameterNumber) new ParameterInt<>(); + } else if (TypeUtility.matches(numType, Long.class)) { + return (ParameterNumber) new ParameterLong<>(); + } else if (TypeUtility.matches(numType, Float.class)) { + return (ParameterNumber) new ParameterFloat<>(); + } else if (TypeUtility.matches(numType, Double.class)) { + return (ParameterNumber) new ParameterDouble<>(); + } else { + throw new IllegalArgumentException("Unsupported number type: " + numType.getName()); + } + } + + @Override + public @Nullable N resolve(ResolvedContext context, @NotNull CommandInputStream commandInputStream) throws ImperatException { + + String input = commandInputStream.currentRaw(); + try { + return parse(input); + } catch (NumberFormatException ex) { + throw new SourceException("Invalid " + display() + " format input '%s'", input); + } + } + + @Override + public boolean matchesInput(String input) { + try { + parse(input); + return true; + } catch (NumberFormatException ex) { + return false; + } + } + + public abstract String display(); + + public abstract N parse(String input) throws NumberFormatException; + + static class ParameterInt extends ParameterNumber { + + protected ParameterInt() { + super(TypeWrap.of(Integer.class)); + } + + @Override + public String display() { + return "integer"; + } + + @Override + public Integer parse(String input) throws NumberFormatException { + return Integer.parseInt(input); + } + } + + static class ParameterFloat extends ParameterNumber { + + protected ParameterFloat() { + super(TypeWrap.of(Float.class)); + } + + @Override + public String display() { + return "float"; + } + + @Override + public Float parse(String input) throws NumberFormatException { + return Float.parseFloat(input); + } + } + + static class ParameterLong extends ParameterNumber { + + protected ParameterLong() { + super(TypeWrap.of(Long.class)); + } + + @Override + public String display() { + return "long"; + } + + @Override + public Long parse(String input) throws NumberFormatException { + return Long.parseLong(input); + } + } + + static class ParameterDouble extends ParameterNumber { + + protected ParameterDouble() { + super(TypeWrap.of(Double.class)); + } + + @Override + public String display() { + return "double"; + } + + @Override + public Double parse(String input) throws NumberFormatException { + return Double.parseDouble(input); + } + } +} diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterString.java b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterString.java new file mode 100644 index 00000000..04d16ecb --- /dev/null +++ b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterString.java @@ -0,0 +1,59 @@ +package dev.velix.imperat.command.parameters.type; + +import dev.velix.imperat.context.ResolvedContext; +import dev.velix.imperat.context.Source; +import dev.velix.imperat.context.internal.sur.CommandInputStream; +import dev.velix.imperat.exception.ImperatException; +import dev.velix.imperat.util.TypeWrap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public final class ParameterString extends BaseParameterType { + + private final static char DOUBLE_QUOTE = '"', SINGLE_QUOTE = '\'', BACKSLASH = '\\'; + + ParameterString() { + super(TypeWrap.of(String.class)); + } + + @Override + public @Nullable String resolve(ResolvedContext context, @NotNull CommandInputStream inputStream) throws ImperatException { + StringBuilder builder = new StringBuilder(); + final Character current = inputStream.currentLetter(); + + if (!isQuoteChar(current)) { + return inputStream.currentRaw(); + } + + Character next; + do { + //quoted + //we shift to next char + next = inputStream.popLetter().orElse(null); + if (next == null) break; + if (Character.isWhitespace(current)) { + continue; + } + + if (next == BACKSLASH) { + //skip + continue; + } + + builder.append(next); + + } while (inputStream.hasNextLetter() && + inputStream.peekLetter().filter((ch) -> !isQuoteChar(ch)).isPresent()); + + return builder.toString(); + } + + private boolean isQuoteChar(char ch) { + return ch == DOUBLE_QUOTE || ch == SINGLE_QUOTE; + } + + @Override + public boolean matchesInput(String input) { + return true; + } +} diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterType.java b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterType.java new file mode 100644 index 00000000..07fbc84e --- /dev/null +++ b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterType.java @@ -0,0 +1,42 @@ +package dev.velix.imperat.command.parameters.type; + +import dev.velix.imperat.context.ResolvedContext; +import dev.velix.imperat.context.Source; +import dev.velix.imperat.context.internal.sur.CommandInputStream; +import dev.velix.imperat.exception.ImperatException; +import dev.velix.imperat.resolvers.TypeSuggestionResolver; +import dev.velix.imperat.util.TypeUtility; +import dev.velix.imperat.util.TypeWrap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Type; +import java.util.Collection; + +public interface ParameterType { + + Type type(); + + @Nullable T resolve(ResolvedContext context, @NotNull CommandInputStream commandInputStream) throws ImperatException; + + Collection suggestions(); + + TypeSuggestionResolver getSuggestionResolver(); + + boolean matchesInput(String input); + + default boolean isRelatedToType(Type type) { + return TypeUtility.areRelatedTypes(type, this.type()); + } + + default boolean equalsExactly(Type type) { + return TypeUtility.matches(type, type()); + } + + @NotNull ParameterType withSuggestions(String... suggestions); + + @SuppressWarnings("unchecked") + default TypeWrap wrappedType() { + return (TypeWrap) TypeWrap.of(type()); + } +} diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterTypes.java b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterTypes.java new file mode 100644 index 00000000..455edcbf --- /dev/null +++ b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterTypes.java @@ -0,0 +1,59 @@ +package dev.velix.imperat.command.parameters.type; + +import dev.velix.imperat.context.CommandFlag; +import dev.velix.imperat.context.Source; +import dev.velix.imperat.util.Registry; +import dev.velix.imperat.util.TypeUtility; +import dev.velix.imperat.util.TypeWrap; + +import java.lang.reflect.Type; + +public final class ParameterTypes { + + private final static Registry> types = new Registry<>(); + + private ParameterTypes() { + throw new AssertionError(); + } + + public static ParameterWord word() { + return new ParameterWord<>(); + } + + public static ParameterString string() { + return new ParameterString<>(); + } + + public static ParameterNumber numeric(Class numType) { + return ParameterNumber.from(numType); + } + + public static ParameterBoolean bool() { + return new ParameterBoolean<>(); + } + + public static ParameterFlag flag(CommandFlag flag) { + return new ParameterFlag<>(flag); + } + + @SuppressWarnings("unchecked") + public static ParameterType from(TypeWrap typeWrap) { + Class type = (Class) typeWrap.getType(); + if (TypeUtility.matches(type, String.class)) { + return (ParameterType) string(); + } else if (TypeUtility.matches(type, Boolean.class)) { + return (ParameterType) bool(); + } else if (TypeUtility.matches(type, Integer.class)) { + return (ParameterType) numeric(Integer.class); + } else if (TypeUtility.matches(type, Long.class)) { + return (ParameterType) numeric(Long.class); + } else if (TypeUtility.matches(type, Float.class)) { + return (ParameterType) numeric(Float.class); + } else if (TypeUtility.matches(type, Double.class)) { + return (ParameterType) numeric(Double.class); + } else { + throw new IllegalArgumentException("Unsupported parameter type: " + type.getName()); + } + } + +} diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterWord.java b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterWord.java new file mode 100644 index 00000000..27b79ae0 --- /dev/null +++ b/core/src/main/java/dev/velix/imperat/command/parameters/type/ParameterWord.java @@ -0,0 +1,59 @@ +package dev.velix.imperat.command.parameters.type; + +import dev.velix.imperat.context.ResolvedContext; +import dev.velix.imperat.context.Source; +import dev.velix.imperat.context.internal.sur.CommandInputStream; +import dev.velix.imperat.exception.ImperatException; +import dev.velix.imperat.exception.SourceException; +import dev.velix.imperat.util.Preconditions; +import dev.velix.imperat.util.TypeWrap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +public final class ParameterWord extends BaseParameterType { + + private final List restrictions = new ArrayList<>(); + + ParameterWord() { + super(TypeWrap.of(String.class)); + } + + @Override + public @Nullable String resolve(ResolvedContext context, @NotNull CommandInputStream commandInputStream) throws ImperatException { + var nextRaw = commandInputStream.currentRaw(); + if (restrictions.isEmpty()) { + return nextRaw; + } + return Optional.of(nextRaw).filter(restrictions::contains) + .orElseThrow(() -> new SourceException("Word '%s' is not within the given restrictions=%s", nextRaw, restrictions.toString())); + } + + @Override + public Collection suggestions() { + return restrictions; + } + + @Override + public boolean matchesInput(String input) { + if (!restrictions.isEmpty()) { + return restrictions.contains(input); + } + return true; + } + + public ParameterWord withRestriction(String restriction) { + Preconditions.notNull(restriction, "not null"); + restrictions.add(restriction); + return this; + } + + public List getRestrictions() { + return restrictions; + } + +} diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/types/ParameterType.java b/core/src/main/java/dev/velix/imperat/command/parameters/types/ParameterType.java deleted file mode 100644 index 04cc79c0..00000000 --- a/core/src/main/java/dev/velix/imperat/command/parameters/types/ParameterType.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.velix.imperat.command.parameters.types; - -import java.lang.reflect.Type; - -public interface ParameterType { - - Type type(); - - boolean matchesInput(String input); - -} diff --git a/core/src/main/java/dev/velix/imperat/command/parameters/types/ParameterTypes.java b/core/src/main/java/dev/velix/imperat/command/parameters/types/ParameterTypes.java deleted file mode 100644 index 0cc2032c..00000000 --- a/core/src/main/java/dev/velix/imperat/command/parameters/types/ParameterTypes.java +++ /dev/null @@ -1,108 +0,0 @@ -package dev.velix.imperat.command.parameters.types; - -import dev.velix.imperat.util.TypeUtility; -import dev.velix.imperat.util.TypeWrap; - -import java.lang.reflect.Type; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Objects; - -public final class ParameterTypes { - - private final static Map PARAMETER_TYPES = new LinkedHashMap<>((int) Math.ceil(6 / 0.75)); - private final static ParameterType STRING_TYPE = new ParameterType() { - @Override - public Type type() { - return String.class; - } - - @Override - public boolean matchesInput(String input) { - return true; - } - }; - - static { - PARAMETER_TYPES.put(String.class, STRING_TYPE); - - PARAMETER_TYPES.put(Boolean.class, new ParameterType() { - @Override - public Type type() { - return Boolean.class; - } - - @Override - public boolean matchesInput(String input) { - return input.equalsIgnoreCase("true") - || input.equalsIgnoreCase("false"); - } - }); - - PARAMETER_TYPES.put(Integer.class, new ParameterType() { - @Override - public Type type() { - return Integer.TYPE; - } - - @Override - public boolean matchesInput(String input) { - return TypeUtility.isInteger(input); - } - }); - - PARAMETER_TYPES.put(Long.class, new ParameterType() { - @Override - public Type type() { - return Long.class; - } - - @Override - public boolean matchesInput(String input) { - return TypeUtility.isLong(input); - } - }); - - PARAMETER_TYPES.put(Float.TYPE, new ParameterType() { - @Override - public Type type() { - return Float.class; - } - - @Override - public boolean matchesInput(String input) { - return TypeUtility.isFloat(input); - } - }); - PARAMETER_TYPES.put(Double.class, new ParameterType() { - @Override - public Type type() { - return Double.class; - } - - @Override - public boolean matchesInput(String input) { - return TypeUtility.isDouble(input); - } - }); - } - - private ParameterTypes() { - throw new AssertionError(); - } - - public static ParameterType getParamType(Type type) { - TypeWrap token = TypeWrap.of(type).wrap(); - - if (token.isArray()) { - return PARAMETER_TYPES.getOrDefault(Objects.requireNonNull(token.getComponentType()).getType(), STRING_TYPE); - } else if (token.isSubtypeOf(Collection.class)) { - return PARAMETER_TYPES.getOrDefault(token.getRawType(), STRING_TYPE); - } else { - return PARAMETER_TYPES.getOrDefault(type, STRING_TYPE); - } - - } - -} diff --git a/core/src/main/java/dev/velix/imperat/command/processors/CommandPostProcessor.java b/core/src/main/java/dev/velix/imperat/command/processors/CommandPostProcessor.java index ee458f39..d60d642c 100644 --- a/core/src/main/java/dev/velix/imperat/command/processors/CommandPostProcessor.java +++ b/core/src/main/java/dev/velix/imperat/command/processors/CommandPostProcessor.java @@ -10,7 +10,7 @@ * Defines a functional interface that processes a {@link Context} * AFTER the resolving of the arguments into values. * - * @param the command sender type + * @param the command sender valueType */ public interface CommandPostProcessor extends CommandProcessor { diff --git a/core/src/main/java/dev/velix/imperat/command/processors/CommandPreProcessor.java b/core/src/main/java/dev/velix/imperat/command/processors/CommandPreProcessor.java index f3464749..0eff9f4f 100644 --- a/core/src/main/java/dev/velix/imperat/command/processors/CommandPreProcessor.java +++ b/core/src/main/java/dev/velix/imperat/command/processors/CommandPreProcessor.java @@ -10,7 +10,7 @@ * Defines a functional interface that processes a {@link Context} * BEFORE the resolving of the arguments into values. * - * @param the command sender type + * @param the command sender valueType */ @FunctionalInterface public interface CommandPreProcessor extends CommandProcessor { diff --git a/core/src/main/java/dev/velix/imperat/command/suggestions/AutoCompleter.java b/core/src/main/java/dev/velix/imperat/command/suggestions/AutoCompleter.java index d72383ae..fca79af4 100644 --- a/core/src/main/java/dev/velix/imperat/command/suggestions/AutoCompleter.java +++ b/core/src/main/java/dev/velix/imperat/command/suggestions/AutoCompleter.java @@ -14,7 +14,7 @@ /** * Represents a class that's responsible for * Handling all auto-completion processes during - * tab-completion per one command, regardless of the sender type + * tab-completion per one command, regardless of the sender valueType */ @ApiStatus.AvailableSince("1.0.0") public abstract class AutoCompleter { diff --git a/core/src/main/java/dev/velix/imperat/command/suggestions/SuggestionResolverRegistry.java b/core/src/main/java/dev/velix/imperat/command/suggestions/SuggestionResolverRegistry.java index a7f17dfb..a9520fd7 100644 --- a/core/src/main/java/dev/velix/imperat/command/suggestions/SuggestionResolverRegistry.java +++ b/core/src/main/java/dev/velix/imperat/command/suggestions/SuggestionResolverRegistry.java @@ -100,7 +100,7 @@ private Optional> getResults(Type type) { @Override public List autoComplete(SuggestionContext context, CommandParameter parameter) { - Type type = parameter.type(); + Type type = parameter.valueType(); return getResults(type) .orElseGet(() -> { registerEnumResolver(type); diff --git a/core/src/main/java/dev/velix/imperat/command/tree/ArgumentNode.java b/core/src/main/java/dev/velix/imperat/command/tree/ArgumentNode.java index f3836ebc..870d8084 100644 --- a/core/src/main/java/dev/velix/imperat/command/tree/ArgumentNode.java +++ b/core/src/main/java/dev/velix/imperat/command/tree/ArgumentNode.java @@ -1,8 +1,6 @@ package dev.velix.imperat.command.tree; import dev.velix.imperat.command.parameters.CommandParameter; -import dev.velix.imperat.command.parameters.types.ParameterType; -import dev.velix.imperat.command.parameters.types.ParameterTypes; import dev.velix.imperat.context.Source; import dev.velix.imperat.util.Patterns; import org.jetbrains.annotations.ApiStatus; @@ -30,8 +28,9 @@ public boolean matchesInput(String input) { return data.asFlagParameter() .flagData().acceptsInput(flagInput); } - ParameterType type = ParameterTypes.getParamType(data.type()); - return type == null || type.matchesInput(input); + var type = data.type(); + return type.matchesInput(input); + //return valueType == null || valueType.matchesInput(input); } @Override diff --git a/core/src/main/java/dev/velix/imperat/command/tree/CommandTree.java b/core/src/main/java/dev/velix/imperat/command/tree/CommandTree.java index b8c3977b..cdf4c604 100644 --- a/core/src/main/java/dev/velix/imperat/command/tree/CommandTree.java +++ b/core/src/main/java/dev/velix/imperat/command/tree/CommandTree.java @@ -71,7 +71,7 @@ private void addParametersToTree( private ParameterNode getChildNode(ParameterNode parent, CommandParameter param) { for (ParameterNode child : parent.getChildren()) { if (child.data.name().equalsIgnoreCase(param.name()) - && TypeUtility.matches(child.data.type(), param.type())) { + && TypeUtility.matches(child.data.valueType(), param.valueType())) { return child; } } diff --git a/core/src/main/java/dev/velix/imperat/context/ArgumentQueue.java b/core/src/main/java/dev/velix/imperat/context/ArgumentQueue.java index 92be2f07..d02326d6 100644 --- a/core/src/main/java/dev/velix/imperat/context/ArgumentQueue.java +++ b/core/src/main/java/dev/velix/imperat/context/ArgumentQueue.java @@ -1,5 +1,6 @@ package dev.velix.imperat.context; +import dev.velix.imperat.util.StringUtils; import org.jetbrains.annotations.*; import java.util.Deque; @@ -13,11 +14,11 @@ public interface ArgumentQueue extends Deque, List, Cloneable { static ArgumentQueue parse(String[] rawArguments) { - return StringTokenizer.parseToQueue(String.join(" ", rawArguments), false); + return StringUtils.parseToQueue(String.join(" ", rawArguments), false); } static ArgumentQueue parse(String string) { - return StringTokenizer.parseToQueue(string, false); + return StringUtils.parseToQueue(string, false); } static ArgumentQueue parseAutoCompletion(String[] argumentsOnly, boolean extraLastSpace) { @@ -36,9 +37,9 @@ static ArgumentQueue parseAutoCompletion(String[] argumentsOnly, boolean extraLa static ArgumentQueue parseAutoCompletion(String string, boolean extraLastSpace) { if (string.isEmpty() || string.isBlank()) { - return StringTokenizer.parseToQueue("", true); + return StringUtils.parseToQueue("", true); } - return StringTokenizer.parseToQueue(string, true, extraLastSpace); + return StringUtils.parseToQueue(string, true, extraLastSpace); } /** @@ -48,6 +49,7 @@ static ArgumentQueue empty() { return new ArgumentQueueImpl(); } + /** * Fetches the element at the specified index * diff --git a/core/src/main/java/dev/velix/imperat/context/ArgumentQueueImpl.java b/core/src/main/java/dev/velix/imperat/context/ArgumentQueueImpl.java index 511b54e8..d46ea13a 100644 --- a/core/src/main/java/dev/velix/imperat/context/ArgumentQueueImpl.java +++ b/core/src/main/java/dev/velix/imperat/context/ArgumentQueueImpl.java @@ -17,6 +17,7 @@ final class ArgumentQueueImpl extends LinkedList implements ArgumentQueu this.unmodifiableView = Collections.unmodifiableList(this); } + public ArgumentQueueImpl(@NotNull String... rawArgs) { Collections.addAll(this, rawArgs); this.unmodifiableView = Collections.unmodifiableList(this); diff --git a/core/src/main/java/dev/velix/imperat/context/CommandFlag.java b/core/src/main/java/dev/velix/imperat/context/CommandFlag.java index 471c371c..87fe2b97 100644 --- a/core/src/main/java/dev/velix/imperat/context/CommandFlag.java +++ b/core/src/main/java/dev/velix/imperat/context/CommandFlag.java @@ -37,7 +37,7 @@ static CommandFlag create(String name, List alias, Type inputType) { List aliases(); /** - * @return the type of input + * @return the valueType of input * from the flag */ Type inputType(); diff --git a/core/src/main/java/dev/velix/imperat/context/CommandSwitch.java b/core/src/main/java/dev/velix/imperat/context/CommandSwitch.java index db1ab69e..9ad4db94 100644 --- a/core/src/main/java/dev/velix/imperat/context/CommandSwitch.java +++ b/core/src/main/java/dev/velix/imperat/context/CommandSwitch.java @@ -5,7 +5,7 @@ import java.util.List; /** - * Represents a flag that returns a value of type boolean + * Represents a flag that returns a value of valueType boolean * which represents merely whether its present in the syntax input or * so they have no input value unlike true flags * @@ -18,7 +18,7 @@ static CommandSwitch create(String name, List aliases) { } /** - * @return the type of input + * @return the valueType of input * from the flag */ @Override diff --git a/core/src/main/java/dev/velix/imperat/context/Context.java b/core/src/main/java/dev/velix/imperat/context/Context.java index 6cf07257..45477113 100644 --- a/core/src/main/java/dev/velix/imperat/context/Context.java +++ b/core/src/main/java/dev/velix/imperat/context/Context.java @@ -8,7 +8,7 @@ * Represents the processes context of a command * entered by {@link Source} * - * @param the command sender type + * @param the command sender valueType */ @ApiStatus.AvailableSince("1.0.0") public interface Context { diff --git a/core/src/main/java/dev/velix/imperat/context/ExecutionContext.java b/core/src/main/java/dev/velix/imperat/context/ExecutionContext.java index 3d3f092e..1dc4f936 100644 --- a/core/src/main/java/dev/velix/imperat/context/ExecutionContext.java +++ b/core/src/main/java/dev/velix/imperat/context/ExecutionContext.java @@ -31,7 +31,7 @@ public interface ExecutionContext extends Context { * OR if the value hasn't been resolved somehow * * @param flagName the flag name - * @param the type of the flag value resolved + * @param the valueType of the flag value resolved * @return the resolved value of the flag input */ @Nullable @@ -41,7 +41,7 @@ public interface ExecutionContext extends Context { * Fetches a resolved argument's value * * @param name the name of the command - * @param the type of this value + * @param the valueType of this value * @return the value of the resolved argument * @see ResolvedArgument */ @@ -59,10 +59,10 @@ default String getRawArgument(int index) { } /** - * Resolves source into a new type of source + * Resolves source into a new valueType of source * using {@link Imperat#getSourceResolver(Type)} * - * @param the type of the resolved source + * @param the valueType of the resolved source * @return the resolved source {@link R} */ @NotNull R getResolvedSource(Type type) throws ImperatException; @@ -71,8 +71,8 @@ default String getRawArgument(int index) { * Fetches the argument/input resolved by the context * using {@link dev.velix.imperat.resolvers.ContextResolver} * - * @param type type of argument to return - * @param the type of this argument parsed value + * @param type valueType of argument to return + * @param the valueType of this argument parsed value * @return the argument/input resolved by the context */ @Nullable T getContextResolvedArgument(Class type) throws ImperatException; diff --git a/core/src/main/java/dev/velix/imperat/context/ResolvedContext.java b/core/src/main/java/dev/velix/imperat/context/ResolvedContext.java index afd628d9..778304a1 100644 --- a/core/src/main/java/dev/velix/imperat/context/ResolvedContext.java +++ b/core/src/main/java/dev/velix/imperat/context/ResolvedContext.java @@ -71,7 +71,7 @@ public interface ResolvedContext extends ExecutionContext { * @param index the position of this argument * @param parameter the parameter of the argument * @param value the resolved value of the argument - * @param the type of resolved value of the argument + * @param the valueType of resolved value of the argument */ void resolveArgument( Command command, diff --git a/core/src/main/java/dev/velix/imperat/context/Source.java b/core/src/main/java/dev/velix/imperat/context/Source.java index 41cc1efd..2e9b1eca 100644 --- a/core/src/main/java/dev/velix/imperat/context/Source.java +++ b/core/src/main/java/dev/velix/imperat/context/Source.java @@ -16,7 +16,7 @@ public interface Source { String name(); /** - * @return The original command sender type instance + * @return The original command sender valueType instance */ Object origin(); diff --git a/core/src/main/java/dev/velix/imperat/context/StringTokenizer.java b/core/src/main/java/dev/velix/imperat/context/StringTokenizer.java deleted file mode 100644 index 3361246f..00000000 --- a/core/src/main/java/dev/velix/imperat/context/StringTokenizer.java +++ /dev/null @@ -1,90 +0,0 @@ -package dev.velix.imperat.context; - -import dev.velix.imperat.exception.TokenParseException; -import org.jetbrains.annotations.ApiStatus; - -@ApiStatus.Internal -public final class StringTokenizer { - - private static final char CHAR_BACKSLASH = '\\'; - private static final char CHAR_SINGLE_QUOTE = '\''; - private static final char CHAR_DOUBLE_QUOTE = '"'; - - private StringTokenizer() { - } - - public static ArgumentQueue parseToQueue(String argumentsInOneLine, boolean autoCompletion, boolean extraSpace) { - if (argumentsInOneLine.isEmpty()) - return !autoCompletion ? ArgumentQueue.empty() : new ArgumentQueueImpl(" "); - - TokenIterator iterator = new TokenIterator(argumentsInOneLine); - ArgumentQueue toCollect = ArgumentQueue.empty(); - while (iterator.hasNext()) { - Character next = iterator.next(); - if (Character.isWhitespace(next)) - continue; - - String arg = nextArg(iterator, next); - toCollect.add(arg); - } - - if (autoCompletion && extraSpace) - toCollect.add(" "); - - return toCollect; - } - - public static ArgumentQueue parseToQueue(String argumentsInOneLine, boolean autoCompletion) { - return parseToQueue(argumentsInOneLine, autoCompletion, false); - } - - private static String nextArg(TokenIterator iterator, Character character) throws TokenParseException { - StringBuilder argBuilder = new StringBuilder(); - - assert character != null; - boolean quoted = (character == CHAR_DOUBLE_QUOTE || character == CHAR_SINGLE_QUOTE); - parseString(iterator, character, argBuilder, quoted); - - return argBuilder.toString(); - } - - private static void parseString(final TokenIterator iterator, - final Character start, - final StringBuilder builder, - final boolean quoted) throws TokenParseException { - // Consume the start quotation character - Character character; - if (quoted) { - if (!iterator.hasNext()) { - builder.append(start); - return; - } - character = iterator.next(); - } else { - character = start; - } - - - builder.append(character); - - while (iterator.hasNext()) { - assert character != null; - character = iterator.next(); - - if ((quoted && character == start) - || (!quoted && Character.isWhitespace(character))) { - break; - } - - if (character == CHAR_BACKSLASH) - parseEscape(iterator, builder); - else - builder.append(character); - } - - } - - private static void parseEscape(TokenIterator state, StringBuilder builder) throws TokenParseException { - builder.append(state.next()); - } -} diff --git a/core/src/main/java/dev/velix/imperat/context/ValueResolverRegistry.java b/core/src/main/java/dev/velix/imperat/context/ValueResolverRegistry.java index 1e00695e..3d5a5fb7 100644 --- a/core/src/main/java/dev/velix/imperat/context/ValueResolverRegistry.java +++ b/core/src/main/java/dev/velix/imperat/context/ValueResolverRegistry.java @@ -102,7 +102,7 @@ public Enum resolve( Cursor cursor, String raw ) throws ImperatException { - var enumType = (Class) parameter.type(); + var enumType = (Class) parameter.valueType(); try { return Enum.valueOf(enumType, raw.toUpperCase()); } catch (EnumConstantNotPresentException ex) { diff --git a/core/src/main/java/dev/velix/imperat/context/internal/ResolvedContextImpl.java b/core/src/main/java/dev/velix/imperat/context/internal/ResolvedContextImpl.java index 8493397c..00ad4e53 100644 --- a/core/src/main/java/dev/velix/imperat/context/internal/ResolvedContextImpl.java +++ b/core/src/main/java/dev/velix/imperat/context/internal/ResolvedContextImpl.java @@ -29,7 +29,7 @@ * the results (resolved arguments) will be used later on to * find the command usage object then use the found command usage to execute the action. * - * @param the sender type + * @param the sender valueType */ @ApiStatus.Internal final class ResolvedContextImpl extends ContextImpl implements ResolvedContext { @@ -115,7 +115,7 @@ public Collection> getResolvedArguments() { @SuppressWarnings("unchecked") public @NotNull R getResolvedSource(Type type) throws ImperatException { if (!dispatcher.hasSourceResolver(type)) { - throw new IllegalArgumentException("Found no SourceResolver for type `" + type.getTypeName() + "`"); + throw new IllegalArgumentException("Found no SourceResolver for valueType `" + type.getTypeName() + "`"); } var sourceResolver = dispatcher.getSourceResolver(type); assert sourceResolver != null; @@ -127,7 +127,7 @@ public Collection> getResolvedArguments() { * Fetches the argument/input resolved by the context * using {@link ContextResolver} * - * @param type type of argument to return + * @param type valueType of argument to return * @return the argument/input resolved by the context */ @Override @@ -183,11 +183,13 @@ public void resolve() throws ImperatException { @Override - public void resolveArgument(Command command, - @Nullable String raw, - int index, - CommandParameter parameter, - @Nullable T value) throws ImperatException { + public void resolveArgument( + Command command, + @Nullable String raw, + int index, + CommandParameter parameter, + @Nullable T value + ) throws ImperatException { if (value != null && TypeUtility.isNumericType(value.getClass()) && parameter instanceof NumericParameter numericParameter diff --git a/core/src/main/java/dev/velix/imperat/context/internal/sur/CommandInputStream.java b/core/src/main/java/dev/velix/imperat/context/internal/sur/CommandInputStream.java new file mode 100644 index 00000000..11b84040 --- /dev/null +++ b/core/src/main/java/dev/velix/imperat/context/internal/sur/CommandInputStream.java @@ -0,0 +1,47 @@ +package dev.velix.imperat.context.internal.sur; + +import dev.velix.imperat.command.parameters.CommandParameter; +import dev.velix.imperat.context.Source; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; + +public interface CommandInputStream { + + @NotNull Cursor cursor(); + + CommandParameter currentParameter(); + + String currentRaw(); + + Character currentLetter(); + + Optional peekLetter(); + + Optional popLetter(); + + Optional peekRaw(); + + Optional popRaw(); + + boolean hasNextLetter(); + + boolean hasNextRaw(); + + boolean hasNextParameter(); + + default boolean skip() { + final Cursor cursor = cursor(); + int prevRaw = cursor.raw; + cursor.shift(ShiftTarget.ALL, ShiftOperation.RIGHT); + return cursor.raw > prevRaw; + } + + default boolean skipRaw() { + final Cursor cursor = cursor(); + int prevRaw = cursor.raw; + cursor.shift(ShiftTarget.RAW_ONLY, ShiftOperation.RIGHT); + return cursor.raw > prevRaw; + } + +} diff --git a/core/src/main/java/dev/velix/imperat/context/internal/sur/SmartUsageResolve.java b/core/src/main/java/dev/velix/imperat/context/internal/sur/SmartUsageResolve.java index 3b296dd8..65f17df5 100644 --- a/core/src/main/java/dev/velix/imperat/context/internal/sur/SmartUsageResolve.java +++ b/core/src/main/java/dev/velix/imperat/context/internal/sur/SmartUsageResolve.java @@ -120,7 +120,7 @@ public void resolve(Imperat dispatcher, ResolvedContext context) throws Im //flag value raw input is NOT NULL, resolving the value input ValueResolver valueResolver = dispatcher.getValueResolver(flag.inputType()); if (valueResolver == null) { - throw new SourceException("Cannot find resolver for flag with input type '" + flag.name() + "'"); + throw new SourceException("Cannot find resolver for flag with input valueType '" + flag.name() + "'"); } context.resolveFlag( currentRaw, @@ -152,7 +152,7 @@ public void resolve(Imperat dispatcher, ResolvedContext context) throws Im //argument input ValueResolver resolver = dispatcher.getValueResolver(currentParameter); if (resolver == null) - throw new SourceException("Cannot find resolver for type '" + currentParameter.type().getTypeName() + "'"); + throw new SourceException("Cannot find resolver for valueType '" + currentParameter.valueType().getTypeName() + "'"); if (currentParameter.isOptional()) { //visualize("Optional parameter '%s' at position %s", currentParameter.getName(), position.parameter); diff --git a/core/src/main/java/dev/velix/imperat/exception/SelfHandledException.java b/core/src/main/java/dev/velix/imperat/exception/SelfHandledException.java index fca704e5..4c102cb8 100644 --- a/core/src/main/java/dev/velix/imperat/exception/SelfHandledException.java +++ b/core/src/main/java/dev/velix/imperat/exception/SelfHandledException.java @@ -11,7 +11,7 @@ public abstract class SelfHandledException extends ImperatException { /** * Handles the exception * - * @param the command-source type + * @param the command-source valueType * @param imperat the api * @param context the context */ diff --git a/core/src/main/java/dev/velix/imperat/help/HelpProvider.java b/core/src/main/java/dev/velix/imperat/help/HelpProvider.java index 9a2781cb..b7ce0df7 100644 --- a/core/src/main/java/dev/velix/imperat/help/HelpProvider.java +++ b/core/src/main/java/dev/velix/imperat/help/HelpProvider.java @@ -18,7 +18,7 @@ * provide/send a help message to the {@link Source} * through the command's {@link Context} * - * @param the type of command source + * @param the valueType of command source */ @ApiStatus.AvailableSince("1.0.0") public interface HelpProvider { diff --git a/core/src/main/java/dev/velix/imperat/help/UsageFormatter.java b/core/src/main/java/dev/velix/imperat/help/UsageFormatter.java index 1ee9809f..3488d29c 100644 --- a/core/src/main/java/dev/velix/imperat/help/UsageFormatter.java +++ b/core/src/main/java/dev/velix/imperat/help/UsageFormatter.java @@ -19,7 +19,7 @@ public interface UsageFormatter { * @param command the command * @param usage the usage to display * @param index the index of the usage - * @param the sender-type + * @param the sender-valueType * @return the usage component */ String format( diff --git a/core/src/main/java/dev/velix/imperat/resolvers/ContextResolver.java b/core/src/main/java/dev/velix/imperat/resolvers/ContextResolver.java index 2d96998c..42905985 100644 --- a/core/src/main/java/dev/velix/imperat/resolvers/ContextResolver.java +++ b/core/src/main/java/dev/velix/imperat/resolvers/ContextResolver.java @@ -13,7 +13,7 @@ * Resolves a default non-overridable value for * missing required arguments * - * @param the type of resolver's parameter + * @param the valueType of resolver's parameter */ @FunctionalInterface public interface ContextResolver { diff --git a/core/src/main/java/dev/velix/imperat/resolvers/SuggestionResolver.java b/core/src/main/java/dev/velix/imperat/resolvers/SuggestionResolver.java index e496aff7..205855e1 100644 --- a/core/src/main/java/dev/velix/imperat/resolvers/SuggestionResolver.java +++ b/core/src/main/java/dev/velix/imperat/resolvers/SuggestionResolver.java @@ -18,7 +18,7 @@ * Represents a suggestion providing interface * for an argument/parameter * - * @param the command-sender type + * @param the command-sender valueType * @see CommandParameter */ @ApiStatus.AvailableSince("1.0.0") @@ -40,11 +40,11 @@ static TypeSuggestionResolver> forCommand(Comma }, list); } - static TypeSuggestionResolver type(Class type, List results) { + static TypeSuggestionResolver type(Class type, Collection results) { return type(TypeWrap.of(type), results); } - static TypeSuggestionResolver type(TypeWrap type, List results) { + static TypeSuggestionResolver type(TypeWrap type, Collection results) { return new TypeSuggestionResolver<>() { @Override @@ -53,7 +53,7 @@ static TypeSuggestionResolver type(TypeWrap type, } @Override - public List autoComplete(SuggestionContext context, CommandParameter parameter) { + public Collection autoComplete(SuggestionContext context, CommandParameter parameter) { return results; } }; diff --git a/core/src/main/java/dev/velix/imperat/resolvers/TypeSuggestionResolver.java b/core/src/main/java/dev/velix/imperat/resolvers/TypeSuggestionResolver.java index 57ae38e3..732a5194 100644 --- a/core/src/main/java/dev/velix/imperat/resolvers/TypeSuggestionResolver.java +++ b/core/src/main/java/dev/velix/imperat/resolvers/TypeSuggestionResolver.java @@ -5,15 +5,15 @@ import org.jetbrains.annotations.NotNull; /** - * Defines a suggestion resolver that has a global type + * Defines a suggestion resolver that has a global valueType * * @param the source - * @param the type + * @param the valueType */ public interface TypeSuggestionResolver extends SuggestionResolver { /** - * @return the type that is specific for these suggestions resolving + * @return the valueType that is specific for these suggestions resolving */ @NotNull TypeWrap getType(); diff --git a/core/src/main/java/dev/velix/imperat/resolvers/ValueResolver.java b/core/src/main/java/dev/velix/imperat/resolvers/ValueResolver.java index 265c31e5..3b687122 100644 --- a/core/src/main/java/dev/velix/imperat/resolvers/ValueResolver.java +++ b/core/src/main/java/dev/velix/imperat/resolvers/ValueResolver.java @@ -12,8 +12,8 @@ * converting the parameter into a value for * the argument input, just using the context, parameter required and the raw input. * - * @param the type of the command sender/source - * @param the type of value that the parameter requires + * @param the valueType of the command sender/source + * @param the valueType of value that the parameter requires */ @ApiStatus.AvailableSince("1.0.0") public interface ValueResolver { diff --git a/core/src/main/java/dev/velix/imperat/supplier/OptionalValueSupplier.java b/core/src/main/java/dev/velix/imperat/supplier/OptionalValueSupplier.java index 9b0e12de..644ebc37 100644 --- a/core/src/main/java/dev/velix/imperat/supplier/OptionalValueSupplier.java +++ b/core/src/main/java/dev/velix/imperat/supplier/OptionalValueSupplier.java @@ -47,7 +47,7 @@ default Type reflectionType() { } /** - * @return The type of value to supply + * @return The valueType of value to supply */ TypeWrap getValueType(); diff --git a/core/src/main/java/dev/velix/imperat/supplier/defaults/BooleanValueSupplier.java b/core/src/main/java/dev/velix/imperat/supplier/defaults/BooleanValueSupplier.java index f616dd5f..7d6b130f 100644 --- a/core/src/main/java/dev/velix/imperat/supplier/defaults/BooleanValueSupplier.java +++ b/core/src/main/java/dev/velix/imperat/supplier/defaults/BooleanValueSupplier.java @@ -8,7 +8,7 @@ public final class BooleanValueSupplier implements OptionalValueSupplier { /** - * @return The type of value to supply + * @return The valueType of value to supply */ @Override public TypeWrap getValueType() { diff --git a/core/src/main/java/dev/velix/imperat/util/StringUtils.java b/core/src/main/java/dev/velix/imperat/util/StringUtils.java index 1702f4b6..7607b331 100644 --- a/core/src/main/java/dev/velix/imperat/util/StringUtils.java +++ b/core/src/main/java/dev/velix/imperat/util/StringUtils.java @@ -1,8 +1,10 @@ package dev.velix.imperat.util; +import dev.velix.imperat.context.ArgumentQueue; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -45,5 +47,21 @@ public static String normalizedParameterFormatting(String parameterContent, bool return prefix + parameterContent + suffix; } + public static ArgumentQueue parseToQueue(String argumentsInOneLine, boolean autoCompletion, boolean extraSpace) { + if (argumentsInOneLine.isEmpty()) + return !autoCompletion ? ArgumentQueue.empty() : ArgumentQueue.parse(" "); + + ArgumentQueue toCollect = ArgumentQueue.empty(); + toCollect.addAll(Arrays.asList(argumentsInOneLine.split(" "))); + + if (autoCompletion && extraSpace) + toCollect.add(" "); + + return toCollect; + } + + public static ArgumentQueue parseToQueue(String argumentsInOneLine, boolean autoCompletion) { + return parseToQueue(argumentsInOneLine, autoCompletion, false); + } } diff --git a/core/src/main/java/dev/velix/imperat/util/TypeVisitor.java b/core/src/main/java/dev/velix/imperat/util/TypeVisitor.java index 3ce20a63..265656cd 100644 --- a/core/src/main/java/dev/velix/imperat/util/TypeVisitor.java +++ b/core/src/main/java/dev/velix/imperat/util/TypeVisitor.java @@ -13,7 +13,7 @@ abstract class TypeVisitor { public final void visit(@Nullable Type... types) { for (final Type type : types) { if (type == null || !visited.add(type)) { - // null owner type, or already visited; + // null owner valueType, or already visited; continue; } @@ -30,7 +30,7 @@ public final void visit(@Nullable Type... types) { } else if (type instanceof GenericArrayType) { visitGenericArrayType((GenericArrayType) type); } else { - throw new AssertionError("Unknown type: " + type); + throw new AssertionError("Unknown valueType: " + type); } succeeded = true; } finally { diff --git a/core/src/main/java/dev/velix/imperat/util/TypeWrap.java b/core/src/main/java/dev/velix/imperat/util/TypeWrap.java index 1e773538..5b2e389d 100644 --- a/core/src/main/java/dev/velix/imperat/util/TypeWrap.java +++ b/core/src/main/java/dev/velix/imperat/util/TypeWrap.java @@ -40,7 +40,7 @@ private Type extractType() { } else if (superclass instanceof Class) { return Object.class; } else { - throw new IllegalArgumentException("TypeWrap must be created with a parameterized type."); + throw new IllegalArgumentException("TypeWrap must be created with a parameterized valueType."); } } diff --git a/core/src/main/java/dev/velix/imperat/util/reflection/FieldAccessor.java b/core/src/main/java/dev/velix/imperat/util/reflection/FieldAccessor.java index 9b30dd5e..92f215c5 100644 --- a/core/src/main/java/dev/velix/imperat/util/reflection/FieldAccessor.java +++ b/core/src/main/java/dev/velix/imperat/util/reflection/FieldAccessor.java @@ -3,7 +3,7 @@ /** * An interface for retrieving the field content. (Credits: TinyProtocol) * - * @param - field type. + * @param - field valueType. * @author Kristian */ public interface FieldAccessor { diff --git a/core/src/main/java/dev/velix/imperat/util/reflection/Reflections.java b/core/src/main/java/dev/velix/imperat/util/reflection/Reflections.java index b83e20d8..d222b955 100644 --- a/core/src/main/java/dev/velix/imperat/util/reflection/Reflections.java +++ b/core/src/main/java/dev/velix/imperat/util/reflection/Reflections.java @@ -8,11 +8,11 @@ public final class Reflections { /** - * Retrieve a field accessor for a specific field type and name. + * Retrieve a field accessor for a specific field valueType and name. * - * @param target - the targetToLoad type. + * @param target - the targetToLoad valueType. * @param name - the name of the field, or NULL to ignore. - * @param fieldType - a compatible field type. + * @param fieldType - a compatible field valueType. * @return The field accessor. */ public static FieldAccessor getField(Class target, String name, Class fieldType) { @@ -20,11 +20,11 @@ public static FieldAccessor getField(Class target, String name, Class< } /** - * Retrieve a field accessor for a specific field type and name. + * Retrieve a field accessor for a specific field valueType and name. * * @param className - lookup name of the class, see {@link #getClass(String)}. * @param name - the name of the field, or NULL to ignore. - * @param fieldType - a compatible field type. + * @param fieldType - a compatible field valueType. * @return The field accessor. */ public static FieldAccessor getField(String className, String name, Class fieldType) { @@ -32,10 +32,10 @@ public static FieldAccessor getField(String className, String name, Class } /** - * Retrieve a field accessor for a specific field type and name. + * Retrieve a field accessor for a specific field valueType and name. * - * @param target - the targetToLoad type. - * @param fieldType - a compatible field type. + * @param target - the targetToLoad valueType. + * @param fieldType - a compatible field valueType. * @return The field accessor. */ public static FieldAccessor getField(Class target, Class fieldType) { @@ -43,10 +43,10 @@ public static FieldAccessor getField(Class target, Class fieldType) } /** - * Retrieve a field accessor for a specific field type and name. + * Retrieve a field accessor for a specific field valueType and name. * - * @param target - the targetToLoad type. - * @param fieldType - a compatible field type. + * @param target - the targetToLoad valueType. + * @param fieldType - a compatible field valueType. * @param index - the number of compatible fields to skip. * @return The field accessor. */ @@ -55,10 +55,10 @@ public static FieldAccessor getField(Class target, Class fieldType, } /** - * Retrieve a field accessor for a specific field type and name. + * Retrieve a field accessor for a specific field valueType and name. * * @param className - lookup name of the class, see {@link #getClass(String)}. - * @param fieldType - a compatible field type. + * @param fieldType - a compatible field valueType. * @param index - the number of compatible fields to skip. * @return The field accessor. */ @@ -114,7 +114,7 @@ public boolean hasField(final Object target) { if (target.getSuperclass() != null) return getField(target.getSuperclass(), name, fieldType, index); - throw new IllegalArgumentException("Cannot find field with type " + fieldType); + throw new IllegalArgumentException("Cannot find field with valueType " + fieldType); } /** diff --git a/core/src/main/java/dev/velix/imperat/verification/TypeTolerantVerifier.java b/core/src/main/java/dev/velix/imperat/verification/TypeTolerantVerifier.java index 36764ab4..e89c817c 100644 --- a/core/src/main/java/dev/velix/imperat/verification/TypeTolerantVerifier.java +++ b/core/src/main/java/dev/velix/imperat/verification/TypeTolerantVerifier.java @@ -12,10 +12,10 @@ * Represents a usage verifier where it checks for ambiguity in a slightly * different way than the {@link SimpleVerifier}. * Example: If you have two usages of a command: `/command ` and `/command `, - * while arg1 is a parameter of type String, and arg2 is a parameter of type Boolean, + * while arg1 is a parameter of valueType String, and arg2 is a parameter of valueType Boolean, * It will not consider this an ambiguity unless both parameters are of same {@link Type} ! * - * @param the command sender type + * @param the command sender valueType */ @ApiStatus.Internal final class TypeTolerantVerifier extends SimpleVerifier { @@ -51,7 +51,7 @@ public boolean areAmbiguous(CommandUsage firstUsage, CommandUsage secondUs private boolean areSimilarParameters(CommandParameter param1, CommandParameter param2) { if (!param1.isCommand() && !param2.isCommand()) { - return TypeUtility.matches(param1.type(), param2.type()); + return TypeUtility.matches(param1.valueType(), param2.valueType()); } else if (param1.isCommand() && param2.isCommand()) { return param1.equals(param2); } diff --git a/core/src/test/java/dev/velix/imperat/TestImperat.java b/core/src/test/java/dev/velix/imperat/TestImperat.java index 8db75a66..4d475f84 100644 --- a/core/src/test/java/dev/velix/imperat/TestImperat.java +++ b/core/src/test/java/dev/velix/imperat/TestImperat.java @@ -17,10 +17,10 @@ public String commandPrefix() { } /** - * Wraps the sender into a built-in command-sender type + * Wraps the sender into a built-in command-sender valueType * * @param sender the sender's actual value - * @return the wrapped command-sender type + * @return the wrapped command-sender valueType */ @Override public TestSource wrapSender(Object sender) { diff --git a/minestom/src/main/java/dev/velix/imperat/MinestomImperat.java b/minestom/src/main/java/dev/velix/imperat/MinestomImperat.java index 49097ca0..e7419045 100644 --- a/minestom/src/main/java/dev/velix/imperat/MinestomImperat.java +++ b/minestom/src/main/java/dev/velix/imperat/MinestomImperat.java @@ -51,15 +51,15 @@ public String commandPrefix() { } /** - * Wraps the sender into a built-in command-sender type + * Wraps the sender into a built-in command-sender valueType * * @param sender the sender's actual value - * @return the wrapped command-sender type + * @return the wrapped command-sender valueType */ @Override public MinestomSource wrapSender(Object sender) { if (!(sender instanceof CommandSender commandSender)) { - throw new IllegalArgumentException("platform sender is not of type `" + CommandSender.class.getName() + "`"); + throw new IllegalArgumentException("platform sender is not of valueType `" + CommandSender.class.getName() + "`"); } return new MinestomSource(commandSender); } diff --git a/minestom/src/main/java/dev/velix/imperat/MinestomSource.java b/minestom/src/main/java/dev/velix/imperat/MinestomSource.java index 0c9203dc..2c38d8c1 100644 --- a/minestom/src/main/java/dev/velix/imperat/MinestomSource.java +++ b/minestom/src/main/java/dev/velix/imperat/MinestomSource.java @@ -24,7 +24,7 @@ public String name() { } /** - * @return The original command sender type instance + * @return The original command sender valueType instance */ @Override public CommandSender origin() { diff --git a/minestom/src/main/java/dev/velix/imperat/SyntaxDataLoader.java b/minestom/src/main/java/dev/velix/imperat/SyntaxDataLoader.java index 250c2f2d..64714d35 100644 --- a/minestom/src/main/java/dev/velix/imperat/SyntaxDataLoader.java +++ b/minestom/src/main/java/dev/velix/imperat/SyntaxDataLoader.java @@ -68,7 +68,7 @@ static Argument[] loadArguments( } private static Argument argFromParameter(CommandParameter parameter) { - var type = parameter.type(); + var type = parameter.valueType(); var id = parameter.name(); if (parameter.isCommand()) { @@ -132,14 +132,14 @@ private static Argument from(String id, Type type) { if (TypeUtility.matches(type, Component.class)) return ArgumentType.Component(id); - /*if (TypeUtility.matches(type, RelativeVec.class)) + /*if (TypeUtility.matches(valueType, RelativeVec.class)) return ArgumentType.RelativeVec3(id); - if (TypeUtility.matches(type, RelativeVec2.class)) + if (TypeUtility.matches(valueType, RelativeVec2.class)) return ArgumentType.RelativeVec2(id); */ - throw new IllegalArgumentException("Unsupported parameter type: " + type); + throw new IllegalArgumentException("Unsupported parameter valueType: " + type); } }