From: <cg...@us...> - 2009-04-27 05:00:44
|
Revision: 6266 http://jython.svn.sourceforge.net/jython/?rev=6266&view=rev Author: cgroves Date: 2009-04-27 05:00:40 +0000 (Mon, 27 Apr 2009) Log Message: ----------- Climb all the way up the stack of superclasses to find methods with respectJavaAccessibility is false. Fixes issue1285. This is going to lead to some weirdness if a superclass defines a method with more restrictive types than a subclass, but ignoring Java accessibility is always going to lead to weirdness, and we already try to steer people away from this flag. Modified Paths: -------------- trunk/jython/Lib/test/test_java_visibility.py trunk/jython/src/org/python/core/PyJavaType.java Added Paths: ----------- trunk/jython/Lib/test/call_overridden_method.py trunk/jython/tests/java/org/python/tests/RespectJavaAccessibility.java Added: trunk/jython/Lib/test/call_overridden_method.py =================================================================== --- trunk/jython/Lib/test/call_overridden_method.py (rev 0) +++ trunk/jython/Lib/test/call_overridden_method.py 2009-04-27 05:00:40 UTC (rev 6266) @@ -0,0 +1,14 @@ +from org.python.tests.RespectJavaAccessibility import Banana, Pear + +p = Pear() +b = Banana() +assert b.amethod() == 'Banana.amethod()' +assert p.amethod() == 'Banana.amethod()' +assert b.amethod(1,2) == 'Banana.amethod(x,y)' +assert p.amethod(1,2) == 'Pear.amethod(x,y)' +assert b.privBanana() == 'Banana.privBanana()' +assert p.privPear() == 'Pear.privPear()' +assert b.protMethod() == 'Banana.protMethod()' +assert p.protMethod() == 'Banana.protMethod()' +assert b.protMethod(1,2) == 'Banana.protMethod(x,y)' +assert p.protMethod(1,2) == 'Pear.protMethod(x,y)' Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2009-04-27 00:56:29 UTC (rev 6265) +++ trunk/jython/Lib/test/test_java_visibility.py 2009-04-27 05:00:40 UTC (rev 6266) @@ -228,6 +228,9 @@ def test_protected_class(self): self.run_accessibility_script("access_protected_class.py", TypeError) + def test_overriding(self): + self.run_accessibility_script("call_overridden_method.py") + class ClassloaderTest(unittest.TestCase): def test_loading_classes_without_import(self): cl = test_support.make_jar_classloader("../callbacker_test.jar") Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-04-27 00:56:29 UTC (rev 6265) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-04-27 05:00:40 UTC (rev 6266) @@ -229,10 +229,15 @@ // returns just the public methods methods = forClass.getMethods(); } else { - methods = forClass.getDeclaredMethods(); - for (Method method : methods) { - method.setAccessible(true); + // Grab all methods on this class and all of its superclasses and make them accessible + List<Method> allMethods = Generic.list(); + for(Class<?> c = forClass; c != null; c = c.getSuperclass()) { + for (Method meth : c.getDeclaredMethods()) { + allMethods.add(meth); + meth.setAccessible(true); + } } + methods = allMethods.toArray(new Method[allMethods.size()]); } boolean isInAwt = name.startsWith("java.awt.") && name.indexOf('.', 9) == -1; Added: trunk/jython/tests/java/org/python/tests/RespectJavaAccessibility.java =================================================================== --- trunk/jython/tests/java/org/python/tests/RespectJavaAccessibility.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/RespectJavaAccessibility.java 2009-04-27 05:00:40 UTC (rev 6266) @@ -0,0 +1,42 @@ +package org.python.tests; + +public class RespectJavaAccessibility { + + public static class Banana { + + public String amethod() { + return "Banana.amethod()"; + } + + public String amethod(int x, int y) { + return "Banana.amethod(x,y)"; + } + + protected String protMethod() { + return "Banana.protMethod()"; + } + + protected String protMethod(int x, int y) { + return "Banana.protMethod(x,y)"; + } + + private String privBanana() { + return "Banana.privBanana()"; + } + } + + public static class Pear extends Banana { + + public String amethod(int x, int y) { + return "Pear.amethod(x,y)"; + } + + protected String protMethod(int x, int y) { + return "Pear.protMethod(x,y)"; + } + + private String privPear() { + return "Pear.privPear()"; + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |