OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """Code shared by the various language-specific code generators.""" | 5 """Code shared by the various language-specific code generators.""" |
6 | 6 |
7 from functools import partial | 7 from functools import partial |
8 import os.path | 8 import os.path |
9 import re | 9 import re |
10 | 10 |
11 import module as mojom | 11 import module as mojom |
12 import mojom.fileutil as fileutil | 12 import mojom.fileutil as fileutil |
13 import pack | 13 import pack |
14 | 14 |
15 | 15 |
16 def ExpectedArraySize(kind): | 16 def ExpectedArraySize(kind): |
17 if mojom.IsArrayKind(kind): | 17 if mojom.IsArrayKind(kind): |
18 return kind.length | 18 return kind.length |
19 return None | 19 return None |
20 | 20 |
21 | 21 |
22 def ToCamel(identifier, lower_initial=False, dilimiter='_'): | 22 def ToCamel(identifier, lower_initial=False, dilimiter='_'): |
23 """Splits |identifier| using |dilimiter|, makes the first character of each | 23 """Splits |identifier| using |dilimiter|, makes the first character of each |
24 word uppercased (but makes the first character of the first word lowercased | 24 word uppercased (but makes the first character of the first word lowercased |
25 if |lower_initial| is set to True), and joins the words. Please note that for | 25 if |lower_initial| is set to True), and joins the words. Please note that for |
26 each word, all the characters except the first one are untouched. | 26 each word, all the characters except the first one are untouched. |
27 """ | 27 """ |
28 result = ''.join( | 28 result = ''.join(word[0].upper() + word[1:] |
29 word[0].upper() + word[1:] for word in identifier.split(dilimiter)) | 29 for word in identifier.split(dilimiter) if word) |
30 if lower_initial: | 30 if lower_initial and result: |
31 result = result[0].lower() + result[1:] | 31 result = result[0].lower() + result[1:] |
32 return result | 32 return result |
33 | 33 |
34 | 34 |
35 class Stylizer(object): | 35 class Stylizer(object): |
36 """Stylizers specify naming rules to map mojom names to names in generated | 36 """Stylizers specify naming rules to map mojom names to names in generated |
37 code. For example, if you would like method_name in mojom to be mapped to | 37 code. For example, if you would like method_name in mojom to be mapped to |
38 MethodName in the generated code, you need to define a subclass of Stylizer | 38 MethodName in the generated code, you need to define a subclass of Stylizer |
39 and override StylizeMethod to do the conversion.""" | 39 and override StylizeMethod to do the conversion.""" |
40 | 40 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 raise NotImplementedError("Subclasses must override/implement this method") | 180 raise NotImplementedError("Subclasses must override/implement this method") |
181 | 181 |
182 def GetJinjaParameters(self): | 182 def GetJinjaParameters(self): |
183 """Returns default constructor parameters for the jinja environment.""" | 183 """Returns default constructor parameters for the jinja environment.""" |
184 return {} | 184 return {} |
185 | 185 |
186 def GetGlobals(self): | 186 def GetGlobals(self): |
187 """Returns global mappings for the template generation.""" | 187 """Returns global mappings for the template generation.""" |
188 return {} | 188 return {} |
189 | 189 |
OLD | NEW |