View | Details | Raw Unified | Return to bug 324189 | Differences between
and this patch

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-13 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 606-621 Link Here
606
	}
606
	}
607
607
608
	// declaring type
608
	// declaring type
609
	char[] qualifiedPattern = qualifiedPattern(this.pattern.declaringSimpleName, this.pattern.declaringQualification);
609
	if (this.pattern.declaringSimpleName == null && this.pattern.declaringQualification == null) return methodLevel; // since any declaring class will do
610
	if (qualifiedPattern == null) return methodLevel; // since any declaring class will do
611
610
612
	boolean subType = !method.isStatic() && !method.isPrivate();
611
	boolean subType = !method.isStatic() && !method.isPrivate();
613
	if (subType && this.pattern.declaringQualification != null && method.declaringClass != null && method.declaringClass.fPackage != null) {
612
	if (subType && this.pattern.declaringQualification != null && method.declaringClass != null && method.declaringClass.fPackage != null) {
614
		subType = CharOperation.compareWith(this.pattern.declaringQualification, method.declaringClass.fPackage.shortReadableName()) == 0;
613
		subType = CharOperation.compareWith(this.pattern.declaringQualification, method.declaringClass.fPackage.shortReadableName()) == 0;
615
	}
614
	}
616
	int declaringLevel = subType
615
	int declaringLevel = subType
617
		? resolveLevelAsSubtype(qualifiedPattern, method.declaringClass, null)
616
		? resolveLevelAsSubtype(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass, null)
618
		: resolveLevelForType(qualifiedPattern, method.declaringClass);
617
		: resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass);
619
	return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker match
618
	return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker match
620
}
619
}
621
protected int resolveLevel(MessageSend messageSend) {
620
protected int resolveLevel(MessageSend messageSend) {
Lines 642-654 Link Here
642
	}
641
	}
643
642
644
	// receiver type
643
	// receiver type
645
	char[] qualifiedPattern = qualifiedPattern(this.pattern.declaringSimpleName, this.pattern.declaringQualification);
644
	if (this.pattern.declaringSimpleName == null && this.pattern.declaringQualification == null) return methodLevel; // since any declaring class will do
646
	if (qualifiedPattern == null) return methodLevel; // since any declaring class will do
647
645
648
	int declaringLevel;
646
	int declaringLevel;
649
	if (isVirtualInvoke(method, messageSend) && (messageSend.actualReceiverType instanceof ReferenceBinding)) {
647
	if (isVirtualInvoke(method, messageSend) && (messageSend.actualReceiverType instanceof ReferenceBinding)) {
650
		ReferenceBinding methodReceiverType = (ReferenceBinding) messageSend.actualReceiverType;
648
		ReferenceBinding methodReceiverType = (ReferenceBinding) messageSend.actualReceiverType;
651
		declaringLevel = resolveLevelAsSubtype(qualifiedPattern, methodReceiverType, method.parameters);
649
		declaringLevel = resolveLevelAsSubtype(this.pattern.declaringSimpleName, this.pattern.declaringQualification, methodReceiverType, method.parameters);
652
		if (declaringLevel == IMPOSSIBLE_MATCH) {
650
		if (declaringLevel == IMPOSSIBLE_MATCH) {
653
			if (method.declaringClass == null || this.allSuperDeclaringTypeNames == null) {
651
			if (method.declaringClass == null || this.allSuperDeclaringTypeNames == null) {
654
				declaringLevel = INACCURATE_MATCH;
652
				declaringLevel = INACCURATE_MATCH;
Lines 664-670 Link Here
664
			return declaringLevel;
662
			return declaringLevel;
665
		}
663
		}
666
	} else {
664
	} else {
667
		declaringLevel = resolveLevelForType(qualifiedPattern, method.declaringClass);
665
		declaringLevel = resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass);
668
	}
666
	}
669
	return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker match
667
	return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker match
670
}
668
}
Lines 676-685 Link Here
676
 * Returns INACCURATE_MATCH if resolve fails
674
 * Returns INACCURATE_MATCH if resolve fails
677
 * Returns IMPOSSIBLE_MATCH if it doesn't.
675
 * Returns IMPOSSIBLE_MATCH if it doesn't.
678
 */
676
 */
