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

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

Issue 1508293004: Simplify Go's Mojom Type Generator (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Add generate_type_info flag to mojom generators Created 5 years 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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 self.Write(self.GenerateInterfaceInternalSource(interface), 490 self.Write(self.GenerateInterfaceInternalSource(interface),
491 '%s_Internal.java' % GetNameForElement(interface)) 491 '%s_Internal.java' % GetNameForElement(interface))
492 492
493 if self.module.constants: 493 if self.module.constants:
494 self.Write(self.GenerateConstantsSource(self.module), 494 self.Write(self.GenerateConstantsSource(self.module),
495 '%s.java' % GetConstantsMainEntityName(self.module)) 495 '%s.java' % GetConstantsMainEntityName(self.module))
496 496
497 def GenerateFiles(self, unparsed_args): 497 def GenerateFiles(self, unparsed_args):
498 parser = argparse.ArgumentParser() 498 parser = argparse.ArgumentParser()
499 parser.add_argument('--java_output_directory', dest='java_output_directory') 499 parser.add_argument('--java_output_directory', dest='java_output_directory')
500 args = parser.parse_args(unparsed_args) 500 (args, _) = parser.parse_known_args(unparsed_args)
azani 2015/12/18 18:12:58 Why is this change here?
alexfandrianto 2015/12/18 19:08:31 This change is here because the new argument will
azani 2015/12/18 23:19:11 Can you add an argument to parser instead?
alexfandrianto 2015/12/18 23:24:10 Done.
501 package_path = GetPackage(self.module).replace('.', '/') 501 package_path = GetPackage(self.module).replace('.', '/')
502 502
503 # Generate the java files in a temporary directory and place a single 503 # Generate the java files in a temporary directory and place a single
504 # srcjar in the output directory. 504 # srcjar in the output directory.
505 basename = self.MatchMojomFilePath("%s.srcjar" % self.module.name) 505 basename = self.MatchMojomFilePath("%s.srcjar" % self.module.name)
506 zip_filename = os.path.join(self.output_dir, basename) 506 zip_filename = os.path.join(self.output_dir, basename)
507 with TempDir() as temp_java_root: 507 with TempDir() as temp_java_root:
508 self.output_dir = os.path.join(temp_java_root, package_path) 508 self.output_dir = os.path.join(temp_java_root, package_path)
509 self.DoGenerateFiles(); 509 self.DoGenerateFiles();
510 ZipContentInto(temp_java_root, zip_filename) 510 ZipContentInto(temp_java_root, zip_filename)
511 511
512 if args.java_output_directory: 512 if args.java_output_directory:
513 # If requested, generate the java files directly into indicated directory. 513 # If requested, generate the java files directly into indicated directory.
514 self.output_dir = os.path.join(args.java_output_directory, package_path) 514 self.output_dir = os.path.join(args.java_output_directory, package_path)
515 self.DoGenerateFiles(); 515 self.DoGenerateFiles();
516 516
517 def GetJinjaParameters(self): 517 def GetJinjaParameters(self):
518 return { 518 return {
519 'lstrip_blocks': True, 519 'lstrip_blocks': True,
520 'trim_blocks': True, 520 'trim_blocks': True,
521 } 521 }
522 522
523 def GetGlobals(self): 523 def GetGlobals(self):
524 return { 524 return {
525 'namespace': self.module.namespace, 525 'namespace': self.module.namespace,
526 'module': self.module, 526 'module': self.module,
527 } 527 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698