parameters: (self, function)
return_statement: return c
docstring: Generate function to create an instance of Params. The generated
      function takes a base::ListValue of arguments.
  
      E.g for function "Bar", generate Bar::Params::Create()
docstring_summary: Generate function to create an instance of Params. The generated
      function takes a base::ListValue of arguments.
docstring_tokens: Generate function to create an instance of Params . The generated function takes a base :: ListValue of arguments .
function: def _GenerateFunctionParamsCreate(self, function):
      """Generate function to create an instance of Params. The generated
      function takes a base::ListValue of arguments.
  
      E.g for function "Bar", generate Bar::Params::Create()
      """
      c = Code()
      (c.Append('// static')
        .Sblock('std::unique_ptr<Params> Params::Create(%s) {' %
                    self._GenerateParams(['const base::ListValue& args']))
      )
      if self._generate_error_messages:
        c.Append('DCHECK(error);')
      (c.Concat(self._GenerateParamsCheck(function, 'args'))
        .Append('std::unique_ptr<Params> params(new Params());')
      )
  
      for param in function.params:
        c.Concat(self._InitializePropertyToDefault(param, 'params'))
  
      for i, param in enumerate(function.params):
        # Any failure will cause this function to return. If any argument is
        # incorrect or missing, those following it are not processed. Note that
        # for optional arguments, we allow missing arguments and proceed because
        # there may be other arguments following it.
        failure_value = 'std::unique_ptr<Params>()'
        c.Append()
        value_var = param.unix_name + '_value'
        (c.Append('const base::Value* %(value_var)s = NULL;')
          .Append('if (args.Get(%(i)s, &%(value_var)s) &&')
          .Sblock('    !%(value_var)s->IsType(base::Value::TYPE_NULL)) {')
          .Concat(self._GeneratePopulatePropertyFromValue(
              param, value_var, 'params', failure_value))
          .Eblock('}')
        )
        if not param.optional:
          (c.Sblock('else {')
            .Concat(self._GenerateError('"\'%%(key)s\' is required"'))
            .Append('return %s;' % failure_value)
            .Eblock('}'))
        c.Substitute({'value_var': value_var, 'i': i, 'key': param.name})
      (c.Append()
        .Append('return params;')
        .Eblock('}')
        .Append()
      )
  
      return c
function_tokens: def _GenerateFunctionParamsCreate ( self , function ) : c = Code ( ) ( c . Append ( '// static' ) . Sblock ( 'std::unique_ptr<Params> Params::Create(%s) {' % self . _GenerateParams ( [ 'const base::ListValue& args' ] ) ) ) if self . _generate_error_messages : c . Append ( 'DCHECK(error);' ) ( c . Concat ( self . _GenerateParamsCheck ( function , 'args' ) ) . Append ( 'std::unique_ptr<Params> params(new Params());' ) ) for param in function . params : c . Concat ( self . _InitializePropertyToDefault ( param , 'params' ) ) for i , param in enumerate ( function . params ) : # Any failure will cause this function to return. If any argument is # incorrect or missing, those following it are not processed. Note that # for optional arguments, we allow missing arguments and proceed because # there may be other arguments following it. failure_value = 'std::unique_ptr<Params>()' c . Append ( ) value_var = param . unix_name + '_value' ( c . Append ( 'const base::Value* %(value_var)s = NULL;' ) . Append ( 'if (args.Get(%(i)s, &%(value_var)s) &&' ) . Sblock ( '    !%(value_var)s->IsType(base::Value::TYPE_NULL)) {' ) . Concat ( self . _GeneratePopulatePropertyFromValue ( param , value_var , 'params' , failure_value ) ) . Eblock ( '}' ) ) if not param . optional : ( c . Sblock ( 'else {' ) . Concat ( self . _GenerateError ( '"\'%%(key)s\' is required"' ) ) . Append ( 'return %s;' % failure_value ) . Eblock ( '}' ) ) c . Substitute ( { 'value_var' : value_var , 'i' : i , 'key' : param . name } ) ( c . Append ( ) . Append ( 'return params;' ) . Eblock ( '}' ) . Append ( ) ) return c