Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: mojo/public/tools/bindings/generators/mojom_java_generator.py

Issue 518703003: mojo: Refactor method name generation for java bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix method name. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if mojom.IsAnyArrayKind(kind): 142 if mojom.IsAnyArrayKind(kind):
143 return _DecodeMethodName(kind.kind) + 's' 143 return _DecodeMethodName(kind.kind) + 's'
144 if mojom.IsEnumKind(kind): 144 if mojom.IsEnumKind(kind):
145 return _DecodeMethodName(mojom.INT32) 145 return _DecodeMethodName(mojom.INT32)
146 if mojom.IsInterfaceRequestKind(kind): 146 if mojom.IsInterfaceRequestKind(kind):
147 return "readInterfaceRequest" 147 return "readInterfaceRequest"
148 if mojom.IsInterfaceKind(kind): 148 if mojom.IsInterfaceKind(kind):
149 return "readServiceInterface" 149 return "readServiceInterface"
150 return _spec_to_decode_method[kind.spec] 150 return _spec_to_decode_method[kind.spec]
151 methodName = _DecodeMethodName(kind) 151 methodName = _DecodeMethodName(kind)
152 additionalParams = '' 152 params = [ str(offset) ]
153 if (kind == mojom.BOOL): 153 if (kind == mojom.BOOL):
154 additionalParams = ', %d' % bit 154 params.append(str(bit))
155 if mojom.IsInterfaceKind(kind): 155 if mojom.IsInterfaceKind(kind):
156 additionalParams = ', %s.MANAGER' % GetJavaType(context, kind) 156 params.append('%s.MANAGER' % GetJavaType(context, kind))
157 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): 157 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind):
158 additionalParams = ', %s.MANAGER' % GetJavaType(context, kind.kind) 158 params.append('%s.MANAGER' % GetJavaType(context, kind.kind))
159 return '%s(%s%s)' % (methodName, offset, additionalParams) 159 return '%s(%s)' % (methodName, ', '.join(params))
160 160
161 @contextfilter 161 @contextfilter
162 def EncodeMethod(context, kind, variable, offset, bit): 162 def EncodeMethod(context, kind, variable, offset, bit):
163 additionalParams = '' 163 params = [ variable, str(offset) ]
164 if (kind == mojom.BOOL): 164 if (kind == mojom.BOOL):
165 additionalParams = ', %d' % bit 165 params.append(str(bit))
166 if mojom.IsInterfaceKind(kind): 166 if mojom.IsInterfaceKind(kind):
167 additionalParams = ', %s.MANAGER' % GetJavaType(context, kind) 167 params.append('%s.MANAGER' % GetJavaType(context, kind))
168 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind): 168 if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind):
169 additionalParams = ', %s.MANAGER' % GetJavaType(context, kind.kind) 169 params.append('%s.MANAGER' % GetJavaType(context, kind.kind))
170 return 'encode(%s, %s%s)' % (variable, offset, additionalParams) 170 return 'encode(%s)' % ', '.join(params)
171 171
172 def GetPackage(module): 172 def GetPackage(module):
173 if 'JavaPackage' in module.attributes: 173 if 'JavaPackage' in module.attributes:
174 return ParseStringAttribute(module.attributes['JavaPackage']) 174 return ParseStringAttribute(module.attributes['JavaPackage'])
175 # Default package. 175 # Default package.
176 return "org.chromium.mojom." + module.namespace 176 return "org.chromium.mojom." + module.namespace
177 177
178 def GetNameForKind(context, kind): 178 def GetNameForKind(context, kind):
179 def _GetNameHierachy(kind): 179 def _GetNameHierachy(kind):
180 hierachy = [] 180 hierachy = []
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 def GetJinjaParameters(self): 412 def GetJinjaParameters(self):
413 return { 413 return {
414 'lstrip_blocks': True, 414 'lstrip_blocks': True,
415 'trim_blocks': True, 415 'trim_blocks': True,
416 } 416 }
417 417
418 def GetGlobals(self): 418 def GetGlobals(self):
419 return { 419 return {
420 'module': self.module, 420 'module': self.module,
421 } 421 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698