Commit b75b48a5 authored by François Grisez's avatar François Grisez

wrappers: replace calls to type() by isinstance() in each genwrapper.py script.

parent 91720d2b
......@@ -60,13 +60,13 @@ class CsharpTranslator(object):
return not methodDict['is_string'] and not methodDict['is_bool'] and not methodDict['is_class'] and not methodDict['is_enum'] and methodDict['list_type'] == None
def is_linphone_type(self, _type, isArg, dllImport=True):
if type(_type) is AbsApi.ClassType:
if isinstance(_type, AbsApi.ClassType)
return False if dllImport else True
elif type(_type) is AbsApi.EnumType:
elif isinstance(_type, AbsApi.EnumType)
return False if dllImport else True
def throws_exception(self, return_type):
if type(return_type) is AbsApi.BaseType:
if isinstance(return_type, AbsApi.BaseType)
if return_type.name == 'status':
return True
return False
......@@ -111,7 +111,7 @@ class CsharpTranslator(object):
methodDict['is_enum'] = self.is_linphone_type(method.returnType, False, False) and type(method.returnType) is AbsApi.EnumType
methodDict['is_generic'] = self.is_generic(methodDict)
methodDict['takeRef'] = 'true'
if type(method.returnType.parent) is AbsApi.Method and len(method.returnType.parent.name.words) >=1:
if isinstance(method.returnType.parent, AbsApi.Method) and len(method.returnType.parent.name.words) >=1:
if method.returnType.parent.name.words == ['new'] or method.returnType.parent.name.words[0] == 'create':
methodDict['takeRef'] = 'false'
......@@ -122,7 +122,7 @@ class CsharpTranslator(object):
methodDict['impl']['args'] += ', '
methodDict['impl']['c_args'] += ', '
if self.is_linphone_type(arg.type, False, False):
if type(arg.type) is AbsApi.ClassType:
if isinstance(arg.type, AbsApi.ClassType)
argname = arg.name.translate(self.nameTranslator)
methodDict['impl']['c_args'] += argname + " != null ? " + argname + ".nativePtr : IntPtr.Zero"
else:
......@@ -168,7 +168,7 @@ class CsharpTranslator(object):
methodDict['is_enum'] = self.is_linphone_type(prop.returnType, False, False) and type(prop.returnType) is AbsApi.EnumType
methodDict['is_generic'] = self.is_generic(methodDict)
methodDict['takeRef'] = 'true'
if type(prop.returnType.parent) is AbsApi.Method and len(prop.returnType.parent.name.words) >=1:
if isinstance(prop.returnType.parent, AbsApi.Method) and len(prop.returnType.parent.name.words) >=1:
if prop.returnType.parent.name.words == ['new'] or prop.returnType.parent.name.words[0] == 'create':
methodDict['takeRef'] = 'false'
......@@ -278,7 +278,7 @@ class CsharpTranslator(object):
listenerDict['delegate']['params'] += "fromNativePtr<" + normalType + ">(" + argName + ")"
elif self.is_linphone_type(arg.type, True, dllImport=False) and type(arg.type) is AbsApi.EnumType:
listenerDict['delegate']['params'] += "(" + normalType + ")" + argName + ""
elif type(arg.type) is AbsApi.ListType:
elif isinstance(arg.type, AbsApi.ListType):
if normalType == "string":
listenerDict['delegate']['params'] += "MarshalStringArray(" + argName + ")"
else:
......
......@@ -148,7 +148,7 @@ class JavaTranslator(object):
def throws_exception(self, _type):
if not self.exceptions:
return False
if type(_type) is AbsApi.BaseType:
if isinstance(_type, AbsApi.BaseType):
if _type.name == 'status':
return True
return False
......@@ -280,11 +280,11 @@ class JavaTranslator(object):
return {'notEmpty': False}
if methodDict['hasListReturn']:
if type(_method.returnType) is AbsApi.BaseType and _method.returnType.name == 'string_array':
if isinstance(_method.returnType, AbsApi.BaseType) and _method.returnType.name == 'string_array':
methodDict['isStringObjectArray'] = True
elif type(_method.returnType.containedTypeDesc) is AbsApi.BaseType:
elif isinstance(_method.returnType.containedTypeDesc, AbsApi.BaseType):
methodDict['isStringObjectArray'] = True
elif type(_method.returnType.containedTypeDesc) is AbsApi.ClassType:
elif isinstance(_method.returnType.containedTypeDesc, AbsApi.ClassType):
methodDict['isRealObjectArray'] = True
methodDict['objectCPrefix'] = 'linphone_' + _method.returnType.containedTypeDesc.desc.name.to_snake_case()
methodDict['objectClassCName'] = 'Linphone' + _method.returnType.containedTypeDesc.desc.name.to_camel_case()
......@@ -310,24 +310,24 @@ class JavaTranslator(object):
methodDict['params'] += arg.translate(self.langTranslator, jni=True, namespace=namespace)
argname = arg.name.translate(self.nameTranslator)
if type(arg.type) is AbsApi.ClassType:
if isinstance(arg.type, AbsApi.ClassType):
classCName = 'Linphone' + arg.type.desc.name.to_camel_case()
if classCName[-8:] == 'Listener':
classCName = 'Linphone' + arg.type.desc.name.to_camel_case()[:-8] + 'Cbs'
methodDict['objects'].append({'object': argname, 'objectClassCName': classCName})
methodDict['params_impl'] += 'c_' + argname
elif type(arg.type) is AbsApi.ListType:
elif isinstance(arg.type, AbsApi.ListType):
isStringList = type(arg.type.containedTypeDesc) is AbsApi.BaseType and arg.type.containedTypeDesc.name == 'string'
isObjList = type(arg.type.containedTypeDesc) is AbsApi.ClassType
methodDict['lists'].append({'list': argname, 'isStringList': isStringList, 'isObjList': isObjList, 'objectClassCName': arg.type.containedTypeDesc.name})
methodDict['params_impl'] += 'bctbx_list_' + argname
elif type(arg.type) is AbsApi.EnumType:
elif isinstance(arg.type, AbsApi.EnumType):
argCType = arg.type.name
methodDict['params_impl'] += '(' + argCType + ') ' + argname
elif type(arg.type) is AbsApi.BaseType:
elif isinstance(arg.type, AbsApi.BaseType):
if arg.type.name == 'integer' and arg.type.size is not None and arg.type.isref:
methodDict['bytes'].append({'bytesargname': argname, 'bytesargtype' : arg.type.translate(self.clangTranslator)})
methodDict['params_impl'] += 'c_' + argname
......@@ -403,11 +403,11 @@ class JavaTranslator(object):
methodDict['jniUpcallMethod'] = 'CallVoidMethod'
methodDict['isJniUpcallBasicType'] = False
methodDict['isJniUpcallObject'] = False
if type(_method.returnType) is AbsApi.ClassType:
if isinstance(_method.returnType, AbsApi.ClassType):
methodDict['jniUpcallMethod'] = 'CallObjectMethod'
methodDict['isJniUpcallObject'] = True
methodDict['jniUpcallType'] = 'jobject'
elif type(_method.returnType) is AbsApi.BaseType:
elif isinstance(_method.returnType, AbsApi.BaseType):
if not _method.returnType.name == 'void':
methodDict['jniUpcallMethod'] = 'CallIntMethod'
methodDict['jniUpcallType'] = _method.returnType.translate(self.langTranslator, jni=True)
......@@ -434,22 +434,22 @@ class JavaTranslator(object):
methodDict['params'] += '{0} {1}'.format(arg.type.translate(self.clangTranslator), argname)
if type(arg.type) is AbsApi.ClassType:
if isinstance(arg.type, AbsApi.ClassType):
methodDict['jparams'] += 'L' + self.jni_path + arg.type.desc.name.to_camel_case() + ';'
methodDict['params_impl'] += 'j_' + argname
methodDict['jobjects'].append({'objectName': argname, 'className': arg.type.desc.name.to_camel_case(), })
elif type(arg.type) is AbsApi.BaseType:
elif isinstance(arg.type, AbsApi.BaseType):
methodDict['jparams'] += arg.type.translate(self.jnilangTranslator)
if arg.type.name == 'string':
methodDict['params_impl'] += 'j_' + argname
methodDict['jstrings'].append({'stringName': argname,})
else:
methodDict['params_impl'] += argname
elif type(arg.type) is AbsApi.EnumType:
elif isinstance(arg.type, AbsApi.EnumType):
methodDict['jparams'] += 'L' + self.jni_path + arg.type.desc.name.translate(self.jninameTranslator) + ';'
methodDict['params_impl'] += 'j_' + argname
methodDict['jenums'].append({'enumName': argname, 'cEnumPrefix': arg.type.desc.name.to_snake_case(fullName=True)})
elif type(arg.type) is AbsApi.ListType:
elif isinstance(arg.type, AbsApi.ListType):
methodDict['jparams'] += '[L' + self.jni_path + arg.type.containedTypeDesc.name + ';'
methodDict['params_impl'] += 'NULL'
......@@ -457,9 +457,9 @@ class JavaTranslator(object):
if (methodDict['return'] == 'void'):
methodDict['jparams'] += 'V'
else:
if type(_method.returnType) is AbsApi.ClassType:
if isinstance(_method.returnType, AbsApi.ClassType):
methodDict['jparams'] += 'L' + self.jni_path + _method.returnType.desc.name.to_camel_case() + ';'
elif type(_method.returnType) is AbsApi.BaseType:
elif isinstance(_method.returnType, AbsApi.BaseType):
methodDict['jparams'] += self.translate_java_jni_base_type_name(_method.returnType.name)
else:
pass #TODO
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment