### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/MethodBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java,v retrieving revision 1.86 diff -u -r1.86 MethodBinding.java --- dom/org/eclipse/jdt/core/dom/MethodBinding.java 24 Sep 2007 22:49:54 -0000 1.86 +++ dom/org/eclipse/jdt/core/dom/MethodBinding.java 11 Oct 2007 13:01:40 -0000 @@ -452,16 +452,7 @@ } public boolean isSubsignature(IMethodBinding otherMethod) { - try { - org.eclipse.jdt.internal.compiler.lookup.MethodBinding other = ((MethodBinding) otherMethod).binding; - if (!CharOperation.equals(this.binding.selector, other.selector)) - return false; - return this.binding.areParameterErasuresEqual(other) && this.binding.areTypeVariableErasuresEqual(other); - } catch (AbortCompilation e) { - // don't surface internal exception to clients - // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=143013 - return false; - } + return overrides(otherMethod, false/*don't check visibility*/); } /** @@ -475,13 +466,19 @@ * @see IMethodBinding#overrides(IMethodBinding) */ public boolean overrides(IMethodBinding overridenMethod) { + return overrides(overridenMethod, true/*check visibility*/); + } + + private boolean overrides(IMethodBinding overridenMethod, boolean checkVisibility) { try { org.eclipse.jdt.internal.compiler.lookup.MethodBinding overridenCompilerBinding = ((MethodBinding) overridenMethod).binding; - if (this.binding == overridenCompilerBinding - || overridenCompilerBinding.isStatic() - || overridenCompilerBinding.isPrivate() - || this.binding.isStatic()) + if (checkVisibility + && (this.binding == overridenCompilerBinding + || overridenCompilerBinding.isStatic() + || overridenCompilerBinding.isPrivate() + || this.binding.isStatic())) return false; + overridenCompilerBinding = overridenCompilerBinding.original(); char[] selector = this.binding.selector; if (!CharOperation.equals(selector, overridenCompilerBinding.selector)) return false; @@ -495,7 +492,7 @@ if (lookupEnvironment == null) return false; MethodVerifier methodVerifier = lookupEnvironment.methodVerifier(); org.eclipse.jdt.internal.compiler.lookup.MethodBinding superMethod = superMethods[i]; - return !(superMethod.isDefault() && (superMethod.declaringClass.getPackage()) != this.binding.declaringClass.getPackage()) + return !(checkVisibility && superMethod.isDefault() && (superMethod.declaringClass.getPackage()) != this.binding.declaringClass.getPackage()) && methodVerifier.doesMethodOverride(this.binding, superMethod); } } @@ -505,7 +502,7 @@ // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=143013 return false; } - } + } /** * For debugging purpose only. #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/CompatibilityRulesTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/CompatibilityRulesTests.java,v retrieving revision 1.18 diff -u -r1.18 CompatibilityRulesTests.java --- src/org/eclipse/jdt/core/tests/dom/CompatibilityRulesTests.java 13 Aug 2007 14:33:26 -0000 1.18 +++ src/org/eclipse/jdt/core/tests/dom/CompatibilityRulesTests.java 11 Oct 2007 13:01:42 -0000 @@ -784,4 +784,222 @@ assertTrue("Y#foo() should not override X#foo()", !bindings[0].overrides(bindings[1])); } + /* + * Ensures that a method with different paramter types is not a subsignature of its super method. + * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..)) + */ + public void test035() throws JavaModelException { + IMethodBinding[] bindings = createMethodBindings( + new String[] { + "/P/p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public void o1_xoo2(A s) {\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + " @Override\n" + + " public void o1_xoo2(A s) {\n" + + " }\n" + + "}", + }, + new String[] { + "Lp1/A;.o1_xoo2(Lp1/A<*>;)V", + "Lp1/A~B;.o1_xoo2(Lp1/A;)V" + }); + assertFalse("B#o1_xoo2() should not be a subsignature of A#o1_xoo2()", bindings[1].isSubsignature(bindings[0])); + } + + /* + * Ensures that a method with different paramter types is not a subsignature of its super method. + * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..)) + */ + public void test036() throws JavaModelException { + IMethodBinding[] bindings = createMethodBindings( + new String[] { + "/P/p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public void o1_xoo3(A s) {\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + " @Override\n" + + " public void o1_xoo3(A s) {\n" + + " }\n" + + "}", + }, + new String[] { + "Lp1/A;.o1_xoo3(Lp1/A<+TT;>;)V", + "Lp1/A~B;.o1_xoo3(Lp1/A<-TS;>;)V" + }); + assertFalse("B#o1_xoo3() should not be a subsignature of A#o1_xoo3()", bindings[1].isSubsignature(bindings[0])); + } + + /* + * Ensures that a method with different paramter types is not a subsignature of its super method. + * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..)) + */ + public void test037() throws JavaModelException { + IMethodBinding[] bindings = createMethodBindings( + new String[] { + "/P/p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public void o2_xoo1(List t) {\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + " @Override\n" + + " public void o2_xoo1(List t) {\n" + + " }\n" + + "}\n" + + "class List {\n" + + "}", + }, + new String[] { + "Lp1/A;.o2_xoo1(Lp1/List<+TT;>;)V", + "Lp1/A~B;.o2_xoo1(Lp1/List<+TW;>;)V" + }); + assertFalse("B#o1_xoo1() should not be a subsignature of A#o1_xoo1()", bindings[1].isSubsignature(bindings[0])); + } + + /* + * Ensures that a method with different paramter types is not a subsignature of its super method. + * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..)) + */ + public void test038() throws JavaModelException { + IMethodBinding[] bindings = createMethodBindings( + new String[] { + "/P/p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public void o3_xoo1(List t) {\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + " @Override\n" + + " public void o3_xoo1(List t) {\n" + + " }\n" + + "}\n" + + "class List {\n" + + "}", + }, + new String[] { + "Lp1/A;.o3_xoo1(Lp1/List;)V", + "Lp1/A~B;.o3_xoo1(Lp1/List;)V" + }); + assertFalse("B#o3_xoo1() should not be a subsignature of A#o3_xoo1()", bindings[1].isSubsignature(bindings[0])); + } + + /* + * Ensures that a method with different paramter types is not a subsignature of its super method. + * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..)) + */ + public void test039() throws JavaModelException { + IMethodBinding[] bindings = createMethodBindings( + new String[] { + "/P/p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public void o4_xoo1(T t) {\n" + + " }\n" + + "}\n" + + "class B extends A> {\n" + + " @Override\n" + + " public void o4_xoo1(List t) {\n" + + " }\n" + + "}\n" + + "class List {\n" + + "}", + }, + new String[] { + "Lp1/A;.o4_xoo1(TT;)V", + "Lp1/A~B;.o4_xoo1(Lp1/List<*>;)V" + }); + assertFalse("B#o4_xoo1() should not be a subsignature of A#o4_xoo1()", bindings[1].isSubsignature(bindings[0])); + } + + /* + * Ensures that a method with different paramter types is not a subsignature of its super method. + * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..)) + */ + public void test040() throws JavaModelException { + IMethodBinding[] bindings = createMethodBindings( + new String[] { + "/P/p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public void tp1_xoo3(X x, Y y) {\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + " @Override\n" + + " public void tp1_xoo3(V x, W y) {\n" + + " }\n" + + "}", + }, + new String[] { + "Lp1/A;.tp1_xoo3(TX;TY;)V", + "Lp1/A~B;.tp1_xoo3(TV;TW;)V" + }); + assertFalse("B#tp1_xoo3() should not be a subsignature of A#tp1_xoo3()", bindings[1].isSubsignature(bindings[0])); + } + + /* + * Ensures that a method with different paramter types is not a subsignature of its super method. + * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..)) + */ + public void test041() throws JavaModelException { + IMethodBinding[] bindings = createMethodBindings( + new String[] { + "/P/p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public void tp1_foo2(S s, X x, Y y) {\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + " @Override\n" + + " public void tp1_foo2(String s, Object x, Object y) {\n" + + " }\n" + + "}", + }, + new String[] { + "Lp1/A;.tp1_foo2(TS;TX;TY;)V", + "Lp1/A~B;.tp1_foo2(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V" + }); + assertTrue("B#tp1_foo2() should be a subsignature of A#tp1_foo2()", bindings[1].isSubsignature(bindings[0])); + } + + /* + * Ensures that a method with different paramter types is not a subsignature of its super method. + * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..)) + */ + public void test042() throws JavaModelException { + IMethodBinding[] bindings = createMethodBindings( + new String[] { + "/P/p1/A.java", + "package p1;\n" + + "public abstract class A {\n" + + " void g2 (T t) {\n" + + " }\n" + + "}\n" + + "class B extends A> {\n" + + " void g2 (List t) {\n" + + " }\n" + + "}\n" + + "class List {\n" + + "}\n" + + "class Number {\n" + + "}", + }, + new String[] { + "Lp1/A~B;.g2(Lp1/List;)V" + }); + ITypeBinding superType = bindings[0].getDeclaringClass().getSuperclass(); // parameterized type + IMethodBinding ag2 = superType.getDeclaredMethods()[1]; + assertTrue("B#g2() should be a subsignature of A#g2()", bindings[0].isSubsignature(ag2)); + } + }