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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java (+35 lines)
Lines 97-102 Link Here
97
public void testApplicationLibrairiesJarAndClassFolder() throws CoreException {
97
public void testApplicationLibrairiesJarAndClassFolder() throws CoreException {
98
	try {
98
	try {
99
		IJavaProject project = createJavaProject("P", new String[] {"src"}, new String[] {"/P/internal.jar", "/P/classfolder"}, "bin");
99
		IJavaProject project = createJavaProject("P", new String[] {"src"}, new String[] {"/P/internal.jar", "/P/classfolder"}, "bin");
100
		createFile("/P/internal.jar", new byte[0]);	// file must exist to be added to the scope since bug 215841
101
		createFolder("/P/classfolder");	// folder must exist to be added to the scope since bug 215841
100
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}, IJavaSearchScope.APPLICATION_LIBRARIES);
102
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}, IJavaSearchScope.APPLICATION_LIBRARIES);
101
		assertScopeEquals(
103
		assertScopeEquals(
102
			"JavaSearchScope on [\n" + 
104
			"JavaSearchScope on [\n" + 
Lines 116-121 Link Here
116
	try {
118
	try {
117
		VariablesInitializer.setInitializer(new ClasspathInitializerTests.DefaultVariableInitializer(new String[] {"TEST_LIB", "/P/lib.jar"}));
119
		VariablesInitializer.setInitializer(new ClasspathInitializerTests.DefaultVariableInitializer(new String[] {"TEST_LIB", "/P/lib.jar"}));
118
		IJavaProject project = createJavaProject("P", new String[] {}, new String[] {"TEST_LIB"}, "");
120
		IJavaProject project = createJavaProject("P", new String[] {}, new String[] {"TEST_LIB"}, "");
121
		createFile("/P/lib.jar", new byte[0]);	// file must exist to be added to the scope since bug 215841
119
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}, IJavaSearchScope.APPLICATION_LIBRARIES);
122
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}, IJavaSearchScope.APPLICATION_LIBRARIES);
120
		assertScopeEquals(
123
		assertScopeEquals(
121
			"JavaSearchScope on [\n" + 
124
			"JavaSearchScope on [\n" + 
Lines 1025-1028 Link Here
1025
		deleteProject("P1");
1028
		deleteProject("P1");
1026
	}
1029
	}
1027
}
1030
}
1031
1032
/**
1033
 * @bug 215841: [search] Opening Type Hierarchy extremely slow
1034
 * @test Ensure that a non-existing library is not added while building the Java search scope
1035
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=215841"
1036
 */
1037
// see #testApplicationLibrairiesJarAndClassFolder()
1038
public void testBug215841() throws CoreException {
1039
	try {
1040
		IJavaProject project = createJavaProject("P", new String[] {"src"}, new String[] {"/P/internal.jar", "/P/classfolder"}, "bin");
1041
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}, IJavaSearchScope.APPLICATION_LIBRARIES);
1042
		assertScopeEquals(
1043
			"JavaSearchScope on [empty scope]",
1044
			scope);
1045
	} finally {
1046
		deleteProject("P");
1047
	}
1048
}
1049
// see #testApplicationLibrairiesClasspathContainer()
1050
public void testBug215841b() throws CoreException {
1051
	try {
1052
		VariablesInitializer.setInitializer(new ClasspathInitializerTests.DefaultVariableInitializer(new String[] {"TEST_LIB", "/P/lib.jar"}));
1053
		IJavaProject project = createJavaProject("P", new String[] {}, new String[] {"TEST_LIB"}, "");
1054
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}, IJavaSearchScope.APPLICATION_LIBRARIES);
1055
		assertScopeEquals(
1056
			"JavaSearchScope on [empty scope]",
1057
			scope);
1058
	} finally {
1059
		deleteProject("P");
1060
		VariablesInitializer.reset();
1061
	}
1062
}
1028
}
1063
}
(-)search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java (-2 / +6 lines)
Lines 147-154 Link Here
147
							IPath path = entry.getPath();
147
							IPath path = entry.getPath();
148
							if (pathToAdd == null || pathToAdd.equals(path)) {
148
							if (pathToAdd == null || pathToAdd.equals(path)) {
149
								String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
149
								String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
150
								add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
150
								// Do not store information inside scope when library does not exist
151
								addEnclosingProjectOrJar(path);
151
								// (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=215841)
152
								if (JavaModel.getTarget(project.getParent(), path, true) != null) {
153
									add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
154
									addEnclosingProjectOrJar(path);
155
								}
152
							}
156
							}
153
						}
157
						}
154
						break;
158
						break;

Return to bug 215841