def __call__()

in swig_post_process.py [0:0]


  def __call__(self, file_str, filename, iteration):
    """Rename all public method arguments from snake_case to camelCase.

    Args:
      file_str: This is a string containing the file contents to be processed.
      filename: Unused.
      iteration: Unused.

    Returns:
      Returns the modified file_str.
    """
    output = []
    function_stack = []
    scope_count = 0
    for line_number, line in enumerate(file_str.splitlines()):
      line_number += 1  # Convert from zero based series to 1 based.
      # Track the number of braces to determine which scope we're in.
      # obviously this is going to break in cases where strings contain
      # braces but we don't generate any code like that at the moment.
      # This also breaks with single line functions e.g
      # public void SomeFunc(int bish_bash) { state += bish_bash; }
      scope_count += line.count('{') - line.count('}')

      # Search for a function on the line.
      function_match = self.function_regexp.search(line)
      if function_match:
        function_name = function_match.groups()[1]
        argument_substitutions = []
        # Build a set of identifier replacements to apply.
        for type_argument in function_match.groups()[2].split(','):
          type_argument = type_argument.strip()
          logging.debug('%d: %s types and args %s', line_number, function_name,
                        str(type_argument))
          # Split type and argument, handling generic types.
          end_of_type = type_argument.rfind('>')
          end_of_type = (end_of_type if end_of_type > 0 else
                         type_argument.rfind(' '))
          argument = type_argument[end_of_type:].strip()
          camel_case_arg = RenameArgsFromSnakeToCamelCase.snake_to_camel_case(
              argument)
          if argument != camel_case_arg:
            logging.debug('%d: %s arg %s --> %s', line_number, function_name,
                          argument, camel_case_arg)
            regex = r'(\b)' + argument + r'(\b)'
            argument_substitutions.append((
                re.compile(regex), r'\g<1>' + camel_case_arg + r'\g<2>'))
        logging.debug('%d: %s(%d), %s args=%s', line_number, function_name,
                      scope_count, 'found function',
                      str([a[1] for a in argument_substitutions]))
        function_stack.append((scope_count, function_name,
                               argument_substitutions))
        # Update the doc string if there is one.
        if output and argument_substitutions:
          line_index = len(output) - 1
          while (line_index >= 0 and
                 output[line_index].lstrip().startswith('///')):
            output[line_index] = (
                RenameArgsFromSnakeToCamelCase.replace_arguments(
                    argument_substitutions, output[line_index]))
            line_index -= 1

      if function_stack:
        if function_stack[0][0] == scope_count:
          line = RenameArgsFromSnakeToCamelCase.replace_arguments(
              function_stack[0][2], line)
          logging.debug('%d: %s(%d), %s', line_number, function_stack[0][1],
                        scope_count, line)
        elif scope_count < function_stack[0][0]:
          logging.debug('%d: %s(%d), %s', line_number, function_stack[0][1],
                        scope_count, 'end of function')
          function_stack.pop()

      output.append(line)
    return '\n'.join(output)