From: <cg...@us...> - 2009-06-30 06:10:13
|
Revision: 6504 http://jython.svn.sourceforge.net/jython/?rev=6504&view=rev Author: cgroves Date: 2009-06-30 06:09:12 +0000 (Tue, 30 Jun 2009) Log Message: ----------- Add a test from Sven Reimers that actually tickles issue 1381 and fix it. Modified Paths: -------------- trunk/jython/Lib/test/test_java_visibility.py trunk/jython/src/org/python/core/PyJavaType.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/RedundantInterfaceDeclarations.java Removed Paths: ------------- trunk/jython/tests/java/org/python/tests/DisagreeingInterfaceOverrides.java Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2009-06-29 06:25:28 UTC (rev 6503) +++ trunk/jython/Lib/test/test_java_visibility.py 2009-06-30 06:09:12 UTC (rev 6504) @@ -5,10 +5,11 @@ from test import test_support from java.lang import Byte, Class, Integer from java.util import ArrayList, Collections, HashMap, LinkedList, Observable, Observer -from org.python.tests import (Coercions, DisagreeingInterfaceOverrides, HiddenSuper, - InterfaceCombination, Invisible, Matryoshka, OnlySubclassable, OtherSubVisible, - SomePyMethods, SubVisible, Visible, VisibleOverride) +from org.python.tests import (Coercions, HiddenSuper, InterfaceCombination, Invisible, Matryoshka, + OnlySubclassable, OtherSubVisible, SomePyMethods, SubVisible, Visible, VisibleOverride) from org.python.tests import VisibilityResults as Results +from org.python.tests.RedundantInterfaceDeclarations import (Implementation, ExtraClass, + ExtraString, ExtraStringAndClass, ExtraClassAndString) class VisibilityTest(unittest.TestCase): def test_invisible(self): @@ -157,14 +158,14 @@ self.assertEquals("a string", synchList.remove(0)) def test_interface_methods_merged(self): - '''Checks that implementing interfaces that use the same method name are all reachable. + '''Checks that declaring an interface redundantly doesn't hide merged methods. Bug #1381''' - imp = DisagreeingInterfaceOverrides.Implementation() - self.assertEquals("String", imp.call("string argument")) - self.assertEquals("int", imp.call(Integer(7))) - self.assertEquals("List", imp.call(LinkedList())) - self.assertEquals("ArrayList", imp.call(ArrayList())) + for impl in Implementation, ExtraString, ExtraClass, ExtraStringAndClass, ExtraClassAndString: + instance = impl() + self.assertEquals("String", instance.call("string argument")) + self.assertEquals("int", instance.call(7)) + self.assertEquals("Class", instance.call(LinkedList)) class JavaClassTest(unittest.TestCase): def test_class_methods_visible(self): Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-06-29 06:25:28 UTC (rev 6503) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-06-30 06:09:12 UTC (rev 6504) @@ -199,6 +199,12 @@ // mro continue; } + if (baseClass != null && iface.isAssignableFrom(baseClass)) { + // Don't include redundant interfaces. If the redundant interface has methods + // that were combined with methods of the same name from other interfaces higher + // in the hierarchy, adding it here hides the forms from those interfaces. + continue; + } visibleBases.add(PyType.fromClassSkippingInners(iface, needsInners)); } if (javaProxy == Object.class) { Deleted: trunk/jython/tests/java/org/python/tests/DisagreeingInterfaceOverrides.java =================================================================== --- trunk/jython/tests/java/org/python/tests/DisagreeingInterfaceOverrides.java 2009-06-29 06:25:28 UTC (rev 6503) +++ trunk/jython/tests/java/org/python/tests/DisagreeingInterfaceOverrides.java 2009-06-30 06:09:12 UTC (rev 6504) @@ -1,51 +0,0 @@ -package org.python.tests; - -import java.util.ArrayList; -import java.util.List; - -/** - * Part of a test for issue #1381. It checks that Jython finds the proper overridden method when - * dealing with several interfaces. The test itself is in - * Lib/test_java_visibility.py#test_interface_methods_merged - */ -public class DisagreeingInterfaceOverrides { - - public interface StringArg { - - String call(String arg); - } - - public interface IntArg { - - String call(int arg); - } - - public interface ListArg { - - String call(List<Object> arg); - } - - public interface ArrayListArg { - - String call(List<Object> arg); - } - - public static class Implementation implements StringArg, IntArg, ListArg, ArrayListArg { - - public String call(String arg) { - return "String"; - } - - public String call(int arg) { - return "int"; - } - - public String call(List<Object> arg) { - return "List"; - } - - public String call(ArrayList<Object> arg) { - return "ArrayList"; - } - } -} Copied: trunk/jython/tests/java/org/python/tests/RedundantInterfaceDeclarations.java (from rev 6503, trunk/jython/tests/java/org/python/tests/DisagreeingInterfaceOverrides.java) =================================================================== --- trunk/jython/tests/java/org/python/tests/RedundantInterfaceDeclarations.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/RedundantInterfaceDeclarations.java 2009-06-30 06:09:12 UTC (rev 6504) @@ -0,0 +1,49 @@ +package org.python.tests; + +/** + * Part of a test for issue #1381. It checks that Jython finds the proper implementation of an + * interface method when dealing with classes that have redundant declarations of implementing + * interfaces. The test itself is in Lib/test_java_visibility.py#test_interface_methods_merged + */ +public class RedundantInterfaceDeclarations { + + public interface IntArg { + + String call(int arg); + } + + public interface ClassArg { + + String call(Class<?> arg); + } + + public interface StringArg extends ClassArg { + + String call(String name); + } + + public static abstract class AbstractImplementation implements StringArg, IntArg { + + public String call(Class<?> arg) { + return "Class"; + } + } + + public static class Implementation extends AbstractImplementation implements StringArg { + public String call(String name) { + return "String"; + } + + public String call(int arg) { + return "int"; + } + } + + public static class ExtraString extends Implementation implements StringArg {} + + public static class ExtraClass extends Implementation implements ClassArg {} + + public static class ExtraStringAndClass extends Implementation implements StringArg, ClassArg {} + + public static class ExtraClassAndString extends Implementation implements ClassArg, StringArg {} +} Property changes on: trunk/jython/tests/java/org/python/tests/RedundantInterfaceDeclarations.java ___________________________________________________________________ Added: svn:mergeinfo + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |