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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (-39 / +41 lines)
Lines 11-16 Link Here
11
package org.eclipse.jdt.core.tests.model;
11
package org.eclipse.jdt.core.tests.model;
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Arrays;
14
import java.util.List;
15
import java.util.List;
15
16
16
import junit.framework.Test;
17
import junit.framework.Test;
Lines 82-87 Link Here
82
	}
83
	}
83
}
84
}
84
85
86
class TypeNameMatchCollector extends TypeNameMatchRequestor {
87
	private int index = -1;
88
	public String[] results = new String[10];
89
	public void acceptTypeNameMatch(TypeNameMatch match) {
90
		int length = results.length;
91
		if (++index > length) {
92
			System.arraycopy(results, 0, results = new String[length+10], 0, length);
93
		}
94
		try {
95
			IType type = match.getType();
96
			if (type != null) {
97
				results[index] = type.toString();
98
			}
99
		}
100
		catch (JavaModelException jme) {
101
			assertTrue("We should not have any JavaModel exception! Message:"+jme.getMessage(), false);
102
		}
103
	}
104
	public String toString() {
105
		String[] strings = new String[index+1];
106
		System.arraycopy(results, 0, strings, 0, index+1);
107
		Arrays.sort(strings);
108
		StringBuffer buffer = new StringBuffer();
109
		for (int i=0; i<=index; i++) {
110
			if (i>0) buffer.append('\n');
111
			buffer.append(strings[i]);
112
		}
113
		return buffer.toString();
114
	}
115
}
85
IJavaSearchScope getJavaSearchScopeBugs() {
116
IJavaSearchScope getJavaSearchScopeBugs() {
86
	return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")});
117
	return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")});
87
}
118
}
Lines 6879-6885 Link Here
6879
		"public class Y {}\n"
6910
		"public class Y {}\n"
6880
	);
6911
	);
6881
	IJavaSearchScope scope = getJavaSearchScopeBugs();
6912
	IJavaSearchScope scope = getJavaSearchScopeBugs();
6882
	TestTypeNameMatchRequestor requestor1 = new TestTypeNameMatchRequestor();
6913
	TypeNameMatchCollector requestor1 = new TypeNameMatchCollector();
6883
	new SearchEngine(this.workingCopies).searchAllTypeNames(
6914
	new SearchEngine(this.workingCopies).searchAllTypeNames(
6884
		"b148380".toCharArray(),
6915
		"b148380".toCharArray(),
6885
		SearchPattern.R_EXACT_MATCH,
6916
		SearchPattern.R_EXACT_MATCH,
Lines 6890-6904 Link Here
6890
		requestor1,
6921
		requestor1,
6891
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
6922
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
6892
		null);
6923
		null);
6893
	assertSearchResults(
6924
	String expected = "class Sub [in [Working copy] Sub.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + 
6894
		"interface I [in [Working copy] I.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + 
6895
		"class X [in [Working copy] X.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + 
6925
		"class X [in [Working copy] X.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + 
6896
		"class Sub [in [Working copy] Sub.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + 
6926
		"class Y [in [Working copy] Y.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + 
6897
		"class Y [in [Working copy] Y.java [in b148380 [in src [in JavaSearchBugs]]]]",
6927
		"interface I [in [Working copy] I.java [in b148380 [in src [in JavaSearchBugs]]]]";
6898
		requestor1);
6928
	assertSearchResults(expected, requestor1);
6899
	/* DISABLED as results order is not the same on different VM...
6929
	//  Expected same result with the wc owner
6900
	 *  Expected same result with the wc owner
6930
	TypeNameMatchCollector requestor2 = new TypeNameMatchCollector();
6901
	TestTypeNameMatchRequestor requestor2 = new TestTypeNameMatchRequestor();
6902
	new SearchEngine(this.wcOwner).searchAllTypeNames(
6931
	new SearchEngine(this.wcOwner).searchAllTypeNames(
6903
		"b148380".toCharArray(),
6932
		"b148380".toCharArray(),
6904
		SearchPattern.R_EXACT_MATCH,
6933
		SearchPattern.R_EXACT_MATCH,
Lines 6909-6924 Link Here
6909
		requestor2,
6938
		requestor2,
6910
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
6939
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
6911
		null);
6940
		null);
6912
	assertSearchResults("class Sub [in [Working copy] Sub.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + 
6941
	assertSearchResults(expected, requestor2);
6913
		"class Y [in [Working copy] Y.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + 
6914
		"interface I [in [Working copy] I.java [in b148380 [in src [in JavaSearchBugs]]]]\n" + 
6915
		"class X [in [Working copy] X.java [in b148380 [in src [in JavaSearchBugs]]]]",
6916
		requestor2);
6917
	*/
