@ Override public < T > List < Pair < ArgumentDefinition , T > > gatherArgumentValuesOfType ( final Class < T > type ) { final List < Pair < ArgumentDefinition , T > > argumentValues = new ArrayList <> ( ) ; // include all named and positional argument definitions final List < ArgumentDefinition > allArgDefs = new ArrayList <> ( namedArgumentDefinitions . size ( ) ) ; allArgDefs . addAll ( namedArgumentDefinitions ) ; if ( positionalArgumentDefinition != null ) { allArgDefs . add ( positionalArgumentDefinition ) ; } for ( final ArgumentDefinition argDef : allArgDefs ) { if ( type . isAssignableFrom ( argDef . getUnderlyingFieldClass ( ) ) ) { // Consider only fields that are either of the target type, subtypes of the target type, // or Collections of the target type or one of its subtypes: if ( argDef . isCollection ( ) ) { // Collection arguments are guaranteed by the parsing system to be non-null (at worst, empty) final Collection < ? > argumentContainer = ( Collection < ? > ) argDef . getArgumentValue ( ) ; // Emit a Pair with an explicit null value for empty Collection arguments if ( argumentContainer . isEmpty ( ) ) { argumentValues . add ( Pair . of ( argDef , null ) ) ; } // Unpack non-empty Collections of the target type into individual values, // each paired with the same Field object. else { for ( final Object argumentValue : argumentContainer ) { argumentValues . add ( Pair . of ( argDef , type . cast ( argumentValue ) ) ) ; } } } else { // Add values for non-Collection arguments of the target type directly argumentValues . add ( Pair . of ( argDef , type . cast ( argDef . getArgumentValue ( ) ) ) ) ; } } } return argumentValues ; }
Locates and returns the VALUES of all Argument - annotated fields of a specified type in a given object pairing each field value with its corresponding Field object .