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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java (-11 / +5 lines)
Lines 44-50 Link Here
44
/**
44
/**
45
 * A Java-specific scope for searching relative to one or more java elements.
45
 * A Java-specific scope for searching relative to one or more java elements.
46
 */
46
 */
47
public class JavaSearchScope extends AbstractSearchScope {
47
public class JavaSearchScope extends AbstractJavaSearchScope {
48
	
48
	
49
	private ArrayList elements;
49
	private ArrayList elements;
50
50
Lines 580-599 Link Here
580
}
580
}
581
581
582
/**
582
/**
583
 * Returns the package fragment root corresponding to a given resource path.
583
 * @see AbstractJavaSearchScope#packageFragmentRoot(String, int, String)
584
 * 
585
 * @param resourcePathString path of expected package fragment root.
586
 * @return the {@link IPackageFragmentRoot package fragment root} which path
587
 * 	match the given one or <code>null</code> if none was found.
588
 */
584
 */
589
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString) {
585
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPath) {
590
	int index = -1;
586
	int index = -1;
591
	int separatorIndex = resourcePathString.indexOf(JAR_FILE_ENTRY_SEPARATOR);
587
	boolean isJarFile = jarSeparatorIndex != -1;
592
	boolean isJarFile = separatorIndex != -1;
593
	if (isJarFile) {
588
	if (isJarFile) {
594
		// internal or external jar (case 3, 4, or 5)
589
		// internal or external jar (case 3, 4, or 5)
595
		String jarPath = resourcePathString.substring(0, separatorIndex);
590
		String relativePath = resourcePathString.substring(jarSeparatorIndex+1);
596
		String relativePath = resourcePathString.substring(separatorIndex+1);
597
		index = indexOf(jarPath, relativePath);
591
		index = indexOf(jarPath, relativePath);
598
	} else {
592
	} else {
599
		// resource in workspace (case 1 or 2)
593
		// resource in workspace (case 1 or 2)
(-)search/org/eclipse/jdt/internal/core/search/JavaWorkspaceScope.java (-38 / +109 lines)
Lines 10-42 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core.search;
11
package org.eclipse.jdt.internal.core.search;
12
12
13
import java.util.HashMap;
13
import java.util.HashSet;
14
import java.util.HashSet;
15
import java.util.Set;
14
16
17
import org.eclipse.core.resources.IFolder;
15
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.Path;
20
import org.eclipse.jdt.core.IClasspathEntry;
16
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.IJavaElementDelta;
22
import org.eclipse.jdt.core.IJavaElementDelta;
23
import org.eclipse.jdt.core.IJavaProject;
24
import org.eclipse.jdt.core.IPackageFragmentRoot;
18
import org.eclipse.jdt.core.JavaModelException;
25
import org.eclipse.jdt.core.JavaModelException;
19
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
26
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
27
import org.eclipse.jdt.internal.core.DeltaProcessor;
28
import org.eclipse.jdt.internal.core.JavaModel;
20
import org.eclipse.jdt.internal.core.JavaModelManager;
29
import org.eclipse.jdt.internal.core.JavaModelManager;
21
import org.eclipse.jdt.internal.core.JavaProject;
30
import org.eclipse.jdt.internal.core.JavaProject;
22
import org.eclipse.jdt.core.IJavaProject;
31
import org.eclipse.jdt.internal.core.util.Util;
23
32
24
/**
33
/**
25
 * A Java-specific scope for searching the entire workspace.
34
 * A Java-specific scope for searching the entire workspace.
26
 * The scope can be configured to not search binaries. By default, binaries
35
 * The scope can be configured to not search binaries. By default, binaries
27
 * are included.
36
 * are included.
28
 */
37
 */
29
public class JavaWorkspaceScope extends JavaSearchScope {
38
public class JavaWorkspaceScope extends AbstractJavaSearchScope {
30
39
31
protected boolean needsInitialize;
40
	private IPath[] enclosingPaths = null;
41
42
public JavaWorkspaceScope() {
43
	// As nothing is stored in the JavaWorkspaceScope now, no initialization is longer needed
44
}
32
45
33
public boolean encloses(IJavaElement element) {
46
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
47
	/*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
48
	 * and thus enclosingProjectAndJars() returns indexes on the classpath only and that these
42
	 * indexes are consistent.)
49
	 * indexes are consistent.)
Lines 45-56 Link Here
45
	return true;
52
	return true;
46
}
53
}
47
public boolean encloses(String resourcePathString) {
54
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
55
	/*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
56
	 * and thus enclosingProjectAndJars() returns indexes on the classpath only and that these
56
	 * indexes are consistent.)
57
	 * indexes are consistent.)
Lines 58-95 Link Here
58
	 */
59
	 */
59
	return true;
60
	return true;
60
}
61
}
62
/* (non-Javadoc)
63
 * @see org.eclipse.jdt.core.search.IJavaSearchScope#enclosingProjectsAndJars()
64
 */
61
public IPath[] enclosingProjectsAndJars() {
65
public IPath[] enclosingProjectsAndJars() {
62
	if (this.needsInitialize) {
66
	if (this.enclosingPaths != null) {
63
		this.initialize(5);
67
		return this.enclosingPaths;
68
	}
69
	long start = BasicSearchEngine.VERBOSE ? System.currentTimeMillis() : -1;
70
	try {
71
		IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
72
		Set paths = new HashSet(projects.length * 2);
73
		for (int i = 0, length = projects.length; i < length; i++) {
74
			JavaProject javaProject = (JavaProject) projects[i];
75
			
76
			// Add project full path
77
			IPath projectPath = javaProject.getProject().getFullPath();
78
			paths.add(projectPath);
79
80
			// Add project libraries paths
81
			IClasspathEntry[] entries = javaProject.getResolvedClasspath();
82
			for (int j = 0, eLength = entries.length; j < eLength; j++) {
83
				IClasspathEntry entry = entries[j];
84
				if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
85
					IPath path = entry.getPath();
86
					Object target = JavaModel.getTarget(path, false/*don't check existence*/);
87
					if (target instanceof IFolder) // case of an external folder
88
						path = ((IFolder) target).getFullPath();
89
					paths.add(entry.getPath());
90
				}
91
			}
92
		}
93
		IPath[] result = new IPath[paths.size()];
94
		paths.toArray(result);
95
		return this.enclosingPaths = result;
96
	} catch (JavaModelException e) {
97
		Util.log(e, "Exception while computing workspace scope's enclosing projects and jars"); //$NON-NLS-1$
98
		return new IPath[0];
99
	} finally {
100
		if (BasicSearchEngine.VERBOSE) {
101
			long time = System.currentTimeMillis() - start;
102
			int length = this.enclosingPaths == null ? 0 : this.enclosingPaths.length;
103
			Util.verbose("JavaWorkspaceScope.enclosingProjectsAndJars: "+length+" paths computed in "+time+"ms."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
104
		}
64
	}
105
	}
65
	return super.enclosingProjectsAndJars();
66
}
106
}
107
67
public boolean equals(Object o) {
108
public boolean equals(Object o) {
68
  return o instanceof JavaWorkspaceScope;
109
  return o == this; // use the singleton pattern
69
}
110
}
111
70
public AccessRuleSet getAccessRuleSet(String relativePath, String containerPath) {
112
public AccessRuleSet getAccessRuleSet(String relativePath, String containerPath) {
71
	if (this.pathRestrictions == null) 
113
	// Do not consider access rules on workspace scope 
72
		return null;
114
	return null;
73
	return super.getAccessRuleSet(relativePath, containerPath);
74
}
115
}
116
75
public int hashCode() {
117
public int hashCode() {
76
	return JavaWorkspaceScope.class.hashCode();
118
	return JavaWorkspaceScope.class.hashCode();
77
}
119
}
78
public void initialize(int size) {
120
79
	super.initialize(size);
121
/**
80
	try {
122
 * @see AbstractJavaSearchScope#packageFragmentRoot(String, int, String)
81
		IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
123
 */
82
		for (int i = 0, length = projects.length; i < length; i++) {
124
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPath) {
83
			int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
125
	HashMap rootInfos = JavaModelManager.getDeltaState().roots;
84
			add((JavaProject) projects[i], null, includeMask, new HashSet(length*2, 1), null);
126
	DeltaProcessor.RootInfo rootInfo = null;
127
	if (jarPath != null) {
128
		IPath path = new Path(jarPath);
129
		rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path);
130
		if (rootInfo == null)
131
			return null;
132
		return rootInfo.project.getPackageFragmentRoot0(path);
133
	} else {
134
		// resource in workspace
135
		IPath path = new Path(resourcePathString);
136
		rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path);
137
		while (rootInfo == null && path.segmentCount() > 0) {
138
			path = path.removeLastSegments(1);
139
			rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path);
85
		}
140
		}
86
	} catch (JavaModelException ignored) {
141
		if (rootInfo == null)
87
		// ignore
142
			return null;
143
		return rootInfo.getPackageFragmentRoot(null/*no resource hint*/);
88
	}
144
	}
89
	this.needsInitialize = false;
90
}
145
}
146
91
public void processDelta(IJavaElementDelta delta, int eventType) {
147
public void processDelta(IJavaElementDelta delta, int eventType) {
92
	if (this.needsInitialize) return;
148
	if (this.enclosingPaths == null) return;
93
	IJavaElement element = delta.getElement();
149
	IJavaElement element = delta.getElement();
94
	switch (element.getElementType()) {
150
	switch (element.getElementType()) {
95
		case IJavaElement.JAVA_MODEL:
151
		case IJavaElement.JAVA_MODEL:
Lines 104-116 Link Here
104
			switch (kind) {
160
			switch (kind) {
105
				case IJavaElementDelta.ADDED:
161
				case IJavaElementDelta.ADDED:
106
				case IJavaElementDelta.REMOVED:
162
				case IJavaElementDelta.REMOVED:
107
					this.needsInitialize = true;
163
					this.enclosingPaths = null;
108
					break;
164
					break;
109
				case IJavaElementDelta.CHANGED:
165
				case IJavaElementDelta.CHANGED:
110
					int flags = delta.getFlags();
166
					int flags = delta.getFlags();
111
					if ((flags & IJavaElementDelta.F_CLOSED) != 0
167
					if ((flags & IJavaElementDelta.F_CLOSED) != 0
112
							|| (flags & IJavaElementDelta.F_OPENED) != 0) {
168
							|| (flags & IJavaElementDelta.F_OPENED) != 0) {
113
						this.needsInitialize = true;
169
						this.enclosingPaths = null;
114
					} else {
170
					} else {
115
						children = delta.getAffectedChildren();
171
						children = delta.getAffectedChildren();
116
						for (int i = 0, length = children.length; i < length; i++) {
172
						for (int i = 0, length = children.length; i < length; i++) {
Lines 126-145 Link Here
126
			switch (kind) {
182
			switch (kind) {
127
				case IJavaElementDelta.ADDED:
183
				case IJavaElementDelta.ADDED:
128
				case IJavaElementDelta.REMOVED:
184
				case IJavaElementDelta.REMOVED:
129
					this.needsInitialize = true;
185
					this.enclosingPaths = null;
130
					break;
186
					break;
131
				case IJavaElementDelta.CHANGED:
187
				case IJavaElementDelta.CHANGED:
132
					int flags = delta.getFlags();
188
					int flags = delta.getFlags();
133
					if ((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) > 0
189
					if ((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) > 0
134
						|| (flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) > 0) {
190
						|| (flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) > 0) {
135
						this.needsInitialize = true;
191
						this.enclosingPaths = null;
136
					}
192
					}
137
					break;
193
					break;
138
			}
194
			}
139
			break;
195
			break;
140
	}
196
	}
141
}
197
}
198
199
142
public String toString() {
200
public String toString() {
143
	return "JavaWorkspaceScope"; //$NON-NLS-1$
201
	StringBuffer result = new StringBuffer("JavaWorkspaceScope on "); //$NON-NLS-1$
202
	IPath[] paths = enclosingProjectsAndJars();
203
	int length = paths == null ? 0 : paths.length;
204
	if (length == 0) {
205
		result.append("[empty scope]"); //$NON-NLS-1$
206
	} else {
207
		result.append("["); //$NON-NLS-1$
208
		for (int i = 0; i < length; i++) {
209
			result.append("\n\t"); //$NON-NLS-1$
210
			result.append(paths[i]);
211
		}
212
		result.append("\n]"); //$NON-NLS-1$
213
	}
214
	return result.toString();
144
}
215
}
145
}
216
}
(-)search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java (-3 / +3 lines)
Lines 70-76 Link Here
70
public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) {
70
public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) {
71
	this.requestor = requestor;
71
	this.requestor = requestor;
72
	this.scope = scope;
72
	this.scope = scope;
73
	if (!(scope instanceof JavaSearchScope)) {
73
	if (!(scope instanceof AbstractJavaSearchScope)) {
74
		this.handleFactory = new HandleFactory();
74
		this.handleFactory = new HandleFactory();
75
	}
75
	}
76
}
76
}
Lines 121-127 Link Here
121
			|| this.lastPkgFragmentRootPath.length() > resourcePath.length()
121
			|| this.lastPkgFragmentRootPath.length() > resourcePath.length()
122
			|| !resourcePath.startsWith(this.lastPkgFragmentRootPath)) {
122
			|| !resourcePath.startsWith(this.lastPkgFragmentRootPath)) {
123
		String jarPath= resourcePath.substring(0, separatorIndex);
123
		String jarPath= resourcePath.substring(0, separatorIndex);
124
		IPackageFragmentRoot root= ((JavaSearchScope)this.scope).packageFragmentRoot(resourcePath);
124
		IPackageFragmentRoot root= ((AbstractJavaSearchScope)this.scope).packageFragmentRoot(resourcePath, separatorIndex, jarPath);
125
		if (root == null) return null;
125
		if (root == null) return null;
126
		this.lastPkgFragmentRootPath= jarPath;
126
		this.lastPkgFragmentRootPath= jarPath;
127
		this.lastPkgFragmentRoot= root;
127
		this.lastPkgFragmentRoot= root;
Lines 153-159 Link Here
153
		|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath) 
153
		|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath) 