6918
}
6942
}
6919
public void testBug148380_SearchAllTypes_cu() throws CoreException, JavaModelException {
6943
public void testBug148380_SearchAllTypes_cu() throws CoreException, JavaModelException {
6920
	IJavaSearchScope scope = getJavaSearchScopeBugs();
6944
	IJavaSearchScope scope = getJavaSearchScopeBugs();
6921
	TestTypeNameMatchRequestor requestor = new TestTypeNameMatchRequestor();
6945
	TypeNameMatchCollector requestor = new TypeNameMatchCollector();
6922
	new SearchEngine().searchAllTypeNames(
6946
	new SearchEngine().searchAllTypeNames(
6923
		null,
6947
		null,
6924
		SearchPattern.R_EXACT_MATCH,
6948
		SearchPattern.R_EXACT_MATCH,
Lines 6936-6942 Link Here
6936
}
6960
}
6937
public void testBug148380_SearchAllTypes_cu_wksp() throws CoreException, JavaModelException {
6961
public void testBug148380_SearchAllTypes_cu_wksp() throws CoreException, JavaModelException {
6938
	IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
6962
	IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
6939
	TestTypeNameMatchRequestor requestor = new TestTypeNameMatchRequestor();
6963
	TypeNameMatchCollector requestor = new TypeNameMatchCollector();
6940
	new SearchEngine().searchAllTypeNames(
6964
	new SearchEngine().searchAllTypeNames(
6941
		null,
6965
		null,
6942
		SearchPattern.R_EXACT_MATCH,
6966
		SearchPattern.R_EXACT_MATCH,
Lines 7083-7108 Link Here
7083
	);
7107
	);
7084
}
7108
}
7085
7109
7086
/**
7087
 * Bug 156491: [1.5][search] interfaces and annotations could be found with only one requets of searchAllTypeName
7088
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491"
7089
 */
7090
class TestTypeNameMatchRequestor extends TypeNameMatchRequestor {
7091
	public StringBuffer results = new StringBuffer();
7092
	public void acceptTypeNameMatch(TypeNameMatch match) {
7093
		if (results.length() > 0) results.append('\n');
7094
		try {
7095
			IType type = match.resolvedType();
7096
			if (type != null) {
7097
				results.append(type.toString());
7098
			}
7099
		}
7100
		catch (JavaModelException jme) {
7101
			assertTrue("We should not have no JavaModel exception! Message:"+jme.getMessage(), false);
7102
		}
7103
	}
7104
	public String toString() {
7105
		return this.results.toString();
7106
	}
7107
}
7108
}
7110
}
(-)search/org/eclipse/jdt/internal/core/search/WorkingCopiesTypeNameMatch.java (-36 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 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.ICompilationUnit;
14
import org.eclipse.jdt.core.search.TypeNameMatch;
15
16
/**
17
 * Specific match collected while searching for all type names
18
 * when type belongs to a working copy.
19
 * 
20
 * @since 3.3
21
 */
22
public class WorkingCopiesTypeNameMatch extends TypeNameMatch {
23
	private ICompilationUnit[] workingCopies;
24
25
public WorkingCopiesTypeNameMatch(int modifiers, char[] packageName, char[] typeName, char[][] enclosingTypeNames, String path, ICompilationUnit[] workingCopies) {
26
	super(modifiers, packageName, typeName, enclosingTypeNames, path);
27
	this.workingCopies = workingCopies;
28
}
29
30
/* (non-Javadoc)
31
 * @see org.eclipse.jdt.core.search.TypeNameMatch#getWorkingCopies()
32
 */
33
protected ICompilationUnit[] getWorkingCopies() {
34
	return this.workingCopies;
35
}
36
}
(-)search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java (-5 / +22 lines)
Lines 326-332 Link Here
326
	 * Returns the list of working copies used by this search engine.
326
	 * Returns the list of working copies used by this search engine.
327
	 * Returns null if none.
327
	 * Returns null if none.
328
	 */
328
	 */
329
	public ICompilationUnit[] getWorkingCopies() {
329
	private ICompilationUnit[] getWorkingCopies() {
330
		ICompilationUnit[] copies;
330
		ICompilationUnit[] copies;
331
		if (this.workingCopies != null) {
331
		if (this.workingCopies != null) {
332
			if (this.workingCopyOwner == null) {
332
			if (this.workingCopyOwner == null) {
Lines 779-785 Link Here
779
			// add type names from working copies
779
			// add type names from working copies
780
			if (copies != null) {
780
			if (copies != null) {
781
				for (int i = 0; i < copiesLength; i++) {
781
				for (int i = 0; i < copiesLength; i++) {
782
					ICompilationUnit workingCopy = copies[i];
782
					final ICompilationUnit workingCopy = copies[i];
783
					if (!scope.encloses(workingCopy)) continue;
783
					if (!scope.encloses(workingCopy)) continue;
784
					final String path = workingCopy.getPath().toString();
784
					final String path = workingCopy.getPath().toString();
785
					if (workingCopy.isConsistent()) {
785
					if (workingCopy.isConsistent()) {
Lines 808-814 Link Here
808
								kind = TypeDeclaration.INTERFACE_DECL;
808
								kind = TypeDeclaration.INTERFACE_DECL;
809
							}
809
							}
810
							if (match(typeSuffix, packageName, typeName, typeMatchRule, kind, packageDeclaration, simpleName)) {
810
							if (match(typeSuffix, packageName, typeName, typeMatchRule, kind, packageDeclaration, simpleName)) {
811
								nameRequestor.acceptType(type.getFlags(), packageDeclaration, simpleName, enclosingTypeNames, path, null);
811
								if (nameRequestor instanceof TypeNameMatchRequestorWrapper) {
812
									((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new TypeNameMatch(type));
813
								} else {
814
									nameRequestor.acceptType(type.getFlags(), packageDeclaration, simpleName, enclosingTypeNames, path, null);
815
								}
812
							}
816
							}
813
						}
817
						}
814
					} else {
818
					} else {
Lines 824-830 Link Here
824
								}
828
								}
825
								public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope compilationUnitScope) {
829
								public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope compilationUnitScope) {
826
									if (match(typeSuffix, packageName, typeName, typeMatchRule, TypeDeclaration.kind(typeDeclaration.modifiers), packageDeclaration, typeDeclaration.name)) {
830
									if (match(typeSuffix, packageName, typeName, typeMatchRule, TypeDeclaration.kind(typeDeclaration.modifiers), packageDeclaration, typeDeclaration.name)) {
827
										nameRequestor.acceptType(typeDeclaration.modifiers, packageDeclaration, typeDeclaration.name, CharOperation.NO_CHAR_CHAR, path, null);
831
										if (nameRequestor instanceof TypeNameMatchRequestorWrapper) {
832
											IType type = workingCopy.getType(new String(typeName));
833
											((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new TypeNameMatch(type, typeDeclaration.modifiers));
834
										} else {
835
											nameRequestor.acceptType(typeDeclaration.modifiers, packageDeclaration, typeDeclaration.name, CharOperation.NO_CHAR_CHAR, path, null);
836
										}
828
									}
837
									}
829
									return true;
838
									return true;
830
								}
839
								}
Lines 842-848 Link Here
842
											}
851
											}
843
										}
852
										}
844
										// report
853
										// report
845
										nameRequestor.acceptType(memberTypeDeclaration.modifiers, packageDeclaration, memberTypeDeclaration.name, enclosingTypeNames, path, null);
854
										if (nameRequestor instanceof TypeNameMatchRequestorWrapper) {
855
											IType type = workingCopy.getType(new String(enclosingTypeNames[0]));
856
											for (int j=1, l=enclosingTypeNames.length; j<l; j++) {
857
												type = type.getType(new String(enclosingTypeNames[j]));
858
											}
859
											((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new TypeNameMatch(type, 0));
860
										} else {
861
											nameRequestor.acceptType(memberTypeDeclaration.modifiers, packageDeclaration, memberTypeDeclaration.name, enclosingTypeNames, path, null);
862
										}
846
									}
863
									}
847
									return true;
864
									return true;
848
								}
865
								}
(-)search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java (-20 / +44 lines)
Lines 16-26 Link Here
16
16
17
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.Path;
21
import org.eclipse.core.runtime.Path;
21
import org.eclipse.jdt.core.*;
22
import org.eclipse.jdt.core.IClasspathContainer;
23
import org.eclipse.jdt.core.IClasspathEntry;
24
import org.eclipse.jdt.core.IJavaElement;
25
import org.eclipse.jdt.core.IJavaElementDelta;
26
import org.eclipse.jdt.core.IJavaModel;
27
import org.eclipse.jdt.core.IJavaProject;
28
import org.eclipse.jdt.core.IMember;
29
import org.eclipse.jdt.core.IPackageFragmentRoot;
30
import org.eclipse.jdt.core.JavaCore;
31
import org.eclipse.jdt.core.JavaModelException;
22
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
32
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
23
import org.eclipse.jdt.internal.core.*;
33
import org.eclipse.jdt.internal.core.ClasspathEntry;
34
import org.eclipse.jdt.internal.core.JavaElement;
35
import org.eclipse.jdt.internal.core.JavaModel;
36
import org.eclipse.jdt.internal.core.JavaModelManager;
37
import org.eclipse.jdt.internal.core.JavaProject;
38
import org.eclipse.jdt.internal.core.PackageFragment;
24
import org.eclipse.jdt.internal.core.util.Util;
39
import org.eclipse.jdt.internal.core.util.Util;
25
40
26
/**
41
/**
Lines 44-50 Link Here
44
	
59
	
45
	private IPath[] enclosingProjectsAndJars;
60
	private IPath[] enclosingProjectsAndJars;
46
	public final static AccessRuleSet NOT_ENCLOSED = new AccessRuleSet(null, null);
61
	public final static AccessRuleSet NOT_ENCLOSED = new AccessRuleSet(null, null);
47
	
62
48
public JavaSearchScope() {
63
public JavaSearchScope() {
49
	this(5);
64
	this(5);
50
}
65
}
Lines 158-164 Link Here
158
				if ((includeMask & SOURCES) != 0) {
173
				if ((includeMask & SOURCES) != 0) {
159
					IPath path = entry.getPath();
174
					IPath path = entry.getPath();
160
					if (pathToAdd == null || pathToAdd.equals(path)) {
175
					if (pathToAdd == null || pathToAdd.equals(path)) {
161
						add(null, Util.relativePath(path,1/*remove project segment*/), projectPathString, false/*not a package*/, access);
