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

Side by Side Diff: base/android/jni_generator/jni_generator.py

Issue 214543002: Android: improves error message for Outer.Inner usage in JNI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/android/jni_generator/jni_generator_tests.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Extracts native methods from a Java file and generates the JNI bindings. 6 """Extracts native methods from a Java file and generates the JNI bindings.
7 If you change this, please run and update the tests.""" 7 If you change this, please run and update the tests."""
8 8
9 import collections 9 import collections
10 import errno 10 import errno
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 prefix += '[' 199 prefix += '['
200 param = param[:-2] 200 param = param[:-2]
201 # Generic? 201 # Generic?
202 if '<' in param: 202 if '<' in param:
203 param = param[:param.index('<')] 203 param = param[:param.index('<')]
204 if param in pod_param_map: 204 if param in pod_param_map:
205 return prefix + pod_param_map[param] 205 return prefix + pod_param_map[param]
206 if '/' in param: 206 if '/' in param:
207 # Coming from javap, use the fully qualified param directly. 207 # Coming from javap, use the fully qualified param directly.
208 return prefix + 'L' + JniParams.RemapClassName(param) + ';' 208 return prefix + 'L' + JniParams.RemapClassName(param) + ';'
209
209 for qualified_name in (object_param_list + 210 for qualified_name in (object_param_list +
210 [JniParams._fully_qualified_class] + 211 [JniParams._fully_qualified_class] +
211 JniParams._inner_classes): 212 JniParams._inner_classes):
212 if (qualified_name.endswith('/' + param) or 213 if (qualified_name.endswith('/' + param) or
213 qualified_name.endswith('$' + param.replace('.', '$')) or 214 qualified_name.endswith('$' + param.replace('.', '$')) or
214 qualified_name == 'L' + param): 215 qualified_name == 'L' + param):
215 return prefix + JniParams.RemapClassName(qualified_name) + ';' 216 return prefix + JniParams.RemapClassName(qualified_name) + ';'
216 217
217 # Is it from an import? (e.g. referecing Class from import pkg.Class; 218 # Is it from an import? (e.g. referecing Class from import pkg.Class;
218 # note that referencing an inner class Inner from import pkg.Class.Inner 219 # note that referencing an inner class Inner from import pkg.Class.Inner
(...skipping 12 matching lines...) Expand all
231 # Is it an inner class from an outer class import? (e.g. referencing 232 # Is it an inner class from an outer class import? (e.g. referencing
232 # Class.Inner from import pkg.Class). 233 # Class.Inner from import pkg.Class).
233 if '.' in param: 234 if '.' in param:
234 components = param.split('.') 235 components = param.split('.')
235 outer = '/'.join(components[:-1]) 236 outer = '/'.join(components[:-1])
236 inner = components[-1] 237 inner = components[-1]
237 for qualified_name in JniParams._imports: 238 for qualified_name in JniParams._imports:
238 if qualified_name.endswith('/' + outer): 239 if qualified_name.endswith('/' + outer):
239 return (prefix + JniParams.RemapClassName(qualified_name) + 240 return (prefix + JniParams.RemapClassName(qualified_name) +
240 '$' + inner + ';') 241 '$' + inner + ';')
242 raise SyntaxError('Inner class (%s) can not be '
243 'used directly by JNI. Please import the outer '
244 'class, probably:\n'
245 'import %s.%s;' %
246 (param, JniParams._package.replace('/', '.'),
247 outer.replace('/', '.')))
241 248
242 # Type not found, falling back to same package as this class. 249 # Type not found, falling back to same package as this class.
243 return (prefix + 'L' + 250 return (prefix + 'L' +
244 JniParams.RemapClassName(JniParams._package + '/' + param) + ';') 251 JniParams.RemapClassName(JniParams._package + '/' + param) + ';')
245 252
246 @staticmethod 253 @staticmethod
247 def Signature(params, returns, wrap): 254 def Signature(params, returns, wrap):
248 """Returns the JNI signature for the given datatypes.""" 255 """Returns the JNI signature for the given datatypes."""
249 items = ['('] 256 items = ['(']
250 items += [JniParams.JavaToJni(param.datatype) for param in params] 257 items += [JniParams.JavaToJni(param.datatype) for param in params]
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 root_name = os.path.splitext(os.path.basename(input_file))[0] 1337 root_name = os.path.splitext(os.path.basename(input_file))[0]
1331 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' 1338 output_file = os.path.join(options.output_dir, root_name) + '_jni.h'
1332 if options.jarjar: 1339 if options.jarjar:
1333 with open(options.jarjar) as f: 1340 with open(options.jarjar) as f:
1334 JniParams.SetJarJarMappings(f.read()) 1341 JniParams.SetJarJarMappings(f.read())
1335 GenerateJNIHeader(input_file, output_file, options) 1342 GenerateJNIHeader(input_file, output_file, options)
1336 1343
1337 1344
1338 if __name__ == '__main__': 1345 if __name__ == '__main__':
1339 sys.exit(main(sys.argv)) 1346 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | base/android/jni_generator/jni_generator_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698