Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 431357 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (-1 / +100 lines)
Lines 80-85 Link Here
80
import org.eclipse.jdt.internal.core.search.indexing.IndexRequest;
80
import org.eclipse.jdt.internal.core.search.indexing.IndexRequest;
81
import org.eclipse.jdt.internal.core.search.matching.AndPattern;
81
import org.eclipse.jdt.internal.core.search.matching.AndPattern;
82
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
82
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
83
import org.eclipse.jdt.internal.core.search.matching.MethodPattern;
83
import org.eclipse.jdt.internal.core.search.matching.PatternLocator;
84
import org.eclipse.jdt.internal.core.search.matching.PatternLocator;
84
import org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern;
85
import org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern;
85
86
Lines 92-98 Link Here
92
// Debug
93
// Debug
93
static {
94
static {
94
//	 org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true;
95
//	 org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true;
95
//	TESTS_NAMES = new String[] {"testBug324189d"};
96
//	TESTS_NAMES = new String[] {"testBug431357"};
96
}
97
}
97
98
98
public JavaSearchBugsTests(String name) {
99
public JavaSearchBugsTests(String name) {
Lines 13426-13430 Link Here
13426
			"src/b400919/X.java b400919.X2 [Marker] EXACT_MATCH" 
13427
			"src/b400919/X.java b400919.X2 [Marker] EXACT_MATCH" 
13427
	);	
13428
	);	
13428
}
13429
}
13430
/** @bug 431357
13431
 * [search] Search API got wrong result, when searching for method references, where the parameter is a member type of another type.
13432
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=431357"
13433
 */
13434
public void testBug431357_001() throws CoreException {
13435
	this.workingCopies = new ICompilationUnit[1];
13436
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
13437
			"interface I { \n" +
13438
			"    public void query(Foo.InnerKey key);// Search result of method query(Foo.InnerKey) returns the method query(Bar.InnerKey) too \n" +
13439
			"    public void query(Bar.InnerKey key);\n" +
13440
			"}\n" +
13441
			"\n" +
13442
			"class Foo { \n" +
13443
			"    static class InnerKey  {}\n" +
13444
			"}\n" +
13445
			"class Bar {\n" +
13446
			"    static class InnerKey {}\n" +
13447
			"}\n" +
13448
			"\n" +
13449
			"class X {\n" +
13450
			"	public static void foo(I i, Foo.InnerKey key) {\n" +
13451
			"		i.query(key);\n" +
13452
			"	}\n" +
13453
			"	public static void bar(I i, Bar.InnerKey key) {\n" +
13454
			"		i.query(key);\n" +
13455
			"	}\n" +
13456
			"	public static I getInstance() {\n" +
13457
			"		return null;\n" +
13458
			"	}\n" +
13459
			"}\n"
13460
	);
13461
13462
	String str = this.workingCopies[0].getSource();
13463
	String selection = "query";
13464
	int start = str.indexOf(selection);
13465
	int length = selection.length();
13466
13467
	IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
13468
	MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], REFERENCES, EXACT_RULE | ERASURE_RULE);
13469
13470
	new SearchEngine(this.workingCopies).search(pattern,
13471
			new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
13472
			getJavaSearchWorkingCopiesScope(),
13473
			this.resultCollector,
13474
			null);
13475
	assertSearchResults(
13476
			"src/X.java void X.foo(I, Foo.InnerKey) [query(key)] EXACT_MATCH"
13477
	);
13478
}
13479
/** @bug 431357
13480
 * [search] Search API got wrong result, when searching for method references, where the parameter is a member type of another type.
13481
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=431357"
13482
 */
13483
public void testBug431357_002() throws CoreException {
13484
	this.workingCopies = new ICompilationUnit[1];
13485
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
13486
			"interface I { \n" +
13487
			"    public void query(Foo.InnerKey key);// Search result of method query(Foo.InnerKey) returns the method query(Bar.InnerKey) too \n" +
13488
			"    public void query(Bar.InnerKey key);\n" +
13489
			"}\n" +
13490
			"\n" +
13491
			"class Foo { \n" +
13492
			"    static class InnerKey  {}\n" +
13493
			"}\n" +
13494
			"class Bar {\n" +
13495
			"    static class InnerKey {}\n" +
13496
			"}\n" +
13497
			"\n" +
13498
			"class X {\n" +
13499
			"	public static void foo(I i, Foo.InnerKey key) {\n" +
13500
			"		i.query(key);\n" +
13501
			"	}\n" +
13502
			"	public static void bar(I i, Bar.InnerKey key) {\n" +
13503
			"		i.query(key);\n" +
13504
			"	}\n" +
13505
			"	public static I getInstance() {\n" +
13506
			"		return null;\n" +
13507
			"	}\n" +
13508
			"}\n"
13509
	);