176
						add(projectPath.toString(), Util.relativePath(path,1/*remove project segment*/), projectPathString, false/*not a package*/, access);
162
					}
177
					}
163
				}
178
				}
164
				break;
179
				break;
Lines 187-206 Link Here
187
			containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
202
			containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
188
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
203
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
189
			IResource rootResource = root.getResource();
204
			IResource rootResource = root.getResource();
205
			String projectPath = root.getJavaProject().getPath().toString();
190
			if (rootResource != null && rootResource.isAccessible()) {
206
			if (rootResource != null && rootResource.isAccessible()) {
191
				String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
207
				String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
192
				add(null, relativePath, containerPathToString, false/*not a package*/, null);
208
				add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
193
			} else {
209
			} else {
194
				add(null, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$
210
				add(projectPath, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$
195
			}
211
			}
196
			break;
212
			break;
197
		case IJavaElement.PACKAGE_FRAGMENT:
213
		case IJavaElement.PACKAGE_FRAGMENT:
198
			root = (IPackageFragmentRoot)element.getParent();
214
			root = (IPackageFragmentRoot)element.getParent();
215
			projectPath = root.getJavaProject().getPath().toString();
199
			if (root.isArchive()) {
216
			if (root.isArchive()) {
200
				String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
217
				String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
201
				containerPath = root.getPath();
218
				containerPath = root.getPath();
202
				containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
219
				containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
203
				add(null, relativePath, containerPathToString, true/*package*/, null);
220
				add(projectPath, relativePath, containerPathToString, true/*package*/, null);
204
			} else {
221
			} else {
205
				IResource resource = element.getResource();
222
				IResource resource = element.getResource();
206
				if (resource != null) {
223
				if (resource != null) {
Lines 212-218 Link Here
212
					}
229
					}
213
					containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
230
					containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
214
					String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount());
231
					String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount());
215
					add(null, relativePath, containerPathToString, true/*package*/, null);
232
					add(projectPath, relativePath, containerPathToString, true/*package*/, null);
216
				}
233
				}
217
			}
234
			}
218
			break;
235
			break;
Lines 225-230 Link Here
225
				this.elements.add(element);
242
				this.elements.add(element);
226
			}
243
			}
227
			root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
244
			root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
245
			projectPath = root.getJavaProject().getPath().toString();
228
			String relativePath;
246
			String relativePath;
229
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
247
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
230
				containerPath = root.getParent().getPath();
248
				containerPath = root.getParent().getPath();
Lines 234-240 Link Here
234
				relativePath = getPath(element, true/*relative path*/).toString();
252
				relativePath = getPath(element, true/*relative path*/).toString();
235
			}
253
			}
236
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
254
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
237
			add(null, relativePath, containerPathToString, false/*not a package*/, null);
255
			add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
238
	}
256
	}
239
	
257
	
240
	if (containerPath != null)
258
	if (containerPath != null)
Lines 259-272 Link Here
259
			index = 0;
277
			index = 0;
260
		}
278
		}
261
	}
279
	}
262
	int idx = -1;
280
	int idx = this.projectPaths.indexOf(projectPath);
263
	if (projectPath != null && !containerPath.startsWith(projectPath)) {
281
	if (idx == -1) {
282
		// store project in separated list to minimize memory footprint
283
		this.projectPaths.add(projectPath);
264
		idx = this.projectPaths.indexOf(projectPath);
284
		idx = this.projectPaths.indexOf(projectPath);
265
		if (idx == -1) {
266
			// store project in separated list to minimize memory footprint
267
			this.projectPaths.add(projectPath);
268
			idx = this.projectPaths.indexOf(projectPath);
269
		}
270
	}
285
	}
271
	this.projectIndexes[index] = idx;
286
	this.projectIndexes[index] = idx;
272
	this.relativePaths[index] = relativePath;
287
	this.relativePaths[index] = relativePath;
Lines 546-555 Link Here
546
 * @param resourcePathString path of the resource
561
 * @param resourcePathString path of the resource
547
 * @return the project path of the resource
562
 * @return the project path of the resource
548
 */
563
 */
549
public String projectPathFor(String resourcePathString) {
564
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString) {
550
	int index = -1;
565
	int index = -1;
551
	int separatorIndex = resourcePathString.indexOf(JAR_FILE_ENTRY_SEPARATOR);
566
	int separatorIndex = resourcePathString.indexOf(JAR_FILE_ENTRY_SEPARATOR);
552
	if (separatorIndex != -1) {
567
	boolean isJarFile = separatorIndex != -1;
568
	if (isJarFile) {
553
		// internal or external jar (case 3, 4, or 5)
569
		// internal or external jar (case 3, 4, or 5)
554
		String jarPath = resourcePathString.substring(0, separatorIndex);
570
		String jarPath = resourcePathString.substring(0, separatorIndex);
555
		String relativePath = resourcePathString.substring(separatorIndex+1);
571
		String relativePath = resourcePathString.substring(separatorIndex+1);
Lines 560-567 Link Here
560
	}
576
	}
561
	if (index >= 0) {
577
	if (index >= 0) {
562
		int idx = projectIndexes[index];
578
		int idx = projectIndexes[index];
563
		if (idx != -1) {
579
		String projectPath = idx == -1 ? null : (String) this.projectPaths.get(idx);
564
			return (String) this.projectPaths.get(idx);
580
		if (projectPath != null) {
581
			IJavaProject project =JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject(projectPath));
582
			if (isJarFile) {
583
				return project.getPackageFragmentRoot(this.containerPaths[index]);
584
			}
585
			Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(this.containerPaths[index]+'/'+this.relativePaths[index]), false);
586
			if (target instanceof IResource) {
587
				return project.getPackageFragmentRoot((IResource)target);
588
			}
565
		}
589
		}
566
	}
590
	}
567
	return null;
591
	return null;
