View | Details | Raw Unified | Return to bug 221065
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+36 lines)
Lines 10197-10202 Link Here
10197
}
10197
}
10198
10198
10199
/**
10199
/**
10200
 * @bug 221065: [search] Search still finds overridden method
10201
 * @test Ensure that correct number of method references are found
10202
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=221065"
10203
 */
10204
public void testBug221065() throws CoreException {
10205
	this.resultCollector.showRule();
10206
	this.workingCopies = new ICompilationUnit[1];
10207
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java",
10208
		"public class Test {\n" +
10209
		"	abstract class A {\n" +
10210
		"		void foo() {}\n" +
10211
		"		void bar() {\n" +
10212
		"			foo();\n" +
10213
		"		}\n" +
10214
		"	}\n" +
10215
		"	class B extends A {\n" +
10216
		"		void foo() {}\n" +
10217
		"		void bar() {\n" +
10218
		"			foo();\n" +
10219
		"		}\n" +
10220
		"	}\n" +
10221
		"	class C extends B {\n" +
10222
		"		void method() {\n" +
10223
		"			foo();\n" +
10224
		"		}\n" +
10225
		"	}\n" +
10226
		"}"
10227
	);
10228
	IMethod method = this.workingCopies[0].getType("Test").getType("A").getMethod("foo", new String[0]);
10229
	search(method, REFERENCES);
10230
	assertSearchResults(
10231
		"src/Test.java void Test$A.bar() [foo()] EXACT_MATCH"
10232
	);
10233
}
10234
10235
/**
10200
 * @bug 222284: [search] ZipException while searching if linked jar doesn't exist any longer
10236
 * @bug 222284: [search] ZipException while searching if linked jar doesn't exist any longer
10201
 * @test Ensure that no exception is raised while searching for a type of the missing jar file
10237
 * @test Ensure that no exception is raised while searching for a type of the missing jar file
10202
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=222284"
10238
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=222284"
(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-23 / +30 lines)
Lines 49-54 Link Here
49
protected int fineGrain() {
49
protected int fineGrain() {
50
	return this.pattern.fineGrain;
50
	return this.pattern.fineGrain;
51
}
51
}
52
53
private MethodBinding getMethodBinding(ReferenceBinding type, TypeBinding[] argumentTypes) {
54
	MethodBinding[] methods = type.getMethods(this.pattern.selector);
55
	MethodBinding method = null;
56
	methodsLoop: for (int i=0, length=methods.length; i<length; i++) {
57
		method = methods[i];
58
		TypeBinding[] parameters = method.parameters;
59
		if (argumentTypes.length == parameters.length) {
60
			for (int j=0,l=parameters.length; j<l; j++) {
61
				if (parameters[j].erasure() != argumentTypes[j].erasure()) {
62
					continue methodsLoop;
63
				}
64
			}
65
			return method;
66
		}
67
	}
68
	return null;
69
}
70
52
public void initializePolymorphicSearch(MatchLocator locator) {
71
public void initializePolymorphicSearch(MatchLocator locator) {
53
	long start = 0;
72
	long start = 0;
54
	if (BasicSearchEngine.VERBOSE) {
73
	if (BasicSearchEngine.VERBOSE) {
Lines 662-668 Link Here
662
681
663
	int level = resolveLevelForType(qualifiedPattern, type);
682
	int level = resolveLevelForType(qualifiedPattern, type);
664
	if (level != IMPOSSIBLE_MATCH) {
683
	if (level != IMPOSSIBLE_MATCH) {
665
		if (!type.isAbstract() && !type.isInterface()) { // if concrete class, then method is overridden
684
		MethodBinding method = argumentTypes == null ? null : getMethodBinding(type, argumentTypes);
685
		if ((method != null && !method.isAbstract() || !type.isAbstract()) && !type.isInterface()) { // if concrete, then method is overridden
666
			level |= OVERRIDDEN_METHOD_FLAVOR;
686
			level |= OVERRIDDEN_METHOD_FLAVOR;
667
		}
687
		}
668
		return level;
688
		return level;
Lines 674-701 Link Here
674
		if (level != IMPOSSIBLE_MATCH) {
694
		if (level != IMPOSSIBLE_MATCH) {
675
			if (argumentTypes != null) {
695
			if (argumentTypes != null) {
676
				// need to verify if method may be overridden
696
				// need to verify if method may be overridden
677
				MethodBinding[] methods = type.getMethods(this.pattern.selector);
697
				MethodBinding method = getMethodBinding(type, argumentTypes);
678
				for (int i=0, length=methods.length; i<length; i++) {
698
				if (method != null) { // one method match in hierarchy
679
					MethodBinding method = methods[i];
699
					if ((level & OVERRIDDEN_METHOD_FLAVOR) != 0) {
680
					TypeBinding[] parameters = method.parameters;
700
						// this method is already overridden on a super class, current match is impossible
681
					if (argumentTypes.length == parameters.length) {
701
						return IMPOSSIBLE_MATCH;
682
						boolean found = true;
702
					}
683
						for (int j=0,l=parameters.length; j<l; j++) {
703
					if (!method.isAbstract() && !type.isInterface()) {
684
							if (parameters[j].erasure() != argumentTypes[j].erasure()) {
704
						// store the fact that the method is overridden
685
								found = false;
705
						level |= OVERRIDDEN_METHOD_FLAVOR;
686
								break;
687
							}
688
						}
689
						if (found) { // one method match in hierarchy
690
							if ((level & OVERRIDDEN_METHOD_FLAVOR) != 0) {
691
								// this method is already overridden on a super class, current match is impossible
692
								return IMPOSSIBLE_MATCH;
693
							}
694
							if (!method.isAbstract() && !type.isInterface()) {
695
								// store the fact that the method is overridden
696
								level |= OVERRIDDEN_METHOD_FLAVOR;
697
							}
698
						}
699
					}
706
					}
700
				}
707
				}
701
			}
708
			}

Return to bug 221065