Package org.incendo.cloud.parser
Interface ParserRegistry<C>
- Type Parameters:
C- command sender type
- All Known Implementing Classes:
StandardParserRegistry
Registry that allows
parsers to be referenced by the type of the values they produce, or by their names.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceParserRegistry.AnnotationMapper<A extends Annotation> -
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>
ParserRegistry<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.default ParserRegistry<C> registerNamedParser(@NonNull String name, @NonNull ParserDescriptor<C, ?> descriptor) Registers a named parser supplier.registerNamedParserSupplier(@NonNull String name, @NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser<C, ?>> supplier) Registers a named parser supplier.default <T> ParserRegistry<C> registerParser(@NonNull ParserDescriptor<C, T> descriptor) Registers the parser described by the givendescriptor.<T> ParserRegistry<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.
-
Method Details
-
registerParserSupplier
<T> ParserRegistry<C> registerParserSupplier(@NonNull TypeToken<T> type, @NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser<C, ?>> supplier) Registers the givensupplieras the default parser supplier for the giventype.- 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
-
registerParser
@API(status=STABLE) default <T> ParserRegistry<C> registerParser(@NonNull ParserDescriptor<C, T> descriptor) Registers the parser described by the givendescriptor.This does not allow for customization of the parser using parser parameters. If the parser has options then it is recommended to use
registerParserSupplier(TypeToken, Function)instead.- Type Parameters:
T- type produced by the parser- Parameters:
descriptor- parser descriptor- Returns:
this
-
registerNamedParserSupplier
ParserRegistry<C> registerNamedParserSupplier(@NonNull String name, @NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser<C, ?>> supplier) Registers a named parser supplier.The named parser will only be created if referenced by name using
createParser(String, ParserParameters). Only unnamed parsers may be referenced by their value types.- Parameters:
name- parser namesupplier- the function that generates the parser- Returns:
this
-
registerNamedParser
default ParserRegistry<C> registerNamedParser(@NonNull String name, @NonNull ParserDescriptor<C, ?> descriptor) Registers a named parser supplier.This does not allow for customization of the parser using parser parameters. If the parser has options then it is recommended to use
registerNamedParserSupplier(String, Function)instead.- Parameters:
name- parser namedescriptor- parser descriptor- Returns:
this
-
registerAnnotationMapper
<A extends Annotation> ParserRegistry<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. -
parseAnnotations
@NonNull ParserParameters parseAnnotations(@NonNull TypeToken<?> parsingType, @NonNull Collection<? extends @NonNull Annotation> annotations) Parses the givenannotationsintoParserParameters.- 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
<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.- 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
<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.- 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
@API(status=STABLE) void registerSuggestionProvider(@NonNull String name, @NonNull SuggestionProvider<C> suggestionProvider) Registers a new named suggestion providers.- Parameters:
name- name of the suggestion provider. The name is case independent.suggestionProvider- the suggestion provider- See Also:
-
getSuggestionProvider
@API(status=STABLE) @NonNull Optional<SuggestionProvider<C>> getSuggestionProvider(@NonNull String name) Returns a named suggestion provider, if it exists.- 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:
-