(-)search/org/eclipse/jdt/internal/core/search/ExternalTypeNameMatch.java (-56 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 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.core.resources.IProject;
14
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.jdt.core.IJavaProject;
16
import org.eclipse.jdt.core.IPackageFragmentRoot;
17
import org.eclipse.jdt.core.JavaCore;
18
import org.eclipse.jdt.core.search.IJavaSearchScope;
19
import org.eclipse.jdt.core.search.TypeNameMatch;
20
21
/**
22
 * Specific match collected while searching for all type names
23
 * when type belongs to an external resource.
24
 * 
25
 * @since 3.3
26
 */
27
public class ExternalTypeNameMatch extends TypeNameMatch {
28
	private String projectPath;
29
	private IPackageFragmentRoot root;
30
31
public ExternalTypeNameMatch(int modifiers, char[] packageName, char[] typeName, char[][] enclosingTypeNames, String path, String project) {
32
	super(modifiers, packageName, typeName, enclosingTypeNames, path);
33
	this.projectPath = project;
34
}
35
36
/* (non-Javadoc)
37
 * @see org.eclipse.jdt.core.search.TypeNameMatch#getProject()
38
 */
39
protected IProject getProject() {
40
	return ResourcesPlugin.getWorkspace().getRoot().getProject(this.projectPath);
41
}
42
43
/* (non-Javadoc)
44
 * @see org.eclipse.jdt.core.search.TypeNameMatch#getPackageFragmentRoot()
45
 */
46
protected IPackageFragmentRoot getPackageFragmentRoot() {
47
	if (this.root == null) {
48
		int separatorIndex = getPath().indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
49
		String jarPath = getPath().substring(0, separatorIndex);
50
		IJavaProject javaProject = JavaCore.create(getProject());
51
		if (javaProject == null) return null; // cannot initialize without a project
52
		this.root = javaProject.getPackageFragmentRoot(jarPath);
53
	}
54
	return root;
55
}
56
}
(-)search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java (-20 / +141 lines)
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core.search;
11
package org.eclipse.jdt.internal.core.search;
12
12
13
import org.eclipse.core.runtime.Path;
14
import org.eclipse.jdt.core.IClassFile;
13
import org.eclipse.jdt.core.ICompilationUnit;
15
import org.eclipse.jdt.core.ICompilationUnit;
16
import org.eclipse.jdt.core.IPackageFragment;
17
import org.eclipse.jdt.core.IPackageFragmentRoot;
18
import org.eclipse.jdt.core.IType;
19
import org.eclipse.jdt.core.JavaModelException;
20
import org.eclipse.jdt.core.compiler.CharOperation;
14
import org.eclipse.jdt.core.search.IJavaSearchScope;
21
import org.eclipse.jdt.core.search.IJavaSearchScope;
15
import org.eclipse.jdt.core.search.TypeNameMatch;
22
import org.eclipse.jdt.core.search.TypeNameMatch;
16
import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
23
import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
17
import org.eclipse.jdt.core.search.TypeNameRequestor;
24
import org.eclipse.jdt.core.search.TypeNameRequestor;
18
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
25
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
26
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
27
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject;
19
28
20
/**
29
/**
21
 * Wrapper used to link {@link IRestrictedAccessTypeRequestor} with {@link TypeNameRequestor}.
30
 * Wrapper used to link {@link IRestrictedAccessTypeRequestor} with {@link TypeNameRequestor}.
Lines 41-54 Link Here
41
 * 	org.eclipse.core.runtime.IProgressMonitor monitor) }.
50
 * 	org.eclipse.core.runtime.IProgressMonitor monitor) }.
42
 */
51
 */
43
public class TypeNameMatchRequestorWrapper implements IRestrictedAccessTypeRequestor {
52
public class TypeNameMatchRequestorWrapper implements IRestrictedAccessTypeRequestor {
44
	private TypeNameMatchRequestor requestor;
53
	TypeNameMatchRequestor requestor;
45
	private IJavaSearchScope scope; // scope is needed to retrieve project path for external resource
54
	private IJavaSearchScope scope; // scope is needed to retrieve project path for external resource
46
	private ICompilationUnit[] workingCopies; // working copies in which types may be found
55
//	private HandleFactory handleFactory;
47
56
48
public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope, ICompilationUnit[] workingCopies) {
57
	/**
58
	 * Cache package fragment root information to optimize speed performance.
59
	 */
60
	private String lastPkgFragmentRootPath;
61
	private IPackageFragmentRoot lastPkgFragmentRoot;
62
63
	/**
64
	 * Cache package handles to optimize memory.
65
	 */
66
	private HashtableOfArrayToObject packageHandles;
67
68
public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) {
49
	this.requestor = requestor;
69
	this.requestor = requestor;
50
	this.scope = scope;
70
	this.scope = scope;
51
	this.workingCopies = workingCopies;
52
}
71
}
53
72
54
/* (non-Javadoc)
73
/* (non-Javadoc)
Lines 56-79 Link Here
56
 */
75
 */
57
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
76
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
58
	if (access == null) { // accept only if there's no access violation
77
	if (access == null) { // accept only if there's no access violation
59
		if (this.scope instanceof JavaSearchScope) {
78
//		if (this.handleFactory == null) {
60
			String projectPath = ((JavaSearchScope)this.scope).projectPathFor(path);
79
//			this.handleFactory = new HandleFactory();
61
			if (projectPath == null) {
80
//		}
62
				if (this.workingCopies == null) {
81
//		Openable openable = this.handleFactory.createOpenable(path, this.scope);
63
					// Internal resource, project path won't be store as it can be computed from path
82
//		if (openable != null) {
64
					TypeNameMatch match = new TypeNameMatch(modifiers, packageName, simpleTypeName, enclosingTypeNames, path);
83
//			try {
65
					this.requestor.acceptTypeNameMatch(match);
84
//				IType type = null;
66
				} else {
85
//				switch (openable.getElementType()) {
67
					// Internal working copy, project path won't be store as it can be computed from path
86
//					case IJavaElement.CLASS_FILE:
68
					WorkingCopiesTypeNameMatch match = new WorkingCopiesTypeNameMatch(modifiers, packageName, simpleTypeName, enclosingTypeNames, path, this.workingCopies);
87
//						type = ((IClassFile)openable).getType();
69
					this.requestor.acceptTypeNameMatch(match);
88
//						break;
70
				}
89
//					case IJavaElement.COMPILATION_UNIT:
71
			} else {
90
//						int length = enclosingTypeNames == null ? 0 : enclosingTypeNames.length;
72
				// External resource, store specific project path
91
//						if (length == 0) {
73
				ExternalTypeNameMatch match = new ExternalTypeNameMatch(modifiers, packageName, simpleTypeName, enclosingTypeNames, path, projectPath);
92
//							type = ((ICompilationUnit)openable).getType(new String(simpleTypeName));
74
				this.requestor.acceptTypeNameMatch(match);
93
//						} else {
94
//							type = ((ICompilationUnit)openable).getType(new String(enclosingTypeNames[0]));
95
//							for (int i=1; i<length; i++) {
96
//								type = type.getType(new String(enclosingTypeNames[i]));
97
//							}
98
//							type = type.getType(new String(simpleTypeName));
99
//						}
100
//						break;
101
//				}
102
//				if (type != null) {
103
//					this.requestor.acceptTypeNameMatch(new TypeNameMatch(type, modifiers));
104
//				}
105
//			} catch (JavaModelException e) {
106
//				// skip
107
//			}
108
//		}
109
		try {
110
			int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
111
			IType type = separatorIndex == -1
112
				? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames)
113
				: createTypeFromJar(path, separatorIndex);
114
			if (type != null) {
115
				this.requestor.acceptTypeNameMatch(new TypeNameMatch(type, modifiers));
75
			}
116
			}
117
		} catch (JavaModelException e) {
118
			// skip
76
		}
119
		}
77
	}
120
	}
