public static Map < String , Object > getAnnotationAttributes ( Annotation annotation , boolean classValuesAsString ) { Map < String , Object > attrs = new HashMap <> ( ) ; Method [ ] methods = annotation . annotationType ( ) . getDeclaredMethods ( ) ; for ( Method method : methods ) { if ( method . getParameterTypes ( ) . length == 0 && method . getReturnType ( ) != void . class ) { try { Object value = method . invoke ( annotation ) ; if ( classValuesAsString ) { if ( value instanceof Class ) { value = ( ( Class ) value ) . getName ( ) ; } else if ( value instanceof Class [ ] ) { Class [ ] clazzArray = ( Class [ ] ) value ; String [ ] newValue = new String [ clazzArray . length ] ; for ( int i = 0 ; i < clazzArray . length ; i ++ ) { newValue [ i ] = clazzArray [ i ] . getName ( ) ; } value = newValue ; } } attrs . put ( method . getName ( ) , value ) ; } catch ( Exception ex ) { throw new IllegalStateException ( "Could not obtain annotation attribute values" , ex ) ; } } } return attrs ; }
Retrieve the given annotation s attributes as a Map .