|
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 |
} |