78
}
121
}
122
private IType createTypeFromJar(String resourcePath, int separatorIndex) throws JavaModelException {
123
	// path to a class file inside a jar
124
	// Optimization: cache package fragment root handle and package handles
125
	if (this.lastPkgFragmentRootPath == null 
126
			|| this.lastPkgFragmentRootPath.length() > resourcePath.length()
127
			|| !resourcePath.startsWith(this.lastPkgFragmentRootPath)) {
128
		String jarPath= resourcePath.substring(0, separatorIndex);
129
		IPackageFragmentRoot root= ((JavaSearchScope)scope).packageFragmentRoot(resourcePath);
130
		if (root == null) return null;
131
		this.lastPkgFragmentRootPath= jarPath;
132
		this.lastPkgFragmentRoot= root;
133
		this.packageHandles= new HashtableOfArrayToObject(5);
134
	}
135
	// create handle
136
	String classFilePath= resourcePath.substring(separatorIndex + 1);
137
	String[] simpleNames = new Path(classFilePath).segments();
138
	String[] pkgName;
139
	int length = simpleNames.length-1;
140
	if (length > 0) {
141
		pkgName = new String[length];
142
		System.arraycopy(simpleNames, 0, pkgName, 0, length);
143
	} else {
144
		pkgName = CharOperation.NO_STRINGS;
145
	}
146
	IPackageFragment pkgFragment= (IPackageFragment) this.packageHandles.get(pkgName);
147
	if (pkgFragment == null) {
148
		pkgFragment= ((PackageFragmentRoot) this.lastPkgFragmentRoot).getPackageFragment(pkgName);
149
		this.packageHandles.put(pkgName, pkgFragment);
150
	}
151
	return pkgFragment.getClassFile(simpleNames[length]).getType();
152
}	
153
private IType createTypeFromPath(String resourcePath, String simpleTypeName, char[][] enclosingTypeNames) throws JavaModelException {
154
	// path to a file in a directory
155
	// Optimization: cache package fragment root handle and package handles
156
	int rootPathLength = -1;
157
	if (this.lastPkgFragmentRootPath == null 
158
		|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath) 
159
			&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
160
			&& resourcePath.charAt(rootPathLength) == '/')) {
161
		IPackageFragmentRoot root= ((JavaSearchScope)scope).packageFragmentRoot(resourcePath);
162
		if (root == null) return null;
163
		this.lastPkgFragmentRoot = root;
164
		this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString();
165
		this.packageHandles = new HashtableOfArrayToObject(5);
166
	}
167
	// create handle
168
	resourcePath = resourcePath.substring(this.lastPkgFragmentRootPath.length() + 1);
169
	String[] simpleNames = new Path(resourcePath).segments();
170
	String[] pkgName;
171
	int length = simpleNames.length-1;
172
	if (length > 0) {
173
		pkgName = new String[length];
174
		System.arraycopy(simpleNames, 0, pkgName, 0, length);
175
	} else {
176
		pkgName = CharOperation.NO_STRINGS;
177
	}
178
	IPackageFragment pkgFragment= (IPackageFragment) this.packageHandles.get(pkgName);
179
	if (pkgFragment == null) {
180
		pkgFragment= ((PackageFragmentRoot) this.lastPkgFragmentRoot).getPackageFragment(pkgName);
181
		this.packageHandles.put(pkgName, pkgFragment);
182
	}
183
	String simpleName= simpleNames[length];
184
	if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(simpleName)) {
185
		ICompilationUnit unit= pkgFragment.getCompilationUnit(simpleName);
186
		int etnLength = enclosingTypeNames == null ? 0 : enclosingTypeNames.length;
187
		IType type = (etnLength == 0) ? unit.getType(simpleTypeName) : unit.getType(new String(enclosingTypeNames[0]));
188
		if (etnLength > 0) {
189
			for (int i=1; i<etnLength; i++) {
190
				type = type.getType(new String(enclosingTypeNames[i]));
191
			}
192
			type = type.getType(simpleTypeName);
193
		}
194
		return type;
195
	} else {
196
		IClassFile classFile= pkgFragment.getClassFile(simpleName);
197
		return classFile.getType();
198
	}
199
}	
79
}
200
}
(-)search/org/eclipse/jdt/core/search/TypeNameMatch.java (-97 / +63 lines)
Lines 10-150 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.search;
11
package org.eclipse.jdt.core.search;
12
12
13
import org.eclipse.core.resources.IProject;
13
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.core.runtime.Path;
16
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.IJavaProject;
18
import org.eclipse.jdt.core.IPackageFragmentRoot;
14
import org.eclipse.jdt.core.IPackageFragmentRoot;
19
import org.eclipse.jdt.core.IType;
15
import org.eclipse.jdt.core.IType;
20
import org.eclipse.jdt.core.JavaCore;
21
import org.eclipse.jdt.core.JavaModelException;
16
import org.eclipse.jdt.core.JavaModelException;
22
import org.eclipse.jdt.core.compiler.CharOperation;
23
17
24
/**
18
/**
25
 * A match collected while searching for all type names
19
 * A match collected while searching for all type names using
26
 * using {@link SearchEngine#searchAllTypeNames(
20
 * {@link SearchEngine#searchAllTypeNames( char[] packageName, int
27
 *		char[] packageName, 
21
 * packageMatchRule, char[] typeName, int typeMatchRule, int searchFor,
28
 *		int packageMatchRule, 
22
 * IJavaSearchScope scope, TypeNameMatchRequestor nameMatchRequestor, int
29
 *		char[] typeName,
23
 * waitingPolicy, org.eclipse.core.runtime.IProgressMonitor monitor)} method
30
 *		int typeMatchRule, 
24
 * <p>
31
 *		int searchFor, 
25
 * User can get type from this match using {@link #getType()} method.
32
 *		IJavaSearchScope scope, 
26
 * </p>
33
 *		TypeNameMatchRequestor nameMatchRequestor,
34
 *		int waitingPolicy,
35
 * 	org.eclipse.core.runtime.IProgressMonitor monitor)}
36
 * method
37
 * <p>
27
 * <p>
38
 * User can get type from this match using {@link #resolvedType()} method.
39
 * </p><p>
40
 * This class is not intended to be instantiated or subclassed by clients.
28
 * This class is not intended to be instantiated or subclassed by clients.
41
 * </p>
29
 * </p>
30
 * 
42
 * @see TypeNameMatchRequestor
31
 * @see TypeNameMatchRequestor
43
 * 
32
 * 
44
 * @since 3.3
33
 * @since 3.3
45
 */
34
 */
