pyjnius/jnius/jnius_utils.pxi

54 lines
1.4 KiB
Cython
Raw Normal View History

2012-08-20 07:35:14 +00:00
cdef parse_definition(definition):
# not a function, just a field
if definition[0] != '(':
return definition, None
# it's a function!
argdef, ret = definition[1:].split(')')
args = []
while len(argdef):
c = argdef[0]
# read the array char
prefix = ''
if c == '[':
prefix = c
argdef = argdef[1:]
c = argdef[0]
# native type
if c in 'ZBCSIJFD':
args.append(prefix + c)
argdef = argdef[1:]
continue
# java class
if c == 'L':
c, argdef = argdef.split(';', 1)
args.append(prefix + c + ';')
return ret, args
cdef void check_exception(JNIEnv *j_env) except *:
cdef jthrowable exc = j_env[0].ExceptionOccurred(j_env)
if exc:
j_env[0].ExceptionDescribe(j_env)
j_env[0].ExceptionClear(j_env)
raise JavaException('JVM exception occured')
cdef bytes lookup_java_object_name(JNIEnv *j_env, jobject j_obj):
from reflect import ensureclass, autoclass
ensureclass('java.lang.Object')
ensureclass('java.lang.Class')
cdef JavaClass obj = autoclass('java.lang.Object')(noinstance=True)
obj.instanciate_from(create_local_ref(j_env, j_obj))
cls = obj.getClass()
name = cls.getName()
ensureclass(name)
return name.replace('.', '/')