From: <cg...@us...> - 2009-01-17 22:48:48
|
Revision: 5942 http://jython.svn.sourceforge.net/jython/?rev=5942&view=rev Author: cgroves Date: 2009-01-17 22:36:27 +0000 (Sat, 17 Jan 2009) Log Message: ----------- Resurrect some PyJavaClass code to fix bug #1235. Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/util/Generic.java Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2009-01-17 20:56:28 UTC (rev 5941) +++ trunk/jython/Lib/test/test_java_integration.py 2009-01-17 22:36:27 UTC (rev 5942) @@ -72,6 +72,12 @@ c.id = 16 self.assertEquals(16, c.id) + def test_awt_hack(self): + # We ignore several deprecated methods in java.awt.* in favor of bean properties that were + # addded in Java 1.1. This tests that one of those bean properties is visible. + c = Container() + c.size = 400, 300 + self.assertEquals(Dimension(400, 300), c.size) class SysIntegrationTest(unittest.TestCase): def setUp(self): Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2009-01-17 20:56:28 UTC (rev 5941) +++ trunk/jython/src/org/python/core/Py.java 2009-01-17 22:36:27 UTC (rev 5942) @@ -84,13 +84,10 @@ public static long TPFLAGS_BASETYPE = 1L << 10; /** Builtin types that are used to setup PyObject. */ - static final Set<Class<?>> BOOTSTRAP_TYPES = Generic.set(); - static { - BOOTSTRAP_TYPES.add(PyObject.class); - BOOTSTRAP_TYPES.add(PyType.class); - BOOTSTRAP_TYPES.add(PyBuiltinCallable.class); - BOOTSTRAP_TYPES.add(PyDataDescr.class); - } + static final Set<Class<?>> BOOTSTRAP_TYPES = Generic.set(PyObject.class, + PyType.class, + PyBuiltinCallable.class, + PyDataDescr.class); /** A unique object to indicate no conversion is possible in __tojava__ methods **/ Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-01-17 20:56:28 UTC (rev 5941) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-01-17 22:36:27 UTC (rev 5942) @@ -23,6 +23,16 @@ private final static Class<?>[] OO = {PyObject.class, PyObject.class}; + /** Deprecated methods in java.awt.* that have bean property equivalents we prefer. */ + private final static Set<String> BAD_AWT_METHODS = Generic.set("layout", + "insets", + "size", + "minimumSize", + "preferredSize", + "maximumSize", + "bounds", + "enable"); + private static Map<Class<?>, PyBuiltinMethod[]> collectionProxies; public static PyObject wrapJavaObject(Object o) { @@ -121,11 +131,22 @@ method.setAccessible(true); } } + + boolean isInAwt = name.startsWith("java.awt.") && name.indexOf('.', 9) == -1; for (Method meth : methods) { if (!declaredOnMember(baseClass, meth) || ignore(meth)) { continue; } + String methname = meth.getName(); + + // Special case a few troublesome methods in java.awt.*. These methods are all + // deprecated and interfere too badly with bean properties to be tolerated. This is + // totally a hack but a lot of code that uses java.awt will break without it. + if (isInAwt && BAD_AWT_METHODS.contains(methname)) { + continue; + } + String nmethname = normalize(methname); PyReflectedFunction reflfunc = (PyReflectedFunction)dict.__finditem__(nmethname); if (reflfunc == null) { Modified: trunk/jython/src/org/python/util/Generic.java =================================================================== --- trunk/jython/src/org/python/util/Generic.java 2009-01-17 20:56:28 UTC (rev 5941) +++ trunk/jython/src/org/python/util/Generic.java 2009-01-17 22:36:27 UTC (rev 5942) @@ -45,4 +45,16 @@ public static <T> Set<T> set() { return new HashSet<T>(); } + + /** + * Makes a Set using the generic type inferred from whatever this is being assigned to filled + * with the items in <code>contents</code>. + */ + public static <T, U extends T> Set<T> set(U...contents) { + Set<T> s = new HashSet<T>(contents.length); + for (U u : contents) { + s.add(u); + } + return s; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |