From: <cg...@us...> - 2009-01-16 09:17:43
|
Revision: 5936 http://jython.svn.sourceforge.net/jython/?rev=5936&view=rev Author: cgroves Date: 2009-01-16 09:17:19 +0000 (Fri, 16 Jan 2009) Log Message: ----------- Check for parent beans of the same name to fill in missing getters or setters when adding beans for a type. Fixes bug #1132. Thanks to garyh for tracking it down and supplying a test case. Modified Paths: -------------- trunk/jython/Lib/test/test_java_visibility.py trunk/jython/src/org/python/core/PyJavaType.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/Child.java trunk/jython/tests/java/org/python/tests/Parent.java Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2009-01-16 08:11:48 UTC (rev 5935) +++ trunk/jython/Lib/test/test_java_visibility.py 2009-01-16 09:17:19 UTC (rev 5936) @@ -187,6 +187,15 @@ self.assertEquals("OtherSubVisible[]", c.takeArray([OtherSubVisible()])) self.assertEquals("SubVisible[]", c.takeArray([SubVisible()])) + def test_iterable_coercion(self): + def simple_gen(): + yield 1 + yield 2 + yield 3 + self.assertEquals(6, Coercions.takeIterable(simple_gen())) + self.assertEquals(True, Coercions.takeBoolIterable(simple_gen())) + + def test_class_coercion(self): c = Coercions() from java.util import Hashtable, HashMap Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-01-16 08:11:48 UTC (rev 5935) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-01-16 09:17:19 UTC (rev 5936) @@ -269,8 +269,31 @@ prop.field = ((PyReflectedField)prev).field; } } + + // 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__); + 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 + // up, it'll be rejected below + if (prop.setMethod == null) { + prop.setMethod = superProp.setMethod; + } else if (superProp.myType == prop.setMethod.getParameterTypes()[0]) { + // Otherwise, we must not have a get method. Only take a get method if the type + // on it agrees with the set method we already have. The bean on this type + // overrides a conflicting one o the parent + prop.getMethod = superProp.getMethod; + prop.myType = superProp.myType; + } + + if (prop.field == null) { + // If the parent bean is hiding a static field, we need it as well. + prop.field = superProp.field; + } + } // If the return types on the set and get methods for a property don't agree, the get - // get method takes precedence + // method takes precedence if (prop.getMethod != null && prop.setMethod != null && prop.myType != prop.setMethod.getParameterTypes()[0]) { prop.setMethod = null; Added: trunk/jython/tests/java/org/python/tests/Child.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Child.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/Child.java 2009-01-16 09:17:19 UTC (rev 5936) @@ -0,0 +1,12 @@ +package org.python.tests; + +public class Child extends Parent { + + public void setId(int newId) { + this.id = newId; + } + + public String getValue() { + return value; + } +} Added: trunk/jython/tests/java/org/python/tests/Parent.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Parent.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/Parent.java 2009-01-16 09:17:19 UTC (rev 5936) @@ -0,0 +1,16 @@ +package org.python.tests; + +public class Parent { + + protected String value = "blah"; + + protected int id = 7; + + public int getId() { + return id; + } + + public void setValue(String value) { + this.value = value; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |