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

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

Issue 12594021: Android: fixes jni_generator for @CalledByNative with generics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 257
258 258
259 def ExtractNatives(contents): 259 def ExtractNatives(contents):
260 """Returns a list of dict containing information about a native method.""" 260 """Returns a list of dict containing information about a native method."""
261 contents = contents.replace('\n', '') 261 contents = contents.replace('\n', '')
262 natives = [] 262 natives = []
263 re_native = re.compile(r'(@NativeClassQualifiedName' 263 re_native = re.compile(r'(@NativeClassQualifiedName'
264 '\(\"(?P<native_class_name>.*?)\"\))?\s*' 264 '\(\"(?P<native_class_name>.*?)\"\))?\s*'
265 '(@NativeCall(\(\"(?P<java_class_name>.*?)\"\)))?\s*' 265 '(@NativeCall(\(\"(?P<java_class_name>.*?)\"\)))?\s*'
266 '(?P<qualifiers>\w+\s\w+|\w+|\s+)\s*?native ' 266 '(?P<qualifiers>\w+\s\w+|\w+|\s+)\s*?native '
267 '(?P<return>\S*?) ' 267 '(?P<return_type>\S*?) '
268 '(?P<name>\w+?)\((?P<params>.*?)\);') 268 '(?P<name>\w+?)\((?P<params>.*?)\);')
269 for match in re.finditer(re_native, contents): 269 for match in re.finditer(re_native, contents):
270 native = NativeMethod( 270 native = NativeMethod(
271 static='static' in match.group('qualifiers'), 271 static='static' in match.group('qualifiers'),
272 java_class_name=match.group('java_class_name'), 272 java_class_name=match.group('java_class_name'),
273 native_class_name=match.group('native_class_name'), 273 native_class_name=match.group('native_class_name'),
274 return_type=match.group('return'), 274 return_type=match.group('return_type'),
275 name=match.group('name').replace('native', ''), 275 name=match.group('name').replace('native', ''),
276 params=JniParams.Parse(match.group('params'))) 276 params=JniParams.Parse(match.group('params')))
277 natives += [native] 277 natives += [native]
278 return natives 278 return natives
279 279
280 280
281 def GetStaticCastForReturnType(return_type): 281 def GetStaticCastForReturnType(return_type):
282 type_map = { 'String' : 'jstring', 282 type_map = { 'String' : 'jstring',
283 'java/lang/String' : 'jstring', 283 'java/lang/String' : 'jstring',
284 'boolean[]': 'jbooleanArray', 284 'boolean[]': 'jbooleanArray',
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 374
375 375
376 # Regex to match the JNI return types that should be included in a 376 # Regex to match the JNI return types that should be included in a
377 # ScopedJavaLocalRef. 377 # ScopedJavaLocalRef.
378 RE_SCOPED_JNI_RETURN_TYPES = re.compile('jobject|jclass|jstring|.*Array') 378 RE_SCOPED_JNI_RETURN_TYPES = re.compile('jobject|jclass|jstring|.*Array')
379 379
380 # Regex to match a string like "@CalledByNative public void foo(int bar)". 380 # Regex to match a string like "@CalledByNative public void foo(int bar)".
381 RE_CALLED_BY_NATIVE = re.compile( 381 RE_CALLED_BY_NATIVE = re.compile(
382 '@CalledByNative(?P<Unchecked>(Unchecked)*?)(?:\("(?P<annotation>.*)"\))?' 382 '@CalledByNative(?P<Unchecked>(Unchecked)*?)(?:\("(?P<annotation>.*)"\))?'
383 '\s+(?P<prefix>[\w ]*?)' 383 '\s+(?P<prefix>[\w ]*?)'
384 '\s*(?P<return_type>[\w\.]+(\[\])*?)' 384 '\s*(?P<return_type>\S+?)'
385 '\s+(?P<name>\w+)' 385 '\s+(?P<name>\w+)'
386 '\s*\((?P<params>[^\)]*)\)') 386 '\s*\((?P<params>[^\)]*)\)')
387 387
388 388
389 def ExtractCalledByNatives(contents): 389 def ExtractCalledByNatives(contents):
390 """Parses all methods annotated with @CalledByNative. 390 """Parses all methods annotated with @CalledByNative.
391 391
392 Args: 392 Args:
393 contents: the contents of the java file. 393 contents: the contents of the java file.
394 394
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 output_file = None 1023 output_file = None
1024 if options.output_dir: 1024 if options.output_dir:
1025 root_name = os.path.splitext(os.path.basename(input_file))[0] 1025 root_name = os.path.splitext(os.path.basename(input_file))[0]
1026 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' 1026 output_file = os.path.join(options.output_dir, root_name) + '_jni.h'
1027 GenerateJNIHeader(input_file, output_file, options.namespace, 1027 GenerateJNIHeader(input_file, output_file, options.namespace,
1028 options.optimize_generation) 1028 options.optimize_generation)
1029 1029
1030 1030
1031 if __name__ == '__main__': 1031 if __name__ == '__main__':
1032 sys.exit(main(sys.argv)) 1032 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