154
			&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
154
			&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
155
			&& resourcePath.charAt(rootPathLength) == '/')) {
155
			&& resourcePath.charAt(rootPathLength) == '/')) {
156
		PackageFragmentRoot root = (PackageFragmentRoot) ((JavaSearchScope)this.scope).packageFragmentRoot(resourcePath);
156
		PackageFragmentRoot root = (PackageFragmentRoot) ((AbstractJavaSearchScope)this.scope).packageFragmentRoot(resourcePath, -1/*not a jar*/, null/*no jar path*/);
157
		if (root == null) return null;
157
		if (root == null) return null;
158
		this.lastPkgFragmentRoot = root;
158
		this.lastPkgFragmentRoot = root;
159
		this.lastPkgFragmentRootPath = root.internalPath().toString();
159
		this.lastPkgFragmentRootPath = root.internalPath().toString();
(-)model/org/eclipse/jdt/internal/core/DeltaProcessor.java (-3 / +3 lines)
Lines 95-104 Link Here
95
		}
95
		}
96
	}
96
	}
97
	
97
	
98
	static class RootInfo {
98
	public static class RootInfo {
99
		char[][] inclusionPatterns;
99
		char[][] inclusionPatterns;
100
		char[][] exclusionPatterns;
100
		char[][] exclusionPatterns;
101
		JavaProject project;
101
		public JavaProject project;
102
		IPath rootPath;
102
		IPath rootPath;
103
		int entryKind;
103
		int entryKind;
104
		IPackageFragmentRoot root;
104
		IPackageFragmentRoot root;
Lines 109-115 Link Here
109
			this.exclusionPatterns = exclusionPatterns;
109
			this.exclusionPatterns = exclusionPatterns;
110
			this.entryKind = entryKind;
110
			this.entryKind = entryKind;
111
		}
111
		}
