Class AnnotationParser<C>

java.lang.Object
cloud.commandframework.annotations.AnnotationParser<C>
Type Parameters:
C - Command sender type

public final class AnnotationParser<C> extends Object
Parser that parses class instances commands
  • Field Details

    • INFERRED_ARGUMENT_NAME

      public static final String INFERRED_ARGUMENT_NAME
      The value of Argument that should be used to infer argument names from parameter names.
      See Also:
  • Constructor Details

    • AnnotationParser

      public AnnotationParser(@NonNull cloud.commandframework.CommandManager<C> manager, @NonNull Class<C> commandSenderClass, @NonNull Function<@NonNull cloud.commandframework.arguments.parser.ParserParameters,@NonNull cloud.commandframework.meta.CommandMeta> metaMapper)
      Construct a new annotation parser
      Parameters:
      manager - Command manager instance
      commandSenderClass - Command sender class
      metaMapper - Function that is used to create CommandMeta instances from annotations on the command methods. These annotations will be mapped to ParserParameter. Mappers for the parser parameters can be registered using registerAnnotationMapper(Class, Function)
    • AnnotationParser

      @API(status=STABLE, since="1.7.0") public AnnotationParser(@NonNull cloud.commandframework.CommandManager<C> manager, @NonNull io.leangen.geantyref.TypeToken<C> commandSenderType, @NonNull Function<@NonNull cloud.commandframework.arguments.parser.ParserParameters,@NonNull cloud.commandframework.meta.CommandMeta> metaMapper)
      Construct a new annotation parser
      Parameters:
      manager - Command manager instance
      commandSenderType - Command sender type
      metaMapper - Function that is used to create CommandMeta instances from annotations on the command methods. These annotations will be mapped to ParserParameter. Mappers for the parser parameters can be registered using registerAnnotationMapper(Class, Function)
      Since:
      1.7.0
  • Method Details

    • manager

      public @NonNull cloud.commandframework.CommandManager<C> manager()
      Returns the command manager that was used to create this parser
      Returns:
      Command manager
      Since:
      1.6.0
    • registerCommandExecutionMethodFactory

      public void registerCommandExecutionMethodFactory(@NonNull Predicate<@NonNull Method> predicate, @NonNull Function<MethodCommandExecutionHandler.CommandMethodContext<C>,MethodCommandExecutionHandler<C>> function)
      Registers a new command execution method factory. This allows for the registration of custom command method execution strategies.
      Parameters:
      predicate - The predicate that decides whether or not to apply the custom execution handler to the given method
      function - The function that produces the command execution handler
      Since:
      1.6.0
    • registerBuilderModifier

      public <A extends Annotation> void registerBuilderModifier(@NonNull Class<A> annotation, @NonNull BiFunction<A,cloud.commandframework.Command.Builder<C>,cloud.commandframework.Command.Builder<C>> builderModifier)
      Register a builder modifier for a specific annotation. The builder modifiers are allowed to act on a Command.Builder after all arguments have been added to the builder. This allows for modifications of the builder instance before the command is registered to the command manager.
      Type Parameters:
      A - Annotation type
      Parameters:
      annotation - Annotation (class) that the builder modifier reacts to
      builderModifier - Modifier that acts on the given annotation and the incoming builder. Command builders are immutable, so the modifier should return the instance of the command builder that is returned as a result of any operation on the builder
    • registerAnnotationMapper

      public <A extends Annotation> void registerAnnotationMapper(@NonNull Class<A> annotation, @NonNull Function<@NonNull A,@NonNull cloud.commandframework.arguments.parser.ParserParameters> mapper)
      Register an annotation mapper
      Type Parameters:
      A - Annotation type
      Parameters:
      annotation - Annotation class
      mapper - Mapping function
    • registerPreprocessorMapper

      public <A extends Annotation> void registerPreprocessorMapper(@NonNull Class<A> annotation, @NonNull Function<A,BiFunction<@NonNull cloud.commandframework.context.CommandContext<C>,@NonNull Queue<@NonNull String>,@NonNull cloud.commandframework.arguments.parser.ArgumentParseResult<Boolean>>> preprocessorMapper)
      Register a preprocessor mapper
      Type Parameters:
      A - Annotation type
      Parameters:
      annotation - Annotation class
      preprocessorMapper - Preprocessor mapper
    • getParameterInjectorRegistry

      public @NonNull cloud.commandframework.annotations.injection.ParameterInjectorRegistry<C> getParameterInjectorRegistry()
      Get the parameter injector registry instance that is used to inject non-argument parameters into CommandMethod annotated methods
      Returns:
      Parameter injector registry
      Since:
      1.2.0
    • stringProcessor

      public @NonNull StringProcessor stringProcessor()
      Returns the string processor used by this parser.
      Returns:
      the string processor
      Since:
      1.7.0
    • stringProcessor

      public void stringProcessor(@NonNull StringProcessor stringProcessor)
      Replaces the string processor of this parser.
      Parameters:
      stringProcessor - the new string processor
      Since:
      1.7.0
    • processString

      public @NonNull String processString(@NonNull String input)
      Processes the input string and returns the processed result.
      Parameters:
      input - the input string
      Returns:
      the processed string
      Since:
      1.7.0
    • processStrings

      public @NonNull String[] processStrings(@NonNull String[] strings)
      Processes the input strings and returns the processed result.
      Parameters:
      strings - the input strings
      Returns:
      the processed strings
      Since:
      1.7.0
    • parseContainers

      public @NonNull Collection<@NonNull cloud.commandframework.Command<C>> parseContainers() throws Exception
      Parses all known command containers.
      Returns:
      Collection of parsed commands
      Throws:
      Exception - re-throws all encountered exceptions.
      Since:
      1.7.0
      See Also:
    • parse

      public <T> @NonNull Collection<@NonNull cloud.commandframework.Command<C>> parse(@NonNull T instance)
      Scan a class instance of CommandMethod annotations and attempt to compile them into Command instances.
      Type Parameters:
      T - Type of the instance
      Parameters:
      instance - Instance to scan
      Returns:
      Collection of parsed commands