From: <cg...@us...> - 2008-11-28 10:07:02
|
Revision: 5654 http://jython.svn.sourceforge.net/jython/?rev=5654&view=rev Author: cgroves Date: 2008-11-28 10:06:54 +0000 (Fri, 28 Nov 2008) Log Message: ----------- Expose static fields through PyBeanProperty if they share a name with the property. Instance fields supercede the propery. Modified Paths: -------------- branches/newstyle-java-types/Lib/test/test_java_integration.py branches/newstyle-java-types/src/org/python/core/PyJavaType.java branches/newstyle-java-types/src/org/python/core/PyObject.java Modified: branches/newstyle-java-types/Lib/test/test_java_integration.py =================================================================== --- branches/newstyle-java-types/Lib/test/test_java_integration.py 2008-11-28 09:13:19 UTC (rev 5653) +++ branches/newstyle-java-types/Lib/test/test_java_integration.py 2008-11-28 10:06:54 UTC (rev 5654) @@ -55,9 +55,6 @@ A() class InstantiationTest(unittest.TestCase): - def test_cant_create_abstract(self): - self.assertRaises(TypeError, Component) - def test_can_subclass_abstract(self): class A(Component): pass @@ -339,8 +336,11 @@ class ColorTest(unittest.TestCase): def test_static_fields(self): - Color.red - Color.blue + self.assertEquals(Color(255, 0, 0), Color.RED) + # The bean accessor for getRed should be active on instances, but the static field red + # should be visible on the class + self.assertEquals(255, Color.red.red) + self.assertEquals(Color(0, 0, 255), Color.blue) def test_is_operator(self): red = Color.red @@ -363,7 +363,7 @@ y = BigDecimalTest().asBigDecimal() self.assertEqual(type(x), type(y), "BigDecimal coerced") - self.assertEqual(x, y, "BigDecimal coerced") + self.assertEqual(x, y, "coerced BigDecimal not equal to directly created version") class MethodInvTest(unittest.TestCase): Modified: branches/newstyle-java-types/src/org/python/core/PyJavaType.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-28 09:13:19 UTC (rev 5653) +++ branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-28 10:06:54 UTC (rev 5654) @@ -100,12 +100,13 @@ } } for (String propname : propnames.keySet()) { - if(propname.equals("")) { + if (propname.equals("")) { continue; } String npropname = normalize_name(StringUtil.decapitalize(propname)); PyObject prev = dict.__finditem__(npropname); - if (prev != null && prev instanceof PyReflectedFunction) { + if (prev != null && (!(prev instanceof PyReflectedField) || + !Modifier.isStatic(((PyReflectedField)prev).field.getModifiers()))) { continue; } Method getter = null; @@ -125,7 +126,11 @@ } } if (setter != null || getter != null) { - dict.__setitem__(npropname, new PyBeanProperty(npropname, proptype, getter, setter)); + PyBeanProperty prop = new PyBeanProperty(npropname, proptype, getter, setter); + if (prev != null) { + prop.field = ((PyReflectedField)prev).field; + } + dict.__setitem__(npropname, prop); } else { // XXX error } Modified: branches/newstyle-java-types/src/org/python/core/PyObject.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-28 09:13:19 UTC (rev 5653) +++ branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-28 10:06:54 UTC (rev 5654) @@ -267,7 +267,7 @@ return Py.NoConversion; } - protected static final Map<Class<?>, Class<?>> primitiveMap = Generic.map(); + private static final Map<Class<?>, Class<?>> primitiveMap = Generic.map(); static { primitiveMap.put(Character.TYPE, Character.class); primitiveMap.put(Boolean.TYPE, Boolean.class); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |