Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: mojo/public/tools/bindings/generators/mojom_java_generator.py

Issue 2855263002: Mojo bindings: support generating identifers using different style rules for different target langu…
Patch Set: . Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 @UseJinja('constants.java.tmpl') 482 @UseJinja('constants.java.tmpl')
483 def GenerateConstantsSource(self, module): 483 def GenerateConstantsSource(self, module):
484 exports = self.GetJinjaExports() 484 exports = self.GetJinjaExports()
485 exports.update({'main_entity': GetConstantsMainEntityName(module), 485 exports.update({'main_entity': GetConstantsMainEntityName(module),
486 'constants': module.constants}) 486 'constants': module.constants})
487 return exports 487 return exports
488 488
489 def DoGenerateFiles(self): 489 def DoGenerateFiles(self):
490 fileutil.EnsureDirectoryExists(self.output_dir) 490 fileutil.EnsureDirectoryExists(self.output_dir)
491 491
492 # Keep this above the others as .GetStructs() changes the state of the 492 for struct in self.module.structs:
493 # module, annotating structs with required information.
494 for struct in self.GetStructs():
495 self.Write(self.GenerateStructSource(struct), 493 self.Write(self.GenerateStructSource(struct),
496 '%s.java' % GetNameForElement(struct)) 494 '%s.java' % GetNameForElement(struct))
497 495
498 for union in self.module.unions: 496 for union in self.module.unions:
499 self.Write(self.GenerateUnionSource(union), 497 self.Write(self.GenerateUnionSource(union),
500 '%s.java' % GetNameForElement(union)) 498 '%s.java' % GetNameForElement(union))
501 499
502 for enum in self.module.enums: 500 for enum in self.module.enums:
503 self.Write(self.GenerateEnumSource(enum), 501 self.Write(self.GenerateEnumSource(enum),
504 '%s.java' % GetNameForElement(enum)) 502 '%s.java' % GetNameForElement(enum))
505 503
506 for interface in self.GetInterfaces(): 504 for interface in self.module.interfaces:
507 self.Write(self.GenerateInterfaceSource(interface), 505 self.Write(self.GenerateInterfaceSource(interface),
508 '%s.java' % GetNameForElement(interface)) 506 '%s.java' % GetNameForElement(interface))
509 self.Write(self.GenerateInterfaceInternalSource(interface), 507 self.Write(self.GenerateInterfaceInternalSource(interface),
510 '%s_Internal.java' % GetNameForElement(interface)) 508 '%s_Internal.java' % GetNameForElement(interface))
511 509
512 if self.module.constants: 510 if self.module.constants:
513 self.Write(self.GenerateConstantsSource(self.module), 511 self.Write(self.GenerateConstantsSource(self.module),
514 '%s.java' % GetConstantsMainEntityName(self.module)) 512 '%s.java' % GetConstantsMainEntityName(self.module))
515 513
516 def GenerateFiles(self, unparsed_args): 514 def GenerateFiles(self, unparsed_args):
517 # TODO(rockot): Support variant output for Java. 515 # TODO(rockot): Support variant output for Java.
518 if self.variant: 516 if self.variant:
519 raise Exception("Variants not supported in Java bindings.") 517 raise Exception("Variants not supported in Java bindings.")
520 518
519 self.FinalizeModule()
520
521 parser = argparse.ArgumentParser() 521 parser = argparse.ArgumentParser()
522 parser.add_argument('--java_output_directory', dest='java_output_directory') 522 parser.add_argument('--java_output_directory', dest='java_output_directory')
523 args = parser.parse_args(unparsed_args) 523 args = parser.parse_args(unparsed_args)
524 package_path = GetPackage(self.module).replace('.', '/') 524 package_path = GetPackage(self.module).replace('.', '/')
525 525
526 # Generate the java files in a temporary directory and place a single 526 # Generate the java files in a temporary directory and place a single
527 # srcjar in the output directory. 527 # srcjar in the output directory.
528 basename = self.MatchMojomFilePath("%s.srcjar" % self.module.name) 528 basename = self.MatchMojomFilePath("%s.srcjar" % self.module.name)
529 zip_filename = os.path.join(self.output_dir, basename) 529 zip_filename = os.path.join(self.output_dir, basename)
530 with TempDir() as temp_java_root: 530 with TempDir() as temp_java_root:
(...skipping 10 matching lines...) Expand all
541 return { 541 return {
542 'lstrip_blocks': True, 542 'lstrip_blocks': True,
543 'trim_blocks': True, 543 'trim_blocks': True,
544 } 544 }
545 545
546 def GetGlobals(self): 546 def GetGlobals(self):
547 return { 547 return {
548 'namespace': self.module.namespace, 548 'namespace': self.module.namespace,
549 'module': self.module, 549 'module': self.module,
550 } 550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698