🔄Dynamic annotation parser
Table of content:
Introduction
The Dynamic Annotation Parser is a feature of the command system that registers argument parsers into your commands by declaring them in annotations.
This is a powerful features that allows command authors to use parameterized argument parsers without having to manually register them for the whole command manager.
This is done by creating an annotation, that is itself annotated with CommandParserFactory. This way, the annotation will specify a ParserFactory class to be constructed. The class will do the heavy lifting and contain the logic for constructing the argument mappers.
Declaring your annotation
The core of the Dynamic Annotation Parser is the ParserFactory interface. This interface defines a method ParserFactory#getArgumentParser, which is responsible for returning a Collection<ParserResult> based on the provided command node, annotation, and generic declaration.
Parameters
commandNode: The command node that the parser is associated with.annotation: The annotation that triggers the parser creation.obj: The generic declaration (either a class or method) where the annotation is applied.
An example annotation can be:
CommandParserFactory
We have created the annotation, but for it to actually do something we need to create a factory.
Lets create a simple factory that uses the argument parser class objects to create a new argument parser instance, and register it to the command.
Now we also have to specify the factory in the annotation:
Scope
The scope of the parser (whether it applies to a method, class) is determined by the Scope enum. This allows fine-grained control over where and how parsers are applied within your command framework.
VARIANT: Just for a specific sub commandCLASS: For the entire classALL: Could be both for method or class it changes base onParseResult