Chromium Code Reviews| 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 21913da76d7f5f22df4447f082ef825bb008f71d..b0ba52bc31f3e96ebd1abe60c4b60c195460bfee 100755 |
| --- a/build/android/gyp/java_cpp_enum.py |
| +++ b/build/android/gyp/java_cpp_enum.py |
| @@ -27,11 +27,12 @@ ENUM_FIXED_TYPE_WHITELIST = ['char', 'unsigned char', |
| class EnumDefinition(object): |
| def __init__(self, original_enum_name=None, class_name_override=None, |
| - enum_package=None, entries=None, fixed_type=None): |
| + enum_package=None, entries=None, comments=None, fixed_type=None): |
| self.original_enum_name = original_enum_name |
| self.class_name_override = class_name_override |
| self.enum_package = enum_package |
| self.entries = collections.OrderedDict(entries or []) |
| + self.comments = collections.OrderedDict(comments or []) |
| self.prefix_to_strip = None |
| self.fixed_type = fixed_type |
| @@ -40,6 +41,11 @@ class EnumDefinition(object): |
| raise Exception('Multiple definitions of key %s found.' % key) |
| self.entries[key] = value |
| + def AppendEntryComment(self, key, value): |
| + if key in self.comments: |
| + raise Exception('Multiple definitions of key %s found.' % key) |
| + self.comments[key] = value |
| + |
| @property |
| def class_name(self): |
| return self.class_name_override or self.original_enum_name |
| @@ -124,7 +130,7 @@ class DirectiveSet(object): |
| class HeaderParser(object): |
| - single_line_comment_re = re.compile(r'\s*//') |
| + single_line_comment_re = re.compile(r'\s*//\s*([^\n]+)') |
| 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*;\.*$') |
| @@ -150,6 +156,7 @@ class HeaderParser(object): |
| self._enum_definitions = [] |
| self._in_enum = False |
| self._current_definition = None |
| + self._current_comments = [] |
| self._generator_directives = DirectiveSet() |
| self._multi_line_generator_directive = None |
| @@ -172,6 +179,10 @@ class HeaderParser(object): |
| def _ParseEnumLine(self, line): |
| if HeaderParser.single_line_comment_re.match(line): |
| + enum_comment = HeaderParser.single_line_comment_re.match(line).groups()[0] |
|
agrieve
2016/08/03 23:09:53
nit: Avoid calling match() twice using a variable.
xunjieli
2016/08/04 13:54:22
Done.
|
| + if len(self._current_comments) > 0: |
| + self._current_comments.append(' ') |
|
agrieve
2016/08/03 23:09:53
nit: Could you just use ' '.join() later on rather
xunjieli
2016/08/04 13:54:22
Done. Ah, you are right! I didn't thought about th
|
| + self._current_comments.append(enum_comment) |
| return |
| if HeaderParser.multi_line_comment_start_re.match(line): |
| raise Exception('Multi-line comments in enums are not supported in ' + |
| @@ -187,6 +198,10 @@ class HeaderParser(object): |
| enum_key = enum_entry.groups()[0] |
| enum_value = enum_entry.groups()[2] |
| self._current_definition.AppendEntry(enum_key, enum_value) |
| + if self._current_comments: |
| + self._current_definition.AppendEntryComment( |
| + enum_key, ''.join(self._current_comments)) |
| + self._current_comments = [] |
| def _ParseMultiLineDirectiveLine(self, line): |
| multi_line_directive_continuation = ( |
| @@ -289,6 +304,17 @@ ${ENUM_ENTRIES} |
| 'NAME': enum_name, |
| 'VALUE': enum_value, |
| } |
| + enum_comments = enum_definition.comments.get(enum_name) |
| + if enum_comments: |
| + enum_comments_indent = ' * ' |
| + comments_line_wrapper = textwrap.TextWrapper( |
| + initial_indent = enum_comments_indent, |
|
agrieve
2016/08/03 23:09:53
nit: no spaces around = for arguments. initial_in
xunjieli
2016/08/04 13:54:22
Done.
|
| + subsequent_indent = enum_comments_indent, |
| + width = 100) |
| + enum_entries_string.append(' /**') |
| + enum_entries_string.append( |
| + '\n'.join(comments_line_wrapper.wrap(enum_comments))) |
| + enum_entries_string.append(' */') |
| enum_entries_string.append(enum_template.substitute(values)) |
| enum_names.append(enum_name) |
| enum_entries_string = '\n'.join(enum_entries_string) |