private static String [ ] guessAndSerializeExampleRequest ( Object exampleRequest ) { checkArgument ( ! ( exampleRequest instanceof CharSequence ) , "can't guess service or method name from a string: " , exampleRequest ) ; boolean guessed = false ; for ( DocServicePlugin plugin : DocService . plugins ) { // Skip if the plugin does not support it. if ( plugin . supportedExampleRequestTypes ( ) . stream ( ) . noneMatch ( type -> type . isInstance ( exampleRequest ) ) ) { continue ; } final Optional < String > serviceName = plugin . guessServiceName ( exampleRequest ) ; final Optional < String > methodName = plugin . guessServiceMethodName ( exampleRequest ) ; // Skip if the plugin cannot guess the service and method name. if ( ! serviceName . isPresent ( ) || ! methodName . isPresent ( ) ) { continue ; } guessed = true ; final String s = serviceName . get ( ) ; final String f = methodName . get ( ) ; final Optional < String > serialized = plugin . serializeExampleRequest ( s , f , exampleRequest ) ; if ( serialized . isPresent ( ) ) { return new String [ ] { s , f , serialized . get ( ) } ; } } if ( guessed ) { throw new IllegalArgumentException ( "could not find a plugin that can serialize: " + exampleRequest ) ; } else { throw new IllegalArgumentException ( "could not find a plugin that can guess the service and method name from: " + exampleRequest ) ; } }
Returns a tuple of a service name a method name and a serialized example request .