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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-4 / +21 lines)
Lines 635-641 Link Here
635
			if (method.declaringClass == null || this.allSuperDeclaringTypeNames == null) {
635
			if (method.declaringClass == null || this.allSuperDeclaringTypeNames == null) {
636
				declaringLevel = INACCURATE_MATCH;
636
				declaringLevel = INACCURATE_MATCH;
637
			} else {
637
			} else {
638
				if (resolveLevelAsSuperInvocation(methodReceiverType)) {
638
				if (resolveLevelAsSuperInvocation(methodReceiverType, method.parameters)) {
639
					declaringLevel = methodLevel // since this is an ACCURATE_MATCH so return the possibly weaker match
639
					declaringLevel = methodLevel // since this is an ACCURATE_MATCH so return the possibly weaker match
640
						| SUPER_INVOCATION_FLAVOR; // this is an overridden method => add flavor to returned level
640
						| SUPER_INVOCATION_FLAVOR; // this is an overridden method => add flavor to returned level
641
				}
641
				}
Lines 723-729 Link Here
723
 * Return whether the given type binding or one of its possible super interfaces
723
 * Return whether the given type binding or one of its possible super interfaces
724
 * matches a type in the declaring type names hierarchy.
724
 * matches a type in the declaring type names hierarchy.
725
 */
725
 */
726
protected boolean resolveLevelAsSuperInvocation(ReferenceBinding type) {
726
protected boolean resolveLevelAsSuperInvocation(ReferenceBinding type, TypeBinding[] argumentTypes) {
727
	char[][] compoundName = type.compoundName;
727
	char[][] compoundName = type.compoundName;
728
	for (int i = 0, max = this.allSuperDeclaringTypeNames.length; i < max; i++) {
728
	for (int i = 0, max = this.allSuperDeclaringTypeNames.length; i < max; i++) {
729
		if (CharOperation.equals(this.allSuperDeclaringTypeNames[i], compoundName)) {
729
		if (CharOperation.equals(this.allSuperDeclaringTypeNames[i], compoundName)) {
Lines 736-743 Link Here
736
		ReferenceBinding[] interfaces = type.superInterfaces();
736
		ReferenceBinding[] interfaces = type.superInterfaces();
737
		if (interfaces == null) return false;
737
		if (interfaces == null) return false;
738
		for (int i = 0; i < interfaces.length; i++) {
738
		for (int i = 0; i < interfaces.length; i++) {
739
			if (resolveLevelAsSuperInvocation(interfaces[i])) {
739
			// need to verify if method may be overridden
740
				return true;
740
			MethodBinding[] methods = interfaces[i].getMethods(this.pattern.selector);
741
			for (int j=0, length=methods.length; j<length; j++) {
742
				MethodBinding method = methods[j];
743
				TypeBinding[] parameters = method.parameters;
744
				if (argumentTypes.length == parameters.length) {
745
					boolean found = true;
746
					for (int k=0,l=parameters.length; k<l; k++) {
747
						if (parameters[k].erasure() != argumentTypes[k].erasure()) {
748
							found = false;
749
							break;
750
						}
751
					}
752
					if (found) { // current method match in hierarchy
753
						if (resolveLevelAsSuperInvocation(interfaces[i], argumentTypes)) {
754
							return true;
755
						}
756
					}
757
				}
741
			}
758
			}
742
		}
759
		}
743
	}
760
	}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+25 lines)
Lines 9141-9144 Link Here
9141
		javaProject.setRawClasspath(originalRawClasspath, null);
9141
		javaProject.setRawClasspath(originalRawClasspath, null);
9142
	}
9142
	}
9143
}
9143
}
9144
9145
/**
9146
 * @bug 209054: [search] for references to method finds wrong interface call
9147
 * @test Ensure that searching method reference does not find wrong interface call
9148
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=209054"
9149
 */
9150
public void testBug209054() throws CoreException {
9151
	workingCopies = new ICompilationUnit[1];
9152
	workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/xy/Try.java",
9153
		"package xy;\n" + 
9154
		"public class Try implements IReferenceUpdating {\n" + 
9155
		"        IMovePolicy fInter;\n" + 
9156
		"        boolean canDo() { // find references\n" + 
9157
		"                return fInter.canDo(); // not a reference\n" + 
9158
		"        }\n" + 
9159
		"}\n" + 
9160
		"interface IMovePolicy extends IReferenceUpdating {\n" + 
9161
		"        boolean canDo();\n" + 
9162
		"}\n" + 
9163
		"interface IReferenceUpdating {}"
9164
	);
9165
	IMethod method = workingCopies[0].getType("Try").getMethod("canDo", new String[0]);
9166
	search(method, REFERENCES);
9167
	assertSearchResults("");
9168
}
9144
}
9169
}

Return to bug 209054