Class FieldSetter

  • All Implemented Interfaces:
    Getter, Setter

    public final class FieldSetter
    extends java.lang.Object
    implements Getter, Setter
    Setter that sets to a Field.
    Author:
    Kohsuke Kawaguchi
    • Constructor Summary

      Constructors 
      Constructor Description
      FieldSetter​(java.lang.Object bean, java.lang.reflect.Field f)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addValue​(java.lang.Object value)
      Adds/sets a value to the property of the option bean.
      java.lang.reflect.AnnotatedElement asAnnotatedElement()
      Returns the AnnotatedElement by which you can access annotations written on this setter.
      FieldSetter asFieldSetter()
      If this setter encapsulates a field, return the direct access to that field as FieldSetter.
      java.lang.Class getType()
      Gets the type of the underlying method/field.
      java.lang.Object getValue()  
      java.util.List<java.lang.Object> getValueList()
      Gets the current value of the property.
      boolean isMultiValued()
      Whether this setter is intrinsically multi-valued.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FieldSetter

        public FieldSetter​(java.lang.Object bean,
                           java.lang.reflect.Field f)
    • Method Detail

      • getType

        public java.lang.Class getType()
        Description copied from interface: Setter
        Gets the type of the underlying method/field.
        Specified by:
        getType in interface Setter
      • isMultiValued

        public boolean isMultiValued()
        Description copied from interface: Setter
        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.

        Specified by:
        isMultiValued in interface Setter
      • asFieldSetter

        public FieldSetter asFieldSetter()
        Description copied from interface: Setter
        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 getValueList()).
        Specified by:
        asFieldSetter in interface Setter
        Returns:
        null if this setter wraps a method.
      • asAnnotatedElement

        public java.lang.reflect.AnnotatedElement asAnnotatedElement()
        Description copied from interface: Setter
        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.

        Specified by:
        asAnnotatedElement in interface Setter
      • addValue

        public void addValue​(java.lang.Object value)
        Description copied from interface: Setter
        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.

        Specified by:
        addValue in interface Setter
      • getValue

        public java.lang.Object getValue()
      • getValueList

        public java.util.List<java.lang.Object> getValueList()
        Description copied from interface: Getter
        Gets the current value of the property.

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

        Specified by:
        getValueList in interface Getter
        Returns:
        empty list or null if there's no current value.