diff options
author | Manoj Palat | 2015-12-02 15:13:33 +0000 |
---|---|---|
committer | Manoj Palat | 2015-12-02 15:13:33 +0000 |
commit | 65a147b80f31dc3e10f9d46f87c3805f7af615cd (patch) | |
tree | 0aded37499c06c3a6c25fbc6486e0529ec6c7b1a | |
parent | 297840d814bc6fb8f78f68a36eb74676aea7b3b0 (diff) | |
download | eclipse.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
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)); } } |