From: <fwi...@us...> - 2009-04-14 21:16:08
|
Revision: 6224 http://jython.svn.sourceforge.net/jython/?rev=6224&view=rev Author: fwierzbicki Date: 2009-04-14 21:16:03 +0000 (Tue, 14 Apr 2009) Log Message: ----------- Applied patch from http://bugs.jython.org/issue1271: Bean property accessors in derived class overide methods in base class. I altered his tests so that they are easily runnable by "ant javatest". Thanks to Geoffrey French for the fix. Also fixed a bad comment in IdentityTest.java. Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/tests/java/org/python/tests/identity/IdentityTest.java trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java Added Paths: ----------- trunk/jython/tests/python/prop_test.py Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-04-13 17:12:00 UTC (rev 6223) +++ trunk/jython/NEWS 2009-04-14 21:16:03 UTC (rev 6224) @@ -2,6 +2,7 @@ Jython 2.5.0 rc 1 Bugs fixed (new numbering due to move to Roundup) + - [ 1271 ] Bean property accessors in derived class overide methods in base class - [ 1264 ] 'is not' test exhibits incorrect behaviour when wrapping Java objects - [ 1295 ] Setting a write-only bean property causes a NPE - [ 1272 ] ASTList ClassCastException Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-04-13 17:12:00 UTC (rev 6223) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-04-14 21:16:03 UTC (rev 6224) @@ -407,7 +407,8 @@ // If one of our superclasses has something defined for this name, check if its a bean // property, and if so, try to fill in any gaps in our property from there - PyObject superForName = lookup(prop.__name__); + PyObject fromType[] = new PyObject[] { null }; + PyObject superForName = lookup_where(prop.__name__, fromType); if (superForName instanceof PyBeanProperty) { PyBeanProperty superProp = ((PyBeanProperty)superForName); // If it has a set method and we don't, take it regardless. If the types don't line @@ -426,6 +427,12 @@ // If the parent bean is hiding a static field, we need it as well. prop.field = superProp.field; } + } else if (superForName != null && fromType[0] != this && !(superForName instanceof PyBeanEvent)) { + // There is already an entry for this name + // It came from a type which is not @this; it came from a superclass + // It is not a bean event + // Do not override methods defined in superclass + continue; } // If the return types on the set and get methods for a property don't agree, the get // method takes precedence Modified: trunk/jython/tests/java/org/python/tests/identity/IdentityTest.java =================================================================== --- trunk/jython/tests/java/org/python/tests/identity/IdentityTest.java 2009-04-13 17:12:00 UTC (rev 6223) +++ trunk/jython/tests/java/org/python/tests/identity/IdentityTest.java 2009-04-14 21:16:03 UTC (rev 6224) @@ -18,7 +18,6 @@ } public void testReadonly() { - //This used to cause an NPE see http://bugs.jython.org/issue1295 interp.execfile("tests/python/identity_test.py"); } } Modified: trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java =================================================================== --- trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java 2009-04-13 17:12:00 UTC (rev 6223) +++ trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java 2009-04-14 21:16:03 UTC (rev 6224) @@ -20,25 +20,8 @@ interp.exec("from org.python.tests.props import Readonly;Readonly().a = 'test'"); } - //This test is for http://bugs.jython.org/issue1271 - public void testBaseProp() { - /* - interp.exec("from org.python.tests.props import PropShadow"); - interp.exec("a = PropShadow.Derived()"); - interp.exec("assert a.foo() == 1, 'a'"); - interp.exec("assert a.bar() == 2, 'b'"); - */ + public void testShadowing() { + interp.execfile("tests/python/prop_test.py"); } - //This test is for http://bugs.jython.org/issue1271 - public void testDerivedProp() { - /* - interp.exec("from org.python.tests.props import PropShadow"); - interp.exec("b = PropShadow.Derived()"); - interp.exec("assert b.getBaz() == 4, 'c'"); - interp.exec("assert b.getFoo() == 3, 'd'"); - interp.exec("assert b.foo() == 1, 'e'"); - interp.exec("assert b.foo() == 1, 'f'"); - */ - } } Added: trunk/jython/tests/python/prop_test.py =================================================================== --- trunk/jython/tests/python/prop_test.py (rev 0) +++ trunk/jython/tests/python/prop_test.py 2009-04-14 21:16:03 UTC (rev 6224) @@ -0,0 +1,16 @@ +from org.python.tests.identity import IdentityObject + +#This test is for http://bugs.jython.org/issue1271 +from org.python.tests.props import PropShadow + +a = PropShadow.Derived() +assert a.foo() == 1, 'a' +assert a.bar() == 2, 'b' + +from org.python.tests.props import PropShadow +b = PropShadow.Derived() +assert b.getBaz() == 4, 'c' +assert b.baz == 4, 'e' +assert b.getFoo() == 3, 'd' +assert b.foo() == 1, 'f' + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |