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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-4 lines)
Lines 332-341 Link Here
332
	return element;
332
	return element;
333
}
333
}
334
334
335
public static boolean isPolymorphicSearch(InternalSearchPattern pattern) {
336
	return pattern.isPolymorphicSearch();
337
}
338
339
public static IJavaElement projectOrJarFocus(InternalSearchPattern pattern) {
335
public static IJavaElement projectOrJarFocus(InternalSearchPattern pattern) {
340
	return pattern == null || pattern.focus == null ? null : getProjectOrJar(pattern.focus);
336
	return pattern == null || pattern.focus == null ? null : getProjectOrJar(pattern.focus);
341
}
337
}
(-)search/org/eclipse/jdt/internal/core/search/IndexSelector.java (-1 / +2 lines)
Lines 25-30 Link Here
25
import org.eclipse.jdt.internal.core.JavaProject;
25
import org.eclipse.jdt.internal.core.JavaProject;
26
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
26
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
27
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
27
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
28
import org.eclipse.jdt.internal.core.search.matching.MethodPattern;
28
29
29
/**
30
/**
30
 * Selects the indexes that correspond to projects in a given search scope
31
 * Selects the indexes that correspond to projects in a given search scope
Lines 135-141 Link Here
135
			int projectIndex = 0;
136
			int projectIndex = 0;
136
			SimpleSet jarsToCheck = new SimpleSet(length);
137
			SimpleSet jarsToCheck = new SimpleSet(length);
137
			IClasspathEntry[] focusEntries = null;
138
			IClasspathEntry[] focusEntries = null;
138
			if (this.pattern != null && MatchLocator.isPolymorphicSearch(this.pattern)) { // isPolymorphicSearch
139
			if (this.pattern instanceof MethodPattern) { // should consider polymorphic search for method patterns
139
				JavaProject focusProject = focus instanceof JarPackageFragmentRoot ? (JavaProject) focus.getParent() : (JavaProject) focus;
140
				JavaProject focusProject = focus instanceof JarPackageFragmentRoot ? (JavaProject) focus.getParent() : (JavaProject) focus;
140
				focusEntries = focusProject.getExpandedClasspath();
141
				focusEntries = focusProject.getExpandedClasspath();
141
			}
142
			}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java (+129 lines)
Lines 24-29 Link Here
24
 * Tests the Java search engine accross multiple projects.
24
 * Tests the Java search engine accross multiple projects.
25
 */
25
 */
26
public class JavaSearchMultipleProjectsTests extends ModifyingResourceTests implements IJavaSearchConstants {
26
public class JavaSearchMultipleProjectsTests extends ModifyingResourceTests implements IJavaSearchConstants {
27
	private final static int UI_DECLARATIONS = DECLARATIONS|IGNORE_DECLARING_TYPE|IGNORE_RETURN_TYPE;
27
public JavaSearchMultipleProjectsTests(String name) {
28
public JavaSearchMultipleProjectsTests(String name) {
28
	super(name);
29
	super(name);
29
}
30
}
Lines 664-667 Link Here
664
		deleteProject("P2");
665
		deleteProject("P2");
665
	}
666
	}
666
}
667
}
668
669
/**
670
 * Bug 151189: [search] Declaration search does not find all matches
671
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=151189"
672
 */
