def process_output_file()

in swig_commenter.py [0:0]


def process_output_file(output_filename, comments):
  """Annontates classes in the given file with the Doxygen comments.

  Scan a file for classes, and if those class_names appear as keys in the given
  class_comments dict, prepend those comments to the class (accounting for
  indentation)

  Args:
    output_filename: The name of the file to insert comments into.
    comments: A dict mapping C# class names to the comments that should be
        prepended to them.
  """
  with open(output_filename, 'r') as output_file:
    file_content = output_file.readlines()

  try:
    with open(output_filename, 'w') as output_file:
      most_recent_enum = None
      for line in file_content:
        captures = []
        if most_recent_enum:
          if extract_regex_captures(captures,
                                    CSHARP_ENUM_VALUE_IDENTIFIER_REGEX, line):
            enum_identifier = captures[0]
            comment = most_recent_enum['values'].get(enum_identifier)
            if comment:
              output_file.write(
                  correct_comment_indentation(comment, indentation(line)))

          elif '}' in line:
            most_recent_enum = None

        else:
          if extract_regex_captures(captures, CSHARP_CLASS_DECLARATION_REGEX,
                                    line):
            class_name = captures[0]
            # b/36068888: we should support symbol renaming properly
            comment = comments['classes'].get(class_name) or comments[
                'classes'].get('Firebase' + class_name)
            if comment:
              output_file.write(
                  correct_comment_indentation(comment, indentation(line)))

          elif extract_regex_captures(captures, CSHARP_ENUM_DECLARATION_REGEX,
                                      line):
            enum_name = captures[0]
            enum_entry = comments['enums'].get(enum_name)
            if enum_entry:
              most_recent_enum = enum_entry
              output_file.write(
                  correct_comment_indentation(enum_entry['comment'],
                                              indentation(line)))

          elif extract_regex_captures(captures, CSHARP_PROPERTY_REGEX, line):
            property_name = captures[0]
            comment = comments['properties'].get(property_name)
            if comment:
              output_file.write(
                  correct_comment_indentation(comment, indentation(line)))

        output_file.write(line)

  except IOError:
    sys.stderr.write('Could not open %s for writing' % output_filename)