Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2015-12-02 15:13:33 +0000
committerManoj Palat2015-12-02 15:13:33 +0000
commit65a147b80f31dc3e10f9d46f87c3805f7af615cd (patch)
tree0aded37499c06c3a6c25fbc6486e0529ec6c7b1a
parent297840d814bc6fb8f78f68a36eb74676aea7b3b0 (diff)
downloadeclipse.jdt.core-65a147b80f31dc3e10f9d46f87c3805f7af615cd.tar.gz
eclipse.jdt.core-65a147b80f31dc3e10f9d46f87c3805f7af615cd.tar.xz
eclipse.jdt.core-65a147b80f31dc3e10f9d46f87c3805f7af615cd.zip
Fix for Bug 483303 [search] searchAllMethodNames API gives invalid
result for method with parameter
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java63
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java40
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/MethodNameMatchRequestorWrapper.java11
3 files changed, 113 insertions, 1 deletions
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 60220c80ec..f8f871ff6b 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
@@ -55,6 +55,8 @@ import org.eclipse.jdt.core.WorkingCopyOwner;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.core.search.MethodNameMatch;
+import org.eclipse.jdt.core.search.MethodNameMatchRequestor;
import org.eclipse.jdt.core.search.MethodReferenceMatch;
import org.eclipse.jdt.core.search.ReferenceMatch;
import org.eclipse.jdt.core.search.SearchEngine;
@@ -14702,4 +14704,65 @@ public void testBug478042_wScope_008() throws Exception {
collector
);
}
+public void testBug483303_001() throws Exception {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/com/test/C1.java",
+ "package com.test;\n" +
+ "public class C1 {\n" +
+ " void m1(int i) {\n" +
+ " }\n" +
+ "}\n"
+ );
+
+ MethodNameMatchCollector collector = new MethodNameMatchCollector() {
+ @Override
+ public String toString() {
+ return toFullyQualifiedNamesString();
+ }
+ };
+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(this.workingCopies);
+ searchAllMethodNames(
+ null, SearchPattern.R_PREFIX_MATCH, //package
+ null, SearchPattern.R_PREFIX_MATCH, // declaring Qualification
+ null, SearchPattern.R_PREFIX_MATCH, // declaring SimpleType
+ "m1", SearchPattern.R_PREFIX_MATCH,
+ scope, collector);
+ assertSearchResults(
+ "/JavaSearchBugs/src/com/test/C1.java void com.test.C1.m1(int i)",
+ collector
+ );
+}
+public void testBug483303_002() throws Exception {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/com/test/C1.java",
+ "package com.test;\n" +
+ "public class C1 {\n" +
+ " void m1(int i) {\n" +
+ " }\n" +
+ "}\n"
+ );
+
+ class Collector extends MethodNameMatchRequestor {
+ List<MethodNameMatch> matches = new ArrayList<>();
+ @Override
+ public void acceptMethodNameMatch(MethodNameMatch match) {
+ this.matches.add(match);
+ }
+ }
+ Collector collector = new Collector();
+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(this.workingCopies);
+ new SearchEngine(this.workingCopies).searchAllMethodNames(
+ null, SearchPattern.R_PREFIX_MATCH, //package
+ null, SearchPattern.R_PREFIX_MATCH, // declaring Qualification
+ null, SearchPattern.R_PREFIX_MATCH, // declaring SimpleType
+ "m1".toCharArray(), SearchPattern.R_PREFIX_MATCH,
+ scope, collector,
+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
+ assertTrue(collector.matches.size() == 1);
+ IMethod method = collector.matches.get(0).getMethod();
+ String name = method.toString();
+ String expectedName = "void m1(int) [in C1 [in [Working copy] C1.java [in com.test [in src [in JavaSearchBugs]]]]]";
+ assertTrue("Unexpected Method Name", expectedName.equals(name));
+ assertTrue("IJavaElement Does not exist", method.exists());
+}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java
index bf96d1e1bf..fd1fc5c2bf 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java
@@ -2240,4 +2240,44 @@ public class JavaSearchBugsTests2 extends AbstractJavaSearchTests {
deleteProject(project);
}
}
+ public void testBug483303_001() throws Exception {
+ IJavaProject project = null;
+ try {
+ project = createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin","1.5");
+ createFolder("P/src/p478042");
+ createFile("/P/src/p478042/AllMethodDeclarations01.java",
+ "package p478042;\n" +
+ "public class AllMethodDeclarations01 {\n" +
+ " public void m1(int i) {}\n" +
+ " public void foo01() {}\n" +
+ " public int foo02(Object o) {return null;}\n" +
+ " public char foo03(Object o, String s) {return null;}\n" +
+ " }");
+ createFile("/P/src/p478042/AllMethodDeclarations01b.java",
+ "package p478042;\n" +
+ "public class AllMethodDeclarations01b {\n" +
+ " public Integer fooInt() {return null;}\n" +
+ " }");
+ class Collector extends MethodNameMatchRequestor {
+ List<MethodNameMatch> matches = new ArrayList<>();
+ @Override
+ public void acceptMethodNameMatch(MethodNameMatch match) {
+ this.matches.add(match);
+ }
+ }
+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, IJavaSearchScope.SOURCES);
+ Collector collector = new Collector();
+ new SearchEngine().searchAllMethodNames(
+ null, SearchPattern.R_EXACT_MATCH,
+ null, SearchPattern.R_EXACT_MATCH,
+ "AllMethodDeclarations01".toCharArray(), SearchPattern.R_EXACT_MATCH,
+ "m1".toCharArray(), SearchPattern.R_PREFIX_MATCH,
+ scope, collector, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
+ assertEquals(1, collector.matches.size());
+ IMethod method = collector.matches.get(0).getMethod();
+ assertTrue(method.exists());
+ } finally {
+ deleteProject("P");
+ }
+ }
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/MethodNameMatchRequestorWrapper.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/MethodNameMatchRequestorWrapper.java
index 7d4b262306..c5c187d49c 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/MethodNameMatchRequestorWrapper.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/MethodNameMatchRequestorWrapper.java
@@ -13,6 +13,7 @@ package org.eclipse.jdt.internal.core.search;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.MethodNameMatchRequestor;
@@ -68,7 +69,15 @@ public class MethodNameMatchRequestorWrapper extends NameMatchRequestorWrapper i
if (type == null) return;
if (!(!(this.scope instanceof HierarchyScope) || ((HierarchyScope) this.scope).enclosesFineGrained(type))) return;
parameterTypes = parameterTypes == null ? CharOperation.NO_CHAR_CHAR : parameterTypes;
- IMethod method = type.getMethod(new String(methodName), CharOperation.toStrings(parameterTypes));
+ String[] paramTypeSigs = CharOperation.NO_STRINGS;
+ if (parameterTypes.length > 0) {
+ int l = parameterTypes.length;
+ paramTypeSigs = new String[l];
+ for (int i = 0; i < l; ++i) {
+ paramTypeSigs[i] = Signature.createTypeSignature(parameterTypes[i], false);
+ }
+ }
+ IMethod method = type.getMethod(new String(methodName), paramTypeSigs);
this.requestor.acceptMethodNameMatch(new JavaSearchMethodNameMatch(method, modifiers));
}
}

Back to the top