- 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 Summary
Modifier and TypeMethodDescriptionCreate a new boolean option.Create a new int option.Create a new String option.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.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.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.Default to use if the option is not defined.Option description, metadata that can be used to list available options and their description.findValue
(CodegenOptions options) Find an option value from the codegen options.name()
Name of the option.type()
Type of the option, metadata that can be used to list available options and their types.default T
value
(CodegenOptions options) Obtain an option value from the codegen options usingdefaultValue()
if none configured.
-
Method Details
-
create
Create a new String option.- Parameters:
name
- name of the optiondescription
- human readable descriptiondefaultValue
- default value to use if not found- Returns:
- a new option
-
create
Create a new boolean option.- Parameters:
name
- name of the optiondescription
- human readable descriptiondefaultValue
- default value to use if not found- Returns:
- a new option
-
create
Create a new int option.- Parameters:
name
- name of the optiondescription
- human readable descriptiondefaultValue
- 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 optiondescription
- description of the optiondefaultValue
- default valuemapper
- mapper from stringtype
- 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 optiondescription
- description of the optiondefaultValue
- default valuemapper
- mapper from stringtype
- 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 optiondescription
- description of the optiondefaultValue
- default valuemapper
- mapper from stringtype
- 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
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
Obtain an option value from the codegen options usingdefaultValue()
if none configured.- Parameters:
options
- as obtained from the caller- Returns:
- value of this option
-