673
public void testBug151189_Workspace() throws CoreException {
674
	try {
675
		// setup project P1
676
		/*IJavaProject p1 = */createJavaProject("P1");
677
		createFolder("/P1/pack");
678
		createFile(
679
			"/P1/pack/Declaration.java",
680
			"package pack;\n" + 
681
			"public class Declaration implements Interface {\n" + 
682
			"	public void doOperation(int val) {}\n" + 
683
			"}\n"
684
		);
685
		createFile(
686
			"/P1/pack/Interface.java",
687
			"package pack;\n" + 
688
			"public interface Interface {\n" + 
689
			"	void doOperation(int val);\n" + 
690
			"}\n"
691
		);
692
693
		// setup project P2
694
		createJavaProject("P2", new String[] {""}, new String[] {"JCL_LIB"}, new String[] { "/P1" }, "");
695
		createFolder("/P2/test");
696
		createFile(
697
			"/P2/test/Declaration_bis.java",
698
			"package test;\n" + 
699
			"import pack.Interface;\n" + 
700
			"public class Declaration_bis implements Interface {\n" + 
701
			"	public void doOperation(int val) {}\n" + 
702
			"}\n"
703
		);
704
705
		// Get method
706
		IMethod method = getCompilationUnit("/P2/test/Declaration_bis.java").getType("Declaration_bis").getMethod("doOperation", new String[] {"I"});
707
708
		// search method declaration in workspace scope
709
		IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); //JavaSearchScope(new IJavaElement[] {p1, p2});
710
		JavaSearchResultCollector resultCollector = new JavaSearchResultCollector();
711
		resultCollector.showProject = true;
712
		search(
713
			method, 
714
			DECLARATIONS,
715
			scope, 
716
			resultCollector);
717
		assertSearchResults(
718
			"Unexpected declarations of method test.Declaration_bis.doOperation(int)",
719
			"test/Declaration_bis.java [in P2] void test.Declaration_bis.doOperation(int) [doOperation]",
720
			resultCollector);
721
722
		// search method declaration in workspace scope with JDT-UI flags
723
		resultCollector = new JavaSearchResultCollector();
724
		resultCollector.showProject = true;
725
		search(
726
			method, 
727
			UI_DECLARATIONS,
728
			scope, 
729
			resultCollector);
730
		assertSearchResults(
731
			"Unexpected declarations of method test.Declaration_bis.doOperation(int)",
732
			"pack/Declaration.java [in P1] void pack.Declaration.doOperation(int) [doOperation]\n" + 
733
			"pack/Interface.java [in P1] void pack.Interface.doOperation(int) [doOperation]\n" + 
734
			"test/Declaration_bis.java [in P2] void test.Declaration_bis.doOperation(int) [doOperation]",
735
			resultCollector);
736
	} finally {
737
		deleteProject("P1");
738
		deleteProject("P2");
739
	}
740
}
741
public void testBug151189_Project() throws CoreException {
742
	try {
743
		// setup project P1
744
		createJavaProject("P1");
745
		createFolder("/P1/pack");
746
		createFile(
747
			"/P1/pack/Declaration.java",
748
			"package pack;\n" + 
749
			"public class Declaration implements Interface {\n" + 
750
			"	public void doOperation(int val) {}\n" + 
751
			"}\n"
752
		);
753
		createFile(
754
			"/P1/pack/Interface.java",
755
			"package pack;\n" + 
756
			"public interface Interface {\n" + 
757
			"	void doOperation(int val);\n" + 
758
			"}\n"
759
		);
760
761
		// setup project P2
762
		IJavaProject p2 = createJavaProject("P2", new String[] {""}, new String[] {"JCL_LIB"}, new String[] { "/P1" }, "");
763
		createFolder("/P2/test");
764
		createFile(
765
			"/P2/test/Declaration_bis.java",
766
			"package test;\n" + 
767
			"import pack.Interface;\n" + 
768
			"public class Declaration_bis implements Interface {\n" + 
769
			"	public void doOperation(int val) {}\n" + 
770
			"}\n"
771
		);
772
773
		// Get method
774
		IMethod method = getCompilationUnit("/P2/test/Declaration_bis.java").getType("Declaration_bis").getMethod("doOperation", new String[] {"I"});
775
776
		// search method declaration in project scope
777
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {p2});
778
		JavaSearchResultCollector resultCollector = new JavaSearchResultCollector();
779
		resultCollector.showProject = true;
780
		search(
781
			method, 
782
			UI_DECLARATIONS,
783
			scope, 
784
			resultCollector);
785
		assertSearchResults(
786
			"Unexpected declarations of method test.Declaration_bis.doOperation(int)",
787
			"pack/Declaration.java [in P1] void pack.Declaration.doOperation(int) [doOperation]\n" + 
788
			"pack/Interface.java [in P1] void pack.Interface.doOperation(int) [doOperation]\n" + 
789
			"test/Declaration_bis.java [in P2] void test.Declaration_bis.doOperation(int) [doOperation]",
790
			resultCollector);
791
	} finally {
792
		deleteProject("P1");
793
		deleteProject("P2");
794
	}
795
}
667
}
796
}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+35 lines)
Lines 5680-5685 Link Here
5680
}
5680
}
5681
5681
5682
/**
5682
/**
5683
 * Bug 113671: [search] AIOOBE in SearchEngine#searchAllTypeNames
5684
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=113671"
5685
 */
