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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/JavaWorkspaceScope.java (-85 / +74 lines)
Lines 11-42 Link Here
11
package org.eclipse.jdt.internal.core.search;
11
package org.eclipse.jdt.internal.core.search;
12
12
13
import java.util.HashSet;
13
import java.util.HashSet;
14
import java.util.Set;
14
15
16
import org.eclipse.core.resources.IFolder;
15
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.jdt.core.IClasspathEntry;
16
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.IJavaElementDelta;
20
import org.eclipse.jdt.core.IJavaElementDelta;
21
import org.eclipse.jdt.core.IJavaProject;
18
import org.eclipse.jdt.core.JavaModelException;
22
import org.eclipse.jdt.core.JavaModelException;
19
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
23
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
24
import org.eclipse.jdt.internal.core.JavaModel;
20
import org.eclipse.jdt.internal.core.JavaModelManager;
25
import org.eclipse.jdt.internal.core.JavaModelManager;
21
import org.eclipse.jdt.internal.core.JavaProject;
26
import org.eclipse.jdt.internal.core.JavaProject;
22
import org.eclipse.jdt.core.IJavaProject;
27
import org.eclipse.jdt.internal.core.util.Util;
23
28
24
/**
29
/**
25
 * A Java-specific scope for searching the entire workspace.
30
 * A Java-specific scope for searching the entire workspace.
26
 * The scope can be configured to not search binaries. By default, binaries
31
 * The scope can be configured to not search binaries. By default, binaries
27
 * are included.
32
 * are included.
28
 */
33
 */
