View | Details | Raw Unified | Return to bug 111093 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/CompatibilityRulesTests.java (+218 lines)
Lines 784-787 Link Here
784
		assertTrue("Y#foo() should not override X#foo()", !bindings[0].overrides(bindings[1]));
784
		assertTrue("Y#foo() should not override X#foo()", !bindings[0].overrides(bindings[1]));
785
	}
785
	}
786
	
786
	
787
	/*
788
	 * Ensures that a method with different paramter types is not a subsignature of its super method.
789
	 * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..))
790
	 */
791
	public void test035() throws JavaModelException {
792
		IMethodBinding[] bindings = createMethodBindings(
793
			new String[] {
794
				"/P/p1/A.java",
795
				"package p1;\n" +
796
				"public class A<T> {\n" + 
797
				"  public void o1_xoo2(A<?> s) {\n" + 
798
				"  }\n" + 
799
				"}\n" +
800
				"class B<S> extends A<S> {\n" + 
801
				"  @Override\n" + 
802
				"  public void o1_xoo2(A<Object> s) {\n" + 
803
				"  }\n" + 
804
				"}",
805
			},
806
			new String[] {
807
				"Lp1/A;.o1_xoo2(Lp1/A<*>;)V",
808
				"Lp1/A~B;.o1_xoo2(Lp1/A<Ljava/lang/Object;>;)V"
809
			});	
810
		assertFalse("B#o1_xoo2() should not be a subsignature of A#o1_xoo2()", bindings[1].isSubsignature(bindings[0]));
811
	}
812
	
813
	/*
814
	 * Ensures that a method with different paramter types is not a subsignature of its super method.
815
	 * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..))
816
	 */
817
	public void test036() throws JavaModelException {
818
		IMethodBinding[] bindings = createMethodBindings(
819
			new String[] {
820
				"/P/p1/A.java",
821
				"package p1;\n" +
822
				"public class A<T> {\n" + 
823
				"  public void o1_xoo3(A<? extends T> s) {\n" + 
824
				"  }\n" + 
825
				"}\n" +
826
				"class B<S> extends A<S> {\n" + 
827
				"  @Override\n" + 
828
				"  public void o1_xoo3(A<? super S> s) {\n" + 
829
				"  }\n" + 
830
				"}",
831
			},
832
			new String[] {
833
				"Lp1/A;.o1_xoo3(Lp1/A<+TT;>;)V",
834
				"Lp1/A~B;.o1_xoo3(Lp1/A<-TS;>;)V"
835
			});	
836
		assertFalse("B#o1_xoo3() should not be a subsignature of A#o1_xoo3()", bindings[1].isSubsignature(bindings[0]));
837
	}
838
	
839
	/*
840
	 * Ensures that a method with different paramter types is not a subsignature of its super method.
841
	 * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..))
842
	 */
843
	public void test037() throws JavaModelException {
844
		IMethodBinding[] bindings = createMethodBindings(
845
			new String[] {
846
				"/P/p1/A.java",
847
				"package p1;\n" +
848
				"public class A<S, T> {\n" + 
849
				"  public void o2_xoo1(List<? extends T> t) {\n" + 
850
				"  }\n" + 
851
				"}\n" +
852
				"class B<V, W> extends A<W, V> {\n" + 
853
				"  @Override\n" + 
854
				"  public void o2_xoo1(List<? extends W> t) {\n" + 
855
				"  }\n" + 
856
				"}\n" +
857
				"class List<T> {\n" +
858
				"}",
859
			},
860
			new String[] {
861
				"Lp1/A;.o2_xoo1(Lp1/List<+TT;>;)V",
862
				"Lp1/A~B;.o2_xoo1(Lp1/List<+TW;>;)V"
863
			});	
864
		assertFalse("B#o1_xoo1() should not be a subsignature of A#o1_xoo1()", bindings[1].isSubsignature(bindings[0]));
865
	}
866
	
867
	/*
868
	 * Ensures that a method with different paramter types is not a subsignature of its super method.
869
	 * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..))
870
	 */
871
	public void test038() throws JavaModelException {
872
		IMethodBinding[] bindings = createMethodBindings(
873
			new String[] {
874
				"/P/p1/A.java",
875
				"package p1;\n" +
876
				"public class A {\n" + 
877
				"  public void o3_xoo1(List t) {\n" + 
878
				"  }\n" + 
879
				"}\n" +
880
				"class B extends A {\n" + 
881
				"  @Override\n" + 
882
				"  public void o3_xoo1(List<Object> t) {\n" + 
883
				"  }\n" + 
884
				"}\n" + 
885
				"class List<T> {\n" +
886
				"}",
887
			},
888
			new String[] {
889
				"Lp1/A;.o3_xoo1(Lp1/List;)V",
890
				"Lp1/A~B;.o3_xoo1(Lp1/List<Ljava/lang/Object;>;)V"
891
			});	
892
		assertFalse("B#o3_xoo1() should not be a subsignature of A#o3_xoo1()", bindings[1].isSubsignature(bindings[0]));
893
	}
