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 errno | 10 import errno |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 class JNIFromJavaP(object): | 449 class JNIFromJavaP(object): |
450 """Uses 'javap' to parse a .class file and generate the JNI header file.""" | 450 """Uses 'javap' to parse a .class file and generate the JNI header file.""" |
451 | 451 |
452 def __init__(self, contents, namespace): | 452 def __init__(self, contents, namespace): |
453 self.contents = contents | 453 self.contents = contents |
454 self.namespace = namespace | 454 self.namespace = namespace |
455 self.fully_qualified_class = re.match( | 455 self.fully_qualified_class = re.match( |
456 '.*?(class|interface) (?P<class_name>.*?)( |{)', | 456 '.*?(class|interface) (?P<class_name>.*?)( |{)', |
457 contents[1]).group('class_name') | 457 contents[1]).group('class_name') |
458 self.fully_qualified_class = self.fully_qualified_class.replace('.', '/') | 458 self.fully_qualified_class = self.fully_qualified_class.replace('.', '/') |
| 459 # Java 7's javap includes type parameters in output, like HashSet<T>. Strip |
| 460 # away the <...> and use the raw class name that Java 6 would've given us. |
| 461 self.fully_qualified_class = self.fully_qualified_class.split('<', 1)[0] |
459 JniParams.SetFullyQualifiedClass(self.fully_qualified_class) | 462 JniParams.SetFullyQualifiedClass(self.fully_qualified_class) |
460 self.java_class_name = self.fully_qualified_class.split('/')[-1] | 463 self.java_class_name = self.fully_qualified_class.split('/')[-1] |
461 if not self.namespace: | 464 if not self.namespace: |
462 self.namespace = 'JNI_' + self.java_class_name | 465 self.namespace = 'JNI_' + self.java_class_name |
463 re_method = re.compile('(?P<prefix>.*?)(?P<return_type>\S+?) (?P<name>\w+?)' | 466 re_method = re.compile('(?P<prefix>.*?)(?P<return_type>\S+?) (?P<name>\w+?)' |
464 '\((?P<params>.*?)\)') | 467 '\((?P<params>.*?)\)') |
465 self.called_by_natives = [] | 468 self.called_by_natives = [] |
466 for content in contents[2:]: | 469 for content in contents[2:]: |
467 match = re.match(re_method, content) | 470 match = re.match(re_method, content) |
468 if not match: | 471 if not match: |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' | 1059 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' |
1057 if options.jarjar: | 1060 if options.jarjar: |
1058 with open(options.jarjar) as f: | 1061 with open(options.jarjar) as f: |
1059 JniParams.SetJarJarMappings(f.read()) | 1062 JniParams.SetJarJarMappings(f.read()) |
1060 GenerateJNIHeader(input_file, output_file, options.namespace, | 1063 GenerateJNIHeader(input_file, output_file, options.namespace, |
1061 options.optimize_generation) | 1064 options.optimize_generation) |
1062 | 1065 |
1063 | 1066 |
1064 if __name__ == '__main__': | 1067 if __name__ == '__main__': |
1065 sys.exit(main(sys.argv)) | 1068 sys.exit(main(sys.argv)) |
OLD | NEW |