29
public class JavaWorkspaceScope extends JavaSearchScope {
34
public class JavaWorkspaceScope extends AbstractJavaSearchScope {
30
35
31
protected boolean needsInitialize;
36
IPath[] enclosingPaths = null;
37
38
public JavaWorkspaceScope() {
39
	// As nothing is stored in the JavaWorkspaceScope now, no initialization is longer needed
40
}
32
41
33
public boolean encloses(IJavaElement element) {
42
public boolean encloses(IJavaElement element) {
34
	/*
35
	if (this.needsInitialize) {
36
		this.initialize();
37
	}
38
	return super.encloses(element);
39
	*/
40
	/*A workspace scope encloses all java elements (this assumes that the index selector
43
	/*A workspace scope encloses all java elements (this assumes that the index selector
41
	 * and thus enclosingProjectAndJars() returns indexes on the classpath only and that these
44
	 * and thus enclosingProjectAndJars() returns indexes on the classpath only and that these
42
	 * indexes are consistent.)
45
	 * indexes are consistent.)
Lines 45-56 Link Here
45
	return true;
48
	return true;
46
}
49
}
47
public boolean encloses(String resourcePathString) {
50
public boolean encloses(String resourcePathString) {
48
	/*
49
	if (this.needsInitialize) {
50
		this.initialize();
51
	}
52
	return super.encloses(resourcePathString);
53
	*/
54
	/*A workspace scope encloses all resources (this assumes that the index selector
51
	/*A workspace scope encloses all resources (this assumes that the index selector
55
	 * and thus enclosingProjectAndJars() returns indexes on the classpath only and that these
52
	 * and thus enclosingProjectAndJars() returns indexes on the classpath only and that these
56
	 * indexes are consistent.)
53
	 * indexes are consistent.)
Lines 58-145 Link Here
58
	 */
55
	 */
59
	return true;
56
	return true;
60
}
57
}
58
/* (non-Javadoc)
59
 * @see org.eclipse.jdt.core.search.IJavaSearchScope#enclosingProjectsAndJars()
60
 */
61
public IPath[] enclosingProjectsAndJars() {
61
public IPath[] enclosingProjectsAndJars() {
62
	if (this.needsInitialize) {
62
	if (this.enclosingPaths != null) return this.enclosingPaths;
63
		this.initialize(5);
63
	long start = System.currentTimeMillis();
64
	try {
65
		IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
66
		Set paths = new HashSet(projects.length * 2);
67
		for (int i = 0, length = projects.length; i < length; i++) {
68
			JavaProject javaProject = (JavaProject) projects[i];
69
			
70
			// Add project full path
71
			IPath projectPath = javaProject.getProject().getFullPath();
72
			paths.add(projectPath);
73
74
			// Add project libraries paths
75
			IClasspathEntry[] entries = javaProject.getResolvedClasspath();
76
			for (int j = 0, eLength = entries.length; j < eLength; j++) {
77
				IClasspathEntry entry = entries[j];
78
				if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
79
					IPath path = entry.getPath();
80
					Object target = JavaModel.getTarget(path, false/*don't check existence*/);
81
					if (target instanceof IFolder) // case of an external folder
82
						path = ((IFolder) target).getFullPath();
83
					paths.add(entry.getPath());
84
				}
85
			}
86
		}
87
		enclosingPaths = new IPath[paths.size()];
88
		paths.toArray(enclosingPaths);
89
	} catch (JavaModelException ignored) {
90
		// ignore
91
	}
92
	if (BasicSearchEngine.VERBOSE) {
93
		long time = System.currentTimeMillis() - start;
94
		int length = enclosingPaths == null ? 0 : enclosingPaths.length;
95
		Util.verbose("JavaWorkspaceScope.enclosingProjectsAndJars: "+length+" paths computed in "+time+"ms."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
64
	}
96
	}
65
	return super.enclosingProjectsAndJars();
97
	return enclosingPaths;
66
}
98
}
99
67
public boolean equals(Object o) {
100
public boolean equals(Object o) {
68
  return o instanceof JavaWorkspaceScope;
101
  return o == this; // use the singleton pattern
69
}
102
}
103
70
public AccessRuleSet getAccessRuleSet(String relativePath, String containerPath) {
104
public AccessRuleSet getAccessRuleSet(String relativePath, String containerPath) {
71
	if (this.pathRestrictions == null) 
105
	// Do not consider access rules on workspace scope 
72
		return null;
106
	return null;
73
	return super.getAccessRuleSet(relativePath, containerPath);
74
}
107
}
108
75
public int hashCode() {
109
public int hashCode() {
76
	return JavaWorkspaceScope.class.hashCode();
110
	return JavaWorkspaceScope.class.hashCode();
77
}
111
}
78
public void initialize(int size) {
112
79
	super.initialize(size);
80
	try {
81
		IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
82
		for (int i = 0, length = projects.length; i < length; i++) {
83
			int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
84
			add((JavaProject) projects[i], null, includeMask, new HashSet(length*2, 1), null);
85
		}
86
	} catch (JavaModelException ignored) {
87
		// ignore
88
	}
89
	this.needsInitialize = false;
90
}
91
public void processDelta(IJavaElementDelta delta, int eventType) {
113
public void processDelta(IJavaElementDelta delta, int eventType) {
92
	if (this.needsInitialize) return;
114
	// Do nothing as workspace scope does not retain any information
93
	IJavaElement element = delta.getElement();
94
	switch (element.getElementType()) {
95
		case IJavaElement.JAVA_MODEL:
96
			IJavaElementDelta[] children = delta.getAffectedChildren();
97
			for (int i = 0, length = children.length; i < length; i++) {
98
				IJavaElementDelta child = children[i];
99
				this.processDelta(child, eventType);
100
			}
101
			break;
102
		case IJavaElement.JAVA_PROJECT:
103
			int kind = delta.getKind();
104
			switch (kind) {
105
				case IJavaElementDelta.ADDED:
106
				case IJavaElementDelta.REMOVED:
107
					this.needsInitialize = true;
108
					break;
109
				case IJavaElementDelta.CHANGED:
110
					int flags = delta.getFlags();
111
					if ((flags & IJavaElementDelta.F_CLOSED) != 0
112
							|| (flags & IJavaElementDelta.F_OPENED) != 0) {
113
						this.needsInitialize = true;
114
					} else {
115
						children = delta.getAffectedChildren();
116
						for (int i = 0, length = children.length; i < length; i++) {
117
							IJavaElementDelta child = children[i];
118
							this.processDelta(child, eventType);
119
						}
120
					}
121
					break;
122
			}
123
			break;
124
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
125
			kind = delta.getKind();
126
			switch (kind) {
127
				case IJavaElementDelta.ADDED:
128
				case IJavaElementDelta.REMOVED:
129
					this.needsInitialize = true;
130
					break;
131
				case IJavaElementDelta.CHANGED:
132
					int flags = delta.getFlags();
133
					if ((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) > 0
134
						|| (flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) > 0) {
135
						this.needsInitialize = true;
136
					}
137
					break;
138
			}
139
			break;
140
	}
141
}
115
}
116
117
142
public String toString() {
118
public String toString() {
143
	return "JavaWorkspaceScope"; //$NON-NLS-1$
119
	StringBuffer result = new StringBuffer("JavaWorkspaceScope on "); //$NON-NLS-1$
120
	IPath[] paths = enclosingProjectsAndJars();
121
	int length = paths == null ? 0 : paths.length;
122
	if (length == 0) {
123
		result.append("[empty scope]"); //$NON-NLS-1$
124
	} else {
125
		result.append("["); //$NON-NLS-1$
126
		for (int i = 0; i < length; i++) {
127
			result.append("\n\t"); //$NON-NLS-1$
128
			result.append(paths[i]);
129
		}
130
		result.append("\n]"); //$NON-NLS-1$
131
	}
132
	return result.toString();
144
}
133
}
145
}
134
}
(-)search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java (-1 / +1 lines)
Lines 43-49 Link Here
43
/**
43
/**
44
 * A Java-specific scope for searching relative to one or more java elements.
44
 * A Java-specific scope for searching relative to one or more java elements.
45
 */