5686
public void testBug113671() throws CoreException {
5687
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5688
	new SearchEngine().searchAllTypeNames(
5689
	   "java.lang".toCharArray(),
5690
		SearchPattern.R_EXACT_MATCH,
5691
		CharOperation.NO_CHAR,
5692
		SearchPattern.R_PREFIX_MATCH,
5693
		IJavaSearchConstants.TYPE,
5694
		getJavaSearchScopeBugs(),
5695
		requestor,
5696
		WAIT_UNTIL_READY_TO_SEARCH,
5697
		null
5698
   );
5699
	assertSearchResults(
5700
		"Unexpected all type names",
5701
		"java.lang.CharSequence\n" + 
5702
		"java.lang.Class\n" + 
5703
		"java.lang.CloneNotSupportedException\n" + 
5704
		"java.lang.Comparable\n" + 
5705
		"java.lang.Enum\n" + 
5706
		"java.lang.Error\n" + 
5707
		"java.lang.Exception\n" + 
5708
		"java.lang.IllegalMonitorStateException\n" + 
5709
		"java.lang.InterruptedException\n" + 
5710
		"java.lang.Object\n" + 
5711
		"java.lang.RuntimeException\n" + 
5712
		"java.lang.String\n" + 
5713
		"java.lang.Throwable",
5714
		requestor);
5715
}
5716
5717
/**
5683
 * @test Bug 114539: [search] Internal error when refactoring code with errors
5718
 * @test Bug 114539: [search] Internal error when refactoring code with errors
5684
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=114539"
5719
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=114539"
5685
 */
5720
 */
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (-58 lines)
Lines 19-28 Link Here
19
import org.eclipse.core.resources.*;
19
import org.eclipse.core.resources.*;
20
import org.eclipse.core.runtime.*;
20
import org.eclipse.core.runtime.*;
21
import org.eclipse.jdt.core.*;
21
import org.eclipse.jdt.core.*;
22
import org.eclipse.jdt.core.compiler.CharOperation;
23
import org.eclipse.jdt.core.search.*;
22
import org.eclipse.jdt.core.search.*;
24
import org.eclipse.jdt.internal.core.JavaModelStatus;
23
import org.eclipse.jdt.internal.core.JavaModelStatus;
25
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
26
24
27
/**
25
/**
28
 * Tests the Java search engine where results are JavaElements and source positions.
26
 * Tests the Java search engine where results are JavaElements and source positions.
Lines 3689-3748 Link Here
3689
		"q1.AA",
3687
		"q1.AA",
3690
		requestor);
3688
		requestor);
3691
}
3689
}
3692
3693
/**
3694
 * Bug 113671: [search] AIOOBE in SearchEngine#searchAllTypeNames
3695
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=113671"
3696
 */
3697
public void testBug113671a() throws CoreException {
3698
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3699
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3700
		null,
3701
		CharOperation.NO_CHAR,
3702
		SearchPattern.R_CAMELCASE_MATCH,
3703
		TYPE,
3704
		getJavaSearchScope(),
3705
		requestor,
3706
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
3707
		null
3708
	);
3709
	assertSearchResults(
3710
		"Unexpected all type names",
3711
		"",
3712
		requestor);
3713
}
3714
public void testBug113671b() throws CoreException {
3715
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3716
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3717
		CharOperation.NO_CHAR,
3718
		CharOperation.NO_CHAR,
3719
		SearchPattern.R_CAMELCASE_MATCH,
3720
		TYPE,
3721
		getJavaSearchScope(),
3722
		requestor,
3723
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
3724
		null
3725
	);
3726
	assertSearchResults(
3727
		"Unexpected all type names",
3728
		"",
3729
		requestor);
3730
}
3731
public void testBug113671c() throws CoreException {
3732
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3733
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3734
		IIndexConstants.ONE_STAR,
3735
		CharOperation.NO_CHAR,
3736
		SearchPattern.R_CAMELCASE_MATCH,
3737
		TYPE,
3738
		getJavaSearchScope(),
3739
		requestor,
3740
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
3741
		null
3742
	);
3743
	assertSearchResults(
3744
		"Unexpected all type names",
3745
		"",
3746
		requestor);
3747
}
3748
}
3690
}

Return to bug 151189