### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java,v retrieving revision 1.90 diff -u -r1.90 MethodLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java 2 Sep 2010 09:00:33 -0000 1.90 +++ search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java 21 Jan 2011 09:33:48 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -606,16 +606,15 @@ } // declaring type - char[] qualifiedPattern = qualifiedPattern(this.pattern.declaringSimpleName, this.pattern.declaringQualification); - if (qualifiedPattern == null) return methodLevel; // since any declaring class will do + if (this.pattern.declaringSimpleName == null && this.pattern.declaringQualification == null) return methodLevel; // since any declaring class will do boolean subType = !method.isStatic() && !method.isPrivate(); if (subType && this.pattern.declaringQualification != null && method.declaringClass != null && method.declaringClass.fPackage != null) { subType = CharOperation.compareWith(this.pattern.declaringQualification, method.declaringClass.fPackage.shortReadableName()) == 0; } int declaringLevel = subType - ? resolveLevelAsSubtype(qualifiedPattern, method.declaringClass, null) - : resolveLevelForType(qualifiedPattern, method.declaringClass); + ? resolveLevelAsSubtype(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass, null) + : resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass); return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker match } protected int resolveLevel(MessageSend messageSend) { @@ -642,13 +641,12 @@ } // receiver type - char[] qualifiedPattern = qualifiedPattern(this.pattern.declaringSimpleName, this.pattern.declaringQualification); - if (qualifiedPattern == null) return methodLevel; // since any declaring class will do + if (this.pattern.declaringSimpleName == null && this.pattern.declaringQualification == null) return methodLevel; // since any declaring class will do int declaringLevel; if (isVirtualInvoke(method, messageSend) && (messageSend.actualReceiverType instanceof ReferenceBinding)) { ReferenceBinding methodReceiverType = (ReferenceBinding) messageSend.actualReceiverType; - declaringLevel = resolveLevelAsSubtype(qualifiedPattern, methodReceiverType, method.parameters); + declaringLevel = resolveLevelAsSubtype(this.pattern.declaringSimpleName, this.pattern.declaringQualification, methodReceiverType, method.parameters); if (declaringLevel == IMPOSSIBLE_MATCH) { if (method.declaringClass == null || this.allSuperDeclaringTypeNames == null) { declaringLevel = INACCURATE_MATCH; @@ -664,7 +662,7 @@ return declaringLevel; } } else { - declaringLevel = resolveLevelForType(qualifiedPattern, method.declaringClass); + declaringLevel = resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass); } return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker match } @@ -676,10 +674,10 @@ * Returns INACCURATE_MATCH if resolve fails * Returns IMPOSSIBLE_MATCH if it doesn't. */ -protected int resolveLevelAsSubtype(char[] qualifiedPattern, ReferenceBinding type, TypeBinding[] argumentTypes) { +protected int resolveLevelAsSubtype(char[] simplePattern, char[] qualifiedPattern, ReferenceBinding type, TypeBinding[] argumentTypes) { if (type == null) return INACCURATE_MATCH; - int level = resolveLevelForType(qualifiedPattern, type); + int level = resolveLevelForType(simplePattern, qualifiedPattern, type); if (level != IMPOSSIBLE_MATCH) { MethodBinding method = argumentTypes == null ? null : getMethodBinding(type, argumentTypes); if (((method != null && !method.isAbstract()) || !type.isAbstract()) && !type.isInterface()) { // if concrete, then method is overridden @@ -690,7 +688,7 @@ // matches superclass if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) { - level = resolveLevelAsSubtype(qualifiedPattern, type.superclass(), argumentTypes); + level = resolveLevelAsSubtype(simplePattern, qualifiedPattern, type.superclass(), argumentTypes); if (level != IMPOSSIBLE_MATCH) { if (argumentTypes != null) { // need to verify if method may be overridden @@ -714,7 +712,7 @@ ReferenceBinding[] interfaces = type.superInterfaces(); if (interfaces == null) return INACCURATE_MATCH; for (int i = 0; i < interfaces.length; i++) { - level = resolveLevelAsSubtype(qualifiedPattern, interfaces[i], null); + level = resolveLevelAsSubtype(simplePattern, qualifiedPattern, interfaces[i], null); if (level != IMPOSSIBLE_MATCH) { if (!type.isAbstract() && !type.isInterface()) { // if concrete class, then method is overridden level |= OVERRIDDEN_METHOD_FLAVOR; #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java,v retrieving revision 1.212 diff -u -r1.212 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 17 Jan 2011 13:00:54 -0000 1.212 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 21 Jan 2011 09:33:56 -0000 @@ -12727,4 +12727,86 @@ deleteProject("P"); } } + +/** + * @bug 324189: [search] Method Search returns false results + * @test Search for Worker.run() should not return results like TestWorker + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=324189" + */ +public void testBug324189a() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b324189/X.java", + "package b324189;\n" + + "public class TestWorker{\n" + + " public void run() {}\n" + + "class AWorker {\n" + + " public void run() {}\n" + + "}\n"+ + "}\n" + ); + search("Worker.run()", METHOD, DECLARATIONS); + assertSearchResults("src/b324189/X.java void b324189.TestWorker$Worker.run() [run] EXACT_MATCH"); +} + +// Worker in the default package should be in the result +public void testBug324189b() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Worker.java", + "public class Worker{\n" + + " public void run() {}\n" + + "}\n" + ); + search("Worker.run()", METHOD, DECLARATIONS); + assertSearchResults("src/Worker.java void Worker.run() [run] EXACT_MATCH"); +} +// bWorker in the package name should also not be in the search result +public void testBug324189c() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/bWorker/X.java", + "package bWorker;\n" + + "public class X{\n" + + " public void run() {}\n" + + "}" + ); + search("Worker.X.run()", METHOD, DECLARATIONS); + assertSearchResults(""); +} +// TestWorker in a class file also should not be in the search result +public void testBug324189d() throws CoreException, IOException { + String libPath = getExternalResourcePath("lib324189.jar"); + try { + // Create project and external jar file + Util.createJar( + new String[] { + "b324189/TestWorker.java", + "package b324189;\n" + + "public class TestWorker{\n" + + " public void run() {}\n" + + "class Worker{\n" + + " public void run() {}\n" + + "}\n"+ + "}", + "b324189/Worker.java", + "package b324189;\n" + + "public class Worker{\n" + + " public void run() {}\n" + + "}" + }, + new HashMap(), + libPath); + IJavaProject javaProject = createJavaProject("P", new String[0], new String[] {libPath}, ""); + waitUntilIndexesReady(); + int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }, mask); + this.resultCollector.showSelection(); + search("Worker.run()", METHOD, DECLARATIONS, scope); + assertSearchResults( + getExternalPath() + "lib324189.jar void b324189.TestWorker$Worker.run() EXACT_MATCH\n" + + getExternalPath() + "lib324189.jar void b324189.Worker.run() EXACT_MATCH" + ); + } finally { + deleteExternalFile(libPath); + deleteProject("P"); + } +} } \ No newline at end of file