46
public class TypeNameMatch {
35
public class TypeNameMatch {
47
36
48
//private IType type;
37
private IType type;
49
private int modifiers;
38
50
private char[] packageName;
39
private int modifiers = -1; // store modifiers to avoid java model population
51
private char[] simpleTypeName;
52
private char[][] enclosingTypeNames;
53
private String path;
54
//private boolean initialized;
55
40
56
/**
41
/**
57
 * Creates a new type name match.
42
 * Creates a new type name match.
58
 */
43
 */
59
public TypeNameMatch(int modifiers, char[] packageName, char[] typeName, char[][] enclosingTypeNames, String path) {
44
public TypeNameMatch(IType type) {
60
	this.modifiers = modifiers;
45
	this.type = type;
61
	this.packageName = packageName;
62
	this.simpleTypeName = typeName;
63
	this.enclosingTypeNames = enclosingTypeNames;
64
	this.path = path;
65
}
46
}
66
47
67
/**
48
public TypeNameMatch(IType type, int modifiers) {
68
 * Returns the enclosing type names (if any) of the type.
49
	this(type);
69
 * 
50
	this.modifiers = modifiers;
70
 * @return the enclosing type names (if any) of the type
71
 */
72
public final char[][] getEnclosingTypeNames() {
73
	return enclosingTypeNames;
74
}
51
}
75
52
76
/**
53
/**
77
 * Fully qualified name of type (e.g. package name + '.' enclosing type names + '.' simple name)
54
 * Returns the java model type corresponding to fully qualified type name (based
55
 * on package, enclosing types and simple name).
78
 * 
56
 * 
79
 * @return Fully qualified type name of the type
57
 * @return the java model type
58
 * @throws JavaModelException
59
 *             happens when type stored information are not valid
80
 */
60
 */
81
public final char[] getFullyQualifiedName() {
61
public IType getType() throws JavaModelException {
82
	return CharOperation.concat(this.packageName, getTypeContainerName(), '.');
62
	return this.type;
83
}
63
}
84
64
85
/**
65
/*
86
 * Returns the modifiers of the type.
66
 * (non-Javadoc)
87
 * 
67
 * 
88
 * @return the type modifiers
68
 * @see java.lang.Object#toString()
89
 */
69
 */
90
public final int getModifiers() {
70
public String toString() {
91
	return modifiers;
71
	return this.type.toString();
92
}
72
}
93
73
94
/*
74
public IPackageFragmentRoot getPackageFragmentRoot() {
95
 * Specific package fragment root while resolving type
75
	return (IPackageFragmentRoot) this.type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
96
 */
97
protected IPackageFragmentRoot getPackageFragmentRoot() {
98
	return null;
99
}
76
}
100
77
101
/**
78
/**
102
 * Returns the package name of the type.
79
 * Fully qualified name of type (e.g. package name + '.' enclosing type names +
80
 * '.' simple name)
103
 * 
81
 * 
104
 * @return the package name
82
 * @return Fully qualified type name of the type
105
 */
83
 */
106
public final char[] getPackageName() {
84
public String getFullyQualifiedName() {
107
	return packageName;
85
	return this.type.getFullyQualifiedName('.');
108
}
86
}
109
87
110
/**
88
/**
111
 * Returns the full path of the resource.
89
 * Fully qualified name of type (e.g. package name + '.' enclosing type names +
112
 * This path may include the jar file path following by '|' separator
90
 * '.' simple name)
113
 * if the type is a binary included in a jar.
114
 * 
91
 * 
115
 * @return the full path of the resource
92
 * @return Fully qualified type name of the type
116
 */
93
 */
117
public final String getPath() {
94
public String getTypeQualifiedName() {
118
	return path;
95
	return this.type.getTypeQualifiedName('.');
119
}
96
}
120
97
121
/*
98
/**
122
 * Project used to resolve type
99
 * Returns the modifiers of the type.
100
 * 
101
 * @return the type modifiers
123
 */
102
 */
124
protected IProject getProject() {
103
public int getModifiers() {
125
	return ResourcesPlugin.getWorkspace().getRoot().getProject(new Path(this.path).segment(0));
104
	return this.modifiers;
126
}
105
}
127
106
128
/**
107
/**
129
 * Returns the name of the type.
108
 * Returns the package name of the type.
130
 * 
109
 * 
131
 * @return the type name
110
 * @return the package name
132
 */
111
 */
133
public final char[] getSimpleTypeName() {
112
public String getPackageName() {
134
	return simpleTypeName;
113
	return this.type.getPackageFragment().getElementName();
135
}
114
}
136
115
137
/**
116
/**
138
 * Returns the java model type corresponding to fully qualified type name
117
 * Returns the name of the type.
139
 * (based on package, enclosing types and simple name).
140
 * 
118
 * 
141
 * @return the java model type
119
 * @return the type name
142
 * @throws JavaModelException happens when type stored information are not valid
143
 */
120
 */
144
public IType resolvedType() throws JavaModelException {
121
public String getSimpleTypeName() {
145
	IJavaProject javaProject = JavaCore.create(getProject());
122
	return this.type.getElementName();
146
	if (javaProject == null) return null; // cannot initialize without a project
147
	return javaProject.findType(new String(packageName), new String(getTypeContainerName()), getPackageFragmentRoot(), getWorkingCopies(), null);
148
}
123
}
149
124
150
/**
125
/**
Lines 152-172 Link Here
152
 * 
127
 * 
153
 * @return Name of the type container
128
 * @return Name of the type container
154
 */
129
 */
155
public final char[] getTypeContainerName() {
130
public String getTypeContainerName() {
156
	return this.enclosingTypeNames == null ? this.simpleTypeName : CharOperation.concatWith(this.enclosingTypeNames, this.simpleTypeName, '.');
131
	IType outerType = this.type.getDeclaringType();
157
}
132
	if (outerType != null) {
158
133
		return outerType.getFullyQualifiedName('.');
159
/*
134
	} else {
160
 * Working copies to look in while resolving type
135
		return this.type.getPackageFragment().getElementName();
161
 */
136
	}
162
protected ICompilationUnit[] getWorkingCopies() {
163
	return null;
164
}
165
166
/* (non-Javadoc)
167
 * @see java.lang.Object#toString()
168
 */
169
public String toString() {
170
	return new String(getFullyQualifiedName());
171
}
137
}
172
}
138
}
(-)search/org/eclipse/jdt/core/search/SearchEngine.java (-1 / +1 lines)
Lines 765-771 Link Here
765
		int waitingPolicy,
765
		int waitingPolicy,
766
		IProgressMonitor progressMonitor)  throws JavaModelException {
766
		IProgressMonitor progressMonitor)  throws JavaModelException {
767
		
767
		
768
		TypeNameMatchRequestorWrapper requestorWrapper = new TypeNameMatchRequestorWrapper(nameMatchRequestor, scope, this.basicEngine.getWorkingCopies());
768
		TypeNameMatchRequestorWrapper requestorWrapper = new TypeNameMatchRequestorWrapper(nameMatchRequestor, scope);
769
		this.basicEngine.searchAllTypeNames(packageName, packageMatchRule, typeName, typeMatchRule, searchFor, scope, requestorWrapper, waitingPolicy, progressMonitor);
769
		this.basicEngine.searchAllTypeNames(packageName, packageMatchRule, typeName, typeMatchRule, searchFor, scope, requestorWrapper, waitingPolicy, progressMonitor);
770
	}
770
	}
771
771
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-24 / +7 lines)
Lines 1218-1232 Link Here
1218
	/*
1218
	/*
1219
	 * Internal findType with instanciated name lookup
1219
	 * Internal findType with instanciated name lookup
1220
	 */
1220
	 */
