Support to map getters to properties.

This commit is contained in:
Benson Margulies 2015-04-30 16:13:16 -04:00
parent 6d91a2fe62
commit 0c86904ede
1 changed files with 9 additions and 1 deletions

View File

@ -137,6 +137,11 @@ def ensureclass(clsname):
registers.append(clsname) registers.append(clsname)
autoclass(clsname) autoclass(clsname)
def lower_name(s):
return s[:1].lower() + s[1:] if s else ''
def bean_getter(s):
return (s.startswith('get') and len(s) > 3 and s[3].isupper()) or (s.startswith('is') and len(s) > 2 and s[2].isupper())
def autoclass(clsname): def autoclass(clsname):
jniname = clsname.replace('.', '/') jniname = clsname.replace('.', '/')
@ -176,9 +181,12 @@ def autoclass(clsname):
get_signature(method.getReturnType())) get_signature(method.getReturnType()))
cls = JavaStaticMethod if static else JavaMethod cls = JavaStaticMethod if static else JavaMethod
classDict[name] = cls(sig, varargs=varargs) classDict[name] = cls(sig, varargs=varargs)
if name != 'getClass' and bean_getter(name) and len(method.getParameterTypes()) == 0:
lowername = lower_name(name[3:])
classDict[lowername] = (lambda n: property(lambda self: getattr(self, n)()))(name)
continue continue
# multpile signatures # multiple signatures
signatures = [] signatures = []
for index, subname in enumerate(methods_name): for index, subname in enumerate(methods_name):
if subname != name: if subname != name: