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

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

Issue 290403002: Adding JNIAdditionalImport annotation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Follow review Created 6 years, 7 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
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 _remappings = [] 156 _remappings = []
157 _implicit_imports = [] 157 _implicit_imports = []
158 158
159 @staticmethod 159 @staticmethod
160 def SetFullyQualifiedClass(fully_qualified_class): 160 def SetFullyQualifiedClass(fully_qualified_class):
161 JniParams._fully_qualified_class = 'L' + fully_qualified_class 161 JniParams._fully_qualified_class = 'L' + fully_qualified_class
162 JniParams._package = '/'.join(fully_qualified_class.split('/')[:-1]) 162 JniParams._package = '/'.join(fully_qualified_class.split('/')[:-1])
163 163
164 @staticmethod 164 @staticmethod
165 def ExtractImportsAndInnerClasses(contents): 165 def ExtractImportsAndInnerClasses(contents):
166 if not JniParams._package:
167 raise RuntimeError('SetFullyQualifiedClass must be called before '
168 'ExtractImportsAndInnerClasses')
166 contents = contents.replace('\n', '') 169 contents = contents.replace('\n', '')
167 re_import = re.compile(r'import.*?(?P<class>\S*?);') 170 re_import = re.compile(r'import.*?(?P<class>\S*?);')
168 for match in re.finditer(re_import, contents): 171 for match in re.finditer(re_import, contents):
169 JniParams._imports += ['L' + match.group('class').replace('.', '/')] 172 JniParams._imports += ['L' + match.group('class').replace('.', '/')]
170 173
171 re_inner = re.compile(r'(class|interface)\s+?(?P<name>\w+?)\W') 174 re_inner = re.compile(r'(class|interface)\s+?(?P<name>\w+?)\W')
172 for match in re.finditer(re_inner, contents): 175 for match in re.finditer(re_inner, contents):
173 inner = match.group('name') 176 inner = match.group('name')
174 if not JniParams._fully_qualified_class.endswith(inner): 177 if not JniParams._fully_qualified_class.endswith(inner):
175 JniParams._inner_classes += [JniParams._fully_qualified_class + '$' + 178 JniParams._inner_classes += [JniParams._fully_qualified_class + '$' +
176 inner] 179 inner]
177 180
181 re_additional_imports = re.compile(
182 r'@JNIAdditionalImport\((?P<class_name>\w+?)\.class\)')
183 for match in re.finditer(re_additional_imports, contents):
184 class_name = match.group('class_name')
185 if '.' in class_name:
186 raise SyntaxError('*.class cannot be used in @JNIAdditionalImport. '
187 'Only import unqualified outer classes.' % class_name)
188 new_import = 'L%s/%s' % (JniParams._package, class_name)
189 if new_import in JniParams._imports:
190 raise SyntaxError('Do not use JNIAdditionalImport on an already '
191 'imported class: %s' % (new_import.replace('/', '.')))
192 JniParams._imports += [new_import]
193
178 @staticmethod 194 @staticmethod
179 def ParseJavaPSignature(signature_line): 195 def ParseJavaPSignature(signature_line):
180 prefix = 'Signature: ' 196 prefix = 'Signature: '
181 return '"%s"' % signature_line[signature_line.index(prefix) + len(prefix):] 197 return '"%s"' % signature_line[signature_line.index(prefix) + len(prefix):]
182 198
183 @staticmethod 199 @staticmethod
184 def JavaToJni(param): 200 def JavaToJni(param):
185 """Converts a java param into a JNI signature type.""" 201 """Converts a java param into a JNI signature type."""
186 pod_param_map = { 202 pod_param_map = {
187 'int': 'I', 203 'int': 'I',
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 root_name = os.path.splitext(os.path.basename(input_file))[0] 1403 root_name = os.path.splitext(os.path.basename(input_file))[0]
1388 output_file = os.path.join(options.output_dir, root_name) + '_jni.h' 1404 output_file = os.path.join(options.output_dir, root_name) + '_jni.h'
1389 if options.jarjar: 1405 if options.jarjar:
1390 with open(options.jarjar) as f: 1406 with open(options.jarjar) as f:
1391 JniParams.SetJarJarMappings(f.read()) 1407 JniParams.SetJarJarMappings(f.read())
1392 GenerateJNIHeader(input_file, output_file, options) 1408 GenerateJNIHeader(input_file, output_file, options)
1393 1409
1394 1410
1395 if __name__ == '__main__': 1411 if __name__ == '__main__':
1396 sys.exit(main(sys.argv)) 1412 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « base/android/java/src/org/chromium/base/JNIAdditionalImport.java ('k') | base/android/jni_generator/jni_generator_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698