| Index: build/android/gyp/java_cpp_enum.py
|
| diff --git a/build/android/gyp/java_cpp_enum.py b/build/android/gyp/java_cpp_enum.py
|
| index c2f1764b1be9ade87751aa7a8c8f4afa1f93abc6..07096e2061f7c8c97ff0ba2ec9bb90e711b94416 100755
|
| --- a/build/android/gyp/java_cpp_enum.py
|
| +++ b/build/android/gyp/java_cpp_enum.py
|
| @@ -29,13 +29,15 @@ class EnumDefinition(object):
|
| self.class_name_override = class_name_override
|
| self.enum_package = enum_package
|
| self.entries = collections.OrderedDict(entries or [])
|
| + self.comments = collections.OrderedDict([])
|
| self.prefix_to_strip = None
|
| self.fixed_type = fixed_type
|
|
|
| - def AppendEntry(self, key, value):
|
| + def AppendEntry(self, key, value, comment):
|
| if key in self.entries:
|
| raise Exception('Multiple definitions of key %s found.' % key)
|
| self.entries[key] = value
|
| + self.comments[key] = comment
|
|
|
| @property
|
| def class_name(self):
|
| @@ -121,7 +123,7 @@ class DirectiveSet(object):
|
|
|
|
|
| class HeaderParser(object):
|
| - single_line_comment_re = re.compile(r'\s*//')
|
| + single_line_comment_re = re.compile(r'\s*//(.*)')
|
| multi_line_comment_start_re = re.compile(r'\s*/\*')
|
| enum_line_re = re.compile(r'^\s*(\w+)(\s*\=\s*([^,\n]+))?,?')
|
| enum_end_re = re.compile(r'^\s*}\s*;\.*$')
|
| @@ -146,6 +148,7 @@ class HeaderParser(object):
|
| self._path = path
|
| self._enum_definitions = []
|
| self._in_enum = False
|
| + self._current_comment = []
|
| self._current_definition = None
|
| self._generator_directives = DirectiveSet()
|
| self._multi_line_generator_directive = None
|
| @@ -168,9 +171,12 @@ class HeaderParser(object):
|
| self._ParseEnumLine(line)
|
|
|
| def _ParseEnumLine(self, line):
|
| - if HeaderParser.single_line_comment_re.match(line):
|
| + comment = HeaderParser.single_line_comment_re.match(line)
|
| + if comment:
|
| + self._current_comment.append(comment.groups()[0])
|
| return
|
| if HeaderParser.multi_line_comment_start_re.match(line):
|
| + self._current_comment = []
|
| raise Exception('Multi-line comments in enums are not supported in ' +
|
| self._path)
|
| enum_end = HeaderParser.enum_end_re.match(line)
|
| @@ -183,7 +189,9 @@ class HeaderParser(object):
|
| elif enum_entry:
|
| enum_key = enum_entry.groups()[0]
|
| enum_value = enum_entry.groups()[2]
|
| - self._current_definition.AppendEntry(enum_key, enum_value)
|
| + self._current_definition.AppendEntry(enum_key, enum_value,
|
| + self._current_comment)
|
| + self._current_comment = []
|
|
|
| def _ParseMultiLineDirectiveLine(self, line):
|
| multi_line_directive_continuation = (
|
| @@ -259,7 +267,7 @@ def DoParseHeaderFile(path):
|
|
|
| def GenerateOutput(source_path, enum_definition):
|
| template = Template("""
|
| -// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -275,15 +283,26 @@ ${ENUM_ENTRIES}
|
| }
|
| """)
|
|
|
| - enum_template = Template(' public static final int ${NAME} = ${VALUE};')
|
| + enum_template = Template('${COMMENT} '
|
| + 'public static final int ${NAME} = ${VALUE};')
|
| enum_entries_string = []
|
| for enum_name, enum_value in enum_definition.entries.iteritems():
|
| + enum_comment_string = []
|
| + line_separator = '\n'
|
| + if enum_name in enum_definition.comments and \
|
| + enum_definition.comments[enum_name]:
|
| + line_separator += '\n'
|
| + enum_comment_string.append(' /**\n')
|
| + for comment_line in enum_definition.comments[enum_name]:
|
| + enum_comment_string.append(' *' + comment_line + '\n')
|
| + enum_comment_string.append(' */\n')
|
| values = {
|
| + 'COMMENT': ''.join(enum_comment_string),
|
| 'NAME': enum_name,
|
| 'VALUE': enum_value,
|
| }
|
| enum_entries_string.append(enum_template.substitute(values))
|
| - enum_entries_string = '\n'.join(enum_entries_string)
|
| + enum_entries_string = line_separator.join(enum_entries_string)
|
|
|
| values = {
|
| 'CLASS_NAME': enum_definition.class_name,
|
|
|