Chromium Code Reviews| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 param = param[:-2] | 161 param = param[:-2] |
| 162 # Generic? | 162 # Generic? |
| 163 if '<' in param: | 163 if '<' in param: |
| 164 param = param[:param.index('<')] | 164 param = param[:param.index('<')] |
| 165 if param in pod_param_map: | 165 if param in pod_param_map: |
| 166 return prefix + pod_param_map[param] | 166 return prefix + pod_param_map[param] |
| 167 if '/' in param: | 167 if '/' in param: |
| 168 # Coming from javap, use the fully qualified param directly. | 168 # Coming from javap, use the fully qualified param directly. |
| 169 return 'L' + param + ';' | 169 return 'L' + param + ';' |
| 170 for qualified_name in (object_param_list + | 170 for qualified_name in (object_param_list + |
| 171 JniParams._imports + | |
| 172 [JniParams._fully_qualified_class] + | 171 [JniParams._fully_qualified_class] + |
| 173 JniParams._inner_classes): | 172 JniParams._inner_classes): |
| 174 if (qualified_name.endswith('/' + param) or | 173 if (qualified_name.endswith('/' + param) or |
| 175 qualified_name.endswith('$' + param.replace('.', '$')) or | 174 qualified_name.endswith('$' + param.replace('.', '$')) or |
| 176 qualified_name == 'L' + param): | 175 qualified_name == 'L' + param): |
| 177 return prefix + qualified_name + ';' | 176 return prefix + qualified_name + ';' |
| 177 | |
| 178 # Is it Bar from import zoo.foo.Bar ? | |
|
joth
2012/11/12 21:22:07
nit: Is it from an inner class import? (e.g. impor
bulach
2012/11/12 22:10:19
Done.
| |
| 179 for qualified_name in JniParams._imports: | |
| 180 if qualified_name.endswith('/' + param): | |
| 181 # Ensure it's not an inner class. | |
| 182 components = qualified_name.split('/') | |
| 183 if len(components) > 2 and components[-2][0].isupper(): | |
| 184 raise SyntaxError('Inner class (%s) can not be imported ' | |
| 185 'and used by JNI (%s). Please import the outer ' | |
| 186 'class and use Outer.Inner instead.' % | |
| 187 (qualified_name, param)) | |
| 188 return prefix + qualified_name + ';' | |
| 189 | |
| 190 # Is it an inner class zoo.Foo.Bar from import zoo.Foo? | |
|
joth
2012/11/12 21:22:07
Is it an inner class from an outer class import? (
bulach
2012/11/12 22:10:19
Done.
| |
| 191 if '.' in param: | |
| 192 components = param.split('.') | |
| 193 outer = '/'.join(components[:-1]) | |
| 194 inner = components[-1] | |
| 195 for qualified_name in JniParams._imports: | |
| 196 if qualified_name.endswith('/' + outer): | |
| 197 return prefix + qualified_name + '$' + inner | |
| 198 | |
| 178 # Type not found, falling back to same package as this class. | 199 # Type not found, falling back to same package as this class. |
| 179 return prefix + 'L' + JniParams._package + '/' + param + ';' | 200 return prefix + 'L' + JniParams._package + '/' + param + ';' |
| 180 | 201 |
| 181 @staticmethod | 202 @staticmethod |
| 182 def Signature(params, returns, wrap): | 203 def Signature(params, returns, wrap): |
| 183 """Returns the JNI signature for the given datatypes.""" | 204 """Returns the JNI signature for the given datatypes.""" |
| 184 items = ['('] | 205 items = ['('] |
| 185 items += [JniParams.JavaToJni(param.datatype) for param in params] | 206 items += [JniParams.JavaToJni(param.datatype) for param in params] |
| 186 items += [')'] | 207 items += [')'] |
| 187 items += [JniParams.JavaToJni(returns)] | 208 items += [JniParams.JavaToJni(returns)] |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 input_file = options.input_file | 989 input_file = options.input_file |
| 969 output_file = None | 990 output_file = None |
| 970 if options.output_dir: | 991 if options.output_dir: |
| 971 root_name = os.path.splitext(os.path.basename(input_file))[0] | 992 root_name = os.path.splitext(os.path.basename(input_file))[0] |
| 972 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' | 993 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' |
| 973 GenerateJNIHeader(input_file, output_file, options.namespace) | 994 GenerateJNIHeader(input_file, output_file, options.namespace) |
| 974 | 995 |
| 975 | 996 |
| 976 if __name__ == '__main__': | 997 if __name__ == '__main__': |
| 977 sys.exit(main(sys.argv)) | 998 sys.exit(main(sys.argv)) |
| OLD | NEW |