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

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

Issue 2213963002: Stop relying on using statements in the JNI generator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 # Checking just the start of the name, rather than a direct comparison, 131 # Checking just the start of the name, rather than a direct comparison,
132 # in order to handle generics. 132 # in order to handle generics.
133 return 'jclass' 133 return 'jclass'
134 else: 134 else:
135 return 'jobject' 135 return 'jobject'
136 136
137 137
138 def WrapCTypeForDeclaration(c_type): 138 def WrapCTypeForDeclaration(c_type):
139 """Wrap the C datatype in a JavaRef if required.""" 139 """Wrap the C datatype in a JavaRef if required."""
140 if re.match(RE_SCOPED_JNI_TYPES, c_type): 140 if re.match(RE_SCOPED_JNI_TYPES, c_type):
141 return 'const JavaParamRef<' + c_type + '>&' 141 return 'const base::android::JavaParamRef<' + c_type + '>&'
142 else: 142 else:
143 return c_type 143 return c_type
144 144
145 145
146 def JavaDataTypeToCForDeclaration(java_type): 146 def JavaDataTypeToCForDeclaration(java_type):
147 """Returns a JavaRef-wrapped C datatype for the given java type.""" 147 """Returns a JavaRef-wrapped C datatype for the given java type."""
148 return WrapCTypeForDeclaration(JavaDataTypeToC(java_type)) 148 return WrapCTypeForDeclaration(JavaDataTypeToC(java_type))
149 149
150 150
151 def JavaDataTypeToCForCalledByNativeParam(java_type): 151 def JavaDataTypeToCForCalledByNativeParam(java_type):
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 951
952 java_name = self.fully_qualified_class.replace('_', '_1').replace('/', '_') 952 java_name = self.fully_qualified_class.replace('_', '_1').replace('/', '_')
953 if native.java_class_name: 953 if native.java_class_name:
954 java_name += '_00024' + native.java_class_name 954 java_name += '_00024' + native.java_class_name
955 955
956 values = {'NAME': native.name, 956 values = {'NAME': native.name,
957 'JAVA_NAME': java_name} 957 'JAVA_NAME': java_name}
958 return template.substitute(values) 958 return template.substitute(values)
959 959
960 def GetJavaParamRefForCall(self, c_type, name): 960 def GetJavaParamRefForCall(self, c_type, name):
961 return Template('JavaParamRef<${TYPE}>(env, ${NAME})').substitute({ 961 return Template(
962 'base::android::JavaParamRef<${TYPE}>(env, ${NAME})').substitute({
962 'TYPE': c_type, 963 'TYPE': c_type,
963 'NAME': name, 964 'NAME': name,
964 }) 965 })
965 966
966 def GetJNIFirstParamForCall(self, native): 967 def GetJNIFirstParamForCall(self, native):
967 c_type = self.GetJNIFirstParamType(native) 968 c_type = self.GetJNIFirstParamType(native)
968 return [self.GetJavaParamRefForCall(c_type, 'jcaller')] 969 return [self.GetJavaParamRefForCall(c_type, 'jcaller')]
969 970
970 def GetNativeStub(self, native): 971 def GetNativeStub(self, native):
971 is_method = native.type == 'method' 972 is_method = native.type == 'method'
972 973
973 if is_method: 974 if is_method:
974 params = native.params[1:] 975 params = native.params[1:]
975 else: 976 else:
976 params = native.params 977 params = native.params
977 params_in_call = ['env'] + self.GetJNIFirstParamForCall(native) 978 params_in_call = ['env'] + self.GetJNIFirstParamForCall(native)
978 for p in params: 979 for p in params:
979 c_type = JavaDataTypeToC(p.datatype) 980 c_type = JavaDataTypeToC(p.datatype)
980 if re.match(RE_SCOPED_JNI_TYPES, c_type): 981 if re.match(RE_SCOPED_JNI_TYPES, c_type):
981 params_in_call.append(self.GetJavaParamRefForCall(c_type, p.name)) 982 params_in_call.append(self.GetJavaParamRefForCall(c_type, p.name))
982 else: 983 else:
983 params_in_call.append(p.name) 984 params_in_call.append(p.name)
984 params_in_call = ', '.join(params_in_call) 985 params_in_call = ', '.join(params_in_call)
985 986
986 return_type = return_declaration = JavaDataTypeToC(native.return_type) 987 return_type = return_declaration = JavaDataTypeToC(native.return_type)
987 post_call = '' 988 post_call = ''
988 if re.match(RE_SCOPED_JNI_TYPES, return_type): 989 if re.match(RE_SCOPED_JNI_TYPES, return_type):
989 post_call = '.Release()' 990 post_call = '.Release()'
990 return_declaration = 'ScopedJavaLocalRef<' + return_type + '>' 991 return_declaration = ('base::android::ScopedJavaLocalRef<' + return_type +
992 '>')
991 values = { 993 values = {
992 'RETURN': return_type, 994 'RETURN': return_type,
993 'RETURN_DECLARATION': return_declaration, 995 'RETURN_DECLARATION': return_declaration,
994 'NAME': native.name, 996 'NAME': native.name,
995 'PARAMS': self.GetParamsInDeclaration(native), 997 'PARAMS': self.GetParamsInDeclaration(native),
996 'PARAMS_IN_STUB': self.GetParamsInStub(native), 998 'PARAMS_IN_STUB': self.GetParamsInStub(native),
997 'PARAMS_IN_CALL': params_in_call, 999 'PARAMS_IN_CALL': params_in_call,
998 'POST_CALL': post_call, 1000 'POST_CALL': post_call,
999 'STUB_NAME': self.GetStubName(native), 1001 'STUB_NAME': self.GetStubName(native),
1000 } 1002 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 return_type = JavaDataTypeToC(called_by_native.return_type) 1066 return_type = JavaDataTypeToC(called_by_native.return_type)
1065 optional_error_return = JavaReturnValueToC(called_by_native.return_type) 1067 optional_error_return = JavaReturnValueToC(called_by_native.return_type)
1066 if optional_error_return: 1068 if optional_error_return:
1067 optional_error_return = ', ' + optional_error_return 1069 optional_error_return = ', ' + optional_error_return
1068 return_declaration = '' 1070 return_declaration = ''
1069 return_clause = '' 1071 return_clause = ''
1070 if return_type != 'void': 1072 if return_type != 'void':
1071 pre_call = ' ' + pre_call 1073 pre_call = ' ' + pre_call
1072 return_declaration = return_type + ' ret =' 1074 return_declaration = return_type + ' ret ='
1073 if re.match(RE_SCOPED_JNI_TYPES, return_type): 1075 if re.match(RE_SCOPED_JNI_TYPES, return_type):
1074 return_type = 'ScopedJavaLocalRef<' + return_type + '>' 1076 return_type = 'base::android::ScopedJavaLocalRef<' + return_type + '>'
1075 return_clause = 'return ' + return_type + '(env, ret);' 1077 return_clause = 'return ' + return_type + '(env, ret);'
1076 else: 1078 else:
1077 return_clause = 'return ret;' 1079 return_clause = 'return ret;'
1078 return { 1080 return {
1079 'JAVA_CLASS': java_class, 1081 'JAVA_CLASS': java_class,
1080 'RETURN_TYPE': return_type, 1082 'RETURN_TYPE': return_type,
1081 'OPTIONAL_ERROR_RETURN': optional_error_return, 1083 'OPTIONAL_ERROR_RETURN': optional_error_return,
1082 'RETURN_DECLARATION': return_declaration, 1084 'RETURN_DECLARATION': return_declaration,
1083 'RETURN_CLAUSE': return_clause, 1085 'RETURN_CLAUSE': return_clause,
1084 'FIRST_PARAM_IN_DECLARATION': first_param_in_declaration, 1086 'FIRST_PARAM_IN_DECLARATION': first_param_in_declaration,
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 GenerateJNIHeader(input_file, output_file, options) 1364 GenerateJNIHeader(input_file, output_file, options)
1363 1365
1364 if options.depfile: 1366 if options.depfile:
1365 build_utils.WriteDepfile( 1367 build_utils.WriteDepfile(
1366 options.depfile, 1368 options.depfile,
1367 build_utils.GetPythonDependencies()) 1369 build_utils.GetPythonDependencies())
1368 1370
1369 1371
1370 if __name__ == '__main__': 1372 if __name__ == '__main__':
1371 sys.exit(main(sys.argv)) 1373 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « base/android/jni_generator/golden_sample_for_tests_jni.h ('k') | base/android/jni_generator/testCalledByNatives.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698