From: <cg...@us...> - 2009-04-27 00:53:30
|
Revision: 6263 http://jython.svn.sourceforge.net/jython/?rev=6263&view=rev Author: cgroves Date: 2009-04-27 00:53:26 +0000 (Mon, 27 Apr 2009) Log Message: ----------- Add the proxy type for a python subclass of a python subclass of a java class before the proxy type for its superclass. This exposes any Java methods overriden in the most derived subclass. Fixes issue1297. Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-04-25 18:45:51 UTC (rev 6262) +++ trunk/jython/src/org/python/core/PyType.java 2009-04-27 00:53:26 UTC (rev 6263) @@ -267,7 +267,7 @@ } } } - + if (wantDict) { createDictSlot(); } @@ -596,6 +596,7 @@ // non-proxy types go straight into our lookup cleanedBases.add(base); } 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 @@ -875,10 +876,21 @@ PyObject candidate = toMerge[i].getCandidate(); for (MROMergeState mergee : toMerge) { - if(mergee.unmergedContains(candidate)) { + if (mergee.pastnextContains(candidate)) { continue scan; } } + if (!(this instanceof PyJavaType) && candidate instanceof PyJavaType + && candidate.javaProxy != null + && PyProxy.class.isAssignableFrom(((Class<?>)candidate.javaProxy)) + && candidate.javaProxy != javaProxy) { + // If this is a subclass of a Python class that subclasses a Java class, slip the + // proxy for this class in before the proxy class in the superclass' mro. + // This exposes the methods from the proxy generated for this class in addition to + // those generated for the superclass while allowing methods from the superclass to + // remain visible from the proxies. + mro.add(PyType.fromClass(((Class<?>)javaProxy))); + } mro.add(candidate); for (MROMergeState element : toMerge) { element.noteMerged(candidate); @@ -893,7 +905,6 @@ return mro.toArray(new PyObject[mro.size()]); } - /** * Must either throw an exception, or bring the merges in <code>toMerge</code> to completion by * finishing filling in <code>mro</code>. @@ -1616,7 +1627,7 @@ /** * Returns true if candidate is in the items past this state's next item to be merged. */ - public boolean unmergedContains(PyObject candidate) { + public boolean pastnextContains(PyObject candidate) { for (int i = next + 1; i < mro.length; i++) { if (mro[i] == candidate) { return true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |