Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 80344 Details for
Bug 111093
More problems with IMethodBinding#isSubsignature(..)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Kent's fix and more regression tests
111093.txt (text/plain), 14.31 KB, created by
Jerome Lanneluc
on 2007-10-15 07:30:25 EDT
(
hide
)
Description:
Kent's fix and more regression tests
Filename:
MIME Type:
Creator:
Jerome Lanneluc
Created:
2007-10-15 07:30:25 EDT
Size:
14.31 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#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 15 Oct 2007 11:26:27 -0000 >@@ -784,4 +784,274 @@ > 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<T> {\n" + >+ " public void o1_xoo2(A<?> s) {\n" + >+ " }\n" + >+ "}\n" + >+ "class B<S> extends A<S> {\n" + >+ " @Override\n" + >+ " public void o1_xoo2(A<Object> s) {\n" + >+ " }\n" + >+ "}", >+ }, >+ new String[] { >+ "Lp1/A;.o1_xoo2(Lp1/A<*>;)V", >+ "Lp1/A~B;.o1_xoo2(Lp1/A<Ljava/lang/Object;>;)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<T> {\n" + >+ " public void o1_xoo3(A<? extends T> s) {\n" + >+ " }\n" + >+ "}\n" + >+ "class B<S> extends A<S> {\n" + >+ " @Override\n" + >+ " public void o1_xoo3(A<? super S> 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<S, T> {\n" + >+ " public void o2_xoo1(List<? extends T> t) {\n" + >+ " }\n" + >+ "}\n" + >+ "class B<V, W> extends A<W, V> {\n" + >+ " @Override\n" + >+ " public void o2_xoo1(List<? extends W> t) {\n" + >+ " }\n" + >+ "}\n" + >+ "class List<T> {\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<Object> t) {\n" + >+ " }\n" + >+ "}\n" + >+ "class List<T> {\n" + >+ "}", >+ }, >+ new String[] { >+ "Lp1/A;.o3_xoo1(Lp1/List;)V", >+ "Lp1/A~B;.o3_xoo1(Lp1/List<Ljava/lang/Object;>;)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<T> {\n" + >+ " public void o4_xoo1(T t) {\n" + >+ " }\n" + >+ "}\n" + >+ "class B extends A<List<String>> {\n" + >+ " @Override\n" + >+ " public void o4_xoo1(List<?> t) {\n" + >+ " }\n" + >+ "}\n" + >+ "class List<T> {\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<S> {\n" + >+ " public <X, Y> void tp1_xoo3(X x, Y y) {\n" + >+ " }\n" + >+ "}\n" + >+ "class B extends A<String> {\n" + >+ " @Override\n" + >+ " public <W, V> void tp1_xoo3(V x, W y) {\n" + >+ " }\n" + >+ "}", >+ }, >+ new String[] { >+ "Lp1/A;.tp1_xoo3<X:Ljava/lang/Object;Y:Ljava/lang/Object;>(TX;TY;)V", >+ "Lp1/A~B;.tp1_xoo3<W:Ljava/lang/Object;V:Ljava/lang/Object;>(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<S> {\n" + >+ " public <X, Y> void tp1_foo2(S s, X x, Y y) {\n" + >+ " }\n" + >+ "}\n" + >+ "class B extends A<String> {\n" + >+ " @Override\n" + >+ " public void tp1_foo2(String s, Object x, Object y) {\n" + >+ " }\n" + >+ "}", >+ }, >+ new String[] { >+ "Lp1/A;.tp1_foo2<X:Ljava/lang/Object;Y:Ljava/lang/Object;>(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<T> {\n" + >+ " void g2 (T t) {\n" + >+ " }\n" + >+ "}\n" + >+ "class B extends A<List<Number>> {\n" + >+ " void g2 (List<Number> t) {\n" + >+ " }\n" + >+ "}\n" + >+ "class List<T> {\n" + >+ "}\n" + >+ "class Number {\n" + >+ "}", >+ }, >+ new String[] { >+ "Lp1/A~B;.g2(Lp1/List<Lp1/Number;>;)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)); >+ } >+ >+ /* >+ * Ensures that a method with same signature in a different hierarchy doesn't overide another one >+ */ >+ public void test043() throws JavaModelException { >+ IMethodBinding[] bindings = createMethodBindings( >+ new String[] { >+ "/P/p1/X.java", >+ "package p1;\n" + >+ "public class X {\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}", >+ "/P/p1/Y.java", >+ "package p1;\n" + >+ "public class Y {\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}", >+ }, >+ new String[] { >+ "Lp1/X;.foo()V", >+ "Lp1/Y;.foo()V" >+ }); >+ assertFalse("Y#foo() should not override X#foo()", bindings[1].overrides(bindings[0])); >+ } >+ >+ /* >+ * Ensures that a method is a subsignature of the same method in a different hierarchy >+ */ >+ public void test044() throws JavaModelException { >+ IMethodBinding[] bindings = createMethodBindings( >+ new String[] { >+ "/P/p1/X.java", >+ "package p1;\n" + >+ "public class X {\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}", >+ "/P/p1/Y.java", >+ "package p1;\n" + >+ "public class Y {\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}", >+ }, >+ new String[] { >+ "Lp1/X;.foo()V", >+ "Lp1/Y;.foo()V" >+ }); >+ assertTrue("Y#foo() should be a subsignature of X#foo()", bindings[1].isSubsignature(bindings[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 15 Oct 2007 11:26:29 -0000 >@@ -22,7 +22,6 @@ > import org.eclipse.jdt.core.compiler.CharOperation; > import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; > import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; >-import org.eclipse.jdt.internal.compiler.lookup.MethodVerifier; > import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding; > import org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding; > import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; >@@ -452,16 +451,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,30 +465,43 @@ > * @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()) >- return false; >- char[] selector = this.binding.selector; >- if (!CharOperation.equals(selector, overridenCompilerBinding.selector)) >+ org.eclipse.jdt.internal.compiler.lookup.MethodBinding overridenBinding = ((MethodBinding) overridenMethod).binding; >+ if (!CharOperation.equals(this.binding.selector, overridenBinding.selector)) > return false; >- TypeBinding match = this.binding.declaringClass.findSuperTypeOriginatingFrom(overridenCompilerBinding.declaringClass); >- if (!(match instanceof ReferenceBinding)) return false; > >- org.eclipse.jdt.internal.compiler.lookup.MethodBinding[] superMethods = ((ReferenceBinding)match).getMethods(selector); >- for (int i = 0, length = superMethods.length; i < length; i++) { >- if (superMethods[i].original() == overridenCompilerBinding) { >- LookupEnvironment lookupEnvironment = this.resolver.lookupEnvironment(); >- 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()) >- && methodVerifier.doesMethodOverride(this.binding, superMethod); >- } >+ if (checkVisibility) { >+ if (this.binding == overridenBinding >+ || overridenBinding.isStatic() >+ || this.binding.isStatic()) >+ return false; >+ if (overridenBinding.isPrivate()) >+ return false; >+ if (overridenBinding.isDefault() >+ && overridenBinding.declaringClass.getPackage() != this.binding.declaringClass.getPackage()) >+ return false; > } >+ >+ LookupEnvironment lookupEnvironment = this.resolver.lookupEnvironment(); >+ if (lookupEnvironment == null) >+ return false; >+ >+ overridenBinding = overridenBinding.original(); >+ TypeBinding match = this.binding.declaringClass.findSuperTypeOriginatingFrom(overridenBinding.declaringClass); >+ if (!(match instanceof ReferenceBinding)) >+ return false; >+ if (match == overridenBinding.declaringClass) >+ return lookupEnvironment.methodVerifier().doesMethodOverride( this.binding, overridenBinding); >+ >+ org.eclipse.jdt.internal.compiler.lookup.MethodBinding[] superMethods = ((ReferenceBinding) match).getMethods(overridenBinding.selector); >+ for (int i = 0, length = superMethods.length; i < length; i++) >+ if (superMethods[i].original() == overridenBinding) >+ return lookupEnvironment.methodVerifier().doesMethodOverride(this.binding, superMethods[i]); > return false; > } catch (AbortCompilation e) { > // don't surface internal exception to clients
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 111093
:
80030
|
80133
|
80344
|
81493
|
81523
|
81635