From: <cg...@us...> - 2008-11-23 23:46:15
|
Revision: 5623 http://jython.svn.sourceforge.net/jython/?rev=5623&view=rev Author: cgroves Date: 2008-11-23 23:46:11 +0000 (Sun, 23 Nov 2008) Log Message: ----------- Create the java proxy object after __init__ runs if it wasn't created by __init__ Modified Paths: -------------- branches/newstyle-java-types/src/org/python/core/PyArrayDerived.java branches/newstyle-java-types/src/org/python/core/PyBaseExceptionDerived.java branches/newstyle-java-types/src/org/python/core/PyBooleanDerived.java branches/newstyle-java-types/src/org/python/core/PyClassMethodDerived.java branches/newstyle-java-types/src/org/python/core/PyComplexDerived.java branches/newstyle-java-types/src/org/python/core/PyDictionaryDerived.java branches/newstyle-java-types/src/org/python/core/PyEnumerateDerived.java branches/newstyle-java-types/src/org/python/core/PyFileDerived.java branches/newstyle-java-types/src/org/python/core/PyFloatDerived.java branches/newstyle-java-types/src/org/python/core/PyFrozenSetDerived.java branches/newstyle-java-types/src/org/python/core/PyIntegerDerived.java branches/newstyle-java-types/src/org/python/core/PyJavaType.java branches/newstyle-java-types/src/org/python/core/PyListDerived.java branches/newstyle-java-types/src/org/python/core/PyLongDerived.java branches/newstyle-java-types/src/org/python/core/PyModuleDerived.java branches/newstyle-java-types/src/org/python/core/PyObject.java branches/newstyle-java-types/src/org/python/core/PyObjectDerived.java branches/newstyle-java-types/src/org/python/core/PyPropertyDerived.java branches/newstyle-java-types/src/org/python/core/PySetDerived.java branches/newstyle-java-types/src/org/python/core/PySliceDerived.java branches/newstyle-java-types/src/org/python/core/PyStringDerived.java branches/newstyle-java-types/src/org/python/core/PySuperDerived.java branches/newstyle-java-types/src/org/python/core/PyTupleDerived.java branches/newstyle-java-types/src/org/python/core/PyTypeDerived.java branches/newstyle-java-types/src/org/python/core/PyUnicodeDerived.java branches/newstyle-java-types/src/org/python/modules/_collections/PyDefaultDictDerived.java branches/newstyle-java-types/src/org/python/modules/_collections/PyDequeDerived.java branches/newstyle-java-types/src/org/python/modules/_csv/PyDialectDerived.java branches/newstyle-java-types/src/org/python/modules/_functools/PyPartialDerived.java branches/newstyle-java-types/src/org/python/modules/_weakref/ReferenceTypeDerived.java branches/newstyle-java-types/src/org/python/modules/random/PyRandomDerived.java branches/newstyle-java-types/src/org/python/modules/thread/PyLocalDerived.java branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporterDerived.java branches/newstyle-java-types/src/templates/object.derived Modified: branches/newstyle-java-types/src/org/python/core/PyArrayDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyArrayDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyArrayDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyBaseExceptionDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyBaseExceptionDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyBaseExceptionDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1069,6 +1069,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyBooleanDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyBooleanDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyBooleanDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyClassMethodDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyClassMethodDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyClassMethodDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyComplexDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyComplexDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyComplexDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyDictionaryDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyDictionaryDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyDictionaryDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyEnumerateDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyEnumerateDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyEnumerateDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyFileDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyFileDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyFileDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyFloatDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyFloatDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyFloatDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyFrozenSetDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyFrozenSetDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyFrozenSetDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyIntegerDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyIntegerDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyIntegerDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyJavaType.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -29,7 +29,7 @@ @Override public Class<?> getProxyType() { - return underlying_class; + return PyObject.class.isAssignableFrom(underlying_class) ? null : underlying_class; } @Override Modified: branches/newstyle-java-types/src/org/python/core/PyListDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyListDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyListDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyLongDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyLongDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyLongDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyModuleDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyModuleDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyModuleDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1069,6 +1069,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyObject.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -101,8 +101,48 @@ * Dispatch __init__ behavior */ public void dispatch__init__(PyType type,PyObject[] args,String[] keywords) { + proxyInit(); } + /** + * Attempts to automatically initialize our Java proxy if we have one and it wasn't initialized + * by our __init__. + */ + protected void proxyInit() { + if (javaProxy != null || getType().getProxyType() == null) { + return; + } + Class<?> c = getType().getProxyType(); + PyProxy proxy; + ThreadState ts = Py.getThreadState(); + try { + ts.pushInitializingProxy(this); + try { + proxy = (PyProxy)c.newInstance(); + } catch (java.lang.InstantiationException e) { + Class<?> sup = c.getSuperclass(); + String msg = "Default constructor failed for Java superclass"; + if (sup != null) { + msg += " " + sup.getName(); + } + throw Py.TypeError(msg); + } catch (NoSuchMethodError nsme) { + throw Py.TypeError("constructor requires arguments"); + } catch (Exception exc) { + throw Py.JavaError(exc); + } + } finally { + ts.popInitializingProxy(); + } + if (javaProxy != null && javaProxy != proxy) { + throw Py.TypeError("Proxy instance already initialized"); + } + PyObject proxyInstance = proxy._getPyInstance(); + if (proxyInstance != null && proxyInstance != this) { + throw Py.TypeError("Proxy initialized with another instance"); + } + javaProxy = proxy; + } /** * Equivalent to the standard Python __repr__ method. This method Modified: branches/newstyle-java-types/src/org/python/core/PyObjectDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyObjectDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyObjectDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyPropertyDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyPropertyDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyPropertyDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PySetDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PySetDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PySetDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PySliceDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PySliceDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PySliceDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyStringDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyStringDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyStringDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PySuperDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PySuperDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PySuperDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyTupleDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyTupleDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyTupleDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyTypeDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyTypeDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyTypeDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1069,6 +1069,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyUnicodeDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyUnicodeDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/core/PyUnicodeDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1093,6 +1093,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_collections/PyDefaultDictDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_collections/PyDefaultDictDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/_collections/PyDefaultDictDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1095,6 +1095,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_collections/PyDequeDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_collections/PyDequeDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/_collections/PyDequeDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1095,6 +1095,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_csv/PyDialectDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_csv/PyDialectDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/_csv/PyDialectDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1071,6 +1071,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_functools/PyPartialDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_functools/PyPartialDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/_functools/PyPartialDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1071,6 +1071,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_weakref/ReferenceTypeDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1095,6 +1095,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/random/PyRandomDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/random/PyRandomDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/random/PyRandomDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1095,6 +1095,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/thread/PyLocalDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/thread/PyLocalDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/thread/PyLocalDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1071,6 +1071,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporterDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporterDerived.java 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporterDerived.java 2008-11-23 23:46:11 UTC (rev 5623) @@ -1071,6 +1071,7 @@ } } } + proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/templates/object.derived =================================================================== --- branches/newstyle-java-types/src/templates/object.derived 2008-11-23 23:12:46 UTC (rev 5622) +++ branches/newstyle-java-types/src/templates/object.derived 2008-11-23 23:46:11 UTC (rev 5623) @@ -428,6 +428,7 @@ } } } + proxyInit(); } public PyObject __index__() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-11-29 00:17:45
|
Revision: 5658 http://jython.svn.sourceforge.net/jython/?rev=5658&view=rev Author: cgroves Date: 2008-11-29 00:17:40 +0000 (Sat, 29 Nov 2008) Log Message: ----------- Only attempt proxyInitting if __init__ has been found and worked, and only actually init instances of PyProxy. Add an __init__ for all Java classes, even interfaces and abstract classes. Handle throwing type errors for uninstantiable classes in PyReflectedConstructor. Pass _is and _isnot through to the javaproxy == if javaproxy is around. This assumes a constant mapping between a given Java type and the PyType wrapping it, but I think that's safe. Modified Paths: -------------- branches/newstyle-java-types/src/org/python/core/Py.java branches/newstyle-java-types/src/org/python/core/PyArrayDerived.java branches/newstyle-java-types/src/org/python/core/PyBaseExceptionDerived.java branches/newstyle-java-types/src/org/python/core/PyBooleanDerived.java branches/newstyle-java-types/src/org/python/core/PyClassMethodDerived.java branches/newstyle-java-types/src/org/python/core/PyComplexDerived.java branches/newstyle-java-types/src/org/python/core/PyDictionaryDerived.java branches/newstyle-java-types/src/org/python/core/PyEnumerateDerived.java branches/newstyle-java-types/src/org/python/core/PyFileDerived.java branches/newstyle-java-types/src/org/python/core/PyFloatDerived.java branches/newstyle-java-types/src/org/python/core/PyFrozenSetDerived.java branches/newstyle-java-types/src/org/python/core/PyIntegerDerived.java branches/newstyle-java-types/src/org/python/core/PyJavaType.java branches/newstyle-java-types/src/org/python/core/PyListDerived.java branches/newstyle-java-types/src/org/python/core/PyLongDerived.java branches/newstyle-java-types/src/org/python/core/PyModuleDerived.java branches/newstyle-java-types/src/org/python/core/PyObject.java branches/newstyle-java-types/src/org/python/core/PyObjectDerived.java branches/newstyle-java-types/src/org/python/core/PyPropertyDerived.java branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java branches/newstyle-java-types/src/org/python/core/PyReflectedFunction.java branches/newstyle-java-types/src/org/python/core/PySetDerived.java branches/newstyle-java-types/src/org/python/core/PySliceDerived.java branches/newstyle-java-types/src/org/python/core/PyStringDerived.java branches/newstyle-java-types/src/org/python/core/PySuperDerived.java branches/newstyle-java-types/src/org/python/core/PyTupleDerived.java branches/newstyle-java-types/src/org/python/core/PyTypeDerived.java branches/newstyle-java-types/src/org/python/core/PyUnicodeDerived.java branches/newstyle-java-types/src/org/python/modules/_collections/PyDefaultDictDerived.java branches/newstyle-java-types/src/org/python/modules/_collections/PyDequeDerived.java branches/newstyle-java-types/src/org/python/modules/_csv/PyDialectDerived.java branches/newstyle-java-types/src/org/python/modules/_functools/PyPartialDerived.java branches/newstyle-java-types/src/org/python/modules/_weakref/ReferenceTypeDerived.java branches/newstyle-java-types/src/org/python/modules/random/PyRandomDerived.java branches/newstyle-java-types/src/org/python/modules/thread/PyLocalDerived.java branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporterDerived.java branches/newstyle-java-types/src/templates/object.derived Removed Paths: ------------- branches/newstyle-java-types/src/org/python/core/CollectionIter.java Deleted: branches/newstyle-java-types/src/org/python/core/CollectionIter.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/CollectionIter.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/CollectionIter.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1,31 +0,0 @@ -// Copyright (c) Finn Bock -package org.python.core; - -import java.util.Enumeration; -import java.util.Iterator; - -class EnumerationIter extends PyIterator { - - private Enumeration<Object> proxy; - - public EnumerationIter(Enumeration<Object> proxy) { - this.proxy = proxy; - } - - public PyObject __iternext__() { - return proxy.hasMoreElements() ? Py.java2py(proxy.nextElement()) : null; - } -} - -class IteratorIter extends PyIterator { - - private Iterator<Object> proxy; - - public IteratorIter(Iterator<Object> proxy) { - this.proxy = proxy; - } - - public PyObject __iternext__() { - return proxy.hasNext() ? Py.java2py(proxy.next()) : null; - } -} Modified: branches/newstyle-java-types/src/org/python/core/Py.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/Py.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/Py.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -16,7 +16,6 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; -import java.util.HashSet; import java.util.Set; import org.python.antlr.ast.modType; @@ -24,6 +23,7 @@ import org.python.core.adapter.ClassicPyObjectAdapter; import org.python.core.adapter.ExtensiblePyObjectAdapter; import org.python.modules.errno; +import org.python.util.Generic; public final class Py { @@ -81,12 +81,13 @@ public static long TPFLAGS_HEAPTYPE; /** Builtin types that are used to setup PyObject. */ - static final Set<Class<?>> BOOTSTRAP_TYPES = new HashSet<Class<?>>(4); + static final Set<Class<?>> BOOTSTRAP_TYPES = Generic.set(); static { BOOTSTRAP_TYPES.add(PyObject.class); BOOTSTRAP_TYPES.add(PyType.class); BOOTSTRAP_TYPES.add(PyBuiltinCallable.class); BOOTSTRAP_TYPES.add(PyDataDescr.class); + BOOTSTRAP_TYPES.add(PyMethodDescr.class); } /** A unique object to indicate no conversion is possible Modified: branches/newstyle-java-types/src/org/python/core/PyArrayDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyArrayDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyArrayDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyBaseExceptionDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyBaseExceptionDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyBaseExceptionDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1067,9 +1067,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyBooleanDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyBooleanDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyBooleanDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyClassMethodDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyClassMethodDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyClassMethodDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyComplexDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyComplexDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyComplexDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyDictionaryDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyDictionaryDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyDictionaryDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyEnumerateDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyEnumerateDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyEnumerateDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyFileDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyFileDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyFileDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyFloatDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyFloatDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyFloatDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyFrozenSetDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyFrozenSetDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyFrozenSetDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyIntegerDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyIntegerDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyIntegerDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyJavaType.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -6,6 +6,8 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Collection; +import java.util.Enumeration; +import java.util.Iterator; import java.util.List; import java.util.Map; import org.python.core.util.StringUtil; @@ -137,27 +139,25 @@ } dict.__setitem__(prop.__name__, prop); } - Constructor<?>[] ctrs = underlying_class.getConstructors(); - if (ctrs.length != 0) { - final PyReflectedConstructor reflctr = new PyReflectedConstructor("_new_impl"); - for (Constructor<?> ctr : ctrs) { - reflctr.addConstructor(ctr); - } - if (PyObject.class.isAssignableFrom(underlying_class)) { - PyObject new_ = new PyNewWrapper(underlying_class, "__new__", -1, -1) { - public PyObject new_impl(boolean init, - PyType subtype, - PyObject[] args, - String[] keywords) { - return reflctr.make(args, keywords); - } - }; - dict.__setitem__("__new__", new_); - } else { - dict.__setitem__("__init__", reflctr); - } + final PyReflectedConstructor reflctr = new PyReflectedConstructor("_new_impl"); + for (Constructor<?> ctr : underlying_class.getConstructors()) { + reflctr.addConstructor(ctr); } + if (PyObject.class.isAssignableFrom(underlying_class)) { + PyObject new_ = new PyNewWrapper(underlying_class, "__new__", -1, -1) { + + public PyObject new_impl(boolean init, + PyType subtype, + PyObject[] args, + String[] keywords) { + return reflctr.make(args, keywords); + } + }; + dict.__setitem__("__new__", new_); + } else { + dict.__setitem__("__init__", reflctr); + } for (Class<?> inner : underlying_class.getClasses()) { dict.__setitem__(inner.getSimpleName(), PyType.fromClass(inner)); } @@ -292,7 +292,33 @@ } } }; + class EnumerationIter extends PyIterator { + private Enumeration<Object> proxy; + + public EnumerationIter(Enumeration<Object> proxy) { + this.proxy = proxy; + } + + public PyObject __iternext__() { + return proxy.hasMoreElements() ? Py.java2py(proxy.nextElement()) : null; + } + } + + private static class IteratorIter extends PyIterator { + + private Iterator<Object> proxy; + + public IteratorIter(Iterator<Object> proxy) { + this.proxy = proxy; + } + + public PyObject __iternext__() { + return proxy.hasNext() ? Py.java2py(proxy.next()) : null; + } + } + + private static final PyBuiltinMethodNarrow ITERABLE_PROXY = new PyBuiltinMethodNarrow("__iter__", 0, 0) { public PyObject __call__() { Modified: branches/newstyle-java-types/src/org/python/core/PyListDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyListDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyListDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyLongDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyLongDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyLongDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyModuleDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyModuleDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyModuleDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1067,9 +1067,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyObject.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -2,7 +2,6 @@ package org.python.core; import java.io.Serializable; -import java.lang.reflect.Modifier; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Iterator; @@ -103,9 +102,7 @@ /** * Dispatch __init__ behavior */ - public void dispatch__init__(PyType type,PyObject[] args,String[] keywords) { - proxyInit(); - } + public void dispatch__init__(PyType type, PyObject[] args, String[] keywords) {} /** * Attempts to automatically initialize our Java proxy if we have one and it wasn't initialized @@ -116,11 +113,8 @@ if (javaProxy != null || c == null) { return; } - int mods = c.getModifiers(); - if (Modifier.isInterface(mods)) { - throw Py.TypeError("can't instantiate interface (" + c.getName() + ")"); - } else if (Modifier.isAbstract(mods)) { - throw Py.TypeError("can't instantiate abstract class (" + c.getName() + ")"); + if (!PyProxy.class.isAssignableFrom(c)) { + throw Py.SystemError("Automatic proxy initialization should only occur on proxy classes"); } PyProxy proxy; ThreadState ts = Py.getThreadState(); @@ -1579,7 +1573,7 @@ * @return the result of the comparison **/ public PyObject _is(PyObject o) { - return this == o ? Py.True : Py.False; + return this == o || (javaProxy != null && javaProxy == o.javaProxy) ? Py.True : Py.False; } /** @@ -1589,7 +1583,7 @@ * @return the result of the comparison **/ public PyObject _isnot(PyObject o) { - return this != o ? Py.True : Py.False; + return this != o || javaProxy != o.javaProxy ? Py.True : Py.False; } /** Modified: branches/newstyle-java-types/src/org/python/core/PyObjectDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyObjectDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyObjectDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -712,7 +712,7 @@ if (impl!=null) { PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyInteger||res instanceof PyLong) - return(PyObject)res; + return res; throw Py.TypeError("__int__"+" should return an integer"); } return super.__int__(); @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyPropertyDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyPropertyDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyPropertyDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -10,53 +10,48 @@ public PyReflectedConstructor(String name) { super(name); - __name__ = name; - argslist = new ReflectedArgs[1]; - nargs = 0; } - public PyReflectedConstructor(Constructor c) { + public PyReflectedConstructor(Constructor<?> c) { this(c.getDeclaringClass().getName()); addConstructor(c); } - private ReflectedArgs makeArgs(Constructor m) { + private ReflectedArgs makeArgs(Constructor<?> m) { return new ReflectedArgs(m, m.getParameterTypes(), m.getDeclaringClass(), true); } - public void addConstructor(Constructor m) { + public void addConstructor(Constructor<?> m) { int mods = m.getModifiers(); // Only add public methods unless we're overriding - if (!Modifier.isPublic(mods) && Options.respectJavaAccessibility) + if (!Modifier.isPublic(mods) && Options.respectJavaAccessibility) { return; + } addArgs(makeArgs(m)); } // xxx temporary solution, type ctr will go through __new__ ... PyObject make(PyObject[] args, String[] keywords) { - ReflectedArgs[] argsl = argslist; ReflectedCallData callData = new ReflectedCallData(); Object method = null; boolean consumes_keywords = false; - int nkeywords = keywords.length; PyObject[] allArgs = null; // Check for a matching constructor to call if (nargs > 0) { // PyArgsKeywordsCall signature, if present, is the first - if (argsl[0].matches(null, args, keywords, callData)) { - method = argsl[0].data; - consumes_keywords = argsl[0].flags == ReflectedArgs.PyArgsKeywordsCall; + if (argslist[0].matches(null, args, keywords, callData)) { + method = argslist[0].data; + consumes_keywords = argslist[0].flags == ReflectedArgs.PyArgsKeywordsCall; } else { allArgs = args; int i = 1; - if (nkeywords > 0) { - args = new PyObject[allArgs.length - nkeywords]; + if (keywords.length > 0) { + args = new PyObject[allArgs.length - keywords.length]; System.arraycopy(allArgs, 0, args, 0, args.length); i = 0; } for (; i < nargs; i++) { - ReflectedArgs rargs = argsl[i]; - if (rargs.matches(null, args, Py.NoKeywords, callData)) { - method = rargs.data; + if (argslist[i].matches(null, args, Py.NoKeywords, callData)) { + method = argslist[i].data; break; } } @@ -67,7 +62,7 @@ throwError(callData.errArg, args.length, true /* xxx? */, false); } // Do the actual constructor call - PyObject obj = null; + PyObject obj; try { obj = (PyObject)((Constructor<?>)method).newInstance(callData.getArgsArray()); } catch (Throwable t) { @@ -75,7 +70,7 @@ } if (!consumes_keywords) { int offset = args.length; - for (int i = 0; i < nkeywords; i++) { + for (int i = 0; i < keywords.length; i++) { obj.__setattr__(keywords[i], allArgs[i + offset]); } } @@ -87,12 +82,13 @@ throw Py.TypeError("invalid self argument to constructor"); } Class<?> javaClass = self.getType().getProxyType(); - + if (nargs == 0) { + throw Py.TypeError("No visible constructors for class (" + javaClass.getName() + ")"); + } Class<?> declaringClass = argslist[0].declaringClass; if (!declaringClass.isAssignableFrom(javaClass)) { throw Py.TypeError("self invalid - must implement: " + declaringClass.getName()); } - // If the declaring class is a pure Java type but we're instantiating a Python proxy, // grab the proxy version of the constructor to instantiate the proper type if (!PyProxy.class.isAssignableFrom(declaringClass) @@ -100,6 +96,12 @@ return PyType.fromClass(javaClass).lookup("__init__").__call__(self, args, keywords); } + int mods = declaringClass.getModifiers(); + if (Modifier.isInterface(mods)) { + throw Py.TypeError("can't instantiate interface (" + declaringClass.getName() + ")"); + } else if (Modifier.isAbstract(mods)) { + throw Py.TypeError("can't instantiate abstract class (" + declaringClass.getName() + ")"); + } if (self.javaProxy != null) { Class<?> sup = javaClass; if (PyProxy.class.isAssignableFrom(sup)) { @@ -131,7 +133,6 @@ } // Do the actual constructor call constructProxy(self, (Constructor<?>)method, callData.getArgsArray(), javaClass); - // Do setattr's for keyword args int offset = args.length; for (int i = 0; i < nkeywords; i++) { Modified: branches/newstyle-java-types/src/org/python/core/PyReflectedFunction.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyReflectedFunction.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyReflectedFunction.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -7,23 +7,28 @@ import org.python.util.Generic; +public class PyReflectedFunction extends PyObject { -public class PyReflectedFunction extends PyObject -{ public String __name__; + public PyObject __doc__ = Py.None; - public ReflectedArgs[] argslist; + + public ReflectedArgs[] argslist = new ReflectedArgs[1]; + public int nargs; - public PyReflectedFunction(String name) { + protected PyReflectedFunction(String name) { __name__ = name; - argslist = new ReflectedArgs[1]; - nargs = 0; } public PyReflectedFunction(Method method) { this(method.getName()); addMethod(method); + if (nargs == 0) { + String msg = String.format("Attempted to make Java method visible, but it isn't " + + "callable[method=%s, class=%s]", method.getName(), method.getDeclaringClass()); + throw Py.SystemError(msg); + } } public PyObject _doget(PyObject container) { @@ -31,13 +36,14 @@ } public PyObject _doget(PyObject container, PyObject wherefound) { - if (container == null) + if (container == null) { return this; + } return new PyMethod(this, container, wherefound); } public boolean _doset(PyObject container) { - throw Py.TypeError("java function not settable: "+__name__); + throw Py.TypeError("java function not settable: " + __name__); } public PyObject getDoc() { @@ -45,7 +51,8 @@ } private ReflectedArgs makeArgs(Method m) { - return new ReflectedArgs(m, m.getParameterTypes(), + return new ReflectedArgs(m, + m.getParameterTypes(), m.getDeclaringClass(), Modifier.isStatic(m.getModifiers())); } @@ -64,63 +71,54 @@ } protected boolean handles(ReflectedArgs args) { - ReflectedArgs[] argsl = argslist; - int n = nargs; - for(int i=0; i<n; i++) { - int cmp = args.compareTo(argsl[i]); - if (cmp == 0) + for (int i = 0; i < nargs; i++) { + int cmp = args.compareTo(argslist[i]); + if (cmp == 0) { return true; - if (cmp == +1) + } else if (cmp == 1) { return false; + } } return false; } public void addMethod(Method m) { - int mods = m.getModifiers(); // Only add public methods unless we're overriding - if (!Modifier.isPublic(mods) && Options.respectJavaAccessibility) + if (!Modifier.isPublic(m.getModifiers()) && Options.respectJavaAccessibility) { return; + } addArgs(makeArgs(m)); } protected void addArgs(ReflectedArgs args) { - ReflectedArgs[] argsl = argslist; - int n = nargs; int i; - for(i=0; i<n; i++) { - int cmp = args.compareTo(argsl[i]); - if (cmp == 0) + for (i = 0; i < nargs; i++) { + int cmp = args.compareTo(argslist[i]); + if (cmp == 0) { return; - if (cmp == ReflectedArgs.REPLACE) { - argsl[i] = args; + } else if (cmp == ReflectedArgs.REPLACE) { + argslist[i] = args; return; - } - if (cmp == -1) + } else if (cmp == -1) { break; + } } - - int nn = n+1; - if (nn > argsl.length) { - argsl = new ReflectedArgs[nn+2]; - System.arraycopy(argslist, 0, argsl, 0, n); - argslist = argsl; + int nn = nargs + 1; + if (nn > argslist.length) { + ReflectedArgs[] newargslist = new ReflectedArgs[nn + 2]; + System.arraycopy(argslist, 0, newargslist, 0, nargs); + argslist = newargslist; } - - for(int j=n; j>i; j--) { - argsl[j] = argsl[j-1]; + for (int j = nargs; j > i; j--) { + argslist[j] = argslist[j - 1]; } - - argsl[i] = args; + argslist[i] = args; nargs = nn; } - public PyObject __call__(PyObject self, PyObject[] args, - String[] keywords) - { + public PyObject __call__(PyObject self, PyObject[] args, String[] keywords) { ReflectedCallData callData = new ReflectedCallData(); Object method = null; - ReflectedArgs[] argsl = argslist; int n = nargs; for (int i = 0; i < n; i++) { @@ -132,19 +130,17 @@ } } if (method == null) { - throwError(callData.errArg, args.length, self != null, - keywords.length != 0); + throwError(callData.errArg, args.length, self != null, keywords.length != 0); } - Object cself = callData.self; Method m = (Method)method; + Object o; try { - - Object o = m.invoke(cself, callData.getArgsArray()); - return Py.java2py(o); + o = m.invoke(cself, callData.getArgsArray()); } catch (Throwable t) { throw Py.JavaError(t); } + return Py.java2py(o); } public PyObject __call__(PyObject[] args, String[] keywords) { @@ -152,59 +148,49 @@ } // A bunch of code to make error handling prettier - - protected void throwError(String message) { - throw Py.TypeError(__name__+"(): "+message); + throw Py.TypeError(__name__ + "(): " + message); } - private static void addRange(StringBuffer buf, int min, int max, - String sep) - { + private static void addRange(StringBuilder buf, int min, int max, String sep) { if (buf.length() > 0) { buf.append(sep); } if (min < max) { - buf.append(Integer.toString(min)+"-"+max); + buf.append(Integer.toString(min)).append('-').append(max); } else { buf.append(min); } } - protected void throwArgCountError(int nArgs, boolean self) { // Assume no argument lengths greater than 40... boolean[] legalArgs = new boolean[40]; int maxArgs = -1; int minArgs = 40; - - ReflectedArgs[] argsl = argslist; - int n = nargs; - for (int i=0; i<n; i++) { - ReflectedArgs rargs = argsl[i]; - + for (int i = 0; i < nargs; i++) { + ReflectedArgs rargs = argslist[i]; int l = rargs.args.length; if (!self && !rargs.isStatic) { l += 1; } - legalArgs[l] = true; - if (l > maxArgs) + if (l > maxArgs) { maxArgs = l; - if (l < minArgs) + } + if (l < minArgs) { minArgs = l; + } } - - StringBuffer buf = new StringBuffer(); - + StringBuilder buf = new StringBuilder(); int startRange = minArgs; - int a = minArgs+1; + int a = minArgs + 1; while (a < maxArgs) { if (legalArgs[a]) { a++; continue; } else { - addRange(buf, startRange, a-1, ", "); + addRange(buf, startRange, a - 1, ", "); a++; while (a <= maxArgs) { if (legalArgs[a]) { @@ -216,21 +202,21 @@ } } addRange(buf, startRange, maxArgs, " or "); - throwError("expected "+buf+" args; got "+nArgs); + throwError("expected " + buf + " args; got " + nArgs); } private static String ordinal(int n) { - switch(n+1) { - case 0: - return "self"; - case 1: - return "1st"; - case 2: - return "2nd"; - case 3: - return "3rd"; - default: - return Integer.toString(n+1)+"th"; + switch(n + 1){ + case 0: + return "self"; + case 1: + return "1st"; + case 2: + return "2nd"; + case 3: + return "3rd"; + default: + return Integer.toString(n + 1) + "th"; } } @@ -239,7 +225,7 @@ return "String"; } if (arg.isArray()) { - return niceName(arg.getComponentType())+"[]"; + return niceName(arg.getComponentType()) + "[]"; } return arg.getName(); } @@ -264,10 +250,9 @@ buf.append(niceName(arg)); buf.append(", "); } - if(buf.length() > 2) { + if (buf.length() > 2) { buf.setLength(buf.length() - 2); } - throwError(ordinal(errArg) + " arg can't be coerced to " + buf); } @@ -283,16 +268,15 @@ // Included only for debugging purposes... public void printArgs() { - System.err.println("nargs: "+nargs); - for(int i=0; i<nargs; i++) { + System.err.println("nargs: " + nargs); + for (int i = 0; i < nargs; i++) { ReflectedArgs args = argslist[i]; System.err.println(args.toString()); } } - public String toString() { - //printArgs(); - return "<java function "+__name__+" "+Py.idstr(this)+">"; + // printArgs(); + return "<java function " + __name__ + " " + Py.idstr(this) + ">"; } } Modified: branches/newstyle-java-types/src/org/python/core/PySetDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PySetDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PySetDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PySliceDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PySliceDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PySliceDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyStringDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyStringDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyStringDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PySuperDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PySuperDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PySuperDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyTupleDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyTupleDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyTupleDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyTypeDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyTypeDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyTypeDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1067,9 +1067,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/core/PyUnicodeDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyUnicodeDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/core/PyUnicodeDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1091,9 +1091,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_collections/PyDefaultDictDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_collections/PyDefaultDictDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/modules/_collections/PyDefaultDictDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1093,9 +1093,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_collections/PyDequeDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_collections/PyDequeDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/modules/_collections/PyDequeDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1093,9 +1093,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_csv/PyDialectDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_csv/PyDialectDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/modules/_csv/PyDialectDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1069,9 +1069,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_functools/PyPartialDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_functools/PyPartialDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/modules/_functools/PyPartialDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1069,9 +1069,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/_weakref/ReferenceTypeDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1093,9 +1093,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/random/PyRandomDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/random/PyRandomDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/modules/random/PyRandomDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1093,9 +1093,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/thread/PyLocalDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/thread/PyLocalDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/modules/thread/PyLocalDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1069,9 +1069,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporterDerived.java =================================================================== --- branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporterDerived.java 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporterDerived.java 2008-11-29 00:17:40 UTC (rev 5658) @@ -1069,9 +1069,9 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { Modified: branches/newstyle-java-types/src/templates/object.derived =================================================================== --- branches/newstyle-java-types/src/templates/object.derived 2008-11-28 21:53:04 UTC (rev 5657) +++ branches/newstyle-java-types/src/templates/object.derived 2008-11-29 00:17:40 UTC (rev 5658) @@ -426,9 +426,9 @@ throw Py.TypeError(String.format("__init__() should return None, not '%.200s'", res.getType().fastGetName())); } + proxyInit(); } } - proxyInit(); } public PyObject __index__() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |