Package org.incendo.cloud.parser
Class StandardParserRegistry<C>
java.lang.Object
org.incendo.cloud.parser.StandardParserRegistry<C>
- Type Parameters:
C- command sender type
- All Implemented Interfaces:
ParserRegistry<C>
@API(status=STABLE)
public final class StandardParserRegistry<C>
extends Object
implements ParserRegistry<C>
Standard implementation of
ParserRegistry-
Nested Class Summary
Nested classes/interfaces inherited from interface org.incendo.cloud.parser.ParserRegistry
ParserRegistry.AnnotationMapper<A extends Annotation> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> @NonNull Optional<ArgumentParser<C, T>> createParser(@NonNull TypeToken<T> type, @NonNull ParserParameters parserParameters) Attempts to create an instance of the defaultArgumentParserfor the giventypeusing an instance ofParserParameterto configure the parser settings.<T> @NonNull Optional<ArgumentParser<C, T>> createParser(@NonNull String name, @NonNull ParserParameters parserParameters) Attempts to create an instance of the parserArgumentParserwith the givennameusing an instance ofParserParameterto configure the parser settings.Returns a named suggestion provider, if it exists.parseAnnotations(@NonNull TypeToken<?> parsingType, @NonNull Collection<? extends @NonNull Annotation> annotations) Parses the givenannotationsintoParserParameters.<A extends Annotation>
StandardParserRegistry<C> registerAnnotationMapper(@NonNull Class<A> annotation, @NonNull ParserRegistry.AnnotationMapper<A> mapper) Registers a mapper that maps annotation instances to a map of parameter-object pairs.registerNamedParserSupplier(@NonNull String name, @NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser<C, ?>> supplier) Registers a named parser supplier.<T> StandardParserRegistry<C> registerParserSupplier(@NonNull TypeToken<T> type, @NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser<C, ?>> supplier) Registers the givensupplieras the default parser supplier for the giventype.voidregisterSuggestionProvider(@NonNull String name, @NonNull SuggestionProvider<C> suggestionProvider) Registers a new named suggestion providers.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.incendo.cloud.parser.ParserRegistry
registerNamedParser, registerParser
-
Constructor Details
-
StandardParserRegistry
public StandardParserRegistry()Construct a newStandardParserRegistryinstance. This will also register all standard annotation mappers and parser suppliers
-
-
Method Details
-
registerParserSupplier
public <T> StandardParserRegistry<C> registerParserSupplier(@NonNull TypeToken<T> type, @NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser<C, ?>> supplier) Description copied from interface:ParserRegistryRegisters the givensupplieras the default parser supplier for the giventype.- Specified by:
registerParserSupplierin interfaceParserRegistry<C>- Type Parameters:
T- generic type specifying what is produced by the parser- Parameters:
type- type that is parsed by the parsersupplier- function that generates the parser- Returns:
this
-
registerNamedParserSupplier
public StandardParserRegistry<C> registerNamedParserSupplier(@NonNull String name, @NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser<C, ?>> supplier) Description copied from interface:ParserRegistryRegisters a named parser supplier.The named parser will only be created if referenced by name using
ParserRegistry.createParser(String, ParserParameters). Only unnamed parsers may be referenced by their value types.- Specified by:
registerNamedParserSupplierin interfaceParserRegistry<C>- Parameters:
name- parser namesupplier- the function that generates the parser- Returns:
this
-
registerAnnotationMapper
public <A extends Annotation> StandardParserRegistry<C> registerAnnotationMapper(@NonNull Class<A> annotation, @NonNull ParserRegistry.AnnotationMapper<A> mapper) Description copied from interface:ParserRegistryRegisters a mapper that maps annotation instances to a map of parameter-object pairs.- Specified by:
registerAnnotationMapperin interfaceParserRegistry<C>- Type Parameters:
A- annotation type- Parameters:
annotation- annotation classmapper- mapper that maps the pair (annotation, type to be parsed) to a map ofparameter-objectpairs- Returns:
this
-
parseAnnotations
public @NonNull ParserParameters parseAnnotations(@NonNull TypeToken<?> parsingType, @NonNull Collection<? extends @NonNull Annotation> annotations) Description copied from interface:ParserRegistryParses the givenannotationsintoParserParameters.- Specified by:
parseAnnotationsin interfaceParserRegistry<C>- Parameters:
parsingType- the type that is produced by the parser that is requesting the parsing parametersannotations- annotations to be parsed- Returns:
- the parsed parameters
-
createParser
public <T> @NonNull Optional<ArgumentParser<C,T>> createParser(@NonNull TypeToken<T> type, @NonNull ParserParameters parserParameters) Description copied from interface:ParserRegistryAttempts to create an instance of the defaultArgumentParserfor the giventypeusing an instance ofParserParameterto configure the parser settings.- Specified by:
createParserin interfaceParserRegistry<C>- Type Parameters:
T- type of values produced by the parser- Parameters:
type- type of values produced by the parserparserParameters- parser parameters- Returns:
- the parser, if one could be created
-
createParser
public <T> @NonNull Optional<ArgumentParser<C,T>> createParser(@NonNull String name, @NonNull ParserParameters parserParameters) Description copied from interface:ParserRegistryAttempts to create an instance of the parserArgumentParserwith the givennameusing an instance ofParserParameterto configure the parser settings.- Specified by:
createParserin interfaceParserRegistry<C>- Type Parameters:
T- type of values produced by the parser- Parameters:
name- name of the parserparserParameters- parser parameters- Returns:
- the parser, if one could be created
-
registerSuggestionProvider
public void registerSuggestionProvider(@NonNull String name, @NonNull SuggestionProvider<C> suggestionProvider) Description copied from interface:ParserRegistryRegisters a new named suggestion providers.- Specified by:
registerSuggestionProviderin interfaceParserRegistry<C>- Parameters:
name- name of the suggestion provider. The name is case independent.suggestionProvider- the suggestion provider- See Also:
-
getSuggestionProvider
Description copied from interface:ParserRegistryReturns a named suggestion provider, if it exists.- Specified by:
getSuggestionProviderin interfaceParserRegistry<C>- Parameters:
name- case-independent suggestion provider name- Returns:
- optional that either contains the suggestion provider, or is empty if no suggestion provider is registered with the given name
- See Also:
-