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 # TODO (qinmin): Need to refactor this file as base should not know about | 6 # TODO (qinmin): Need to refactor this file as base should not know about |
7 # higher level concepts. Currently this file has knowledge about higher level | 7 # higher level concepts. Currently this file has knowledge about higher level |
8 # java classes. | 8 # java classes. |
9 | 9 |
10 """Extracts native methods from a Java file and generates the JNI bindings. | 10 """Extracts native methods from a Java file and generates the JNI bindings. |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 name=match.group('name'), | 464 name=match.group('name'), |
465 params=ParseParams(match.group('params').replace('.', '/')))] | 465 params=ParseParams(match.group('params').replace('.', '/')))] |
466 re_constructor = re.compile('.*? public ' + | 466 re_constructor = re.compile('.*? public ' + |
467 self.fully_qualified_class.replace('/', '.') + | 467 self.fully_qualified_class.replace('/', '.') + |
468 '\((?P<params>.*?)\)') | 468 '\((?P<params>.*?)\)') |
469 for content in contents[2:]: | 469 for content in contents[2:]: |
470 match = re.match(re_constructor, content) | 470 match = re.match(re_constructor, content) |
471 if not match: | 471 if not match: |
472 continue | 472 continue |
473 self.called_by_natives += [CalledByNative( | 473 self.called_by_natives += [CalledByNative( |
474 system_class=False, | 474 system_class=True, |
475 unchecked=False, | 475 unchecked=False, |
476 static=False, | 476 static=False, |
477 java_class_name='', | 477 java_class_name='', |
478 return_type=self.fully_qualified_class, | 478 return_type=self.fully_qualified_class, |
479 name='Constructor', | 479 name='Constructor', |
480 params=ParseParams(match.group('params').replace('.', '/')), | 480 params=ParseParams(match.group('params').replace('.', '/')), |
481 is_constructor=True)] | 481 is_constructor=True)] |
482 self.called_by_natives = MangleCalledByNatives(self.called_by_natives) | 482 self.called_by_natives = MangleCalledByNatives(self.called_by_natives) |
483 self.inl_header_file_generator = InlHeaderFileGenerator( | 483 self.inl_header_file_generator = InlHeaderFileGenerator( |
484 self.namespace, self.fully_qualified_class, [], self.called_by_natives) | 484 self.namespace, self.fully_qualified_class, [], self.called_by_natives) |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 ret = [] | 916 ret = [] |
917 for clazz in self.GetUniqueClasses(self.called_by_natives): | 917 for clazz in self.GetUniqueClasses(self.called_by_natives): |
918 values = {'JAVA_CLASS': clazz} | 918 values = {'JAVA_CLASS': clazz} |
919 ret += [template.substitute(values)] | 919 ret += [template.substitute(values)] |
920 return '\n'.join(ret) | 920 return '\n'.join(ret) |
921 | 921 |
922 def GetMethodIDImpl(self, called_by_native): | 922 def GetMethodIDImpl(self, called_by_native): |
923 """Returns the implementation of GetMethodID.""" | 923 """Returns the implementation of GetMethodID.""" |
924 template = Template("""\ | 924 template = Template("""\ |
925 g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = | 925 g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = |
926 base::android::Get${STATIC}MethodID( | 926 base::android::Get${STATIC}MethodID${SUFFIX}( |
927 env, g_${JAVA_CLASS}_clazz, | 927 env, g_${JAVA_CLASS}_clazz, |
928 "${JNI_NAME}", | 928 "${JNI_NAME}", |
929 ${JNI_SIGNATURE}); | 929 ${JNI_SIGNATURE}); |
930 """) | 930 """) |
931 jni_name = called_by_native.name | 931 jni_name = called_by_native.name |
932 jni_return_type = called_by_native.return_type | 932 jni_return_type = called_by_native.return_type |
933 if called_by_native.is_constructor: | 933 if called_by_native.is_constructor: |
934 jni_name = '<init>' | 934 jni_name = '<init>' |
935 jni_return_type = 'void' | 935 jni_return_type = 'void' |
936 values = { | 936 values = { |
937 'JAVA_CLASS': called_by_native.java_class_name or self.class_name, | 937 'JAVA_CLASS': called_by_native.java_class_name or self.class_name, |
938 'JNI_NAME': jni_name, | 938 'JNI_NAME': jni_name, |
939 'METHOD_ID_VAR_NAME': called_by_native.method_id_var_name, | 939 'METHOD_ID_VAR_NAME': called_by_native.method_id_var_name, |
940 'STATIC': 'Static' if called_by_native.static else '', | 940 'STATIC': 'Static' if called_by_native.static else '', |
| 941 'SUFFIX': 'OrNull' if called_by_native.system_class else '', |
941 'JNI_SIGNATURE': JniSignature(called_by_native.params, | 942 'JNI_SIGNATURE': JniSignature(called_by_native.params, |
942 jni_return_type, | 943 jni_return_type, |
943 True) | 944 True) |
944 } | 945 } |
945 return template.substitute(values) | 946 return template.substitute(values) |
946 | 947 |
947 | 948 |
948 def WrapOutput(output): | 949 def WrapOutput(output): |
949 ret = [] | 950 ret = [] |
950 for line in output.splitlines(): | 951 for line in output.splitlines(): |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 input_file = options.input_file | 1044 input_file = options.input_file |
1044 output_file = None | 1045 output_file = None |
1045 if options.output_dir: | 1046 if options.output_dir: |
1046 root_name = os.path.splitext(os.path.basename(input_file))[0] | 1047 root_name = os.path.splitext(os.path.basename(input_file))[0] |
1047 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' | 1048 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' |
1048 GenerateJNIHeader(input_file, output_file, options.namespace) | 1049 GenerateJNIHeader(input_file, output_file, options.namespace) |
1049 | 1050 |
1050 | 1051 |
1051 if __name__ == '__main__': | 1052 if __name__ == '__main__': |
1052 sys.exit(main(sys.argv)) | 1053 sys.exit(main(sys.argv)) |
OLD | NEW |