Package org.incendo.cloud.annotations
Class AnnotationParser<C>
java.lang.Object
org.incendo.cloud.annotations.AnnotationParser<C>
- Type Parameters:
C- command sender type
Parser that parses class instances
commands-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAnnotationParser(@NonNull CommandManager<C> manager, @NonNull TypeToken<C> commandSenderClass) Construct a new annotation parserAnnotationParser(@NonNull CommandManager<C> manager, @NonNull TypeToken<C> commandSenderType, @NonNull Function<@NonNull ParserParameters, @NonNull CommandMeta> metaMapper) Construct a new annotation parserAnnotationParser(@NonNull CommandManager<C> manager, @NonNull Class<C> commandSenderClass) Construct a new annotation parserAnnotationParser(@NonNull CommandManager<C> manager, @NonNull Class<C> commandSenderClass, @NonNull Function<@NonNull ParserParameters, @NonNull CommandMeta> metaMapper) Construct a new annotation parser -
Method Summary
Modifier and TypeMethodDescriptionReturns the argument assembler.voidargumentAssembler(@NonNull ArgumentAssembler<C> argumentAssembler) Sets the argument assemblerReturns the argument extractor.voidargumentExtractor(@NonNull ArgumentExtractor argumentExtractor) Sets the argument extractor.Returns the command extractor.voidcommandExtractor(@NonNull CommandExtractor commandExtractor) Sets the command extractor.Returns the default value registry.voiddefaultValueRegistry(@NonNull DefaultValueRegistry<C> defaultValueRegistry) Sets the default value registry.Returns the description mapper.voiddescriptionMapper(@NonNull DescriptionMapper descriptionMapper) Sets the description mapper.Returns the exception provider factory.voidexceptionHandlerFactory(@NonNull ExceptionHandlerFactory<C> exceptionHandlerFactory) Sets the exception provider factory.Returns the flag assembler.voidflagAssembler(@NonNull FlagAssembler flagAssembler) Sets the flag assemblerReturns the flag extractor.voidflagExtractor(@NonNull FlagExtractor flagExtractor) Sets the flag extractor.manager()Returns the command manager that was used to create this parsermapDescription(@NonNull String string) Maps the givenstringinto aDescription.Returns the method argument parser factory.voidmethodArgumentParserFactory(@NonNull MethodArgumentParserFactory<C> methodArgumentParserFactory) Sets the method argument parser factory.parse(@NonNull Collection<@NonNull Object> instances) Parses all knowncommand containers.parseContainers(@NonNull ClassLoader classLoader) Parses all knowncommand containers.@NonNull Map<@NonNull Class<? extends Annotation>, @NonNull PreprocessorMapper<?, C>> Returns an unmodifiable view of the preprocessor mappers.processString(@NonNull String input) Processes theinputstring and returns the processed result.processStrings(@NonNull String[] strings) Processes the inputstringsand returns the processed result.processStrings(@NonNull Collection<@NonNull String> strings) Processes the inputstringsand returns the processed result.<A extends Annotation>
voidregisterAnnotationMapper(@NonNull Class<A> annotation, @NonNull AnnotationMapper<A> mapper) Register an annotation mappervoidregisterBuilderDecorator(@NonNull BuilderDecorator<C> decorator) Registers the givendecorator.<A extends Annotation>
voidregisterBuilderModifier(@NonNull Class<A> annotation, @NonNull BuilderModifier<A, C> builderModifier) Register a builder modifier for a specific annotation.voidregisterCommandExecutionMethodFactory(@NonNull Predicate<@NonNull Method> predicate, @NonNull CommandMethodExecutionHandlerFactory<C> factory) Registers a new command execution method factory.<A extends Annotation>
voidregisterPreprocessorMapper(@NonNull Class<A> annotation, @NonNull PreprocessorMapper<A, C> preprocessorMapper) Registers a preprocessor mapperReturns the string processor used by this parser.voidstringProcessor(@NonNull StringProcessor stringProcessor) Replaces the string processor of this parser.Returns the suggestion provider factory.voidsuggestionProviderFactory(@NonNull SuggestionProviderFactory<C> suggestionProviderFactory) Sets the suggestion provider factory.Returns the syntax parser.voidsyntaxParser(@NonNull SyntaxParser syntaxParser) Sets the syntax parser.
-
Field Details
-
INFERRED_ARGUMENT_NAME
The value ofArgumentthat should be used to infer argument names from parameter names.- See Also:
-
-
Constructor Details
-
AnnotationParser
public AnnotationParser(@NonNull CommandManager<C> manager, @NonNull Class<C> commandSenderClass, @NonNull Function<@NonNull ParserParameters, @NonNull CommandMeta> metaMapper) Construct a new annotation parser- Parameters:
manager- Command manager instancecommandSenderClass- Command sender classmetaMapper- Function that is used to createCommandMetainstances from annotations on the command methods. These annotations will be mapped toParserParameter. Mappers for the parser parameters can be registered usingregisterAnnotationMapper(Class, AnnotationMapper)
-
AnnotationParser
Construct a new annotation parser- Parameters:
manager- Command manager instancecommandSenderClass- Command sender class
-
AnnotationParser
public AnnotationParser(@NonNull CommandManager<C> manager, @NonNull TypeToken<C> commandSenderClass) Construct a new annotation parser- Parameters:
manager- Command manager instancecommandSenderClass- Command sender class
-
AnnotationParser
@API(status=STABLE) public AnnotationParser(@NonNull CommandManager<C> manager, @NonNull TypeToken<C> commandSenderType, @NonNull Function<@NonNull ParserParameters, @NonNull CommandMeta> metaMapper) Construct a new annotation parser- Parameters:
manager- Command manager instancecommandSenderType- Command sender typemetaMapper- Function that is used to createCommandMetainstances from annotations on the command methods. These annotations will be mapped toParserParameter. Mappers for the parser parameters can be registered usingregisterAnnotationMapper(Class, AnnotationMapper)
-
-
Method Details
-
manager
Returns the command manager that was used to create this parser- Returns:
- Command manager
-
registerCommandExecutionMethodFactory
@API(status=STABLE) public void registerCommandExecutionMethodFactory(@NonNull Predicate<@NonNull Method> predicate, @NonNull CommandMethodExecutionHandlerFactory<C> factory) 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 to apply the custom execution handler to the given methodfactory- the function that produces the command execution handler
-
registerBuilderModifier
public <A extends Annotation> void registerBuilderModifier(@NonNull Class<A> annotation, @NonNull BuilderModifier<A, C> builderModifier) Register a builder modifier for a specific annotation. The builder modifiers are allowed to act on aCommand.Builderafter 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 tobuilderModifier- 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
-
registerBuilderDecorator
Registers the givendecorator.The decorators are allowed to modify the command builders to set up default values. All other steps of the command construction process take priority over the decorators.
- Parameters:
decorator- the decorator
-
registerAnnotationMapper
public <A extends Annotation> void registerAnnotationMapper(@NonNull Class<A> annotation, @NonNull AnnotationMapper<A> mapper) Register an annotation mapper- Type Parameters:
A- Annotation type- Parameters:
annotation- Annotation classmapper- Mapping function
-
registerPreprocessorMapper
@API(status=STABLE) public <A extends Annotation> void registerPreprocessorMapper(@NonNull Class<A> annotation, @NonNull PreprocessorMapper<A, C> preprocessorMapper) Registers a preprocessor mapper- Type Parameters:
A- annotation type- Parameters:
annotation- annotation classpreprocessorMapper- preprocessor mapper
-
preprocessorMappers
@API(status=STABLE) public @NonNull Map<@NonNull Class<? extends Annotation>,@NonNull PreprocessorMapper<?, preprocessorMappers()C>> Returns an unmodifiable view of the preprocessor mappers.- Returns:
- the preprocessor mappers
-
stringProcessor
Returns the string processor used by this parser.- Returns:
- the string processor
-
stringProcessor
Replaces the string processor of this parser.- Parameters:
stringProcessor- the new string processor
-
processString
Processes theinputstring and returns the processed result.- Parameters:
input- the input string- Returns:
- the processed string
-
processStrings
Processes the inputstringsand returns the processed result.- Parameters:
strings- the input strings- Returns:
- the processed strings
-
processStrings
@API(status=STABLE) public @NonNull List<@NonNull String> processStrings(@NonNull Collection<@NonNull String> strings) Processes the inputstringsand returns the processed result.- Parameters:
strings- the input strings- Returns:
- the processed strings
-
syntaxParser
Returns the syntax parser.- Returns:
- the syntax parser
-
syntaxParser
Sets the syntax parser.- Parameters:
syntaxParser- new syntax parser
-
argumentExtractor
Returns the argument extractor.- Returns:
- the argument extractor
-
argumentExtractor
Sets the argument extractor.- Parameters:
argumentExtractor- new argument extractor
-
argumentAssembler
Returns the argument assembler.- Returns:
- the argument assembler
-
argumentAssembler
Sets the argument assembler- Parameters:
argumentAssembler- new argument assembler
-
flagExtractor
Returns the flag extractor.- Returns:
- the flag extractor
-
flagExtractor
Sets the flag extractor.- Parameters:
flagExtractor- new flag extractor
-
flagAssembler
Returns the flag assembler.- Returns:
- the flag assembler
-
flagAssembler
Sets the flag assembler- Parameters:
flagAssembler- new flag assembler
-
commandExtractor
Returns the command extractor.- Returns:
- the command extractor
-
commandExtractor
Sets the command extractor.- Parameters:
commandExtractor- new command extractor
-
suggestionProviderFactory
Returns the suggestion provider factory.- Returns:
- the suggestion provider factory
-
suggestionProviderFactory
@API(status=STABLE) public void suggestionProviderFactory(@NonNull SuggestionProviderFactory<C> suggestionProviderFactory) Sets the suggestion provider factory.- Parameters:
suggestionProviderFactory- new suggestion provider factory
-
methodArgumentParserFactory
@API(status=EXPERIMENTAL) public @NonNull MethodArgumentParserFactory<C> methodArgumentParserFactory()Returns the method argument parser factory.- Returns:
- the method argument parser factory
-
methodArgumentParserFactory
@API(status=EXPERIMENTAL) public void methodArgumentParserFactory(@NonNull MethodArgumentParserFactory<C> methodArgumentParserFactory) Sets the method argument parser factory.- Parameters:
methodArgumentParserFactory- new method argument parser factory
-
exceptionHandlerFactory
Returns the exception provider factory.- Returns:
- the exception provider factory
-
exceptionHandlerFactory
@API(status=STABLE) public void exceptionHandlerFactory(@NonNull ExceptionHandlerFactory<C> exceptionHandlerFactory) Sets the exception provider factory.- Parameters:
exceptionHandlerFactory- new exception provider factory
-
descriptionMapper
Returns the description mapper.- Returns:
- the description mapper
-
descriptionMapper
Sets the description mapper.- Parameters:
descriptionMapper- new description mapper
-
defaultValueRegistry
Returns the default value registry.- Returns:
- the default value registry
-
defaultValueRegistry
Sets the default value registry.- Parameters:
defaultValueRegistry- default value registry
-
parseContainers
Parses all knowncommand containers.This will use the
class loaderof the current class to retrieve the stored information about the command containers.- Returns:
- Collection of parsed commands
- Throws:
Exception- re-throws all encountered exceptions.- See Also:
-
parseContainers
@API(status=STABLE) public @NonNull Collection<@NonNull Command<C>> parseContainers(@NonNull ClassLoader classLoader) throws Exception Parses all knowncommand containers.- Parameters:
classLoader- class loader to use to scan forCommandContainerProcessor.PATH- Returns:
- Collection of parsed commands
- Throws:
Exception- re-throws all encountered exceptions.- See Also:
-
parse
- Parameters:
instances- instances to scan- Returns:
- collection of parsed commands
-
parse
public @NonNull Collection<@NonNull Command<C>> parse(@NonNull Collection<@NonNull Object> instances) - Parameters:
instances- instances to scan- Returns:
- collection of parsed commands
-
mapDescription
@API(status=INTERNAL, consumers="org.incendo.cloud.annotations.*") public @NonNull Description mapDescription(@NonNull String string) Maps the givenstringinto aDescription.- Parameters:
string- description literal- Returns:
- the description
-