Skip to content

Commit

Permalink
Resurrect some PyJavaClass code to fix bug #1235.
Browse files Browse the repository at this point in the history
  • Loading branch information
groves committed Jan 17, 2009
1 parent 1f43040 commit de52c22
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Lib/test/test_java_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def test_inheriting_half_bean(self):
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):
Expand Down
11 changes: 4 additions & 7 deletions src/org/python/core/Py.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,10 @@ private Object readResolve() throws ObjectStreamException {
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 **/
Expand Down
21 changes: 21 additions & 0 deletions src/org/python/core/PyJavaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public class PyJavaType extends PyType {

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) {
Expand Down Expand Up @@ -121,11 +131,22 @@ protected void init(Class<?> forClass) {
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) {
Expand Down
12 changes: 12 additions & 0 deletions src/org/python/util/Generic.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ public static <K, V> Map<K, V> map() {
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;
}
}

0 comments on commit de52c22

Please sign in to comment.