894
	
895
	/*
896
	 * Ensures that a method with different paramter types is not a subsignature of its super method.
897
	 * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..))
898
	 */
899
	public void test039() throws JavaModelException {
900
		IMethodBinding[] bindings = createMethodBindings(
901
			new String[] {
902
				"/P/p1/A.java",
903
				"package p1;\n" +
904
				"public class A<T> {\n" + 
905
				"  public void o4_xoo1(T t) {\n" + 
906
				"  }\n" + 
907
				"}\n" +
908
				"class B extends A<List<String>> {\n" + 
909
				"  @Override\n" + 
910
				"  public void o4_xoo1(List<?> t) {\n" + 
911
				"  }\n" + 
912
				"}\n" + 
913
				"class List<T> {\n" +
914
				"}",
915
			},
916
			new String[] {
917
				"Lp1/A;.o4_xoo1(TT;)V",
918
				"Lp1/A~B;.o4_xoo1(Lp1/List<*>;)V"
919
			});	
920
		assertFalse("B#o4_xoo1() should not be a subsignature of A#o4_xoo1()", bindings[1].isSubsignature(bindings[0]));
921
	}
922
	
923
	/*
924
	 * Ensures that a method with different paramter types is not a subsignature of its super method.
925
	 * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..))
926
	 */
927
	public void test040() throws JavaModelException {
928
		IMethodBinding[] bindings = createMethodBindings(
929
			new String[] {
930
				"/P/p1/A.java",
931
				"package p1;\n" +
932
				"public class A<S> {\n" + 
933
				"  public <X, Y> void tp1_xoo3(X x, Y y) {\n" + 
934
				"  }\n" + 
935
				"}\n" +
936
				"class B extends A<String> {\n" + 
937
				"  @Override\n" + 
938
				"  public <W, V> void tp1_xoo3(V x, W y) {\n" + 
939
				"  }\n" + 
940
				"}",
941
			},
942
			new String[] {
943
				"Lp1/A;.tp1_xoo3<X:Ljava/lang/Object;Y:Ljava/lang/Object;>(TX;TY;)V",
944
				"Lp1/A~B;.tp1_xoo3<W:Ljava/lang/Object;V:Ljava/lang/Object;>(TV;TW;)V"
945
			});	
946
		assertFalse("B#tp1_xoo3() should not be a subsignature of A#tp1_xoo3()", bindings[1].isSubsignature(bindings[0]));
947
	}
948
	
949
	/*
950
	 * Ensures that a method with different paramter types is not a subsignature of its super method.
951
	 * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..))
952
	 */
953
	public void test041() throws JavaModelException {
954
		IMethodBinding[] bindings = createMethodBindings(
955
			new String[] {
956
				"/P/p1/A.java",
957
				"package p1;\n" +
958
				"public class A<S> {\n" + 
959
				"  public <X, Y> void tp1_foo2(S s, X x, Y y) {\n" + 
960
				"  }\n" + 
961
				"}\n" +
962
				"class B extends A<String> {\n" + 
963
				"  @Override\n" + 
964
				"  public void tp1_foo2(String s, Object x, Object y) {\n" + 
965
				"  }\n" + 
966
				"}",
967
			},
968
			new String[] {
969
				"Lp1/A;.tp1_foo2<X:Ljava/lang/Object;Y:Ljava/lang/Object;>(TS;TX;TY;)V",
970
				"Lp1/A~B;.tp1_foo2(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V"
971
			});	
972
		assertTrue("B#tp1_foo2() should be a subsignature of A#tp1_foo2()", bindings[1].isSubsignature(bindings[0]));
973
	}
974
	
975
	/*
976
	 * Ensures that a method with different paramter types is not a subsignature of its super method.
977
	 * (regression test for bug 111093 More problems with IMethodBinding#isSubsignature(..))
978
	 */
