OLD | NEW |
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 optparse | 10 import optparse |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 line1, line2) | 416 line1, line2) |
417 return MangleCalledByNatives(called_by_natives) | 417 return MangleCalledByNatives(called_by_natives) |
418 | 418 |
419 | 419 |
420 class JNIFromJavaP(object): | 420 class JNIFromJavaP(object): |
421 """Uses 'javap' to parse a .class file and generate the JNI header file.""" | 421 """Uses 'javap' to parse a .class file and generate the JNI header file.""" |
422 | 422 |
423 def __init__(self, contents, namespace): | 423 def __init__(self, contents, namespace): |
424 self.contents = contents | 424 self.contents = contents |
425 self.namespace = namespace | 425 self.namespace = namespace |
426 self.fully_qualified_class = re.match('.*?class (?P<class_name>.*?) ', | 426 self.fully_qualified_class = re.match( |
427 contents[1]).group('class_name') | 427 '.*?(class|interface) (?P<class_name>.*?)( |{)', |
| 428 contents[1]).group('class_name') |
428 self.fully_qualified_class = self.fully_qualified_class.replace('.', '/') | 429 self.fully_qualified_class = self.fully_qualified_class.replace('.', '/') |
429 JniParams.SetFullyQualifiedClass(self.fully_qualified_class) | 430 JniParams.SetFullyQualifiedClass(self.fully_qualified_class) |
430 self.java_class_name = self.fully_qualified_class.split('/')[-1] | 431 self.java_class_name = self.fully_qualified_class.split('/')[-1] |
431 if not self.namespace: | 432 if not self.namespace: |
432 self.namespace = 'JNI_' + self.java_class_name | 433 self.namespace = 'JNI_' + self.java_class_name |
433 re_method = re.compile('(?P<prefix>.*?)(?P<return_type>\S+?) (?P<name>\w+?)' | 434 re_method = re.compile('(?P<prefix>.*?)(?P<return_type>\S+?) (?P<name>\w+?)' |
434 '\((?P<params>.*?)\)') | 435 '\((?P<params>.*?)\)') |
435 self.called_by_natives = [] | 436 self.called_by_natives = [] |
436 for content in contents[2:]: | 437 for content in contents[2:]: |
437 match = re.match(re_method, content) | 438 match = re.match(re_method, content) |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 output_file = None | 1019 output_file = None |
1019 if options.output_dir: | 1020 if options.output_dir: |
1020 root_name = os.path.splitext(os.path.basename(input_file))[0] | 1021 root_name = os.path.splitext(os.path.basename(input_file))[0] |
1021 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' | 1022 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' |
1022 GenerateJNIHeader(input_file, output_file, options.namespace, | 1023 GenerateJNIHeader(input_file, output_file, options.namespace, |
1023 options.optimize_generation) | 1024 options.optimize_generation) |
1024 | 1025 |
1025 | 1026 |
1026 if __name__ == '__main__': | 1027 if __name__ == '__main__': |
1027 sys.exit(main(sys.argv)) | 1028 sys.exit(main(sys.argv)) |
OLD | NEW |