From: <cg...@us...> - 2008-10-28 07:58:52
|
Revision: 5523 http://jython.svn.sourceforge.net/jython/?rev=5523&view=rev Author: cgroves Date: 2008-10-28 07:58:42 +0000 (Tue, 28 Oct 2008) Log Message: ----------- Make Java static inner classes visible from Java subclasses. From garyh's patch. Resolves issue 1147. Modified Paths: -------------- trunk/jython/Lib/test/test_java_visibility.py trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyJavaClass.java trunk/jython/tests/java/org/python/tests/Visible.java Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-10-27 21:15:22 UTC (rev 5522) +++ trunk/jython/Lib/test/test_java_visibility.py 2008-10-28 07:58:42 UTC (rev 5523) @@ -14,7 +14,7 @@ Visible.__init__(self, publicValue) else: Visible.__init__(self) - # TODO - protectedStaticMethod, protectedStaticField, and protectedField should + # TODO - protectedStaticMethod, protectedStaticField, StaticInner, and protectedField should # be here s = SubVisible() self.assertEquals(Results.PROTECTED_METHOD, s.protectedMethod(0)) @@ -37,6 +37,7 @@ v.visibleStatic('a')) self.assertEquals(Results.EXTRA_ARG_PUBLIC_STATIC_METHOD, v.visibleStatic(0, 'a')) + self.assertEquals(Results.PUBLIC_STATIC_FIELD, Visible.StaticInner.visibleStaticField) # Ensure that the visibleInstance method from SubVisible that takes a double doesn't # leak through to the parent @@ -57,7 +58,9 @@ # Java methods don't allow direct calling of the superclass method, so it should # return the subclass value here. self.assertEquals(Results.SUBCLASS_OVERRIDE, Visible.visibleInstance(s, 3)) + self.assertEquals(Results.PUBLIC_STATIC_FIELD, SubVisible.StaticInner.visibleStaticField) + def test_in_dict(self): for c in Visible, SubVisible, VisibleOverride: self.failUnless('visibleInstance' in c.__dict__, Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-10-27 21:15:22 UTC (rev 5522) +++ trunk/jython/src/org/python/core/Py.java 2008-10-28 07:58:42 UTC (rev 5523) @@ -762,20 +762,6 @@ return true; } - public static Class relFindClass(Class home, String name) { - try { - ClassLoader loader = home.getClassLoader(); - if (loader != null) { - return loader.loadClass(name); - } else { - return Class.forName(name); - } - } catch (ClassNotFoundException exc) { - return null; - } catch (Throwable t) { - throw Py.JavaError(t); - } - } private static boolean secEnv = false; public static Class findClass(String name) { Modified: trunk/jython/src/org/python/core/PyJavaClass.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaClass.java 2008-10-27 21:15:22 UTC (rev 5522) +++ trunk/jython/src/org/python/core/PyJavaClass.java 2008-10-28 07:58:42 UTC (rev 5523) @@ -709,10 +709,16 @@ } private PyObject findInnerClass(String name) { - Class p = getProxyClass(); - Class innerClass = Py.relFindClass(p, p.getName() + "$" + name); - if (innerClass == null) + Class<?> innerClass = null; + for (Class<?> inner : getProxyClass().getClasses()) { + if(inner.getSimpleName().equals(name)) { + innerClass = inner; + break; + } + } + if (innerClass == null) { return null; + } PyObject jinner = Py.java2py(innerClass); // xxx lookup(innerClass); __dict__.__setitem__(name, jinner); return jinner; Modified: trunk/jython/tests/java/org/python/tests/Visible.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Visible.java 2008-10-27 21:15:22 UTC (rev 5522) +++ trunk/jython/tests/java/org/python/tests/Visible.java 2008-10-28 07:58:42 UTC (rev 5523) @@ -12,6 +12,11 @@ public static int visibleStatic = PUBLIC_STATIC_METHOD_FIELD; + public static class StaticInner { + + public static int visibleStaticField = PUBLIC_STATIC_FIELD; + } + public Visible() { this(PUBLIC_FIELD); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |