OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Generates java source files from a mojom.Module.""" | 5 """Generates java source files from a mojom.Module.""" |
6 | 6 |
7 import argparse | 7 import argparse |
8 import ast | 8 import ast |
9 import contextlib | 9 import contextlib |
10 import os | 10 import os |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 'name': GetNameForElement, | 430 'name': GetNameForElement, |
431 'new_array': NewArray, | 431 'new_array': NewArray, |
432 'ucc': lambda x: UpperCamelCase(x.name), | 432 'ucc': lambda x: UpperCamelCase(x.name), |
433 } | 433 } |
434 | 434 |
435 def GetJinjaExports(self): | 435 def GetJinjaExports(self): |
436 return { | 436 return { |
437 'package': GetPackage(self.module), | 437 'package': GetPackage(self.module), |
438 } | 438 } |
439 | 439 |
| 440 @staticmethod |
| 441 def GetTemplatePrefix(): |
| 442 return "java_templates" |
| 443 |
| 444 @classmethod |
| 445 def GetFilters(cls): |
| 446 return cls.java_filters |
| 447 |
440 def GetJinjaExportsForInterface(self, interface): | 448 def GetJinjaExportsForInterface(self, interface): |
441 exports = self.GetJinjaExports() | 449 exports = self.GetJinjaExports() |
442 exports.update({'interface': interface}) | 450 exports.update({'interface': interface}) |
443 return exports | 451 return exports |
444 | 452 |
445 @UseJinja('java_templates/enum.java.tmpl', filters=java_filters) | 453 @UseJinja('enum.java.tmpl') |
446 def GenerateEnumSource(self, enum): | 454 def GenerateEnumSource(self, enum): |
447 exports = self.GetJinjaExports() | 455 exports = self.GetJinjaExports() |
448 exports.update({'enum': enum}) | 456 exports.update({'enum': enum}) |
449 return exports | 457 return exports |
450 | 458 |
451 @UseJinja('java_templates/struct.java.tmpl', filters=java_filters) | 459 @UseJinja('struct.java.tmpl') |
452 def GenerateStructSource(self, struct): | 460 def GenerateStructSource(self, struct): |
453 exports = self.GetJinjaExports() | 461 exports = self.GetJinjaExports() |
454 exports.update({'struct': struct}) | 462 exports.update({'struct': struct}) |
455 return exports | 463 return exports |
456 | 464 |
457 @UseJinja('java_templates/union.java.tmpl', filters=java_filters) | 465 @UseJinja('union.java.tmpl') |
458 def GenerateUnionSource(self, union): | 466 def GenerateUnionSource(self, union): |
459 exports = self.GetJinjaExports() | 467 exports = self.GetJinjaExports() |
460 exports.update({'union': union}) | 468 exports.update({'union': union}) |
461 return exports | 469 return exports |
462 | 470 |
463 @UseJinja('java_templates/interface.java.tmpl', filters=java_filters) | 471 @UseJinja('interface.java.tmpl') |
464 def GenerateInterfaceSource(self, interface): | 472 def GenerateInterfaceSource(self, interface): |
465 return self.GetJinjaExportsForInterface(interface) | 473 return self.GetJinjaExportsForInterface(interface) |
466 | 474 |
467 @UseJinja('java_templates/interface_internal.java.tmpl', filters=java_filters) | 475 @UseJinja('interface_internal.java.tmpl') |
468 def GenerateInterfaceInternalSource(self, interface): | 476 def GenerateInterfaceInternalSource(self, interface): |
469 return self.GetJinjaExportsForInterface(interface) | 477 return self.GetJinjaExportsForInterface(interface) |
470 | 478 |
471 @UseJinja('java_templates/constants.java.tmpl', filters=java_filters) | 479 @UseJinja('constants.java.tmpl') |
472 def GenerateConstantsSource(self, module): | 480 def GenerateConstantsSource(self, module): |
473 exports = self.GetJinjaExports() | 481 exports = self.GetJinjaExports() |
474 exports.update({'main_entity': GetConstantsMainEntityName(module), | 482 exports.update({'main_entity': GetConstantsMainEntityName(module), |
475 'constants': module.constants}) | 483 'constants': module.constants}) |
476 return exports | 484 return exports |
477 | 485 |
478 def DoGenerateFiles(self): | 486 def DoGenerateFiles(self): |
479 fileutil.EnsureDirectoryExists(self.output_dir) | 487 fileutil.EnsureDirectoryExists(self.output_dir) |
480 | 488 |
481 # Keep this above the others as .GetStructs() changes the state of the | 489 # Keep this above the others as .GetStructs() changes the state of the |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 return { | 538 return { |
531 'lstrip_blocks': True, | 539 'lstrip_blocks': True, |
532 'trim_blocks': True, | 540 'trim_blocks': True, |
533 } | 541 } |
534 | 542 |
535 def GetGlobals(self): | 543 def GetGlobals(self): |
536 return { | 544 return { |
537 'namespace': self.module.namespace, | 545 'namespace': self.module.namespace, |
538 'module': self.module, | 546 'module': self.module, |
539 } | 547 } |
OLD | NEW |