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

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

Issue 277753004: Android: optimizes jni_generator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | 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 #!/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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 raise SyntaxError('Unable to find "package" line in %s' % java_file_name) 352 raise SyntaxError('Unable to find "package" line in %s' % java_file_name)
353 return (matches[0].replace('.', '/') + '/' + 353 return (matches[0].replace('.', '/') + '/' +
354 os.path.splitext(os.path.basename(java_file_name))[0]) 354 os.path.splitext(os.path.basename(java_file_name))[0])
355 355
356 356
357 def ExtractNatives(contents, ptr_type): 357 def ExtractNatives(contents, ptr_type):
358 """Returns a list of dict containing information about a native method.""" 358 """Returns a list of dict containing information about a native method."""
359 contents = contents.replace('\n', '') 359 contents = contents.replace('\n', '')
360 natives = [] 360 natives = []
361 re_native = re.compile(r'(@NativeClassQualifiedName' 361 re_native = re.compile(r'(@NativeClassQualifiedName'
362 '\(\"(?P<native_class_name>.*?)\"\))?\s*' 362 '\(\"(?P<native_class_name>.*?)\"\)\s+)?'
363 '(@NativeCall(\(\"(?P<java_class_name>.*?)\"\)))?\s*' 363 '(@NativeCall(\(\"(?P<java_class_name>.*?)\"\))\s+)?'
364 '(?P<qualifiers>\w+\s\w+|\w+|\s+)\s*?native ' 364 '(?P<qualifiers>\w+\s\w+|\w+|\s+)\s*native '
365 '(?P<return_type>\S*?) ' 365 '(?P<return_type>\S*) '
366 '(?P<name>native\w+?)\((?P<params>.*?)\);') 366 '(?P<name>native\w+)\((?P<params>.*?)\);')
367 for match in re.finditer(re_native, contents): 367 for match in re.finditer(re_native, contents):
368 native = NativeMethod( 368 native = NativeMethod(
369 static='static' in match.group('qualifiers'), 369 static='static' in match.group('qualifiers'),
370 java_class_name=match.group('java_class_name'), 370 java_class_name=match.group('java_class_name'),
371 native_class_name=match.group('native_class_name'), 371 native_class_name=match.group('native_class_name'),
372 return_type=match.group('return_type'), 372 return_type=match.group('return_type'),
373 name=match.group('name').replace('native', ''), 373 name=match.group('name').replace('native', ''),
374 params=JniParams.Parse(match.group('params')), 374 params=JniParams.Parse(match.group('params')),
375 ptr_type=ptr_type) 375 ptr_type=ptr_type)
376 natives += [native] 376 natives += [native]
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 root_name = os.path.splitext(os.path.basename(input_file))[0] 1386 root_name = os.path.splitext(os.path.basename(input_file))[0]
1387 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' 1387 output_file = os.path.join(options.output_dir, root_name) + '_jni.h'
1388 if options.jarjar: 1388 if options.jarjar:
1389 with open(options.jarjar) as f: 1389 with open(options.jarjar) as f:
1390 JniParams.SetJarJarMappings(f.read()) 1390 JniParams.SetJarJarMappings(f.read())
1391 GenerateJNIHeader(input_file, output_file, options) 1391 GenerateJNIHeader(input_file, output_file, options)
1392 1392
1393 1393
1394 if __name__ == '__main__': 1394 if __name__ == '__main__':
1395 sys.exit(main(sys.argv)) 1395 sys.exit(main(sys.argv))
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