private StepFormatter . Formatting < ? , ? > getFormatting ( Annotation [ ] annotations , Set < Class < ? > > visitedTypes , Annotation originalAnnotation , String parameterName ) { List < StepFormatter . Formatting < ? , ? > > foundFormatting = Lists . newArrayList ( ) ; Table tableAnnotation = null ; for ( Annotation annotation : annotations ) { try { if ( annotation instanceof Format ) { Format arg = ( Format ) annotation ; foundFormatting . add ( new StepFormatter . ArgumentFormatting ( ReflectionUtil . newInstance ( arg . value ( ) ) , arg . args ( ) ) ) ; } else if ( annotation instanceof Table ) { tableAnnotation = ( Table ) annotation ; } else if ( annotation instanceof AnnotationFormat ) { AnnotationFormat arg = ( AnnotationFormat ) annotation ; foundFormatting . add ( new StepFormatter . ArgumentFormatting ( new StepFormatter . AnnotationBasedFormatter ( arg . value ( ) . newInstance ( ) , originalAnnotation ) ) ) ; } else { Class < ? extends Annotation > annotationType = annotation . annotationType ( ) ; if ( ! visitedTypes . contains ( annotationType ) ) { visitedTypes . add ( annotationType ) ; StepFormatter . Formatting < ? , ? > formatting = getFormatting ( annotationType . getAnnotations ( ) , visitedTypes , annotation , parameterName ) ; if ( formatting != null ) { foundFormatting . add ( formatting ) ; } } } } catch ( Exception e ) { throw Throwables . propagate ( e ) ; } } if ( foundFormatting . size ( ) > 1 ) { Formatting < ? , ? > innerFormatting = Iterables . getLast ( foundFormatting ) ; foundFormatting . remove ( innerFormatting ) ; ChainedFormatting < ? > chainedFormatting = new StepFormatter . ChainedFormatting < Object > ( ( ObjectFormatter < Object > ) innerFormatting ) ; for ( StepFormatter . Formatting < ? , ? > formatting : Lists . reverse ( foundFormatting ) ) { chainedFormatting . addFormatting ( ( StepFormatter . Formatting < ? , String > ) formatting ) ; } foundFormatting . clear ( ) ; foundFormatting . add ( chainedFormatting ) ; } if ( tableAnnotation != null ) { ObjectFormatter < ? > objectFormatter = foundFormatting . isEmpty ( ) ? DefaultFormatter . INSTANCE : foundFormatting . get ( 0 ) ; return getTableFormatting ( annotations , parameterName , tableAnnotation , objectFormatter ) ; } if ( foundFormatting . isEmpty ( ) ) { return null ; } return foundFormatting . get ( 0 ) ; }
Recursively searches for formatting annotations .