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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 @UseJinja('constants.java.tmpl') | 479 @UseJinja('constants.java.tmpl') |
480 def _GenerateConstantsSource(self, module): | 480 def _GenerateConstantsSource(self, module): |
481 exports = self._GetJinjaExports() | 481 exports = self._GetJinjaExports() |
482 exports.update({'main_entity': GetConstantsMainEntityName(module), | 482 exports.update({'main_entity': GetConstantsMainEntityName(module), |
483 'constants': module.constants}) | 483 'constants': module.constants}) |
484 return exports | 484 return exports |
485 | 485 |
486 def _DoGenerateFiles(self): | 486 def _DoGenerateFiles(self): |
487 fileutil.EnsureDirectoryExists(self.output_dir) | 487 fileutil.EnsureDirectoryExists(self.output_dir) |
488 | 488 |
489 # Keep this above the others as .GetStructs() changes the state of the | 489 for struct in self.module.structs: |
490 # module, annotating structs with required information. | |
491 for struct in self.GetStructs(): | |
492 self.Write(self._GenerateStructSource(struct), | 490 self.Write(self._GenerateStructSource(struct), |
493 '%s.java' % GetNameForElement(struct)) | 491 '%s.java' % GetNameForElement(struct)) |
494 | 492 |
495 for union in self.module.unions: | 493 for union in self.module.unions: |
496 self.Write(self._GenerateUnionSource(union), | 494 self.Write(self._GenerateUnionSource(union), |
497 '%s.java' % GetNameForElement(union)) | 495 '%s.java' % GetNameForElement(union)) |
498 | 496 |
499 for enum in self.module.enums: | 497 for enum in self.module.enums: |
500 self.Write(self._GenerateEnumSource(enum), | 498 self.Write(self._GenerateEnumSource(enum), |
501 '%s.java' % GetNameForElement(enum)) | 499 '%s.java' % GetNameForElement(enum)) |
502 | 500 |
503 for interface in self.GetInterfaces(): | 501 for interface in self.module.interfaces: |
504 self.Write(self._GenerateInterfaceSource(interface), | 502 self.Write(self._GenerateInterfaceSource(interface), |
505 '%s.java' % GetNameForElement(interface)) | 503 '%s.java' % GetNameForElement(interface)) |
506 self.Write(self._GenerateInterfaceInternalSource(interface), | 504 self.Write(self._GenerateInterfaceInternalSource(interface), |
507 '%s_Internal.java' % GetNameForElement(interface)) | 505 '%s_Internal.java' % GetNameForElement(interface)) |
508 | 506 |
509 if self.module.constants: | 507 if self.module.constants: |
510 self.Write(self._GenerateConstantsSource(self.module), | 508 self.Write(self._GenerateConstantsSource(self.module), |
511 '%s.java' % GetConstantsMainEntityName(self.module)) | 509 '%s.java' % GetConstantsMainEntityName(self.module)) |
512 | 510 |
513 def GenerateFiles(self, unparsed_args): | 511 def GenerateFiles(self, unparsed_args): |
(...skipping 24 matching lines...) Expand all Loading... |
538 return { | 536 return { |
539 'lstrip_blocks': True, | 537 'lstrip_blocks': True, |
540 'trim_blocks': True, | 538 'trim_blocks': True, |
541 } | 539 } |
542 | 540 |
543 def GetGlobals(self): | 541 def GetGlobals(self): |
544 return { | 542 return { |
545 'namespace': self.module.namespace, | 543 'namespace': self.module.namespace, |
546 'module': self.module, | 544 'module': self.module, |
547 } | 545 } |
OLD | NEW |