45
 */
46
public class JavaSearchScope extends AbstractSearchScope {
46
public class JavaSearchScope extends AbstractJavaSearchScope {
47
	
47
	
48
	private ArrayList elements;
48
	private ArrayList elements;
49
49
(-)model/org/eclipse/jdt/internal/core/util/HandleFactory.java (-1 / +1 lines)
Lines 263-269 Link Here
263
		
263
		
264
		// walk projects in the scope and find the first one that has the given jar path in its classpath
264
		// walk projects in the scope and find the first one that has the given jar path in its classpath
265
		IJavaProject[] projects;
265
		IJavaProject[] projects;
266
		if (scope != null) {
266
		if (scope != null && !JavaModelManager.getJavaModelManager().isWorkspaceScope(scope)) {
267
			IPath[] enclosingProjectsAndJars = scope.enclosingProjectsAndJars();
267
			IPath[] enclosingProjectsAndJars = scope.enclosingProjectsAndJars();
268
			int length = enclosingProjectsAndJars.length;
268
			int length = enclosingProjectsAndJars.length;
269
			projects = new IJavaProject[length];
269
			projects = new IJavaProject[length];
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-1 / +6 lines)
Lines 39-44 Link Here
39
import org.eclipse.jdt.core.compiler.CompilationParticipant;
39
import org.eclipse.jdt.core.compiler.CompilationParticipant;
40
import org.eclipse.jdt.core.compiler.IProblem;
40
import org.eclipse.jdt.core.compiler.IProblem;
41
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
41
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
42
import org.eclipse.jdt.core.search.IJavaSearchScope;
42
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
43
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
43
import org.eclipse.jdt.internal.codeassist.SelectionEngine;
44
import org.eclipse.jdt.internal.codeassist.SelectionEngine;
44
import org.eclipse.jdt.internal.compiler.AbstractAnnotationProcessorManager;
45
import org.eclipse.jdt.internal.compiler.AbstractAnnotationProcessorManager;
Lines 2097-2109 Link Here
2097
			return result;
2098
			return result;
2098
		}		
2099
		}		
2099
	}
2100
	}
2100
	
2101
2101
	public JavaWorkspaceScope getWorkspaceScope() {
2102
	public JavaWorkspaceScope getWorkspaceScope() {
2102
		if (this.workspaceScope == null) {
2103
		if (this.workspaceScope == null) {
2103
			this.workspaceScope = new JavaWorkspaceScope();
2104
			this.workspaceScope = new JavaWorkspaceScope();
2104
		}
2105
		}
2105
		return this.workspaceScope;
2106
		return this.workspaceScope;
2106
	}
2107
	}
2108
2109
	public boolean isWorkspaceScope(IJavaSearchScope scope) {
2110
		return this.workspaceScope != null && scope == this.workspaceScope;
2111
	}
2107
	
2112
	
2108
	/**
2113
	/**
2109
	 * Returns the open ZipFile at the given path. If the ZipFile
2114
	 * Returns the open ZipFile at the given path. If the ZipFile
(-)search/org/eclipse/jdt/internal/core/search/AbstractJavaSearchScope.java (+25 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core.search;
12
13
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
14
15
16
public abstract class AbstractJavaSearchScope extends AbstractSearchScope {
17
18
/**
19
 * Get access rule set corresponding to a given path.
20
 * @param relativePath The path user want to have restriction access
21
 * @return The access rule set for given path or null if none is set for it.
22
 * 	Returns specific unit access rule set when scope does not enclose the given path.
23
 */
24
abstract public AccessRuleSet getAccessRuleSet(String relativePath, String containerPath);
25
}

Return to bug 182738