private static Optional < String > getMethodReturnValueName ( ConstraintViolation < ? > violation ) { int returnValueNames = - 1 ; final StringBuilder result = new StringBuilder ( "server response" ) ; for ( Path . Node node : violation . getPropertyPath ( ) ) { if ( node . getKind ( ) . equals ( ElementKind . RETURN_VALUE ) ) { returnValueNames = 0 ; } else if ( returnValueNames >= 0 ) { result . append ( returnValueNames ++ == 0 ? " " : "." ) . append ( node ) ; } } return returnValueNames >= 0 ? Optional . of ( result . toString ( ) ) : Optional . empty ( ) ; }
Gets the method return value name if the violation is raised in it