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 (+148 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 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
}
13528
/** @bug 431357
13529
 * [search] Search API got wrong result, when searching for method references, where the parameter is a member type of another type.
13530
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=431357"
13531
 */
13532
public void testBug431357_003() throws CoreException {
13533
	this.workingCopies = new ICompilationUnit[1];
13534
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java",
13535
			"interface I { \n" +
13536
			"    public void query(Foo.InnerKey key);// Search result of method query(Foo.InnerKey) returns the method query(Bar.InnerKey) too \n" +
13537
			"    public void query/*here*/(Bar.InnerKey key);\n" +
13538
			"}\n" +
13539
			"\n" +
13540
			"class Foo { \n" +
13541
			"    static class InnerKey  {}\n" +
13542
			"}\n" +
13543
			"class Bar {\n" +
13544
			"    static class InnerKey {}\n" +
13545
			"}\n" +
13546
			"\n" +
13547
			"class X {\n" +
13548
			"	public static void foo(I i, Foo.InnerKey key) {\n" +
13549
			"		i.query(key);\n" +
13550
			"	}\n" +
13551
			"	public static void bar(I i, Bar.InnerKey key) {\n" +
13552
			"		i.query(key);\n" +
13553
			"	}\n" +
13554
			"	public static I getInstance() {\n" +
13555
			"		return null;\n" +
13556
			"	}\n" +
13557
			"}\n"
13558
	);
13559
13560
	String str = this.workingCopies[0].getSource();
13561
	String selection = "query/*here*/";
13562
	int start = str.indexOf(selection);
13563
	int length = "query".length();
13564
13565
	IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length);
13566
	MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], REFERENCES | IMPLEMENTORS, EXACT_RULE | ERASURE_RULE);
13567
13568
	new SearchEngine(this.workingCopies).search(pattern,
13569
			new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
13570
			getJavaSearchWorkingCopiesScope(),
13571
			this.resultCollector,
13572
			null);
13573
	assertSearchResults("src/X.java void I.query(Bar.InnerKey) [query] EXACT_MATCH\n" + 
13574
			"src/X.java void X.bar(I, Bar.InnerKey) [query(key)] EXACT_MATCH"
13575
	);
13576
}
13429
// Add new tests in JavaSearchBugsTests2
13577
// Add new tests in JavaSearchBugsTests2
13430
}
13578
}
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-3 / +12 lines)
Lines 990-998 Link Here
990
				boolean found = false;
990
				boolean found = false;
991
				if (methodParameters != null && paramLength == paramTypeslength) {
991
				if (methodParameters != null && paramLength == paramTypeslength) {
992
					for (int p=0; p<paramLength; p++) {
992
					for (int p=0; p<paramLength; p++) {
993
						if (CharOperation.equals(methodParameters[p].sourceName(), parameterTypes[p])) {
993
						char[] sourceName = methodParameters[p].sourceName();
994
							// param erasure match
994
						if (CharOperation.equals(sourceName, parameterTypes[p])) {
995
							found = true;
995
							char[] parameterQualification = methodPattern.parameterQualifications[p];
996
							char[] qualifiedSourceName = methodParameters[p].qualifiedSourceName();
997
							if (parameterQualification != null && qualifiedSourceName != null) {
998
								String qualifier = String.valueOf(qualifiedSourceName);
999
								int l = qualifier.lastIndexOf(String.valueOf(sourceName)) - 1;
1000
								found = l <= 0 ? true : qualifier.substring(0, l).equals(String.valueOf(parameterQualification));
1001
							} else {
1002
								// param erasure match
1003
								found = true;
1004
							}
996
						} else {
1005
						} else {
997
							// type variable
1006
							// type variable
998
							found = false;
1007
							found = false;
(-)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