979
	public void test042() throws JavaModelException {
980
		IMethodBinding[] bindings = createMethodBindings(
981
			new String[] {
982
				"/P/p1/A.java",
983
				"package p1;\n" +
984
				"public abstract class A<T> {\n" + 
985
				"  void g2 (T t) {\n" + 
986
				"  }\n" + 
987
				"}\n" + 
988
				"class B extends A<List<Number>> {\n" + 
989
				"  void g2 (List<Number> t) {\n" + 
990
				"  }\n" + 
991
				"}\n" + 
992
				"class List<T> {\n" + 
993
				"}\n" +
994
				"class Number {\n" +
995
				"}",
996
			},
997
			new String[] {
998
				"Lp1/A~B;.g2(Lp1/List<Lp1/Number;>;)V"
999
			});	
1000
		ITypeBinding superType = bindings[0].getDeclaringClass().getSuperclass(); // parameterized type
1001
		IMethodBinding ag2 = superType.getDeclaredMethods()[1];
1002
		assertTrue("B#g2() should be a subsignature of A#g2()", bindings[0].isSubsignature(ag2));
1003
	}
1004
	
787
}
1005
}
(-)dom/org/eclipse/jdt/core/dom/MethodBinding.java (-17 / +13 lines)
Lines 452-467 Link Here
452
	}
452
	}
453
453
454
	public boolean isSubsignature(IMethodBinding otherMethod) {
454
	public boolean isSubsignature(IMethodBinding otherMethod) {
455
		try {
455
		return overrides(otherMethod, false/*don't check visibility*/);
456
			org.eclipse.jdt.internal.compiler.lookup.MethodBinding other = ((MethodBinding) otherMethod).binding;
457
			if (!CharOperation.equals(this.binding.selector, other.selector))
458
				return false;
459
			return this.binding.areParameterErasuresEqual(other) && this.binding.areTypeVariableErasuresEqual(other);
460
		} catch (AbortCompilation e) {
461
			// don't surface internal exception to clients
462
			// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=143013
463
			return false;
464
		}
465
	}
456
	}
466
457
467
	/**
458
	/**
Lines 475-486 Link Here
475
	 * @see IMethodBinding#overrides(IMethodBinding)
466
	 * @see IMethodBinding#overrides(IMethodBinding)
476
	 */
467
	 */
477
	public boolean overrides(IMethodBinding overridenMethod) {
468
	public boolean overrides(IMethodBinding overridenMethod) {
469
		return overrides(overridenMethod, true/*check visibility*/);
470
	}
471
	
472
	private boolean overrides(IMethodBinding overridenMethod, boolean checkVisibility) {
478
		try {
473
		try {
479
			org.eclipse.jdt.internal.compiler.lookup.MethodBinding overridenCompilerBinding = ((MethodBinding) overridenMethod).binding;
474
			org.eclipse.jdt.internal.compiler.lookup.MethodBinding overridenCompilerBinding = ((MethodBinding) overridenMethod).binding.original();
480
			if (this.binding == overridenCompilerBinding
475
			if (checkVisibility 
481
					|| overridenCompilerBinding.isStatic()
476
					&& (this.binding == overridenCompilerBinding
482
					|| overridenCompilerBinding.isPrivate()
477
						|| overridenCompilerBinding.isStatic()
483
					|| this.binding.isStatic())
478
						|| overridenCompilerBinding.isPrivate()
479
						|| this.binding.isStatic()))
484
				return false;
480
				return false;
485
			char[] selector = this.binding.selector;
481
			char[] selector = this.binding.selector;
486
			if (!CharOperation.equals(selector, overridenCompilerBinding.selector))
482
			if (!CharOperation.equals(selector, overridenCompilerBinding.selector))
Lines 495-501 Link Here
495
					if (lookupEnvironment == null) return false;
491
					if (lookupEnvironment == null) return false;
496
					MethodVerifier methodVerifier = lookupEnvironment.methodVerifier();
492
					MethodVerifier methodVerifier = lookupEnvironment.methodVerifier();
497
					org.eclipse.jdt.internal.compiler.lookup.MethodBinding superMethod = superMethods[i];
493
					org.eclipse.jdt.internal.compiler.lookup.MethodBinding superMethod = superMethods[i];
498
					return !(superMethod.isDefault() && (superMethod.declaringClass.getPackage()) != this.binding.declaringClass.getPackage())
494
					return !(checkVisibility && superMethod.isDefault() && (superMethod.declaringClass.getPackage()) != this.binding.declaringClass.getPackage())
499
						&& methodVerifier.doesMethodOverride(this.binding, superMethod);
495
						&& methodVerifier.doesMethodOverride(this.binding, superMethod);
500
				}
496
				}
501
			}
497
			}
Lines 505-511 Link Here
505
			// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=143013
501
			// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=143013
506
			return false;
502
			return false;
507
		}
503
		}
508
	}
504
		}
509
505
510
	/**
506
	/**
511
	 * For debugging purpose only.
507
	 * For debugging purpose only.

Return to bug 111093