OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import collections | 7 import collections |
8 from datetime import date | 8 from datetime import date |
9 import re | 9 import re |
10 import optparse | 10 import optparse |
11 import os | 11 import os |
12 from string import Template | 12 from string import Template |
13 import sys | 13 import sys |
| 14 import textwrap |
14 import zipfile | 15 import zipfile |
15 | 16 |
16 from util import build_utils | 17 from util import build_utils |
17 | 18 |
18 # List of C++ types that are compatible with the Java code generated by this | 19 # List of C++ types that are compatible with the Java code generated by this |
19 # script. | 20 # script. |
20 # | 21 # |
21 # This script can parse .idl files however, at present it ignores special | 22 # This script can parse .idl files however, at present it ignores special |
22 # rules such as [cpp_enum_prefix_override="ax_attr"]. | 23 # rules such as [cpp_enum_prefix_override="ax_attr"]. |
23 ENUM_FIXED_TYPE_WHITELIST = ['char', 'unsigned char', | 24 ENUM_FIXED_TYPE_WHITELIST = ['char', 'unsigned char', |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // Use of this source code is governed by a BSD-style license that can be | 259 // Use of this source code is governed by a BSD-style license that can be |
259 // found in the LICENSE file. | 260 // found in the LICENSE file. |
260 | 261 |
261 // This file is autogenerated by | 262 // This file is autogenerated by |
262 // ${SCRIPT_NAME} | 263 // ${SCRIPT_NAME} |
263 // From | 264 // From |
264 // ${SOURCE_PATH} | 265 // ${SOURCE_PATH} |
265 | 266 |
266 package ${PACKAGE}; | 267 package ${PACKAGE}; |
267 | 268 |
| 269 import android.support.annotation.IntDef; |
| 270 |
| 271 import java.lang.annotation.Retention; |
| 272 import java.lang.annotation.RetentionPolicy; |
| 273 |
268 public class ${CLASS_NAME} { | 274 public class ${CLASS_NAME} { |
| 275 @IntDef({ |
| 276 ${INT_DEF} |
| 277 }) |
| 278 @Retention(RetentionPolicy.SOURCE) |
| 279 public @interface ${ANNOTATION} {} |
269 ${ENUM_ENTRIES} | 280 ${ENUM_ENTRIES} |
270 } | 281 } |
271 """) | 282 """) |
272 | 283 |
273 enum_template = Template(' public static final int ${NAME} = ${VALUE};') | 284 enum_template = Template(' public static final int ${NAME} = ${VALUE};') |
274 enum_entries_string = [] | 285 enum_entries_string = [] |
| 286 enum_names = [] |
275 for enum_name, enum_value in enum_definition.entries.iteritems(): | 287 for enum_name, enum_value in enum_definition.entries.iteritems(): |
276 values = { | 288 values = { |
277 'NAME': enum_name, | 289 'NAME': enum_name, |
278 'VALUE': enum_value, | 290 'VALUE': enum_value, |
279 } | 291 } |
280 enum_entries_string.append(enum_template.substitute(values)) | 292 enum_entries_string.append(enum_template.substitute(values)) |
| 293 enum_names.append(enum_name) |
281 enum_entries_string = '\n'.join(enum_entries_string) | 294 enum_entries_string = '\n'.join(enum_entries_string) |
282 | 295 |
| 296 enum_names_indent = ' ' * 6 |
| 297 wrapper = textwrap.TextWrapper(initial_indent = enum_names_indent, |
| 298 subsequent_indent = enum_names_indent, |
| 299 width = 100) |
| 300 enum_names_string = '\n'.join(wrapper.wrap(', '.join(enum_names))) |
| 301 |
| 302 annotation_template = Template('${NAME}Enum') |
| 303 annotation_values = { 'NAME': enum_definition.class_name, } |
| 304 annotation_name = annotation_template.substitute(annotation_values) |
| 305 |
283 values = { | 306 values = { |
284 'CLASS_NAME': enum_definition.class_name, | 307 'CLASS_NAME': enum_definition.class_name, |
285 'ENUM_ENTRIES': enum_entries_string, | 308 'ENUM_ENTRIES': enum_entries_string, |
286 'PACKAGE': enum_definition.enum_package, | 309 'PACKAGE': enum_definition.enum_package, |
| 310 'INT_DEF': enum_names_string, |
| 311 'ANNOTATION': annotation_name, |
287 'SCRIPT_NAME': GetScriptName(), | 312 'SCRIPT_NAME': GetScriptName(), |
288 'SOURCE_PATH': source_path, | 313 'SOURCE_PATH': source_path, |
289 'YEAR': str(date.today().year) | 314 'YEAR': str(date.today().year) |
290 } | 315 } |
291 return template.substitute(values) | 316 return template.substitute(values) |
292 | 317 |
293 | 318 |
294 def AssertFilesList(output_paths, assert_files_list): | 319 def AssertFilesList(output_paths, assert_files_list): |
295 actual = set(output_paths) | 320 actual = set(output_paths) |
296 expected = set(assert_files_list) | 321 expected = set(assert_files_list) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 if options.verbose: | 385 if options.verbose: |
361 print 'Output paths:' | 386 print 'Output paths:' |
362 print '\n'.join(output_paths) | 387 print '\n'.join(output_paths) |
363 | 388 |
364 # Used by GYP. | 389 # Used by GYP. |
365 return ' '.join(output_paths) | 390 return ' '.join(output_paths) |
366 | 391 |
367 | 392 |
368 if __name__ == '__main__': | 393 if __name__ == '__main__': |
369 DoMain(sys.argv[1:]) | 394 DoMain(sys.argv[1:]) |
OLD | NEW |