1221
	IType findType(String packageName, String typeQualifiedName, IPackageFragmentRoot root, NameLookup lookup, boolean considerSecondaryTypes, IProgressMonitor progressMonitor) throws JavaModelException {
1221
	IType findType(String packageName, String typeQualifiedName, NameLookup lookup, boolean considerSecondaryTypes, IProgressMonitor progressMonitor) throws JavaModelException {
1222
		NameLookup.Answer answer = lookup.findType(
1222
		NameLookup.Answer answer = lookup.findType(
1223
			typeQualifiedName, 
1223
			typeQualifiedName, 
1224
			packageName,
1224
			packageName,
1225
			root,
1226
			false,
1225
			false,
1227
			NameLookup.ACCEPT_ALL,
1226
			NameLookup.ACCEPT_ALL,
1228
			considerSecondaryTypes, // wait for indexes (in case we need to consider secondary types)
1227
			considerSecondaryTypes,
1229
			true,
1228
			true, // wait for indexes (in case we need to consider secondary types)
1230
			false/*don't check restrictions*/,
1229
			false/*don't check restrictions*/,
1231
			progressMonitor);
1230
			progressMonitor);
1232
		return answer == null ? null : answer.type;
1231
		return answer == null ? null : answer.type;
Lines 1239-1247 Link Here
1239
		return findType(
1238
		return findType(
1240
			packageName,
1239
			packageName,
1241
			typeQualifiedName, 
1240
			typeQualifiedName, 
1242
			null,
1241
			lookup,
1243
			lookup, // do not consider secondary types
1242
			false, // do not consider secondary types
1244
			false,
1245
			null);
1243
			null);
1246
	}	
1244
	}	
1247
	
1245
	
Lines 1253-1275 Link Here
1253
		return findType(
1251
		return findType(
1254
			packageName,
1252
			packageName,
1255
			typeQualifiedName, 
1253
			typeQualifiedName, 
1256
			null,
1254
			lookup,
1257
			lookup, // consider secondary types
1255
			true, // consider secondary types
1258
			true,
1259
			progressMonitor);
1260
	}
1261
	
1262
	/**
1263
	 * @see IJavaProject#findType(String, String, IPackageFragmentRoot, ICompilationUnit[], IProgressMonitor)
1264
	 */
1265
	public IType findType(String packageName, String typeQualifiedName, IPackageFragmentRoot root, ICompilationUnit[] workingCopies, IProgressMonitor progressMonitor) throws JavaModelException {
1266
		NameLookup lookup = newNameLookup(workingCopies);
1267
		return findType(
1268
			packageName,
1269
			typeQualifiedName,
1270
			root,
1271
			lookup, // consider secondary types
1272
			true,
1273
			progressMonitor);
1256
			progressMonitor);
1274
	}
1257
	}
