Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 247094 Details for
Bug 431357
[search] Search API got wrong result, when searching for method references, where the parameter is a member type of another type.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Proposed Patch
Fix-for-Bug-431357-search-Search-API-got-wrong-resul.patch (text/plain), 26.69 KB, created by
Manoj N Palat
on 2014-09-15 21:00:24 EDT
(
hide
)
Description:
Proposed Patch
Filename:
MIME Type:
Creator:
Manoj N Palat
Created:
2014-09-15 21:00:24 EDT
Size:
26.69 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java >index e03059e..76d85ee 100644 >--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java >+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java >@@ -80,6 +80,7 @@ > import org.eclipse.jdt.internal.core.search.indexing.IndexRequest; > import org.eclipse.jdt.internal.core.search.matching.AndPattern; > import org.eclipse.jdt.internal.core.search.matching.MatchLocator; >+import org.eclipse.jdt.internal.core.search.matching.MethodPattern; > import org.eclipse.jdt.internal.core.search.matching.PatternLocator; > import org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern; > >@@ -13426,5 +13427,595 @@ > "src/b400919/X.java b400919.X2 [Marker] EXACT_MATCH" > ); > } >-// Add new tests in JavaSearchBugsTests2 >+/** @bug 431357 >+ * [search] Search API got wrong result, when searching for method references, where the parameter is a member type of another type. >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=431357" >+ */ >+public void testBug431357_001() throws CoreException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", >+ "interface I { \n" + >+ " public void query(Foo.InnerKey key);// Search result of method query(Foo.InnerKey) returns the method query(Bar.InnerKey) too \n" + >+ " public void query(Bar.InnerKey key);\n" + >+ "}\n" + >+ "\n" + >+ "class Foo { \n" + >+ " static class InnerKey {}\n" + >+ "}\n" + >+ "class Bar {\n" + >+ " static class InnerKey {}\n" + >+ "}\n" + >+ "\n" + >+ "class X {\n" + >+ " public static void foo(I i, Foo.InnerKey key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ " public static void bar(I i, Bar.InnerKey key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ " public static I getInstance() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ ); >+ >+ String str = this.workingCopies[0].getSource(); >+ String selection = "query"; >+ int start = str.indexOf(selection); >+ int length = selection.length(); >+ >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); >+ MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], REFERENCES, EXACT_RULE | ERASURE_RULE); >+ >+ new SearchEngine(this.workingCopies).search(pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ getJavaSearchWorkingCopiesScope(), >+ this.resultCollector, >+ null); >+ assertSearchResults( >+ "src/X.java void X.foo(I, Foo.InnerKey) [query(key)] EXACT_MATCH" >+ ); >+} >+/** @bug 431357 >+ * [search] Search API got wrong result, when searching for method references, where the parameter is a member type of another type. >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=431357" >+ */ >+public void testBug431357_002() throws CoreException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", >+ "interface I { \n" + >+ " public void query(Foo.InnerKey key);// Search result of method query(Foo.InnerKey) returns the method query(Bar.InnerKey) too \n" + >+ " public void query(Bar.InnerKey key);\n" + >+ "}\n" + >+ "\n" + >+ "class Foo { \n" + >+ " static class InnerKey {}\n" + >+ "}\n" + >+ "class Bar {\n" + >+ " static class InnerKey {}\n" + >+ "}\n" + >+ "\n" + >+ "class X {\n" + >+ " public static void foo(I i, Foo.InnerKey key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ " public static void bar(I i, Bar.InnerKey key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ " public static I getInstance() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ ); >+ >+ String str = this.workingCopies[0].getSource(); >+ String selection = "query"; >+ int start = str.indexOf(selection); >+ int length = selection.length(); >+ >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); >+ MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], ALL_OCCURRENCES, EXACT_RULE | ERASURE_RULE); >+ >+ new SearchEngine(this.workingCopies).search(pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ getJavaSearchWorkingCopiesScope(), >+ this.resultCollector, >+ null); >+ assertSearchResults( "src/X.java void I.query(Foo.InnerKey) [query] EXACT_MATCH\n" + >+ "src/X.java void X.foo(I, Foo.InnerKey) [query(key)] EXACT_MATCH" >+ ); >+} >+/** @bug 431357 >+ * [search] Search API got wrong result, when searching for method references, where the parameter is a member type of another type. >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=431357" >+ */ >+public void testBug431357_003() throws CoreException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", >+ "interface I { \n" + >+ " public void query(Foo.InnerKey key);// Search result of method query(Foo.InnerKey) returns the method query(Bar.InnerKey) too \n" + >+ " public void query/*here*/(Bar.InnerKey key);\n" + >+ "}\n" + >+ "\n" + >+ "class Foo { \n" + >+ " static class InnerKey {}\n" + >+ "}\n" + >+ "class Bar {\n" + >+ " static class InnerKey {}\n" + >+ "}\n" + >+ "\n" + >+ "class X {\n" + >+ " public static void foo(I i, Foo.InnerKey key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ " public static void bar(I i, Bar.InnerKey key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ " public static I getInstance() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ ); >+ >+ String str = this.workingCopies[0].getSource(); >+ String selection = "query/*here*/"; >+ int start = str.indexOf(selection); >+ int length = "query".length(); >+ >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); >+ MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], ALL_OCCURRENCES, EXACT_RULE | ERASURE_RULE); >+ >+ new SearchEngine(this.workingCopies).search(pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ getJavaSearchWorkingCopiesScope(), >+ this.resultCollector, >+ null); >+ assertSearchResults("src/X.java void I.query(Bar.InnerKey) [query] EXACT_MATCH\n" + >+ "src/X.java void X.bar(I, Bar.InnerKey) [query(key)] EXACT_MATCH" >+ ); >+} >+/** @bug 431357 >+ * [search] Search API got wrong result, when searching for method references, where the parameter is a member type of another type. >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=431357" >+ */ >+public void testBug431357_004() throws CoreException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", >+ "// --\n" + >+ "interface I { \n" + >+ " public void query/*here*/(Foo.Key key);// Search result of method query(Foo.Key) returns the method query(Bar.Key) too \n" + >+ " public void query(Key key);\n" + >+ "}\n" + >+ "\n" + >+ "class Foo { \n" + >+ " static class Key { \n" + >+ " }\n" + >+ " public static void foo(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ " \n" + >+ "}\n" + >+ "\n" + >+ "class Key {\n" + >+ " \n" + >+ "}\n" + >+ "class Bar {\n" + >+ " \n" + >+ " public static void bar(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ "}\n" + >+ "\n" + >+ "public class X {\n" + >+ " public static I getInstance() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ ); >+ >+ String str = this.workingCopies[0].getSource(); >+ String selection = "query/*here*/"; >+ int start = str.indexOf(selection); >+ int length = "query".length(); >+ >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); >+ MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], ALL_OCCURRENCES, EXACT_RULE | ERASURE_RULE); >+ >+ new SearchEngine(this.workingCopies).search(pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ getJavaSearchWorkingCopiesScope(), >+ this.resultCollector, >+ null); >+ assertSearchResults( >+ "src/X.java void I.query(Foo.Key) [query] EXACT_MATCH\n" + >+ "src/X.java void Foo.foo(I, Key) [query(key)] EXACT_MATCH" >+ ); >+} >+/** @bug 431357 >+ * [search] Search API got wrong result, when searching for method references, where the parameter is a member type of another type. >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=431357" >+ */ >+public void testBug431357_005() throws CoreException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", >+ "// --\n" + >+ "interface I { \n" + >+ " public void query(Foo.Key key);// Search result of method query(Foo.Key) returns the method query(Bar.Key) too \n" + >+ " public void query/*here*/(Key key);\n" + >+ "}\n" + >+ "\n" + >+ "class Foo { \n" + >+ " static class Key { \n" + >+ " }\n" + >+ " public static void foo(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ " \n" + >+ "}\n" + >+ "\n" + >+ "class Key {\n" + >+ " \n" + >+ "}\n" + >+ "class Bar {\n" + >+ " \n" + >+ " public static void bar(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ "}\n" + >+ "\n" + >+ "public class X {\n" + >+ " public static I getInstance() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ ); >+ >+ String str = this.workingCopies[0].getSource(); >+ String selection = "query/*here*/"; >+ int start = str.indexOf(selection); >+ int length = "query".length(); >+ >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); >+ MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], ALL_OCCURRENCES, EXACT_RULE | ERASURE_RULE); >+ >+ new SearchEngine(this.workingCopies).search(pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ getJavaSearchWorkingCopiesScope(), >+ this.resultCollector, >+ null); >+ assertSearchResults( >+ "src/X.java void I.query(Key) [query] EXACT_MATCH\n" + >+ "src/X.java void Bar.bar(I, Key) [query(key)] EXACT_MATCH" >+ ); >+} >+/** @bug 431357 >+ * [search] Search API got wrong result, when searching for method references, where the parameter is a member type of another type. >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=431357" >+ */ >+public void testBug431357_006() throws CoreException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", >+ "// --\n" + >+ "interface I { \n" + >+ " public void query/*here*/(Foo.Key key);// Search result of method query(Foo.Key) returns the method query(Bar.Key) too \n" + >+ " public void query(Key key);\n" + >+ " public void query(Bar.Key key);\n" + >+ "}\n" + >+ "\n" + >+ "class Foo { \n" + >+ " static class Key { \n" + >+ " }\n" + >+ " public static void foo(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ " \n" + >+ "}\n" + >+ "\n" + >+ "class Key {\n" + >+ " \n" + >+ "}\n" + >+ "class Bar {\n" + >+ " static class Key {\n" + >+ " \n" + >+ " } \n" + >+ " public static void bar(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ "}\n" + >+ "\n" + >+ "public class X {\n" + >+ " public static I getInstance() {\n" + >+ " return null;\n" + >+ " }\n" + >+ " public static void bar(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ "}\n" >+ ); >+ >+ String str = this.workingCopies[0].getSource(); >+ String selection = "query/*here*/"; >+ int start = str.indexOf(selection); >+ int length = "query".length(); >+ >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); >+ MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], ALL_OCCURRENCES, EXACT_RULE | ERASURE_RULE); >+ >+ new SearchEngine(this.workingCopies).search(pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ getJavaSearchWorkingCopiesScope(), >+ this.resultCollector, >+ null); >+ assertSearchResults( >+ "src/X.java void I.query(Foo.Key) [query] EXACT_MATCH\n" + >+ "src/X.java void Foo.foo(I, Key) [query(key)] EXACT_MATCH" >+ ); >+} >+public void testBug431357_007() throws CoreException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", >+ "// --\n" + >+ "interface I { \n" + >+ " public void query(Foo.Key key);// Search result of method query(Foo.Key) returns the method query(Bar.Key) too \n" + >+ " public void query/*here*/(Key key);\n" + >+ " public void query(Bar.Key key);\n" + >+ "}\n" + >+ "\n" + >+ "class Foo { \n" + >+ " static class Key { \n" + >+ " }\n" + >+ " public static void foo(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ " \n" + >+ "}\n" + >+ "\n" + >+ "class Key {\n" + >+ " \n" + >+ "}\n" + >+ "class Bar {\n" + >+ " static class Key {\n" + >+ " \n" + >+ " } \n" + >+ " public static void bar(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ "}\n" + >+ "\n" + >+ "public class X {\n" + >+ " public static I getInstance() {\n" + >+ " return null;\n" + >+ " }\n" + >+ " public static void bar(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ "}\n" >+ ); >+ >+ String str = this.workingCopies[0].getSource(); >+ String selection = "query/*here*/"; >+ int start = str.indexOf(selection); >+ int length = "query".length(); >+ >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); >+ MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], ALL_OCCURRENCES, EXACT_RULE | ERASURE_RULE); >+ >+ new SearchEngine(this.workingCopies).search(pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ getJavaSearchWorkingCopiesScope(), >+ this.resultCollector, >+ null); >+ assertSearchResults( >+ "src/X.java void I.query(Key) [query] EXACT_MATCH\n" + >+ "src/X.java void X.bar(I, Key) [query(key)] EXACT_MATCH" >+ ); >+} >+public void testBug431357_008() throws CoreException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", >+ "// --\n" + >+ "interface I { \n" + >+ " public void query(Foo.Key key);// Search result of method query(Foo.Key) returns the method query(Bar.Key) too \n" + >+ " public void query(Key key);\n" + >+ " public void query/*here*/(Bar.Key key);\n" + >+ "}\n" + >+ "\n" + >+ "class Foo { \n" + >+ " static class Key { \n" + >+ " }\n" + >+ " public static void foo(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ " \n" + >+ "}\n" + >+ "\n" + >+ "class Key {\n" + >+ " \n" + >+ "}\n" + >+ "class Bar {\n" + >+ " static class Key {\n" + >+ " \n" + >+ " } \n" + >+ " public static void bar(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ "}\n" + >+ "\n" + >+ "public class X {\n" + >+ " public static I getInstance() {\n" + >+ " return null;\n" + >+ " }\n" + >+ " public static void bar(I i, Key key) {\n" + >+ " i.query(key);\n" + >+ " }\n" + >+ "}\n" >+ ); >+ >+ String str = this.workingCopies[0].getSource(); >+ String selection = "query/*here*/"; >+ int start = str.indexOf(selection); >+ int length = "query".length(); >+ >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); >+ MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], ALL_OCCURRENCES, EXACT_RULE | ERASURE_RULE); >+ >+ new SearchEngine(this.workingCopies).search(pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ getJavaSearchWorkingCopiesScope(), >+ this.resultCollector, >+ null); >+ assertSearchResults( >+ "src/X.java void I.query(Bar.Key) [query] EXACT_MATCH\n" + >+ "src/X.java void Bar.bar(I, Key) [query(key)] EXACT_MATCH" >+ ); >+} >+public void testBug431357_009() throws CoreException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", >+ "interface MyIF { \n" + >+ " public void query(Foo.InnerKey fk, Bar.InnerKey bk, String s); \n" + >+ " public void query/*here*/(Bar.InnerKey fk, Bar.InnerKey bk, String s);\n" + >+ "}\n" + >+ "\n" + >+ "class Foo { \n" + >+ " static class InnerKey { \n" + >+ " }\n" + >+ "\n" + >+ "}\n" + >+ "\n" + >+ "class Bar {\n" + >+ " static class InnerKey {\n" + >+ " }\n" + >+ " public static void bar(MyIF i, Foo.InnerKey fk, Bar.InnerKey bk) {\n" + >+ " i.query(fk, bk, \"\");\n" + >+ " }\n" + >+ "}\n" + >+ "public class X {}\n" >+ ); >+ >+ String str = this.workingCopies[0].getSource(); >+ String selection = "query/*here*/"; >+ int start = str.indexOf(selection); >+ int length = "query".length(); >+ >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); >+ MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], REFERENCES, EXACT_RULE | ERASURE_RULE); >+ >+ new SearchEngine(this.workingCopies).search(pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ getJavaSearchWorkingCopiesScope(), >+ this.resultCollector, >+ null); >+ assertSearchResults("" >+ ); >+} >+public void testBug431357_010() throws CoreException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", >+ "interface MyIF { \n" + >+ " public void query(Foo.InnerKey fk, String s); \n" + >+ " public void query/*here*/(Bar.InnerKey fk, String s);\n" + >+ "}\n" + >+ "\n" + >+ "class Foo { \n" + >+ " static class InnerKey {}\n" + >+ "}\n" + >+ "\n" + >+ "class Bar {\n" + >+ " static class InnerKey {}\n" + >+ " public static void bar(MyIF i, Foo.InnerKey fk) {\n" + >+ " i.query(fk, \"\");\n" + >+ " }\n" + >+ "}\n" + >+ "public class X {}\n" >+ ); >+ >+ String str = this.workingCopies[0].getSource(); >+ String selection = "query/*here*/"; >+ int start = str.indexOf(selection); >+ int length = "query".length(); >+ >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); >+ MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], REFERENCES, EXACT_RULE | ERASURE_RULE); >+ >+ new SearchEngine(this.workingCopies).search(pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ getJavaSearchWorkingCopiesScope(), >+ this.resultCollector, >+ null); >+ assertSearchResults("" >+ ); >+} >+public void testBug431357_011() throws CoreException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", >+ "interface MyIF { \n" + >+ " public void query(String s, Foo.InnerKey fk); \n" + >+ "}\n" + >+ "\n" + >+ "class Foo { \n" + >+ " static class InnerKey {}\n" + >+ "}\n" + >+ "\n" + >+ "class Bar {\n" + >+ " static class InnerKey {}\n" + >+ " public static void bar(MyIF i, Foo.InnerKey fk) {\n" + >+ " i.query(\"\", fk);\n" + >+ " }\n" + >+ "}\n" + >+ "public class X {}\n" >+ ); >+ >+ String nonExistentPattern = "MyIF.query(String, Bar.InnerKey)"; >+ MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(nonExistentPattern, IJavaSearchConstants.METHOD, REFERENCES, EXACT_RULE | ERASURE_RULE); >+ >+ new SearchEngine(this.workingCopies).search(pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ getJavaSearchWorkingCopiesScope(), >+ this.resultCollector, >+ null); >+ assertSearchResults("" >+ );// Add new tests in JavaSearchBugsTests2 >+} >+public void testBug431357_012() throws CoreException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/X.java", >+ "interface MyIF { \n" + >+ " public void query/*here*/(Foo.InnerKey fk, Bar.InnerKey bk, String s); \n" + >+ " public void query(Bar.InnerKey fk, Bar.InnerKey bk, String s);\n" + >+ "}\n" + >+ "\n" + >+ "class Foo { \n" + >+ " static class InnerKey { \n" + >+ " }\n" + >+ " \n" + >+ "}\n" + >+ "\n" + >+ "class Bar {\n" + >+ " static class InnerKey extends Foo.InnerKey {\n" + >+ " }\n" + >+ " public static void bar(MyIF i, Foo.InnerKey fk, Bar.InnerKey bk) {\n" + >+ " i.query(fk, bk, \"\");\n" + >+ " }\n" + >+ "}\n" + >+ "public class X {}\n" >+ ); >+ >+ String str = this.workingCopies[0].getSource(); >+ String selection = "query/*here*/"; >+ int start = str.indexOf(selection); >+ int length = "query".length(); >+ >+ IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length); >+ MethodPattern pattern = (MethodPattern) SearchPattern.createPattern(elements[0], ALL_OCCURRENCES, EXACT_RULE | ERASURE_RULE); >+ >+ new SearchEngine(this.workingCopies).search(pattern, >+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, >+ getJavaSearchWorkingCopiesScope(), >+ this.resultCollector, >+ null); >+ assertSearchResults("src/X.java void MyIF.query(Foo.InnerKey, Bar.InnerKey, String) [query] EXACT_MATCH\n" + >+ "src/X.java void Bar.bar(MyIF, Foo.InnerKey, Bar.InnerKey) [query(fk, bk, \"\")] EXACT_MATCH" >+ ); >+} > } >\ No newline at end of file >diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java >index 9c80563..060eae7 100644 >--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java >+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java >@@ -953,6 +953,25 @@ > } > return null; > } >+ >+private boolean isSameQualifier(char[] patternParameterQualification, char[] methodQualifiedSourceName, char[] sourceName) { >+ String methodParameterQualification = null; >+ if (methodQualifiedSourceName != null) { >+ String qualifier = String.valueOf(methodQualifiedSourceName); >+ int l = qualifier.lastIndexOf(String.valueOf(sourceName)) - 1; >+ if (l > 0) { >+ methodParameterQualification = qualifier.substring(0, l); >+ } >+ } >+ >+ String patternParameterQualifier = patternParameterQualification != null ? String.valueOf(patternParameterQualification) : null; >+ if (patternParameterQualifier == null && methodParameterQualification == null) >+ return true; >+ if (patternParameterQualifier != null && methodParameterQualification != null) >+ return patternParameterQualifier.equals(methodParameterQualification); >+ return false; >+} >+ > private MethodBinding getMethodBinding0(MethodPattern methodPattern) { > if (this.unitScope == null) return null; > // Try to get binding from cache >@@ -982,17 +1001,24 @@ > int methodsLength = methods.length; > TypeVariableBinding[] refTypeVariables = referenceBinding.typeVariables(); > int typeVarLength = refTypeVariables==null ? 0 : refTypeVariables.length; >+ int possibleIndex = -1; > for (int i=0; i<methodsLength; i++) { > TypeBinding[] methodParameters = methods[i].parameters; > int paramLength = methodParameters==null ? 0 : methodParameters.length; > TypeVariableBinding[] methodTypeVariables = methods[i].typeVariables; > int methTypeVarLength = methodTypeVariables==null ? 0 : methodTypeVariables.length; > boolean found = false; >+ possibleIndex = -1; > if (methodParameters != null && paramLength == paramTypeslength) { > for (int p=0; p<paramLength; p++) { >- if (CharOperation.equals(methodParameters[p].sourceName(), parameterTypes[p])) { >- // param erasure match >- found = true; >+ char[] sourceName = methodParameters[p].sourceName(); >+ if (CharOperation.equals(sourceName, parameterTypes[p])) { >+ boolean tmp = isSameQualifier(methodPattern.parameterQualifications[p], methodParameters[p].qualifiedSourceName(), sourceName); >+ found = p == 0 ? tmp : found & tmp; >+ if (!found) { >+ // ref bug 41018 - catch this at isCompatible(arg) >+ possibleIndex = i; >+ } > } else { > // type variable > found = false; >@@ -1023,6 +1049,10 @@ > return methods[i]; > } > } >+ if (possibleIndex > -1 && possibleIndex < methodsLength) { >+ this.bindings.put(methodPattern, methods[possibleIndex]); >+ return methods[possibleIndex]; >+ } > } > } > this.bindings.put(methodPattern, new ProblemMethodBinding(methodPattern.selector, null, ProblemReasons.NotFound)); >diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java >index 61bc89c..17635e3 100644 >--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java >+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java >@@ -309,15 +309,25 @@ > return INACCURATE_MATCH; > } > boolean foundTypeVariable = false; >+ MethodBinding focusMethodBinding = null; >+ boolean checkedFocus = false; > // verify each parameter > for (int i = 0; i < parameterCount; i++) { > TypeBinding argType = method.parameters[i]; > int newLevel = IMPOSSIBLE_MATCH; >- if (argType.isMemberType()) { >- // only compare source name for member type (bug 41018) >- newLevel = CharOperation.match(this.pattern.parameterSimpleNames[i], argType.sourceName(), this.isCaseSensitive) >- ? ACCURATE_MATCH >- : IMPOSSIBLE_MATCH; >+ boolean foundLevel = false; >+ if (argType.isMemberType() || this.pattern.parameterQualifications[i] != null) { >+ if (!checkedFocus) { >+ focusMethodBinding = this.matchLocator.getMethodBinding(this.pattern); >+ checkedFocus = true; >+ } >+ if (focusMethodBinding != null) {// textual comparison insufficient >+ TypeBinding[] parameters = focusMethodBinding.parameters; >+ if (parameters.length >= parameterCount) { >+ newLevel = argType.isEquivalentTo((parameters[i])) ? ACCURATE_MATCH : IMPOSSIBLE_MATCH; >+ foundLevel = true; >+ } >+ } > } else { > // TODO (frederic) use this call to refine accuracy on parameter types > // newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], this.pattern.parametersTypeArguments[i], 0, argType); >@@ -328,7 +338,9 @@ > if (skipImpossibleArg) { > // Do not consider match as impossible while finding declarations and source level >= 1.5 > // (see bugs https://bugs.eclipse.org/bugs/show_bug.cgi?id=79990, 96761, 96763) >- newLevel = level; >+ if (!foundLevel) { >+ newLevel = level; >+ } > } else if (argType.isTypeVariable()) { > newLevel = level; > foundTypeVariable = true; >@@ -342,7 +354,8 @@ > if (foundTypeVariable) { > if (!method.isStatic() && !method.isPrivate()) { > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=123836, No point in textually comparing type variables, captures etc with concrete types. >- MethodBinding focusMethodBinding = this.matchLocator.getMethodBinding(this.pattern); >+ if (!checkedFocus) >+ focusMethodBinding = this.matchLocator.getMethodBinding(this.pattern); > if (focusMethodBinding != null) { > if (matchOverriddenMethod(focusMethodBinding.declaringClass, focusMethodBinding, method)) { > return ACCURATE_MATCH;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 431357
:
245177
|
246151
|
246299
|
246984
|
247051
|
247094
|
248117