Class ArgumentParser<T>

java.lang.Object
net.apartium.cocoabeans.commands.parsers.ArgumentParser<T>
Type Parameters:
T - output type
All Implemented Interfaces:
Comparable<ArgumentParser<?>>
Direct Known Subclasses:
BooleanParser, CompoundParser, ContextualMapBasedParser, DoubleParser, DummyParser, FloatParser, IntParser, LongParser, ParagraphParser, QuotedStringParser, RegisterArgumentParser, StringParser, StringsParser, UUIDParser, WrappedArgumentParser

public abstract class ArgumentParser<T> extends Object implements Comparable<ArgumentParser<?>>
Base class for all parsers

It's recommended that each implementing of ArgumentParser class should define its own DEFAULT_KEYWORD to represent the default keyword


Note: That all parsers should have at least those 2 constructors
Parser(int priority)/Parser(int priority, String keyword)so we can use @WithParser on them
See Also:
  • Constructor Details

    • ArgumentParser

      protected ArgumentParser(String keyword, Class<T> clazz, int priority)
      Constructs a new parser
      Parameters:
      keyword - keyword of the parser
      clazz - output class
      priority - priority
  • Method Details

    • parse

      public abstract Optional<ArgumentParser.ParseResult<T>> parse(CommandProcessingContext processingContext)
      Tries to parse next argument in the context
      Parameters:
      processingContext - cmd processing context
      Returns:
      empty if failed, otherwise result
    • tryParse

      public abstract OptionalInt tryParse(CommandProcessingContext processingContext)
      Tries to lazily parse next argument in the context
      Parameters:
      processingContext - cmd processing context
      Returns:
      new index int if success, empty if not
    • tabCompletion

      public abstract Optional<ArgumentParser.TabCompletionResult> tabCompletion(CommandProcessingContext processingContext)
      Retrieves available options for tab completion of this argument
      Parameters:
      processingContext - cmd processing context
      Returns:
      tab completion result if success, otherwise empty option
    • getArgumentType

      public Class<T> getArgumentType()
      Get argument type
      Returns:
      argument type
    • getPriority

      public int getPriority()
      Get priority
      Returns:
      priority
    • compareTo

      public int compareTo(@NotNull @NotNull ArgumentParser<?> other)
      Specified by:
      compareTo in interface Comparable<T>
    • getKeyword

      public String getKeyword()
      Get type keyword, like int or string
      Returns:
      type keyword