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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 params.append('%s.MANAGER' % GetJavaType(context, kind)) | 196 params.append('%s.MANAGER' % GetJavaType(context, kind)) |
197 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): | 197 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): |
198 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) | 198 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) |
199 return '%s(%s)' % (methodName, ', '.join(params)) | 199 return '%s(%s)' % (methodName, ', '.join(params)) |
200 | 200 |
201 @contextfilter | 201 @contextfilter |
202 def EncodeMethod(context, kind, variable, offset, bit): | 202 def EncodeMethod(context, kind, variable, offset, bit): |
203 params = [ variable, str(offset) ] | 203 params = [ variable, str(offset) ] |
204 if (kind == mojom.BOOL): | 204 if (kind == mojom.BOOL): |
205 params.append(str(bit)) | 205 params.append(str(bit)) |
206 if mojom.IsReferenceKind(kind): | |
207 if mojom.IsAnyArrayKind(kind): | |
208 params.append(GetArrayNullabilityFlags(kind)) | |
209 else: | |
210 params.append(GetJavaTrueFalse(mojom.IsNullableKind(kind))) | |
206 if mojom.IsAnyArrayKind(kind): | 211 if mojom.IsAnyArrayKind(kind): |
207 if mojom.IsFixedArrayKind(kind): | 212 if mojom.IsFixedArrayKind(kind): |
208 params.append(str(kind.length)) | 213 params.append(str(kind.length)) |
209 else: | 214 else: |
210 params.append( | 215 params.append( |
211 "org.chromium.mojo.bindings.BindingsHelper.UNSPECIFIED_ARRAY_LENGTH"); | 216 "org.chromium.mojo.bindings.BindingsHelper.UNSPECIFIED_ARRAY_LENGTH"); |
212 if mojom.IsInterfaceKind(kind): | 217 if mojom.IsInterfaceKind(kind): |
213 params.append('%s.MANAGER' % GetJavaType(context, kind)) | 218 params.append('%s.MANAGER' % GetJavaType(context, kind)) |
214 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): | 219 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): |
215 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) | 220 params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) |
qsr
2014/09/02 07:41:44
It might be time to refactor the append part in a
ppi
2014/09/02 16:50:43
Done.
| |
216 return 'encode(%s)' % ', '.join(params) | 221 return 'encode(%s)' % ', '.join(params) |
217 | 222 |
218 def GetPackage(module): | 223 def GetPackage(module): |
219 if 'JavaPackage' in module.attributes: | 224 if 'JavaPackage' in module.attributes: |
220 return ParseStringAttribute(module.attributes['JavaPackage']) | 225 return ParseStringAttribute(module.attributes['JavaPackage']) |
221 # Default package. | 226 # Default package. |
222 return "org.chromium.mojom." + module.namespace | 227 return "org.chromium.mojom." + module.namespace |
223 | 228 |
224 def GetNameForKind(context, kind): | 229 def GetNameForKind(context, kind): |
225 def _GetNameHierachy(kind): | 230 def _GetNameHierachy(kind): |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 def GetJinjaParameters(self): | 466 def GetJinjaParameters(self): |
462 return { | 467 return { |
463 'lstrip_blocks': True, | 468 'lstrip_blocks': True, |
464 'trim_blocks': True, | 469 'trim_blocks': True, |
465 } | 470 } |
466 | 471 |
467 def GetGlobals(self): | 472 def GetGlobals(self): |
468 return { | 473 return { |
469 'module': self.module, | 474 'module': self.module, |
470 } | 475 } |
OLD | NEW |