Index: src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java,v retrieving revision 1.31 diff -u -r1.31 JavaSearchMultipleProjectsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java 23 Jun 2005 16:15:17 -0000 1.31 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java 29 Jun 2005 14:03:55 -0000 @@ -36,9 +36,10 @@ // Use this static initializer to specify subset for tests // All specified tests which do not belong to the class are skipped... static { -// TESTS_NAMES = new String[] { "testMethodOccurences" }; +// TESTS_NAMES = new String[] { "testJavaSearchScopeBug101426" }; // TESTS_NUMBERS = new int[] { 101426 }; // TESTS_RANGE = new int[] { 16, -1 }; +// TESTS_PREFIX = "testScopeEncloses"; } protected void tearDown() throws Exception { // Cleanup caches @@ -872,6 +873,560 @@ deleteProject("P2"); } } +/* + * Ensures that a Java project is enclosed in a scope on the project (proj=src) + * (resourcePath case) + */ +public void testScopeEncloses01() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P\"", scope.encloses("/P")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a Java project is enclosed in a scope on the project (proj=src) + * (Java element case) + */ +public void testScopeEncloses02() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose P", scope.encloses(project)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a root is enclosed in a scope on the project (proj=src) + * (resource path with traling slash case) + */ +public void testScopeEncloses03() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/\"", scope.encloses("/P/")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a root is enclosed in a scope on the project (proj=src) + * (Java element case) + */ +public void testScopeEncloses04() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + IPackageFragmentRoot root = project.getPackageFragmentRoot(project.getProject()); + assertTrue("scope on P should enclose root P", scope.encloses(root)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a package is enclosed in a scope on the project (proj=src) + * (resource path case) + */ +public void testScopeEncloses05() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/x/y\"", scope.encloses("/P/x/y")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a package is enclosed in a scope on the project (proj=src) + * (resource path with trailing slash case) + */ +public void testScopeEncloses06() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/x/y/\"", scope.encloses("/P/x/y/")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a package is enclosed in a scope on the project (proj=src) + * (Java element case) + */ +public void testScopeEncloses07() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + IPackageFragment pkg = getPackage("/P/x/y"); + assertTrue("scope on P should enclose package x.y", scope.encloses(pkg)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a default package is enclosed in a scope on the project (proj=src) + * (Java element case) + */ +public void testScopeEncloses08() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + IPackageFragment pkg = getPackage("/P"); + assertTrue("scope on P should enclose default package", scope.encloses(pkg)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a compilation unit is enclosed in a scope on the project (proj=src) + * (resource path case) + */ +public void testScopeEncloses09() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/x/y/A.java\"", scope.encloses("/P/x/y/A.java")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a compilation unit is enclosed in a scope on the project (proj=src) + * (Java element case) + */ +public void testScopeEncloses10() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + ICompilationUnit cu = getCompilationUnit("/P/x/y/A.java"); + assertTrue("scope on P should enclose compilation unit A.java", scope.encloses(cu)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a compilation unit in the default package is enclosed in a scope on the project (proj=src) + * (resource path case) + */ +public void testScopeEncloses11() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/A.java\"", scope.encloses("/P/A.java")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a compilation unit in the default package is enclosed in a scope on the project (proj=src) + * (Java element case) + */ +public void testScopeEncloses12() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + ICompilationUnit cu = getCompilationUnit("/P/A.java"); + assertTrue("scope on P should enclose compilation unit A.java", scope.encloses(cu)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a source type is enclosed in a scope on the project (proj=src) + * (Java element case) + */ +public void testScopeEncloses13() throws CoreException { + try { + IJavaProject project = createJavaProject("P"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + ICompilationUnit cu = getCompilationUnit("/P/x/y/A.java"); + IType type = cu.getType("A"); + assertTrue("scope on P should enclose type A", scope.encloses(type)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a Java project is not enclosed in a scope on the project (proj != src) + * (resourcePath case) + */ +public void testScopeEncloses14() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should not enclose \"/P\"", !scope.encloses("/P")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a Java project is not enclosed in a scope on the project (proj != src) + * (Java element case) + */ +public void testScopeEncloses15() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose P", !scope.encloses(project)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a root is enclosed in a scope on the project (proj != src) + * (resource path case) + */ +public void testScopeEncloses16() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/src\"", scope.encloses("/P/src")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a root is enclosed in a scope on the project (proj != src) + * (resource path with traling slash case) + */ +public void testScopeEncloses17() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/src/\"", scope.encloses("/P/src/")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a root is enclosed in a scope on the project (proj != src) + * (Java element case) + */ +public void testScopeEncloses18() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + IPackageFragmentRoot root = project.getPackageFragmentRoot(project.getProject().getFolder("src")); + assertTrue("scope on P should enclose root P/src", scope.encloses(root)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a package is enclosed in a scope on the project (proj != src) + * (resource path case) + */ +public void testScopeEncloses19() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/src/x/y\"", scope.encloses("/P/src/x/y")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a package is enclosed in a scope on the project (proj != src) + * (resource path with trailing slash case) + */ +public void testScopeEncloses20() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/src/x/y/\"", scope.encloses("/P/src/x/y/")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a package is enclosed in a scope on the project (proj != src) + * (Java element case) + */ +public void testScopeEncloses21() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + IPackageFragment pkg = getPackage("/P/src/x/y"); + assertTrue("scope on P should enclose package x.y", scope.encloses(pkg)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a default package is enclosed in a scope on the project (proj != src) + * (Java element case) + */ +public void testScopeEncloses22() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + IPackageFragment pkg = getPackage("/P/src"); + assertTrue("scope on P should enclose default package", scope.encloses(pkg)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a compilation unit is enclosed in a scope on the project (proj != src) + * (resource path case) + */ +public void testScopeEncloses23() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/src/x/y/A.java\"", scope.encloses("/P/src/x/y/A.java")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a compilation unit is enclosed in a scope on the project (proj != src) + * (Java element case) + */ +public void testScopeEncloses24() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + ICompilationUnit cu = getCompilationUnit("/P/src/x/y/A.java"); + assertTrue("scope on P should enclose compilation unit A.java", scope.encloses(cu)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a compilation unit in the default package is enclosed in a scope on the project (proj != src) + * (resource path case) + */ +public void testScopeEncloses25() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/src/A.java\"", scope.encloses("/P/src/A.java")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a compilation unit in the default package is enclosed in a scope on the project (proj != src) + * (Java element case) + */ +public void testScopeEncloses26() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + ICompilationUnit cu = getCompilationUnit("/P/src/A.java"); + assertTrue("scope on P should enclose compilation unit A.java", scope.encloses(cu)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a source type is enclosed in a scope on the project (proj != src) + * (Java element case) + */ +public void testScopeEncloses27() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + ICompilationUnit cu = getCompilationUnit("/P/src/x/y/A.java"); + IType type = cu.getType("A"); + assertTrue("scope on P should enclose type A", scope.encloses(type)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a Java project is not enclosed in a scope on the project (proj != src/) + * (resourcePath case) + */ +public void testScopeEncloses28() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should not enclose \"/P\"", !scope.encloses("/P")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a Java project is not enclosed in a scope on the project (proj != src/) + * (Java element case) + */ +public void testScopeEncloses29() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose P", !scope.encloses(project)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a root is enclosed in a scope on the project (proj != src/) + * (resource path case) + */ +public void testScopeEncloses30() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/src\"", scope.encloses("/P/src")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a root is enclosed in a scope on the project (proj != src/) + * (resource path with traling slash case) + */ +public void testScopeEncloses31() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/src/\"", scope.encloses("/P/src/")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a root is enclosed in a scope on the project (proj != src/) + * (Java element case) + */ +public void testScopeEncloses32() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + IPackageFragmentRoot root = project.getPackageFragmentRoot(project.getProject().getFolder("src")); + assertTrue("scope on P should enclose root P/src", scope.encloses(root)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a package is enclosed in a scope on the project (proj != src/) + * (resource path case) + */ +public void testScopeEncloses33() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/src/x/y\"", scope.encloses("/P/src/x/y")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a package is enclosed in a scope on the project (proj != src/) + * (resource path with trailing slash case) + */ +public void testScopeEncloses34() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/src/x/y/\"", scope.encloses("/P/src/x/y/")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a package is enclosed in a scope on the project (proj != src/) + * (Java element case) + */ +public void testScopeEncloses35() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + IPackageFragment pkg = getPackage("/P/src/x/y"); + assertTrue("scope on P should enclose package x.y", scope.encloses(pkg)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a default package is enclosed in a scope on the project (proj != src/) + * (Java element case) + */ +public void testScopeEncloses36() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + IPackageFragment pkg = getPackage("/P/src"); + assertTrue("scope on P should enclose default package", scope.encloses(pkg)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a compilation unit is enclosed in a scope on the project (proj != src/) + * (resource path case) + */ +public void testScopeEncloses37() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/src/x/y/A.java\"", scope.encloses("/P/src/x/y/A.java")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a compilation unit is enclosed in a scope on the project (proj != src/) + * (Java element case) + */ +public void testScopeEncloses38() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + ICompilationUnit cu = getCompilationUnit("/P/src/x/y/A.java"); + assertTrue("scope on P should enclose compilation unit A.java", scope.encloses(cu)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a compilation unit in the default package is enclosed in a scope on the project (proj != src/) + * (resource path case) + */ +public void testScopeEncloses39() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + assertTrue("scope on P should enclose \"/P/src/A.java\"", scope.encloses("/P/src/A.java")); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a compilation unit in the default package is enclosed in a scope on the project (proj != src/) + * (Java element case) + */ +public void testScopeEncloses40() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + ICompilationUnit cu = getCompilationUnit("/P/src/A.java"); + assertTrue("scope on P should enclose compilation unit A.java", scope.encloses(cu)); + } finally { + deleteProject("P"); + } +} +/* + * Ensures that a source type is enclosed in a scope on the project (proj != src/) + * (Java element case) + */ +public void testScopeEncloses41() throws CoreException { + try { + IJavaProject project = createJavaProject("P", new String[] {"src/"}, "bin"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); + ICompilationUnit cu = getCompilationUnit("/P/src/x/y/A.java"); + IType type = cu.getType("A"); + assertTrue("scope on P should enclose type A", scope.encloses(type)); + } finally { + deleteProject("P"); + } +} /** * Type declaration in external jar file that is shared by 2 projects. * (regression test for bug 27485 SearchEngine returns wrong java element when searching in an archive that is included by two distinct java projects.)