From: <cg...@us...> - 2009-01-26 00:33:27
|
Revision: 5979 http://jython.svn.sourceforge.net/jython/?rev=5979&view=rev Author: cgroves Date: 2009-01-26 00:33:21 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Include Python Java subclasses as bases as well as the Java proxy type, as it may have additional methods in its Python. Return the proxyClass directly from getProxyType as we're setting that on Python subclasses now. Modified Paths: -------------- trunk/jython/Lib/test/test_java_subclasses.py trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyType.java trunk/jython/tests/java/org/python/tests/Coercions.java Modified: trunk/jython/Lib/test/test_java_subclasses.py =================================================================== --- trunk/jython/Lib/test/test_java_subclasses.py 2009-01-25 21:06:04 UTC (rev 5978) +++ trunk/jython/Lib/test/test_java_subclasses.py 2009-01-26 00:33:21 UTC (rev 5979) @@ -12,7 +12,7 @@ from java.awt import Color, Component, Dimension, Rectangle from javax.swing.table import AbstractTableModel -from org.python.tests import BeanInterface, Callbacker +from org.python.tests import BeanInterface, Callbacker, Coercions class InterfaceTest(unittest.TestCase): def test_java_calling_python_interface_implementation(self): @@ -117,16 +117,27 @@ pass def test_multilevel_override(self): - class SubDate(Date): - def toString(self): - s = Date.toString(self) - return 'SubDate -> Date' + runs = [] + class SubDate(Date): + def run(self): + runs.append("SubDate") - class SubSubDate(SubDate): + def method(self): + return "SubDateMethod" + + def toString(self): + s = Date.toString(self) + return 'SubDate -> Date' + + class SubSubDate(SubDate, Runnable): def toString(self): return 'SubSubDate -> ' + SubDate.toString(self) + self.assertEquals("SubDate -> Date", SubDate().toString()) self.assertEquals("SubSubDate -> SubDate -> Date", SubSubDate().toString()) + self.assertEquals("SubDateMethod", SubSubDate().method()) + Coercions.runRunnable(SubSubDate()) + self.assertEquals(["SubDate"], runs) def test_passthrough(self): class CallbackPassthrough(Callbacker.Callback): Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-01-25 21:06:04 UTC (rev 5978) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-01-26 00:33:21 UTC (rev 5979) @@ -58,11 +58,6 @@ super(TYPE == null ? fromClass(PyType.class) : TYPE); } - @Override - public Class<?> getProxyType() { - return (Class<?>)javaProxy; - } - // Java types are ok with things being added and removed from their dicts as long as there isn't // something there, so let these checks through @Override Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-01-25 21:06:04 UTC (rev 5978) +++ trunk/jython/src/org/python/core/PyType.java 2009-01-26 00:33:21 UTC (rev 5979) @@ -191,13 +191,24 @@ List<PyObject> cleanedBases = Generic.list(); boolean addedProxyType = false; for (PyObject base : bases_list) { - if (base instanceof PyJavaType) { - if (!addedProxyType) { + if (!(base instanceof PyType)) { + cleanedBases.add(base); + continue; + } + Class<?> proxy = ((PyType)base).getProxyType(); + if (proxy == null) { + cleanedBases.add(base);// non-proxy types go straight into our lookup + } else { + if (!(base instanceof PyJavaType)) { + // python subclasses of proxy types need to be added as a base so their + // version of methods will show up + cleanedBases.add(base); + } else if (!addedProxyType) { + // Only add a single Java type, since everything's going to go through the + // proxy type cleanedBases.add(proxyType); addedProxyType = true; } - } else { - cleanedBases.add(base); } } bases_list = cleanedBases.toArray(new PyObject[cleanedBases.size()]); @@ -593,15 +604,7 @@ * Returns the Java Class that this type inherits from, or null if this type is Python-only. */ public Class<?> getProxyType() { - for (PyObject base : bases) { - if (base instanceof PyType) { - Class<?> javaType = ((PyType)base).getProxyType(); - if (javaType != null) { - return javaType; - } - } - } - return null; + return (Class<?>)javaProxy; } private synchronized void attachSubclass(PyType subtype) { @@ -1206,6 +1209,10 @@ throw Py.TypeError(String.format("can't delete %s.__name__", name)); } + /** + * Returns the actual dict underlying this type instance. Changes to Java types should go + * through {@link #addMethod} and {@link #removeMethod}, or unexpected mro errors can occur. + */ public PyObject fastGetDict() { return dict; } Modified: trunk/jython/tests/java/org/python/tests/Coercions.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Coercions.java 2009-01-25 21:06:04 UTC (rev 5978) +++ trunk/jython/tests/java/org/python/tests/Coercions.java 2009-01-26 00:33:21 UTC (rev 5979) @@ -100,4 +100,8 @@ } return true; } + + public static void runRunnable(Runnable r){ + r.run(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |