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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 def EncodeMethod(context, kind, variable, offset, bit): | 212 def EncodeMethod(context, kind, variable, offset, bit): |
213 params = AppendEncodeDecodeParams( | 213 params = AppendEncodeDecodeParams( |
214 [ variable, str(offset) ], context, kind, bit) | 214 [ variable, str(offset) ], context, kind, bit) |
215 return 'encode(%s)' % ', '.join(params) | 215 return 'encode(%s)' % ', '.join(params) |
216 | 216 |
217 def GetPackage(module): | 217 def GetPackage(module): |
218 if module.attributes and 'JavaPackage' in module.attributes: | 218 if module.attributes and 'JavaPackage' in module.attributes: |
219 return ParseStringAttribute(module.attributes['JavaPackage']) | 219 return ParseStringAttribute(module.attributes['JavaPackage']) |
220 # Default package. | 220 # Default package. |
221 if module.namespace: | 221 if module.namespace: |
222 return 'org.chromium.mojom.' + module.namespace | 222 return 'org.chromium.' + module.namespace |
223 return 'org.chromium.mojom' | 223 return 'org.chromium' |
224 | 224 |
225 def GetNameForKind(context, kind): | 225 def GetNameForKind(context, kind): |
226 def _GetNameHierachy(kind): | 226 def _GetNameHierachy(kind): |
227 hierachy = [] | 227 hierachy = [] |
228 if kind.parent_kind: | 228 if kind.parent_kind: |
229 hierachy = _GetNameHierachy(kind.parent_kind) | 229 hierachy = _GetNameHierachy(kind.parent_kind) |
230 hierachy.append(GetNameForElement(kind)) | 230 hierachy.append(GetNameForElement(kind)) |
231 return hierachy | 231 return hierachy |
232 | 232 |
233 module = context.resolve('module') | 233 module = context.resolve('module') |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 return { | 544 return { |
545 'lstrip_blocks': True, | 545 'lstrip_blocks': True, |
546 'trim_blocks': True, | 546 'trim_blocks': True, |
547 } | 547 } |
548 | 548 |
549 def GetGlobals(self): | 549 def GetGlobals(self): |
550 return { | 550 return { |
551 'namespace': self.module.namespace, | 551 'namespace': self.module.namespace, |
552 'module': self.module, | 552 'module': self.module, |
553 } | 553 } |
OLD | NEW |