Class StandardParserRegistry<C>

  • Type Parameters:
    C - Command sender type
    All Implemented Interfaces:
    ParserRegistry<C>

    public final class StandardParserRegistry<C>
    extends java.lang.Object
    implements ParserRegistry<C>
    Standard implementation of ParserRegistry
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> @NonNull java.util.Optional<ArgumentParser<C,​T>> createParser​(@NonNull io.leangen.geantyref.TypeToken<T> type, @NonNull ParserParameters parserParameters)
      Attempt to create a ArgumentParser for a specified type, using an instance of ParserParameter to configure the parser settings
      <T> @NonNull java.util.Optional<ArgumentParser<C,​T>> createParser​(@NonNull java.lang.String name, @NonNull ParserParameters parserParameters)
      Attempt to create a ArgumentParser for a specified type, using an instance of ParserParameter to configure the parser settings
      @NonNull java.util.Optional<java.util.function.BiFunction<@NonNull CommandContext<C>,​@NonNull java.lang.String,​@NonNull java.util.List<java.lang.String>>> getSuggestionProvider​(@NonNull java.lang.String name)
      Get a named suggestion provider, if a suggestion provider with the given name exists in the registry
      @NonNull ParserParameters parseAnnotations​(@NonNull io.leangen.geantyref.TypeToken<?> parsingType, @NonNull java.util.Collection<? extends java.lang.annotation.Annotation> annotations)
      Parse annotations into ParserParameters
      <A extends java.lang.annotation.Annotation,​T>
      void
      registerAnnotationMapper​(@NonNull java.lang.Class<A> annotation, @NonNull java.util.function.BiFunction<@NonNull A,​@NonNull io.leangen.geantyref.TypeToken<?>,​@NonNull ParserParameters> mapper)
      Register a mapper that maps annotation instances to a map of parameter-object pairs
      void registerNamedParserSupplier​(@NonNull java.lang.String name, @NonNull java.util.function.Function<@NonNull ParserParameters,​@NonNull ArgumentParser<C,​?>> supplier)
      Register a named parser supplier
      <T> void registerParserSupplier​(@NonNull io.leangen.geantyref.TypeToken<T> type, @NonNull java.util.function.Function<@NonNull ParserParameters,​@NonNull ArgumentParser<C,​?>> supplier)
      Register a parser supplier
      void registerSuggestionProvider​(@NonNull java.lang.String name, @NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,​@NonNull java.lang.String,​@NonNull java.util.List<java.lang.String>> suggestionsProvider)
      Register a new named suggestion provider
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StandardParserRegistry

        public StandardParserRegistry()
        Construct a new StandardParserRegistry instance. This will also register all standard annotation mappers and parser suppliers
    • Method Detail

      • registerParserSupplier

        public <T> void registerParserSupplier​(@NonNull io.leangen.geantyref.TypeToken<T> type,
                                               @NonNull java.util.function.Function<@NonNull ParserParameters,​@NonNull ArgumentParser<C,​?>> supplier)
        Description copied from interface: ParserRegistry
        Register a parser supplier
        Specified by:
        registerParserSupplier in interface ParserRegistry<C>
        Type Parameters:
        T - Generic type specifying what is produced by the parser
        Parameters:
        type - The type that is parsed by the parser
        supplier - The function that generates the parser. The map supplied my contain parameters used to configure the parser, many of which are documented in StandardParameters
      • registerNamedParserSupplier

        public void registerNamedParserSupplier​(@NonNull java.lang.String name,
                                                @NonNull java.util.function.Function<@NonNull ParserParameters,​@NonNull ArgumentParser<C,​?>> supplier)
        Description copied from interface: ParserRegistry
        Register a named parser supplier
        Specified by:
        registerNamedParserSupplier in interface ParserRegistry<C>
        Parameters:
        name - Parser name
        supplier - The function that generates the parser. The map supplied my contain parameters used to configure the parser, many of which are documented in StandardParameters
      • registerAnnotationMapper

        public <A extends java.lang.annotation.Annotation,​T> void registerAnnotationMapper​(@NonNull java.lang.Class<A> annotation,
                                                                                                 @NonNull java.util.function.BiFunction<@NonNull A,​@NonNull io.leangen.geantyref.TypeToken<?>,​@NonNull ParserParameters> mapper)
        Description copied from interface: ParserRegistry
        Register a mapper that maps annotation instances to a map of parameter-object pairs
        Specified by:
        registerAnnotationMapper in interface ParserRegistry<C>
        Type Parameters:
        A - Annotation type
        T - Type of the object that the parser is retrieved for
        Parameters:
        annotation - Annotation class
        mapper - Mapper that maps the pair (annotation, type to be parsed) to a map of parameter-object pairs
      • parseAnnotations

        public @NonNull ParserParameters parseAnnotations​(@NonNull io.leangen.geantyref.TypeToken<?> parsingType,
                                                          @NonNull java.util.Collection<? extends java.lang.annotation.Annotation> annotations)
        Description copied from interface: ParserRegistry
        Parse annotations into ParserParameters
        Specified by:
        parseAnnotations in interface ParserRegistry<C>
        Parameters:
        parsingType - The type that is produced by the parser that is requesting the parsing parameters
        annotations - The annotations to be parsed
        Returns:
        Parsed parameters
      • createParser

        public <T> @NonNull java.util.Optional<ArgumentParser<C,​T>> createParser​(@NonNull io.leangen.geantyref.TypeToken<T> type,
                                                                                       @NonNull ParserParameters parserParameters)
        Description copied from interface: ParserRegistry
        Attempt to create a ArgumentParser for a specified type, using an instance of ParserParameter to configure the parser settings
        Specified by:
        createParser in interface ParserRegistry<C>
        Type Parameters:
        T - Generic type
        Parameters:
        type - Type that should be produced by the parser
        parserParameters - Parser parameters
        Returns:
        Parser, if one can be created
      • createParser

        public <T> @NonNull java.util.Optional<ArgumentParser<C,​T>> createParser​(@NonNull java.lang.String name,
                                                                                       @NonNull ParserParameters parserParameters)
        Description copied from interface: ParserRegistry
        Attempt to create a ArgumentParser for a specified type, using an instance of ParserParameter to configure the parser settings
        Specified by:
        createParser in interface ParserRegistry<C>
        Type Parameters:
        T - Generic type
        Parameters:
        name - Parser
        parserParameters - Parser parameters
        Returns:
        Parser, if one can be created
      • registerSuggestionProvider

        public void registerSuggestionProvider​(@NonNull java.lang.String name,
                                               @NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,​@NonNull java.lang.String,​@NonNull java.util.List<java.lang.String>> suggestionsProvider)
        Description copied from interface: ParserRegistry
        Register a new named suggestion provider
        Specified by:
        registerSuggestionProvider in interface ParserRegistry<C>
        Parameters:
        name - Name of the suggestions provider. The name is case independent.
        suggestionsProvider - The suggestions provider
        See Also:
        Get a suggestion provider
      • getSuggestionProvider

        public @NonNull java.util.Optional<java.util.function.BiFunction<@NonNull CommandContext<C>,​@NonNull java.lang.String,​@NonNull java.util.List<java.lang.String>>> getSuggestionProvider​(@NonNull java.lang.String name)
        Description copied from interface: ParserRegistry
        Get a named suggestion provider, if a suggestion provider with the given name exists in the registry
        Specified by:
        getSuggestionProvider in interface ParserRegistry<C>
        Parameters:
        name - Suggestion provider name. The name is case independent.
        Returns:
        Optional that either contains the suggestion provider, or is empty if no suggestion provider is registered with the given name
        See Also:
        Register a suggestion provider