679
protected int resolveLevelAsSubtype(char[] qualifiedPattern, ReferenceBinding type, TypeBinding[] argumentTypes) {
677
protected int resolveLevelAsSubtype(char[] simplePattern, char[] qualifiedPattern, ReferenceBinding type, TypeBinding[] argumentTypes) {
680
	if (type == null) return INACCURATE_MATCH;
678
	if (type == null) return INACCURATE_MATCH;
681
679
682
	int level = resolveLevelForType(qualifiedPattern, type);
680
	int level = resolveLevelForType(simplePattern, qualifiedPattern, type);
683
	if (level != IMPOSSIBLE_MATCH) {
681
	if (level != IMPOSSIBLE_MATCH) {
684
		MethodBinding method = argumentTypes == null ? null : getMethodBinding(type, argumentTypes);
682
		MethodBinding method = argumentTypes == null ? null : getMethodBinding(type, argumentTypes);
685
		if (((method != null && !method.isAbstract()) || !type.isAbstract()) && !type.isInterface()) { // if concrete, then method is overridden
683
		if (((method != null && !method.isAbstract()) || !type.isAbstract()) && !type.isInterface()) { // if concrete, then method is overridden
Lines 690-696 Link Here
690
688
691
	// matches superclass
689
	// matches superclass
692
	if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) {
690
	if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) {
693
		level = resolveLevelAsSubtype(qualifiedPattern, type.superclass(), argumentTypes);
691
		level = resolveLevelAsSubtype(simplePattern, qualifiedPattern, type.superclass(), argumentTypes);
694
		if (level != IMPOSSIBLE_MATCH) {
692
		if (level != IMPOSSIBLE_MATCH) {
695
			if (argumentTypes != null) {
693
			if (argumentTypes != null) {
696
				// need to verify if method may be overridden
694
				// need to verify if method may be overridden
Lines 714-720 Link Here
714
	ReferenceBinding[] interfaces = type.superInterfaces();
712
	ReferenceBinding[] interfaces = type.superInterfaces();
715
	if (interfaces == null) return INACCURATE_MATCH;
713
	if (interfaces == null) return INACCURATE_MATCH;
716
	for (int i = 0; i < interfaces.length; i++) {
714
	for (int i = 0; i < interfaces.length; i++) {
717
		level = resolveLevelAsSubtype(qualifiedPattern, interfaces[i], null);
715
		level = resolveLevelAsSubtype(simplePattern, qualifiedPattern, interfaces[i], null);
718
		if (level != IMPOSSIBLE_MATCH) {
716
		if (level != IMPOSSIBLE_MATCH) {
719
			if (!type.isAbstract() && !type.isInterface()) { // if concrete class, then method is overridden
717
			if (!type.isAbstract() && !type.isInterface()) { // if concrete class, then method is overridden
720
				level |= OVERRIDDEN_METHOD_FLAVOR;
718
				level |= OVERRIDDEN_METHOD_FLAVOR;
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+82 lines)
Lines 12727-12730 Link Here
12727
		deleteProject("P");
12727
		deleteProject("P");
12728
	}
12728
	}
12729
}
12729
}
12730
12731
/**
12732
 * @bug 324189: [search] Method Search returns false results
12733
 * @test Search for Worker.run() should not return results like TestWorker
12734
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=324189"
12735
 */
12736
public void testBug324189a() throws CoreException {
12737
	this.workingCopies = new ICompilationUnit[1];
12738
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b324189/X.java",
12739
		"package b324189;\n" +
12740
		"public class TestWorker{\n" +
12741
		" public void run() {}\n" +
12742
		"class AWorker {\n" + 
12743
		" public void run() {}\n" +
12744
		"}\n"+
12745
		"}\n"
12746
	);
12747
	search("Worker.run()", METHOD, DECLARATIONS);
12748
	assertSearchResults("");
12749
}
12750
12751
// Worker in the default package should be in the result
12752
public void testBug324189b() throws CoreException {
12753
	this.workingCopies = new ICompilationUnit[1];
12754
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Worker.java",
12755
		"public class Worker{\n" +
12756
		" public void run() {}\n" +
12757
		"}\n"
12758
	);
12759
	search("Worker.run()", METHOD, DECLARATIONS);
12760
	assertSearchResults("src/Worker.java void Worker.run() [run] EXACT_MATCH");
12761
}
12762
// bWorker in the package name should also not be in the search result
12763
public void testBug324189c() throws CoreException {
12764
	this.workingCopies = new ICompilationUnit[1];
12765
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/bWorker/X.java",
12766
		"package bWorker;\n" +
12767
		"public class X{\n" +
12768
		" public void run() {}\n" +
12769
		"}"
12770
	);
12771
	search("Worker.X.run()", METHOD, DECLARATIONS);
12772
	assertSearchResults("");
12773
}
12774
// TestWorker in a class file also should not be in the search result
12775
public void testBug324189d() throws CoreException, IOException {
12776
	String libPath = getExternalResourcePath("lib324189.jar");
12777
	try {
12778
		// Create project and external jar file
12779
		Util.createJar(
12780
			new String[] {
12781
				"b324189/TestWorker.java",
12782
				"package b324189;\n" +
12783
				"public class TestWorker{\n" +
12784
				" public void run() {}\n" +
12785
				"class Worker{\n" +
12786
				" public void run() {}\n" +
12787
				"}\n"+
12788
				"}",
12789
				"b324189/Worker.java",
12790
				"package b324189;\n" +
12791
				"public class Worker{\n" +
12792
				" public void run() {}\n" +
12793
				"}"
12794
			},
12795
			new HashMap(),
12796
			libPath);
12797
		IJavaProject javaProject = createJavaProject("P", new String[0], new String[] {libPath}, "");
12798
		waitUntilIndexesReady();
12799
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ;
12800
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }, mask);
12801
		this.resultCollector.showSelection();
12802
		search("Worker.run()", METHOD, DECLARATIONS, scope);
12803
		assertSearchResults(
12804
				getExternalPath() + "lib324189.jar void b324189.TestWorker$Worker.run() EXACT_MATCH\n" + 
12805
				getExternalPath() + "lib324189.jar void b324189.Worker.run() EXACT_MATCH"
12806
		);
12807
	} finally {
12808
		deleteExternalFile(libPath);
12809
		deleteProject("P");
12810
	}
12811
}
12730
}
12812
}

Return to bug 324189