112
		IPackageFragmentRoot getPackageFragmentRoot(IResource resource) {
112
		public IPackageFragmentRoot getPackageFragmentRoot(IResource resource) {
113
			if (this.root == null) {
113
			if (this.root == null) {
114
				if (resource != null) {
114
				if (resource != null) {
115
					this.root = this.project.getPackageFragmentRoot(resource);
115
					this.root = this.project.getPackageFragmentRoot(resource);
(-)search/org/eclipse/jdt/internal/core/search/AbstractJavaSearchScope.java (+37 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.core.IPackageFragmentRoot;
14
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
15
16
17
public abstract class AbstractJavaSearchScope extends AbstractSearchScope {
18
19
/**
20
 * Get access rule set corresponding to a given path.
21
 * @param relativePath The path user want to have restriction access
22
 * @return The access rule set for given path or null if none is set for it.
23
 * 	Returns specific unit access rule set when scope does not enclose the given path.
24
 */
25
abstract public AccessRuleSet getAccessRuleSet(String relativePath, String containerPath);
26
27
/**
28
 * Returns the package fragment root corresponding to a given resource path.
29
 * 
30
 * @param resourcePathString path of expected package fragment root.
31
 * @param jarSeparatorIndex the index of the jar separator in the resource path, or -1 if none
32
 * @param jarPath the already extracted jar path, or null if none
33
 * @return the {@link IPackageFragmentRoot package fragment root} which path
34
 * 	match the given one or <code>null</code> if none was found.
35
 */
36
abstract public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPath);
37
}

Return to bug 182738