Top Description Methods
org.kohsuke.args4j.spi

public Interface Setter<T>

Known Direct Implementers
org.kohsuke.args4j.spi.ArrayFieldSetter, org.kohsuke.args4j.spi.FieldSetter, org.kohsuke.args4j.spi.MethodSetter, org.kohsuke.args4j.spi.MultiValueFieldSetter
Imports
org.kohsuke.args4j.Argument, .CmdLineException, .Option, java.lang.reflect.AnnotatedElement

Abstraction of the value setter.

This abstracts away the difference between a field and a setter method, which object we are setting the value to, and/or how we handle collection fields differently.

Author
Kohsuke Kawaguchi
See Also
Getter

Method Summary

Modifier and TypeMethod and Description
public void
addValue(T value)

Adds/sets a value to the property of the option bean.

public AnnotatedElement
asAnnotatedElement()

Returns the AnnotatedElement by which you can access annotations written on this setter.

public FieldSetter

Returns:

null if this setter wraps a method.
asFieldSetter
()

If this setter encapsulates a field, return the direct access to that field as FieldSetter.

public Class<T>
getType()

Gets the type of the underlying method/field.

public boolean
isMultiValued()

Whether this setter is intrinsically multi-valued.

Method Detail

addValueback to summary
public void addValue(T value) throws CmdLineException

Adds/sets a value to the property of the option bean.

A Setter object has an implicit knowledge about the property it's setting, and the instance of the option bean.

asAnnotatedElementback to summary
public AnnotatedElement asAnnotatedElement()

Returns the AnnotatedElement by which you can access annotations written on this setter. This is the same AnnotatedElement that had Option/Argument.

This enables OptionHandler to further tweak its behavior based on additional annotations.

asFieldSetterback to summary
public FieldSetter asFieldSetter()

If this setter encapsulates a field, return the direct access to that field as FieldSetter. This method serves two purposes:

  1. This lets OptionHandlers bypass the collection/array handling of fields. This is useful if you're defining an option handler that produces array or collection from a single argument.
  2. The other is to retrieve the current value of the field (via FieldSetter#getValueList()).
Returns:FieldSetter

null if this setter wraps a method.

getTypeback to summary
public Class<T> getType()

Gets the type of the underlying method/field.

isMultiValuedback to summary
public boolean isMultiValued()

Whether this setter is intrinsically multi-valued.

When parsing arguments (instead of options), intrinsically multi-valued setters consume all the remaining arguments. So, if the setter can store multiple values, this method should return true.

This characteristics of a setter doesn't affect option parsing at all; any options can be specified multiple times. In many cases, this is a no-op--but when your shell script expands multiple environment variables (each of which may contain options), tolerating such redundant options can be useful.