1275
1258
(-)model/org/eclipse/jdt/internal/core/NameLookup.java (-8 / +2 lines)
Lines 571-577 Link Here
571
	public Answer findType(String typeName, String packageName, boolean partialMatch, int acceptFlags, boolean checkRestrictions) {
571
	public Answer findType(String typeName, String packageName, boolean partialMatch, int acceptFlags, boolean checkRestrictions) {
572
		return findType(typeName,
572
		return findType(typeName,
573
			packageName,
573
			packageName,
574
			null,
575
			partialMatch,
574
			partialMatch,
576
			acceptFlags,
575
			acceptFlags,
577
			true/* consider secondary types */,
576
			true/* consider secondary types */,
Lines 586-596 Link Here
586
	public Answer findType(
585
	public Answer findType(
587
			String typeName, 
586
			String typeName, 
588
			String packageName, 
587
			String packageName, 
589
			IPackageFragmentRoot root, 
590
			boolean partialMatch, 
588
			boolean partialMatch, 
591
			int acceptFlags, 
589
			int acceptFlags, 
592
			boolean considerSecondaryTypes, 
590
			boolean considerSecondaryTypes, 
593
			boolean waitForIndexes,
591
			boolean waitForIndexes, 
594
			boolean checkRestrictions,
592
			boolean checkRestrictions,
595
			IProgressMonitor monitor) {
593
			IProgressMonitor monitor) {
596
		if (packageName == null || packageName.length() == 0) {
594
		if (packageName == null || packageName.length() == 0) {
Lines 612-621 Link Here
612
		IJavaProject javaProject = null;
610
		IJavaProject javaProject = null;
613
		Answer suggestedAnswer = null;
611
		Answer suggestedAnswer = null;
614
		for (int i= 0; i < length; i++) {
612
		for (int i= 0; i < length; i++) {
615
			if (root != null && !packages[i].getParent().equals(root)) {
616
				// filter package which are not in same root
617
				continue;
618
			}
619
			type = findType(typeName, packages[i], partialMatch, acceptFlags);
613
			type = findType(typeName, packages[i], partialMatch, acceptFlags);
620
			if (type != null) {
614
			if (type != null) {
621
				AccessRestriction accessRestriction = null;
615
				AccessRestriction accessRestriction = null;
Lines 770-776 Link Here
770
			packageName= name.substring(0, index);
764
			packageName= name.substring(0, index);
771
			className= name.substring(index + 1);
765
			className= name.substring(index + 1);
772
		}
766
		}
773
		return findType(className, packageName, null, partialMatch, acceptFlags, considerSecondaryTypes, waitForIndexes, checkRestrictions, monitor);
767
		return findType(className, packageName, partialMatch, acceptFlags, considerSecondaryTypes, waitForIndexes, checkRestrictions, monitor);
774
	}
768
	}
775
769
776
	private IType getMemberType(IType type, String name, int dot) {
770
	private IType getMemberType(IType type, String name, int dot) {
(-)model/org/eclipse/jdt/core/IJavaProject.java (-28 lines)
Lines 344-377 Link Here
344
	 * @since 3.2
344
	 * @since 3.2
345
	 */
345
	 */
346
	IType findType(String packageName, String typeQualifiedName, WorkingCopyOwner owner, IProgressMonitor progressMonitor) throws JavaModelException;
346
	IType findType(String packageName, String typeQualifiedName, WorkingCopyOwner owner, IProgressMonitor progressMonitor) throws JavaModelException;
347
	/**
348
	 * Returns the first type found following this project's classpath 
349
	 * with the given package name and type qualified name
350
	 * or <code>null</code> if none is found.
351
	 * The package name is a dot-separated name.
352
	 * The type qualified name is also a dot-separated name. For example,
353
	 * a class B defined as a member type of a class A should have the 
354
	 * type qualified name "A.B".
355
	 * The returned type may be a part of one of the given compilation units.
356
	 * If a package fragment root is specified, then the returned type, if any,
357
	 * will belong to a package fragment which parent is the given package fragment root.
358
	 * 
359
	 * @param packageName the given package name
360
	 * @param typeQualifiedName the given type qualified name
361
	 * @param root Package fragment root which must include the search type.
362
	 * 	May be <code>null</code>.
363
	 * @param units Compilation units returned may be a part of.
364
	 * 	May be <code>null</code>.
365
	 * @param progressMonitor the progress monitor to report progress to,
366
	 * 	or <code>null</code> if no progress monitor is provided
367
	 * @exception JavaModelException if this project does not exist or if an
368
	 *		exception occurs while accessing its corresponding resource
369
	 * @return the first type found following this project's classpath 
370
	 * with the given fully qualified name or <code>null</code> if none is found
371
	 * @see IType#getFullyQualifiedName(char)
372
	 * @since 3.3
373
	 */
374
	IType findType(String packageName, String typeQualifiedName, IPackageFragmentRoot root, ICompilationUnit[] units, IProgressMonitor progressMonitor) throws JavaModelException;
375
	
347
	
376
	/**
348
	/**
377
	 * Returns all of the existing package fragment roots that exist
349
	 * Returns all of the existing package fragment roots that exist
(-)model/org/eclipse/jdt/core/JavaCore.java (-25 / +28 lines)
Lines 1322-1352 Link Here
1322
		return JavaModelManager.create(file, null/*unknown java project*/);
1322
		return JavaModelManager.create(file, null/*unknown java project*/);
1323
	}
1323
	}
1324
	/**
1324
	/**
1325
	 * Returns the Java element corresponding to the given file, its project being the given
1326
	 * project.
1327
	 * Returns <code>null</code> if unable to associate the given file
1328
	 * with a Java element.
1329
	 *
1330
	 * <p>The file must be one of:<ul>
1331
	 *	<li>a file with one of the {@link JavaCore#getJavaLikeExtensions() 
1332
	 *      Java-like extensions} - the element returned is the corresponding <code>ICompilationUnit</code></li>
1333
	 *	<li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
1334
	 *	<li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
1335
	 *	</ul>
1336
	 * <p>
1337
	 * Creating a Java element has the side effect of creating and opening all of the
1338
	 * element's parents if they are not yet open.
1339
	 * 
1340
	 * @param file the given file
1341
	 * @return the Java element corresponding to the given file, or
1342
	 * <code>null</code> if unable to associate the given file
1343
	 * with a Java element
1344
	 * @since 3.3
1345
	 */
1346
	public static IJavaElement create(IFile file, IJavaProject project) {
1347
		return JavaModelManager.create(file, project);
1348
	}
1349
	/**
1350
	 * Returns the package fragment or package fragment root corresponding to the given folder, or
1325
	 * Returns the package fragment or package fragment root corresponding to the given folder, or
1351
	 * <code>null</code> if unable to associate the given folder with a Java element.
1326
	 * <code>null</code> if unable to associate the given folder with a Java element.
1352
	 * <p>
1327
	 * <p>
Lines 1408-1413 Link Here
1408
		return JavaModelManager.create(resource, null/*unknown java project*/);
1383
		return JavaModelManager.create(resource, null/*unknown java project*/);
1409
	}
1384
	}
1410
	/**
1385
	/**
1386
	 * Returns the Java element corresponding to the given file, its project being the given
1387
	 * project. Returns <code>null</code> if unable to associate the given resource
1388
	 * with a Java element.
1389
	 *<p>
1390
	 * The resource must be one of:<ul>
1391
	 *	<li>a project - the element returned is the corresponding <code>IJavaProject</code></li>
1392
	 *	<li>a file with one of the {@link JavaCore#getJavaLikeExtensions() 
1393
	 *      Java-like extensions} - the element returned is the corresponding <code>ICompilationUnit</code></li>
1394
	 *	<li>a <code>.class</code> file - the element returned is the corresponding <code>IClassFile</code></li>
1395
	 *	<li>a <code>.jar</code> file - the element returned is the corresponding <code>IPackageFragmentRoot</code></li>
1396
	 *  <li>a folder - the element returned is the corresponding <code>IPackageFragmentRoot</code>
1397
	 *    	or <code>IPackageFragment</code></li>
1398
	 *  <li>the workspace root resource - the element returned is the <code>IJavaModel</code></li>
1399
	 *	</ul>
1400
	 * <p>
1401
	 * Creating a Java element has the side effect of creating and opening all of the
1402
	 * element's parents if they are not yet open.
1403
	 * 
1404
	 * @param resource the given resource
1405
	 * @return the Java element corresponding to the given file, or
1406
	 * <code>null</code> if unable to associate the given file
1407
	 * with a Java element
1408
	 * @since 3.3
1409
	 */
1410
	public static IJavaElement create(IResource resource, IJavaProject project) {
1411
		return JavaModelManager.create(resource, project);
1412
	}
1413
	/**
1411
	 * Returns the Java model.
1414
	 * Returns the Java model.
1412
	 * 
1415
	 * 
1413
	 * @param root the given root
1416
	 * @param root the given root
(-)buildnotes_jdt-core.html (-38 / +13 lines)
Lines 52-57 Link Here
52
<h2>What's new in this drop</h2>
52
<h2>What's new in this drop</h2>
53
<ul>
53
<ul>
54
<li>Raw type reference are now reported by default. See bug <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=159456">159456</a>.</li>
54
<li>Raw type reference are now reported by default. See bug <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=159456">159456</a>.</li>
55
<li>API of <code>TypeNameMatch</code> has been changed to improve memory consumption performance.
56
It now creates IType handle while accepting the type information from indexes and stores their modifiers
57
to avoid java element opening while getting this piece of information.<br>
58
Note that there's no Java Model initialization nor populating while creating handles...<br>
59
Note also that previously added API method on IJavaProject has been removed:
60
<pre>
61
IType findType(String packageName,
62
	String typeQualifiedName,
63
	IPackageFragmentRoot root,
64
	ICompilationUnit[] units,
65
	IProgressMonitor progressMonitor) throws JavaModelException;
66
</pre>
67
</li>
55
</ul>
68
</ul>
56
69
57
<h3>Problem Reports Fixed</h3>
70
<h3>Problem Reports Fixed</h3>
Lines 138-181 Link Here
138
This should avoid to have too many similar <code>searchAllTypeNames</code> available methods...
151
This should avoid to have too many similar <code>searchAllTypeNames</code> available methods...
139
</li>
152
</li>
140
<li>
153
<li>
141
Added new <code>IJavaProject</code> API method to let clients finding types in a project with additional working copies
142
and in a specific package fragment root:
143
<pre>
144
/**
145
 * Returns the first type found following this project's classpath 
146
 * with the given package name and type qualified name
147
 * or <code>null</code> if none is found.
148
 * The package name is a dot-separated name.
149
 * The type qualified name is also a dot-separated name. For example,
150
 * a class B defined as a member type of a class A should have the 
151
 * type qualified name "A.B".
152
 * The returned type may be a part of one of the given compilation units.
153
 * If a package fragment root is specified, then the returned type, if any,
154
 * will belong to a package fragment which parent is the given package fragment root.
155
 * 
156
 * @param packageName the given package name
157
 * @param typeQualifiedName the given type qualified name
158
 * @param root Package fragment root which must include the search type.
159
 * 	May be <code>null</code>.
160
 * @param units Compilation units returned may be a part of.
161
 * 	May be <code>null</code>.
162
 * @param progressMonitor the progress monitor to report progress to,
163
 * 	or <code>null</code> if no progress monitor is provided
164
 * @exception JavaModelException if this project does not exist or if an
165
 *		exception occurs while accessing its corresponding resource
166
 * @return the first type found following this project's classpath 
167
 * with the given fully qualified name or <code>null</code> if none is found
168
 * @see IType#getFullyQualifiedName(char)
169
 * @since 3.3
170
 */
171
IType findType(String packageName,
172
	String typeQualifiedName,
173
	IPackageFragmentRoot root,
174
	ICompilationUnit[] units,
175
	IProgressMonitor progressMonitor) throws JavaModelException;
176
</pre>
177
</li>
178
<li>
179
Added new <code>JavaCore</code> API method to create a java element from an <code>IFile</code>
154
Added new <code>JavaCore</code> API method to create a java element from an <code>IFile</code>
180
using a specific project:
155
using a specific project:
181
<pre>
156
<pre>

Return to bug 148380