Interface Option<T>

Type Parameters:
T - option type, as options are always loaded from String, the type has to map from a String or list of strings

public interface Option<T>
Option definition. When implementing your own, hashCode and equals should return value of name(), to correctly match against other option instances.
  • Method Details

    • create

      static Option<String> create(String name, String description, String defaultValue)
      Create a new String option.
      Parameters:
      name - name of the option
      description - human readable description
      defaultValue - default value to use if not found
      Returns:
      a new option
    • create

      static Option<Boolean> create(String name, String description, boolean defaultValue)
      Create a new boolean option.
      Parameters:
      name - name of the option
      description - human readable description
      defaultValue - default value to use if not found
      Returns:
      a new option
    • create

      static Option<Integer> create(String name, String description, int defaultValue)
      Create a new int option.
      Parameters:
      name - name of the option
      description - human readable description
      defaultValue - default value to use if not found
      Returns:
      a new option
    • create

      static <T> Option<T> create(String name, String description, T defaultValue, Function<String,T> mapper, GenericType<T> type)
      Create a new option with a custom mapper.
      Type Parameters:
      T - type of the option
      Parameters:
      name - name of the option
      description - description of the option
      defaultValue - default value
      mapper - mapper from string
      type - type of the option
      Returns:
      a new option that can be used to load value from CodegenOptions
    • createSet

      static <T> Option<Set<T>> createSet(String name, String description, Set<T> defaultValue, Function<String,T> mapper, GenericType<Set<T>> type)
      Create a new option that has a set of values, with a custom mapper.
      Type Parameters:
      T - type of the option
      Parameters:
      name - name of the option
      description - description of the option
      defaultValue - default value
      mapper - mapper from string
      type - type of the option
      Returns:
      a new option that can be used to load value from CodegenOptions
    • createList

      static <T> Option<List<T>> createList(String name, String description, List<T> defaultValue, Function<String,T> mapper, GenericType<List<T>> type)
      Create a new option that has a list of values, with a custom mapper.
      Type Parameters:
      T - type of the option
      Parameters:
      name - name of the option
      description - description of the option
      defaultValue - default value
      mapper - mapper from string
      type - type of the option
      Returns:
      a new option that can be used to load value from CodegenOptions
    • type

      GenericType<T> type()
      Type of the option, metadata that can be used to list available options and their types.
      Returns:
      type of this option
    • name

      String name()
      Name of the option. The name can be configured in Maven plugin, through command line arguments, or through -A prefixed annotation processing arguments to compiler.
      Returns:
      name of the option
    • description

      String description()
      Option description, metadata that can be used to list available options and their description.
      Returns:
      option description
    • defaultValue

      T defaultValue()
      Default to use if the option is not defined.
      Returns:
      default value
    • findValue

      Optional<T> findValue(CodegenOptions options)
      Find an option value from the codegen options.
      Parameters:
      options - as obtained from the caller
      Returns:
      value of this option, or empty if not configured
    • value

      default T value(CodegenOptions options)
      Obtain an option value from the codegen options using defaultValue() if none configured.
      Parameters:
      options - as obtained from the caller
      Returns:
      value of this option