13510
13511
	String str = this.workingCopies[0].getSource();
13512
	String selection = "query";
13513
	int start = str.indexOf(selection);
13514
	int length = selection.length();
13515
13516
	IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
13517
	MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], REFERENCES | IMPLEMENTORS, EXACT_RULE | ERASURE_RULE);
13518
13519
	new SearchEngine(this.workingCopies).search(pattern,
13520
			new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
13521
			getJavaSearchWorkingCopiesScope(),
13522
			this.resultCollector,
13523
			null);
13524
	assertSearchResults( "src/X.java void I.query(Foo.InnerKey) [query] EXACT_MATCH\n" +
13525
			"src/X.java void X.foo(I, Foo.InnerKey) [query(key)] EXACT_MATCH"
13526
	);
13527
}
13429
// Add new tests in JavaSearchBugsTests2
13528
// Add new tests in JavaSearchBugsTests2
13430
}
13529
}
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-5 / +18 lines)
Lines 313-323 Link Here
313
		for (int i = 0; i < parameterCount; i++) {
313
		for (int i = 0; i < parameterCount; i++) {
314
			TypeBinding argType = method.parameters[i];
314
			TypeBinding argType = method.parameters[i];
315
			int newLevel = IMPOSSIBLE_MATCH;
315
			int newLevel = IMPOSSIBLE_MATCH;
316
			boolean foundLevel = false;
316
			if (argType.isMemberType()) {
317
			if (argType.isMemberType()) {
317
				// only compare source name for member type (bug 41018)
318
				MethodBinding focusMethodBinding = this.matchLocator.getMethodBinding(this.pattern);
318
				newLevel = CharOperation.match(this.pattern.parameterSimpleNames[i], argType.sourceName(), this.isCaseSensitive)
319
				if (focusMethodBinding != null) {// textual comparison insufficient
319
					? ACCURATE_MATCH
320
					TypeBinding[] parameters = focusMethodBinding.parameters;
320
					: IMPOSSIBLE_MATCH;
321
					if (parameters.length >= parameterCount) {
322
						newLevel = argType.isCompatibleWith((parameters[i])) ? ACCURATE_MATCH : IMPOSSIBLE_MATCH;
323
						foundLevel = true;
324
					}
325
				}
326
				if (!foundLevel) { // a safety net
327
					// only compare source name for member type (bug 41018)
328
					newLevel = CharOperation.match(this.pattern.parameterSimpleNames[i], argType.sourceName(), this.isCaseSensitive)
329
							? ACCURATE_MATCH
330
							: IMPOSSIBLE_MATCH;
331
				}
321
			} else {
332
			} else {
322
				// TODO (frederic) use this call to refine accuracy on parameter types
333
				// TODO (frederic) use this call to refine accuracy on parameter types
323
//				 newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], this.pattern.parametersTypeArguments[i], 0, argType);
334
//				 newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], this.pattern.parametersTypeArguments[i], 0, argType);
Lines 328-334 Link Here
328
					if (skipImpossibleArg) {
339
					if (skipImpossibleArg) {
329
						// Do not consider match as impossible while finding declarations and source level >= 1.5
340
						// Do not consider match as impossible while finding declarations and source level >= 1.5
330
					 	// (see  bugs https://bugs.eclipse.org/bugs/show_bug.cgi?id=79990, 96761, 96763)
341
					 	// (see  bugs https://bugs.eclipse.org/bugs/show_bug.cgi?id=79990, 96761, 96763)
331
						newLevel = level;
342
						if (!foundLevel) {
343
							newLevel = level;
344
						}
332
					} else if (argType.isTypeVariable()) {
345
					} else if (argType.isTypeVariable()) {
333
						newLevel = level;
346
						newLevel = level;
334
						foundTypeVariable = true;
347
						foundTypeVariable = true;

Return to bug 431357