Index: mojo/public/tools/bindings/generators/mojom_java_generator.py |
diff --git a/mojo/public/tools/bindings/generators/mojom_java_generator.py b/mojo/public/tools/bindings/generators/mojom_java_generator.py |
index 91e8b8e0a578702157417f1d12783112ac468802..4b839d75e8424eb1140384fe0f88b3935b2d4346 100644 |
--- a/mojo/public/tools/bindings/generators/mojom_java_generator.py |
+++ b/mojo/public/tools/bindings/generators/mojom_java_generator.py |
@@ -165,20 +165,8 @@ def GetArrayNullabilityFlags(kind): |
return " | ".join(flags_to_set) |
-@contextfilter |
-def DecodeMethod(context, kind, offset, bit): |
- def _DecodeMethodName(kind): |
- if mojom.IsAnyArrayKind(kind): |
- return _DecodeMethodName(kind.kind) + 's' |
- if mojom.IsEnumKind(kind): |
- return _DecodeMethodName(mojom.INT32) |
- if mojom.IsInterfaceRequestKind(kind): |
- return "readInterfaceRequest" |
- if mojom.IsInterfaceKind(kind): |
- return "readServiceInterface" |
- return _spec_to_decode_method[kind.spec] |
- methodName = _DecodeMethodName(kind) |
- params = [ str(offset) ] |
+def AppendEncodeDecodeParams(params, context, kind, bit): |
+ """ Appends standard parameters shared between encode and decode calls. """ |
if (kind == mojom.BOOL): |
params.append(str(bit)) |
if mojom.IsReferenceKind(kind): |
@@ -196,23 +184,29 @@ def DecodeMethod(context, kind, offset, bit): |
params.append('%s.MANAGER' % GetJavaType(context, kind)) |
if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): |
params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) |
+ return params |
qsr
2014/09/03 07:56:28
This is modifying its argument, you might not want
ppi
2014/09/03 08:53:46
Done.
|
+ |
+ |
+@contextfilter |
+def DecodeMethod(context, kind, offset, bit): |
+ def _DecodeMethodName(kind): |
+ if mojom.IsAnyArrayKind(kind): |
+ return _DecodeMethodName(kind.kind) + 's' |
+ if mojom.IsEnumKind(kind): |
+ return _DecodeMethodName(mojom.INT32) |
+ if mojom.IsInterfaceRequestKind(kind): |
+ return "readInterfaceRequest" |
+ if mojom.IsInterfaceKind(kind): |
+ return "readServiceInterface" |
+ return _spec_to_decode_method[kind.spec] |
+ methodName = _DecodeMethodName(kind) |
+ params = AppendEncodeDecodeParams([ str(offset) ], context, kind, bit) |
return '%s(%s)' % (methodName, ', '.join(params)) |
@contextfilter |
def EncodeMethod(context, kind, variable, offset, bit): |
- params = [ variable, str(offset) ] |
- if (kind == mojom.BOOL): |
- params.append(str(bit)) |
- if mojom.IsAnyArrayKind(kind): |
- if mojom.IsFixedArrayKind(kind): |
- params.append(str(kind.length)) |
- else: |
- params.append( |
- "org.chromium.mojo.bindings.BindingsHelper.UNSPECIFIED_ARRAY_LENGTH"); |
- if mojom.IsInterfaceKind(kind): |
- params.append('%s.MANAGER' % GetJavaType(context, kind)) |
- if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): |
- params.append('%s.MANAGER' % GetJavaType(context, kind.kind)) |
+ params = AppendEncodeDecodeParams( |
+ [ variable, str(offset) ], context, kind, bit) |
return 'encode(%s)' % ', '.join(params) |
def GetPackage(module): |