Index: src/org/python/core/PyJavaClass.java =================================================================== --- src/org/python/core/PyJavaClass.java (revision 5292) +++ src/org/python/core/PyJavaClass.java (working copy) @@ -75,8 +75,21 @@ init(c); } - protected PyJavaClass(String name,PackageManager mgr) { - __name__ = name; + public String __module__; + /** + * Set the full name of this class. + */ + private void setName(String name) { + __name__ = name.substring(name.lastIndexOf(".")+1, name.length()); + __module__ = name.substring(0, name.lastIndexOf(".")); + } + + private String fullName() { + return __module__ + "." + __name__; + } + + protected PyJavaClass(String name, PackageManager mgr) { + setName(name); this.__mgr__ = mgr; } @@ -97,7 +110,7 @@ } private static final void initLazy(PyJavaClass jc) { - Class c = jc.__mgr__.findClass(null,jc.__name__,"lazy java class"); + Class c = jc.__mgr__.findClass(null,jc.fullName(),"lazy java class"); check_lazy_allowed(c); // xxx jc.init(c); tbl.putCanonical(jc.proxyClass,jc); @@ -209,7 +222,7 @@ private void init(Class c) { proxyClass = c; - __name__ = c.getName(); + setName(c.getName()); } /** @@ -761,6 +774,8 @@ } if (name == "__name__") return new PyString(__name__); + if (name == "__module__") + return new PyString(__module__); if (name == "__bases__") { if (__bases__ == null) initialize(); @@ -851,11 +866,11 @@ if (PyObject.class.isAssignableFrom(proxyClass)) { if (Modifier.isAbstract(proxyClass.getModifiers())) { throw Py.TypeError("can't instantiate abstract class ("+ - __name__+")"); + fullName()+")"); } if (__init__ == null) { throw Py.TypeError("no public constructors for "+ - __name__); + fullName()); } return __init__.make(args,keywords); } @@ -872,6 +887,6 @@ } public String toString() { - return ""; + return ""; } } Index: Lib/test/test_class_jy.py =================================================================== --- Lib/test/test_class_jy.py (revision 5292) +++ Lib/test/test_class_jy.py (working copy) @@ -273,12 +273,29 @@ self.assert_(isinstance(retro, OldStyle)) +class JavaClassNamingTestCase(unittest.TestCase): + """ + Tests for PyJavaClass naming. + """ + + def test_java_class_name(self): + """ + The __name__ and __module__ attributes of Java classes should be set + according to the same convention that Python uses. + """ + from java.lang import String + self.assertEqual(String.__name__, "String") + self.assertEqual(String.__module__, "java.lang") + + + def test_main(): test_support.run_unittest(ClassGeneralTestCase, ClassNamelessModuleTestCase, BrokenNameTestCase, ClassLocalsTestCase, - IsDescendentTestCase) + IsDescendentTestCase, + JavaClassNamingTestCase) if __name__ == "__main__":