Class AnnotationParser<C>
java.lang.Object
cloud.commandframework.annotations.AnnotationParser<C>
- Type Parameters:
C- Command sender type
Parser that parses class instances
commands-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAnnotationParser(@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 parserAnnotationParser(@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 -
Method Summary
Modifier and TypeMethodDescription@NonNull cloud.commandframework.annotations.injection.ParameterInjectorRegistry<C>Get the parameter injector registry instance that is used to inject non-argumentparameters intoCommandMethodannotatedmethods@NonNull cloud.commandframework.CommandManager<C>manager()Returns the command manager that was used to create this parser<T> @NonNull Collection<@NonNull cloud.commandframework.Command<C>>parse(@NonNull T instance) Scan a class instance ofCommandMethodannotations and attempt to compile them intoCommandinstances.@NonNull Collection<@NonNull cloud.commandframework.Command<C>>Parses all knowncommand containers.@NonNull StringprocessString(@NonNull String input) Processes theinputstring and returns the processed result.@NonNull String[]processStrings(@NonNull String[] strings) Processes the inputstringsand returns the processed result.<A extends Annotation>
voidregisterAnnotationMapper(@NonNull Class<A> annotation, @NonNull Function<@NonNull A, @NonNull cloud.commandframework.arguments.parser.ParserParameters> mapper) Register an annotation mapper<A extends Annotation>
voidregisterBuilderModifier(@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.voidregisterCommandExecutionMethodFactory(@NonNull Predicate<@NonNull Method> predicate, @NonNull Function<MethodCommandExecutionHandler.CommandMethodContext<C>, MethodCommandExecutionHandler<C>> function) Registers a new command execution method factory.<A extends Annotation>
voidregisterPreprocessorMapper(@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@NonNull StringProcessorReturns the string processor used by this parser.voidstringProcessor(@NonNull StringProcessor stringProcessor) Replaces the string processor of this 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 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 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, 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 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, Function)- Since:
- 1.7.0
-
-
Method Details
-
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 methodfunction- 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 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
-
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 classmapper- 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 classpreprocessorMapper- Preprocessor mapper
-
getParameterInjectorRegistry
public @NonNull cloud.commandframework.annotations.injection.ParameterInjectorRegistry<C> getParameterInjectorRegistry()Get the parameter injector registry instance that is used to inject non-argumentparameters intoCommandMethodannotatedmethods- Returns:
- Parameter injector registry
- Since:
- 1.2.0
-
stringProcessor
Returns the string processor used by this parser.- Returns:
- the string processor
- Since:
- 1.7.0
-
stringProcessor
Replaces the string processor of this parser.- Parameters:
stringProcessor- the new string processor- Since:
- 1.7.0
-
processString
Processes theinputstring and returns the processed result.- Parameters:
input- the input string- Returns:
- the processed string
- Since:
- 1.7.0
-
processStrings
Processes the inputstringsand 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 ExceptionParses all knowncommand 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 ofCommandMethodannotations and attempt to compile them intoCommandinstances.- Type Parameters:
T- Type of the instance- Parameters:
instance- Instance to scan- Returns:
- Collection of parsed commands
-