# HG changeset patch # User Paul Boddie # Date 1105397564 -3600 # Node ID 2420bedaf1848aa5c84283c4083b8f9435015544 # Parent 0b546623231ea99440fccf5faa9513a2ea155658 Moved the lang module contents into the lang package. Fixed various java.lang and java.io circular imports by introducing a java.lang._object module. Corrected various base classes (object -> java.lang.Object, Exception -> java.lang.Exception) and fixed raising of exceptions in certain cases. Added reflection capabilities. diff -r 0b546623231e -r 2420bedaf184 java/lang/reflect.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/lang/reflect.py Mon Jan 10 23:52:44 2005 +0100 @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +import java.lang + +class Class(java.lang.Object): + def __init__(self, obj): + self.obj = obj + + def getMethod(self, name, parameterTypes): + + """ + Find the method on this class with the given 'name' and + 'parameterTypes'. Return a Method object. + + Note that this implementation remembers which object was used to obtain + this class. This allows the Method objects to be called in Python. + """ + + # Build the Python name. + + types = [] + for parameterType in parameterTypes: + types.append("__".join(parameterType.split("."))) + method_name = unicode(name) + "___" + "___".join(types) + + # Either return a Method object or raise the appropriate exception. + try: + return Method(getattr(self.obj, method_name)) + except AttributeError: + raise Exception, java.lang.NoSuchMethodException(name) + + getMethod___java__lang__String___java__lang__Class_array_ = getMethod + +class Method(java.lang.Object): + def __init__(self, method): + self.method = method + + def __call__(self, *args): + return self.method(*args) + +# vim: tabstop=4 expandtab shiftwidth=4