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 246299 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), 10.03 KB, created by
Manoj N Palat
on 2014-08-25 04:24:33 EDT
(
hide
)
Description:
Proposed Patch
Filename:
MIME Type:
Creator:
Manoj N Palat
Created:
2014-08-25 04:24:33 EDT
Size:
10.03 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..d062b0f 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,152 @@ > "src/b400919/X.java b400919.X2 [Marker] 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_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], REFERENCES | IMPLEMENTORS, 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], REFERENCES | IMPLEMENTORS, 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" >+ ); >+} > // Add new tests in JavaSearchBugsTests2 > } >\ 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..fc5c068 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 >@@ -990,9 +990,18 @@ > boolean found = false; > 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])) { >+ char[] parameterQualification = methodPattern.parameterQualifications[p]; >+ char[] qualifiedSourceName = methodParameters[p].qualifiedSourceName(); >+ if (parameterQualification != null && qualifiedSourceName != null) { >+ String qualifier = String.valueOf(qualifiedSourceName); >+ int l = qualifier.lastIndexOf(String.valueOf(sourceName)) - 1; >+ found = l <= 0 ? true : qualifier.substring(0, l).equals(String.valueOf(parameterQualification)); >+ } else { >+ // param erasure match >+ found = true; >+ } > } else { > // type variable > found = false; >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..f3ad0a6 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 >@@ -313,11 +313,22 @@ > for (int i = 0; i < parameterCount; i++) { > TypeBinding argType = method.parameters[i]; > int newLevel = IMPOSSIBLE_MATCH; >+ boolean foundLevel = false; > 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; >+ MethodBinding focusMethodBinding = this.matchLocator.getMethodBinding(this.pattern); >+ if (focusMethodBinding != null) {// textual comparison insufficient >+ TypeBinding[] parameters = focusMethodBinding.parameters; >+ if (parameters.length >= parameterCount) { >+ newLevel = argType.isCompatibleWith((parameters[i])) ? ACCURATE_MATCH : IMPOSSIBLE_MATCH; >+ foundLevel = true; >+ } >+ } >+ if (!foundLevel) { // a safety net >+ // only compare source name for member type (bug 41018) >+ newLevel = CharOperation.match(this.pattern.parameterSimpleNames[i], argType.sourceName(), this.isCaseSensitive) >+ ? ACCURATE_MATCH >+ : IMPOSSIBLE_MATCH; >+ } > } 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 +339,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;
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