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 os | 9 import os |
10 import re | 10 import re |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 def NameToComponent(name): | 89 def NameToComponent(name): |
90 # insert '_' between anything and a Title name (e.g, HTTPEntry2FooBar -> | 90 # insert '_' between anything and a Title name (e.g, HTTPEntry2FooBar -> |
91 # HTTP_Entry2_FooBar) | 91 # HTTP_Entry2_FooBar) |
92 name = re.sub('([^_])([A-Z][^A-Z_]+)', r'\1_\2', name) | 92 name = re.sub('([^_])([A-Z][^A-Z_]+)', r'\1_\2', name) |
93 # insert '_' between non upper and start of upper blocks (e.g., | 93 # insert '_' between non upper and start of upper blocks (e.g., |
94 # HTTP_Entry2_FooBar -> HTTP_Entry2_Foo_Bar) | 94 # HTTP_Entry2_FooBar -> HTTP_Entry2_Foo_Bar) |
95 name = re.sub('([^A-Z_])([A-Z])', r'\1_\2', name) | 95 name = re.sub('([^A-Z_])([A-Z])', r'\1_\2', name) |
96 return [x.lower() for x in name.split('_')] | 96 return [x.lower() for x in name.split('_')] |
97 | 97 |
98 def CapitalizeFirst(string): | |
99 return string[0].upper() + string[1:] | |
100 | |
101 def UpperCamelCase(name): | 98 def UpperCamelCase(name): |
102 return ''.join([CapitalizeFirst(x) for x in NameToComponent(name)]) | 99 return ''.join([x.capitalize() for x in NameToComponent(name)]) |
103 | 100 |
104 def CamelCase(name): | 101 def CamelCase(name): |
105 uccc = UpperCamelCase(name) | 102 uccc = UpperCamelCase(name) |
106 return uccc[0].lower() + uccc[1:] | 103 return uccc[0].lower() + uccc[1:] |
107 | 104 |
108 def ConstantStyle(name): | 105 def ConstantStyle(name): |
109 components = NameToComponent(name) | 106 components = NameToComponent(name) |
110 if components[0] == 'k': | 107 if components[0] == 'k': |
111 components = components[1:] | 108 components = components[1:] |
112 return '_'.join([x.upper() for x in components]) | 109 return '_'.join([x.upper() for x in components]) |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 def GetJinjaParameters(self): | 458 def GetJinjaParameters(self): |
462 return { | 459 return { |
463 'lstrip_blocks': True, | 460 'lstrip_blocks': True, |
464 'trim_blocks': True, | 461 'trim_blocks': True, |
465 } | 462 } |
466 | 463 |
467 def GetGlobals(self): | 464 def GetGlobals(self): |
468 return { | 465 return { |
469 'module': self.module, | 466 'module': self.module, |
470 } | 467 } |
OLD | NEW |