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

Collapse All | Expand All

(-)search/org/eclipse/jdt/core/search/SearchEngine.java (-2 / +86 lines)
Lines 588-593 Link Here
588
	 *		<li>the classpath is incorrectly set</li>
588
	 *		<li>the classpath is incorrectly set</li>
589
	 *	</ul>
589
	 *	</ul>
590
	 * @since 3.1
590
	 * @since 3.1
591
	 * @deprecated Use {@link #searchAllTypeNames(char[], int, char[], int, int, IJavaSearchScope, TypeNameRequestor, int, IProgressMonitor)}
592
	 * 	instead
591
	 */
593
	 */
592
	public void searchAllTypeNames(
594
	public void searchAllTypeNames(
593
		final char[] packageExactName, 
595
		final char[] packageExactName, 
Lines 599-606 Link Here
599
		int waitingPolicy,
601
		int waitingPolicy,
600
		IProgressMonitor progressMonitor)  throws JavaModelException {
602
		IProgressMonitor progressMonitor)  throws JavaModelException {
601
		
603
		
602
		TypeNameRequestorWrapper requestorWrapper = new TypeNameRequestorWrapper(nameRequestor);
604
		searchAllTypeNames(packageExactName, SearchPattern.R_EXACT_MATCH, typeName, matchRule, searchFor, scope, nameRequestor, waitingPolicy, progressMonitor);
603
		this.basicEngine.searchAllTypeNames(packageExactName, SearchPattern.R_EXACT_MATCH, typeName, matchRule, searchFor, scope, requestorWrapper, waitingPolicy, progressMonitor);
604
	}
605
	}
605
606
606
	/**
607
	/**
Lines 681-686 Link Here
681
	}
682
	}
682
683
683
	/**
684
	/**
685
	 * Searches for all top-level types and member types in the given scope.
686
	 * The search can be selecting specific types (given a package name using specific match mode
687
	 * and/or a type name using another specific match mode).
688
	 * <p>
689
	 * SearchRequestor needs to be provided to this method. It will accept a specific search match
690
	 * ({@link TypeDeclarationNameMatch}) which may compute model operation as resolving the type.
691
	 * Note that this operation should be used carefully as it will consume more memory than
692
	 * <code>searchAllTypeNames</code> with {@link TypeNameRequestor} (a match for each type
693
	 * found will be created).
694
	 * 
695
	 * @param packageName the full name of the package of the searched types, or a prefix for this
696
	 *						package, or a wild-carded string for this package.
697
	 * @param typeName the dot-separated qualified name of the searched type (the qualification include
698
	 *					the enclosing types if the searched type is a member type), or a prefix
699
	 *					for this type, or a wild-carded string for this type.
700
	 * @param packageMatchRule one of
701
	 * <ul>
702
	 *		<li>{@link SearchPattern#R_EXACT_MATCH} if the package name and type name are the full names
703
	 *			of the searched types.</li>
704
	 *		<li>{@link SearchPattern#R_PREFIX_MATCH} if the package name and type name are prefixes of the names
705
	 *			of the searched types.</li>
706
	 *		<li>{@link SearchPattern#R_PATTERN_MATCH} if the package name and type name contain wild-cards.</li>
707
	 *		<li>{@link SearchPattern#R_CAMELCASE_MATCH} if type name are camel case of the names of the searched types.</li>
708
	 * </ul>
709
	 * combined with {@link SearchPattern#R_CASE_SENSITIVE},
710
	 *   e.g. {@link SearchPattern#R_EXACT_MATCH} | {@link SearchPattern#R_CASE_SENSITIVE} if an exact and case sensitive match is requested, 
711
	 *   or {@link SearchPattern#R_PREFIX_MATCH} if a prefix non case sensitive match is requested.
712
	 * @param typeMatchRule one of
713
	 * <ul>
714
	 *		<li>{@link SearchPattern#R_EXACT_MATCH} if the package name and type name are the full names
715
	 *			of the searched types.</li>
716
	 *		<li>{@link SearchPattern#R_PREFIX_MATCH} if the package name and type name are prefixes of the names
717
	 *			of the searched types.</li>
718
	 *		<li>{@link SearchPattern#R_PATTERN_MATCH} if the package name and type name contain wild-cards.</li>
719
	 *		<li>{@link SearchPattern#R_CAMELCASE_MATCH} if type name are camel case of the names of the searched types.</li>
720
	 * </ul>
721
	 * combined with {@link SearchPattern#R_CASE_SENSITIVE},
722
	 *   e.g. {@link SearchPattern#R_EXACT_MATCH} | {@link SearchPattern#R_CASE_SENSITIVE} if an exact and case sensitive match is requested, 
723
	 *   or {@link SearchPattern#R_PREFIX_MATCH} if a prefix non case sensitive match is requested.
724
	 * @param searchFor determines the nature of the searched elements
725
	 *	<ul>
726
	 * 	<li>{@link IJavaSearchConstants#CLASS}: only look for classes</li>
727
	 *		<li>{@link IJavaSearchConstants#INTERFACE}: only look for interfaces</li>
728
	 * 	<li>{@link IJavaSearchConstants#ENUM}: only look for enumeration</li>
729
	 *		<li>{@link IJavaSearchConstants#ANNOTATION_TYPE}: only look for annotation type</li>
730
	 * 	<li>{@link IJavaSearchConstants#CLASS_AND_ENUM}: only look for classes and enumerations</li>
731
	 *		<li>{@link IJavaSearchConstants#CLASS_AND_INTERFACE}: only look for classes and interfaces</li>
732
	 * 	<li>{@link IJavaSearchConstants#TYPE}: look for all types (ie. classes, interfaces, enum and annotation types)</li>
733
	 *	</ul>
734
	 * @param scope the scope to search in
735
	 * @param searchNameRequestor the search requestor that collects all the matches found during the search
736
	 * @param waitingPolicy one of
737
	 * <ul>
738
	 *		<li>{@link IJavaSearchConstants#FORCE_IMMEDIATE_SEARCH} if the search should start immediately</li>
739
	 *		<li>{@link IJavaSearchConstants#CANCEL_IF_NOT_READY_TO_SEARCH} if the search should be cancelled if the
740
	 *			underlying indexer has not finished indexing the workspace</li>
741
	 *		<li>{@link IJavaSearchConstants#WAIT_UNTIL_READY_TO_SEARCH} if the search should wait for the
742
	 *			underlying indexer to finish indexing the workspace</li>
743
	 * </ul>
744
	 * @param progressMonitor the progress monitor to report progress to, or <code>null</code> if no progress
745
	 *							monitor is provided
746
	 * @exception JavaModelException if the search failed. Reasons include:
747
	 *	<ul>
748
	 *		<li>the classpath is incorrectly set</li>
749
	 *	</ul>
750
	 * @since 3.3
751
	 */
752
	public void searchAllTypeNames(
753
		final char[] packageName, 
754
		final int packageMatchRule, 
755
		final char[] typeName,
756
		final int typeMatchRule, 
757
		int searchFor, 
758
		IJavaSearchScope scope, 
759
		final SearchRequestor searchNameRequestor,
760
		int waitingPolicy,
761
		IProgressMonitor progressMonitor)  throws JavaModelException {
762
		
763
		TypeNameSearchRequestor requestorWrapper = new TypeNameSearchRequestor(searchNameRequestor, scope);
764
		this.basicEngine.searchAllTypeNames(packageName, packageMatchRule, typeName, typeMatchRule, searchFor, scope, requestorWrapper, waitingPolicy, progressMonitor);
765
	}
766
767
	/**
684
	 * Searches for all top-level types and member types in the given scope matching any of the given qualifications
768
	 * Searches for all top-level types and member types in the given scope matching any of the given qualifications
685
	 * and type names in a case sensitive way.
769
	 * and type names in a case sensitive way.
686
	 * 
770
	 * 
(-)search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java (-1 / +1 lines)
Lines 625-631 Link Here
625
	 * The search can be selecting specific types (given a package or a type name
625
	 * The search can be selecting specific types (given a package or a type name
626
	 * prefix and match modes). 
626
	 * prefix and match modes). 
627
	 * 
627
	 * 
628
	 * @see SearchEngine#searchAllTypeNames(char[], char[], int, int, IJavaSearchScope, TypeNameRequestor, int, IProgressMonitor)
628
	 * @see SearchEngine#searchAllTypeNames(char[], int, char[], int, int, IJavaSearchScope, TypeNameRequestor, int, IProgressMonitor)
629
	 * 	for detailed comment
629
	 * 	for detailed comment
630
	 */
630
	 */
631
	public void searchAllTypeNames(
631
	public void searchAllTypeNames(
(-)search/org/eclipse/jdt/internal/core/search/TypeNameRequestorWrapper.java (+1 lines)
Lines 27-32 Link Here
27
 * 	org.eclipse.core.runtime.IProgressMonitor monitor) }.
27
 * 	org.eclipse.core.runtime.IProgressMonitor monitor) }.
28
 * from  API method {@link org.eclipse.jdt.core.search.SearchEngine#searchAllTypeNames(
28
 * from  API method {@link org.eclipse.jdt.core.search.SearchEngine#searchAllTypeNames(
29
 * 	char[] packageName, 
29
 * 	char[] packageName, 
30
 * 	int packageMatchRule,
30
 * 	char[] typeName,
31
 * 	char[] typeName,
31
 * 	int matchRule, 
32
 * 	int matchRule, 
32
 * 	int searchFor, 
33
 * 	int searchFor, 
(-)search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java (-10 / +46 lines)
Lines 33-38 Link Here
33
	/* The paths of the resources in this search scope 
33
	/* The paths of the resources in this search scope 
34
	    (or the classpath entries' paths if the resources are projects) 
34
	    (or the classpath entries' paths if the resources are projects) 
35
	*/
35
	*/
36
	private String[] projectPaths; // projects in which some container paths (typically class folders) may be enclosed (e.g. /P)
36
	private String[] containerPaths; // path to the container (e.g. /P/src, /P/lib.jar, c:\temp\mylib.jar)
37
	private String[] containerPaths; // path to the container (e.g. /P/src, /P/lib.jar, c:\temp\mylib.jar)
37
	private String[] relativePaths; // path relative to the container (e.g. x/y/Z.class, x/y, (empty))
38
	private String[] relativePaths; // path relative to the container (e.g. x/y/Z.class, x/y, (empty))
38
	private boolean[] isPkgPath; // in the case of packages, matches must be direct children of the folder
39
	private boolean[] isPkgPath; // in the case of packages, matches must be direct children of the folder
Lines 124-130 Link Here
124
							IPath path = entry.getPath();
125
							IPath path = entry.getPath();
125
							if (pathToAdd == null || pathToAdd.equals(path)) {
126
							if (pathToAdd == null || pathToAdd.equals(path)) {
126
								String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
127
								String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
127
								add("", pathToString, false/*not a package*/, access); //$NON-NLS-1$
128
								add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
128
								addEnclosingProjectOrJar(path);
129
								addEnclosingProjectOrJar(path);
129
							}
130
							}
130
						}
131
						}
Lines 137-143 Link Here
137
							IPath path = entry.getPath();
138
							IPath path = entry.getPath();
138
							if (pathToAdd == null || pathToAdd.equals(path)) {
139
							if (pathToAdd == null || pathToAdd.equals(path)) {
139
								String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
140
								String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
140
								add("", pathToString, false/*not a package*/, access); //$NON-NLS-1$
141
								add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
141
								addEnclosingProjectOrJar(path);
142
								addEnclosingProjectOrJar(path);
142
							}
143
							}
143
						}
144
						}
Lines 156-162 Link Here
156
				if ((includeMask & SOURCES) != 0) {
157
				if ((includeMask & SOURCES) != 0) {
157
					IPath path = entry.getPath();
158
					IPath path = entry.getPath();
158
					if (pathToAdd == null || pathToAdd.equals(path)) {
159
					if (pathToAdd == null || pathToAdd.equals(path)) {
159
						add(Util.relativePath(path,1/*remove project segment*/), projectPathString, false/*not a package*/, access);
160
						add(projectPath.toString(), Util.relativePath(path,1/*remove project segment*/), projectPathString, false/*not a package*/, access);
160
					}
161
					}
161
				}
162
				}
162
				break;
163
				break;
Lines 185-204 Link Here
185
			containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
186
			containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
186
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
187
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
187
			IResource rootResource = root.getResource();
188
			IResource rootResource = root.getResource();
189
			String projectPath = root.getJavaProject().getPath().toString();
188
			if (rootResource != null && rootResource.isAccessible()) {
190
			if (rootResource != null && rootResource.isAccessible()) {
189
				String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
191
				String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
190
				add(relativePath, containerPathToString, false/*not a package*/, null);
192
				add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
191
			} else {
193
			} else {
192
				add("", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$
194
				add(projectPath, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$
193
			}
195
			}
194
			break;
196
			break;
195
		case IJavaElement.PACKAGE_FRAGMENT:
197
		case IJavaElement.PACKAGE_FRAGMENT:
196
			root = (IPackageFragmentRoot)element.getParent();
198
			root = (IPackageFragmentRoot)element.getParent();
199
			projectPath = root.getJavaProject().getPath().toString();
197
			if (root.isArchive()) {
200
			if (root.isArchive()) {
198
				String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
201
				String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
199
				containerPath = root.getPath();
202
				containerPath = root.getPath();
200
				containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
203
				containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
201
				add(relativePath, containerPathToString, true/*package*/, null);
204
				add(projectPath, relativePath, containerPathToString, true/*package*/, null);
202
			} else {
205
			} else {
203
				IResource resource = element.getResource();
206
				IResource resource = element.getResource();
204
				if (resource != null) {
207
				if (resource != null) {
Lines 210-216 Link Here
210
					}
213
					}
211
					containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
214
					containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
212
					String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount());
215
					String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount());
213
					add(relativePath, containerPathToString, true/*package*/, null);
216
					add(projectPath, relativePath, containerPathToString, true/*package*/, null);
214
				}
217
				}
215
			}
218
			}
216
			break;
219
			break;
Lines 223-228 Link Here
223
				this.elements.add(element);
226
				this.elements.add(element);
224
			}
227
			}
225
			root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
228
			root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
229
			projectPath = root.getJavaProject().getPath().toString();
226
			String relativePath;
230
			String relativePath;
227
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
231
			if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
228
				containerPath = root.getParent().getPath();
232
				containerPath = root.getParent().getPath();
Lines 232-238 Link Here
232
				relativePath = getPath(element, true/*relative path*/).toString();
236
				relativePath = getPath(element, true/*relative path*/).toString();
233
			}
237
			}
234
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
238
			containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
235
			add(relativePath, containerPathToString, false/*not a package*/, null);
239
			add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
236
	}
240
	}
237
	
241
	
238
	if (containerPath != null)
242
	if (containerPath != null)
Lines 243-249 Link Here
243
 * Adds the given path to this search scope. Remember if subfolders need to be included
247
 * Adds the given path to this search scope. Remember if subfolders need to be included
244
 * and associated access restriction as well.
248
 * and associated access restriction as well.
245
 */
249
 */
246
private void add(String relativePath, String containerPath, boolean isPackage, AccessRuleSet access) {
250
private void add(String projectPath, String relativePath, String containerPath, boolean isPackage, AccessRuleSet access) {
247
	// normalize containerPath and relativePath
251
	// normalize containerPath and relativePath
248
	containerPath = normalize(containerPath);
252
	containerPath = normalize(containerPath);
249
	relativePath = normalize(relativePath);
253
	relativePath = normalize(relativePath);
Lines 257-262 Link Here
257
			index = 0;
261
			index = 0;
258
		}
262
		}
259
	}
263
	}
264
	this.projectPaths[index] = projectPath;
260
	this.relativePaths[index] = relativePath;
265
	this.relativePaths[index] = relativePath;
261
	this.containerPaths[index] = containerPath;
266
	this.containerPaths[index] = containerPath;
262
	this.isPkgPath[index] = isPackage;
267
	this.isPkgPath[index] = isPackage;
Lines 464-469 Link Here
464
		extraRoom++;
469
		extraRoom++;
465
	this.relativePaths = new String[extraRoom];
470
	this.relativePaths = new String[extraRoom];
466
	this.containerPaths = new String[extraRoom];
471
	this.containerPaths = new String[extraRoom];
472
	this.projectPaths = new String[extraRoom];
467
	this.isPkgPath = new boolean[extraRoom];
473
	this.isPkgPath = new boolean[extraRoom];
468
	this.pathRestrictions = null; // null to optimize case where no access rules are used
474
	this.pathRestrictions = null; // null to optimize case where no access rules are used
469
475
Lines 526-540 Link Here
526
	}
532
	}
527
}
533
}
528
534
535
/**
536
 * Returns the project path corresponding to a given resource path.
537
 * 
538
 * @param resourcePathString path of the resource
539
 * @return the project path of the resource
540
 */
541
public String projectPathFor(String resourcePathString) {
542
	int index = -1;
543
	int separatorIndex = resourcePathString.indexOf(JAR_FILE_ENTRY_SEPARATOR);
544
	if (separatorIndex != -1) {
545
		// internal or external jar (case 3, 4, or 5)
546
		String jarPath = resourcePathString.substring(0, separatorIndex);
547
		String relativePath = resourcePathString.substring(separatorIndex+1);
548
		index = indexOf(jarPath, relativePath);
549
	} else {
550
		// resource in workspace (case 1 or 2)
551
		index = indexOf(resourcePathString);
552
	}
553
	if (index >= 0) {
554
		String path = this.projectPaths[index];
555
		if (path != null) return path;
556
		path = this.containerPaths[index];
557
		int sep = path.indexOf('/', 1); // first char is a '/'
558
		if (sep < 0) return path;
559
		return path.substring(0, sep);
560
	}
561
	return null;
562
}
563
529
private void rehash() {
564
private void rehash() {
530
	JavaSearchScope newScope = new JavaSearchScope(this.pathsCount * 2);		// double the number of expected elements
565
	JavaSearchScope newScope = new JavaSearchScope(this.pathsCount * 2);		// double the number of expected elements
531
	String currentPath;
566
	String currentPath;
532
	for (int i = this.relativePaths.length; --i >= 0;)
567
	for (int i = this.relativePaths.length; --i >= 0;)
533
		if ((currentPath = this.relativePaths[i]) != null)
568
		if ((currentPath = this.relativePaths[i]) != null)
534
			newScope.add(currentPath, this.containerPaths[i], this.isPkgPath[i], this.pathRestrictions == null ? null : this.pathRestrictions[i]);
569
			newScope.add(this.projectPaths[i], currentPath, this.containerPaths[i], this.isPkgPath[i], this.pathRestrictions == null ? null : this.pathRestrictions[i]);
535
570
536
	this.relativePaths = newScope.relativePaths;
571
	this.relativePaths = newScope.relativePaths;
537
	this.containerPaths = newScope.containerPaths;
572
	this.containerPaths = newScope.containerPaths;
573
	this.projectPaths = newScope.projectPaths;
538
	this.isPkgPath = newScope.isPkgPath;
574
	this.isPkgPath = newScope.isPkgPath;
539
	this.pathRestrictions = newScope.pathRestrictions;
575
	this.pathRestrictions = newScope.pathRestrictions;
540
	this.threshold = newScope.threshold;
576
	this.threshold = newScope.threshold;
(-)model/org/eclipse/jdt/core/JavaCore.java (+26 lines)
Lines 1322-1327 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
	/**
1325
	 * Returns the package fragment or package fragment root corresponding to the given folder, or
1350
	 * Returns the package fragment or package fragment root corresponding to the given folder, or
1326
	 * <code>null</code> if unable to associate the given folder with a Java element.
1351
	 * <code>null</code> if unable to associate the given folder with a Java element.
1327
	 * <p>
1352
	 * <p>
Lines 2857-2862 Link Here
2857
			try {
2882
			try {
2858
				engine.searchAllTypeNames(
2883
				engine.searchAllTypeNames(
2859
					null,
2884
					null,
2885
					SearchPattern.R_EXACT_MATCH,
2860
					"!@$#!@".toCharArray(), //$NON-NLS-1$
2886
					"!@$#!@".toCharArray(), //$NON-NLS-1$
2861
					SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE,
2887
					SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE,
2862
					IJavaSearchConstants.CLASS,
2888
					IJavaSearchConstants.CLASS,
(-)search/org/eclipse/jdt/core/search/TypeDeclarationNameMatch.java (+151 lines)
Added 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.core.search;
12
13
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IWorkspaceRoot;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.jdt.core.IJavaProject;
18
import org.eclipse.jdt.core.IType;
19
import org.eclipse.jdt.core.JavaCore;
20
import org.eclipse.jdt.core.JavaModelException;
21
import org.eclipse.jdt.core.compiler.CharOperation;
22
23
/**
24
 * A Java search match that represents a type declaration name
25
 * found in index files.
26
 * The element is an <code>IType</code> only initialized when
27
 * requested by clients.
28
 * <p>
29
 * This class is intended to be instantiated and subclassed by clients.
30
 * </p>
31
 * 
32
 * @since 3.3
33
 */
34
public class TypeDeclarationNameMatch extends SearchMatch {
35
36
private int modifiers;
37
private char[] packageName;
38
private char[] typeName;
39
private char[][] enclosingTypeNames;
40
private String path;
41
private String projectPath;
42
private boolean initialized;
43
44
/**
45
 * Creates a new type declaration name match.
46
 */
47
public TypeDeclarationNameMatch(int modifiers, char[] packageName, char[] typeName, char[][] enclosingTypeNames, String path, String project) {
48
	super(null, A_ACCURATE, -1, -1, null, null);
49
	this.modifiers = modifiers;
50
	this.packageName = packageName;
51
	this.typeName = typeName;
52
	this.enclosingTypeNames = enclosingTypeNames;
53
	this.path = path;
54
	this.projectPath = project;
55
}
56
57
/**
58
 * Returns the enclosing type names (if any) of the type as they were found in the index.
59
 * 
60
 * @return the type enclosing type names
61
 */
62
public char[][] getEnclosingTypeNames() {
63
	return enclosingTypeNames;
64
}
65
66
/**
67
 * Returns the modifiers of the type as they were found in the index.
68
 * 
69
 * @return the type modifiers
70
 */
71
public int getModifiers() {
72
	return modifiers;
73
}
74
75
/**
76
 * Returns the full path of the resource as it was found in the index.
77
 * This path may include the jar file path following by '|' separator
78
 * if the type is a binary included in a jar.
79
 * 
80
 * @return the full path of the resource
81
 */
82
public String getPath() {
83
	return path;
84
}
85
86
/**
87
 * Returns the project path of the type.
88
 * 
89
 * @return the project path
90
 */
91
public String getProjectPath() {
92
	return projectPath;
93
}
94
95
/**
96
 * Returns the package name of the type as it was found in the index.
97
 * 
98
 * @return the package name
99
 */
100
public char[] getPackageName() {
101
	return packageName;
102
}
103
104
/**
105
 * Returns the name of the type as it was found in the index.
106
 * 
107
 * @return the type name
108
 */
109
public char[] getTypeName() {
110
	return typeName;
111
}
112
113
/**
114
 * Returns the type of the java model corresponding to information found
115
 * in index.
116
 * 
117
 * @return the java model type
118
 * @throws JavaModelException happens when index information are not valid
119
 */
120
public IType getType() throws JavaModelException {
121
	if (!this.initialized) {
122
		initialize();
123
	}
124
	return (IType) getElement();
125
}
126
127
/*
128
 * Initialize type.
129
 */
130
private void initialize() throws JavaModelException {
131
	this.initialized = true;
132
	
133
	// Find resource and project
134
	IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
135
	int index = path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
136
	IResource resource =  index == -1 ? root.findMember(path) : null;
137
	if (resource == null && this.projectPath == null) return; // no enough stored information, cannot initialize
138
	IProject project = this.projectPath == null ? getResource().getProject() : root.getProject(projectPath);
139
	IJavaProject javaProject = JavaCore.create(project);
140
	if (javaProject == null) return; // cannot initialize without a project
141
	setResource(resource == null ? project : resource);
142
143
	// Find type in project
144
	String packageNameString = new String(packageName);
145
	String qualifiedTypeName = this.enclosingTypeNames == null
146
		? new String(this.typeName)
147
		: new String(CharOperation.concatWith(this.typeName, enclosingTypeNames, '.'));
148
	IType type = javaProject.findType(packageNameString, qualifiedTypeName);
149
	setElement(type);
150
}
151
}
(-)search/org/eclipse/jdt/internal/core/search/TypeNameSearchRequestor.java (+67 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 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.runtime.CoreException;
14
import org.eclipse.jdt.core.search.IJavaSearchScope;
15
import org.eclipse.jdt.core.search.SearchRequestor;
16
import org.eclipse.jdt.core.search.TypeDeclarationNameMatch;
17
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
18
19
/**
20
 * Wrapper used to link {@link IRestrictedAccessTypeRequestor} with {@link SearchRequestor}.
21
 * This wrapper specifically allows usage of internal method {@link BasicSearchEngine#searchAllTypeNames(
22
 * 	char[] packageName, 
23
 * 	int packageMatchRule, 
24
 * 	char[] typeName,
25
 * 	int typeMatchRule, 
26
 * 	int searchFor, 
27
 * 	org.eclipse.jdt.core.search.IJavaSearchScope scope, 
28
 * 	IRestrictedAccessTypeRequestor nameRequestor,
29
 * 	int waitingPolicy,
30
 * 	org.eclipse.core.runtime.IProgressMonitor monitor) }.
31
 * from  API method {@link org.eclipse.jdt.core.search.SearchEngine#searchAllTypeNames(
32
 * 	char[] packageName, 
33
 * 	int packageMatchRule,
34
 * 	char[] typeName,
35
 * 	int matchRule, 
36
 * 	int searchFor, 
37
 * 	org.eclipse.jdt.core.search.IJavaSearchScope scope, 
38
 * 	SearchRequestor searchRequestor,
39
 * 	int waitingPolicy,
40
 * 	org.eclipse.core.runtime.IProgressMonitor monitor) }.
41
 */
42
public class TypeNameSearchRequestor implements IRestrictedAccessTypeRequestor {
43
	SearchRequestor requestor; // need the search requestor to make the link
44
	JavaSearchScope scope; // need  a scope to get path of the project (not stored in index file)
45
	
46
	public TypeNameSearchRequestor(SearchRequestor requestor, IJavaSearchScope scope) {
47
		this.requestor = requestor;
48
		this.scope = (JavaSearchScope) scope;
49
	}
50
	
51
	/**
52
	 * Accepting type from searchAllTypeNames query.
53
	 * Get project path from stored scope, create {@link TypeDeclarationNameMatch} and send it to search requestor.
54
	 */
55
	public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
56
		if (access == null) {
57
			try {
58
				String projectPath = this.scope.projectPathFor(path);
59
				TypeDeclarationNameMatch match = new TypeDeclarationNameMatch(modifiers, packageName, simpleTypeName, enclosingTypeNames, path, projectPath);
60
				this.requestor.acceptSearchMatch(match);
61
			}
62
			catch (CoreException e) {
63
				// skip
64
			}
65
		}
66
	}
67
}
(-)src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java (+1 lines)
Lines 229-234 Link Here
229
	TypeNameCounter requestor = new TypeNameCounter();
229
	TypeNameCounter requestor = new TypeNameCounter();
230
	new SearchEngine().searchAllTypeNames(
230
	new SearchEngine().searchAllTypeNames(
231
		null,
231
		null,
232
		SearchPattern.R_EXACT_MATCH,
232
		null,
233
		null,
233
		SearchPattern.R_PREFIX_MATCH, // not case sensitive
234
		SearchPattern.R_PREFIX_MATCH, // not case sensitive
234
		IJavaSearchConstants.TYPE,
235
		IJavaSearchConstants.TYPE,
(-)src/org/eclipse/jdt/core/tests/model/CodeCorrectionTests.java (+1 lines)
Lines 62-67 Link Here
62
	try {
62
	try {
63
		engine.searchAllTypeNames(
63
		engine.searchAllTypeNames(
64
			null,
64
			null,
65
			SearchPattern.R_EXACT_MATCH,
65
			"!@$#!@".toCharArray(),
66
			"!@$#!@".toCharArray(),
66
			SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE,
67
			SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE,
67
			IJavaSearchConstants.CLASS,
68
			IJavaSearchConstants.CLASS,
(-)src/org/eclipse/jdt/core/tests/model/SearchTests.java (+1 lines)
Lines 148-153 Link Here
148
	SearchTypeNameRequestor requestor = new SearchTypeNameRequestor();
148
	SearchTypeNameRequestor requestor = new SearchTypeNameRequestor();
149
	searchEngine.searchAllTypeNames(
149
	searchEngine.searchAllTypeNames(
150
		null,
150
		null,
151
		SearchPattern.R_EXACT_MATCH,
151
		null,
152
		null,
152
		SearchPattern.R_PATTERN_MATCH, // case insensitive
153
		SearchPattern.R_PATTERN_MATCH, // case insensitive
153
		TYPE,
154
		TYPE,
(-)src/org/eclipse/jdt/core/tests/model/ExistenceTests.java (-3 / +36 lines)
Lines 12-25 Link Here
12
12
13
import junit.framework.Test;
13
import junit.framework.Test;
14
14
15
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFolder;
16
import org.eclipse.core.resources.IFolder;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.jdt.core.*;
20
import org.eclipse.jdt.core.*;
20
import org.eclipse.jdt.core.IClassFile;
21
import org.eclipse.jdt.core.IJavaProject;
22
import org.eclipse.jdt.core.IPackageFragmentRoot;
23
import org.eclipse.jdt.core.tests.util.Util;
21
import org.eclipse.jdt.core.tests.util.Util;
24
public class ExistenceTests extends ModifyingResourceTests {
22
public class ExistenceTests extends ModifyingResourceTests {
25
public ExistenceTests(String name) {
23
public ExistenceTests(String name) {
Lines 96-101 Link Here
96
		this.deleteProject("P");
94
		this.deleteProject("P");
97
	}
95
	}
98
}
96
}
97
public void testClassFileInLibraryInOtherProject() throws CoreException {
98
	try {
99
		this.createJavaProject("P2", new String[] {}, "bin");
100
		this.createFolder("P2/lib");
101
		String path = "P2/lib/X.class";
102
		IFile file = this.createFile(path, "");
103
		IJavaProject p1 = createJavaProject("P1", new String[] {}, new String[] {"/P2/lib"}, "bin");
104
		IClassFile nonExistingFile = getClassFile(path);
105
		assertFalse(nonExistingFile.exists());
106
		IClassFile existingFile = (IClassFile)JavaCore.create(file, p1);
107
		assertTrue(existingFile.exists());
108
	} finally {
109
		this.deleteProject("P1");
110
		this.deleteProject("P2");
111
	}
112
}
113
public void testJarFile() throws Exception {
114
	try {
115
		IJavaProject p2 = createJavaProject("P2");
116
		String[] pathsAndContents = new String[] {
117
			"test/X.java", 
118
			"package test;\n" +
119
			"public class X {\n" + 
120
			"}",
121
		};
122
		addLibrary(p2, "lib.jar", "libsrc.zip", pathsAndContents, JavaCore.VERSION_1_5);
123
		IJavaProject p1 = createJavaProject("P1", new String[] {}, new String[] {"/P2/lib.jar"}, "bin");
124
		IPackageFragmentRoot root2 = getPackageFragmentRoot("/P2/lib.jar");
125
		assertTrue(root2.exists());
126
		assertEquals(p1.getPackageFragmentRoots()[0], root2);
127
	} finally {
128
		this.deleteProject("P1");
129
		this.deleteProject("P2");
130
	}
131
}
99
/*
132
/*
100
 * Ensure that an IClassFile handle created on a .class file in a source folder
133
 * Ensure that an IClassFile handle created on a .class file in a source folder
101
 * doesn't not exist.
134
 * doesn't not exist.
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+86 lines)
Lines 3017-3022 Link Here
3017
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3017
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3018
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3018
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3019
		null,
3019
		null,
3020
		SearchPattern.R_EXACT_MATCH,
3020
		null,
3021
		null,
3021
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3022
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3022
		TYPE,
3023
		TYPE,
Lines 3039-3044 Link Here
3039
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3040
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3040
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3041
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3041
		null,
3042
		null,
3043
		SearchPattern.R_EXACT_MATCH,
3042
		IIndexConstants.ONE_STAR,
3044
		IIndexConstants.ONE_STAR,
3043
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3045
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3044
		CLASS,
3046
		CLASS,
Lines 3059-3064 Link Here
3059
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3061
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3060
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3062
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3061
		null,
3063
		null,
3064
		SearchPattern.R_EXACT_MATCH,
3062
		null,
3065
		null,
3063
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3066
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3064
		CLASS_AND_INTERFACE,
3067
		CLASS_AND_INTERFACE,
Lines 3080-3085 Link Here
3080
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3083
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3081
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3084
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3082
		null,
3085
		null,
3086
		SearchPattern.R_EXACT_MATCH,
3083
		null,
3087
		null,
3084
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3088
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3085
		CLASS_AND_ENUM,
3089
		CLASS_AND_ENUM,
Lines 3101-3106 Link Here
3101
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3105
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3102
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3106
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3103
		null,
3107
		null,
3108
		SearchPattern.R_EXACT_MATCH,
3104
		null,
3109
		null,
3105
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3110
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3106
		INTERFACE,
3111
		INTERFACE,
Lines 3120-3125 Link Here
3120
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3125
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3121
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3126
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3122
		null,
3127
		null,
3128
		SearchPattern.R_EXACT_MATCH,
3123
		null,
3129
		null,
3124
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3130
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3125
		ENUM,
3131
		ENUM,
Lines 3139-3144 Link Here
3139
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3145
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3140
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3146
	new SearchEngine(this.workingCopies).searchAllTypeNames(
3141
		null,
3147
		null,
3148
		SearchPattern.R_EXACT_MATCH,
3142
		null,
3149
		null,
3143
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3150
		SearchPattern.R_PATTERN_MATCH, // case insensitive
3144
		ANNOTATION_TYPE,
3151
		ANNOTATION_TYPE,
Lines 3674-3679 Link Here
3674
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3681
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3675
	new SearchEngine().searchAllTypeNames(
3682
	new SearchEngine().searchAllTypeNames(
3676
		null,
3683
		null,
3684
		SearchPattern.R_EXACT_MATCH,
3677
		"E*".toCharArray(),
3685
		"E*".toCharArray(),
3678
		SearchPattern.R_PATTERN_MATCH,
3686
		SearchPattern.R_PATTERN_MATCH,
3679
		TYPE,
3687
		TYPE,
Lines 4870-4875 Link Here
4870
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4878
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4871
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4879
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4872
		null,
4880
		null,
4881
		SearchPattern.R_EXACT_MATCH,
4873
		"AA".toCharArray(),
4882
		"AA".toCharArray(),
4874
		SearchPattern.R_CAMELCASE_MATCH,
4883
		SearchPattern.R_CAMELCASE_MATCH,
4875
		TYPE,
4884
		TYPE,
Lines 4892-4897 Link Here
4892
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4901
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4893
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4902
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4894
		null,
4903
		null,
4904
		SearchPattern.R_EXACT_MATCH,
4895
		"AA".toCharArray(),
4905
		"AA".toCharArray(),
4896
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH,
4906
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH,
4897
		TYPE,
4907
		TYPE,
Lines 4914-4919 Link Here
4914
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4924
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4915
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4925
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4916
		null,
4926
		null,
4927
		SearchPattern.R_EXACT_MATCH,
4917
		"AA".toCharArray(),
4928
		"AA".toCharArray(),
4918
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_CASE_SENSITIVE,
4929
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_CASE_SENSITIVE,
4919
		TYPE,
4930
		TYPE,
Lines 4936-4941 Link Here
4936
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4947
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4937
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4948
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4938
		null,
4949
		null,
4950
		SearchPattern.R_EXACT_MATCH,
4939
		"AA".toCharArray(),
4951
		"AA".toCharArray(),
4940
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE,
4952
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE,
4941
		TYPE,
4953
		TYPE,
Lines 4958-4963 Link Here
4958
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4970
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4959
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4971
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4960
		null,
4972
		null,
4973
		SearchPattern.R_EXACT_MATCH,
4961
		"AA".toCharArray(),
4974
		"AA".toCharArray(),
4962
		SearchPattern.R_PREFIX_MATCH,
4975
		SearchPattern.R_PREFIX_MATCH,
4963
		TYPE,
4976
		TYPE,
Lines 4978-4983 Link Here
4978
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4991
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4979
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4992
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4980
		null,
4993
		null,
4994
		SearchPattern.R_EXACT_MATCH,
4981
		"AA".toCharArray(),
4995
		"AA".toCharArray(),
4982
		SearchPattern.R_CASE_SENSITIVE,
4996
		SearchPattern.R_CASE_SENSITIVE,
4983
		TYPE,
4997
		TYPE,
Lines 4997-5002 Link Here
4997
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5011
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
4998
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5012
	new SearchEngine(this.workingCopies).searchAllTypeNames(
4999
		null,
5013
		null,
5014
		SearchPattern.R_EXACT_MATCH,
5000
		"AA".toCharArray(),
5015
		"AA".toCharArray(),
5001
		SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE,
5016
		SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE,
5002
		TYPE,
5017
		TYPE,
Lines 5017-5022 Link Here
5017
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5032
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5018
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5033
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5019
		null,
5034
		null,
5035
		SearchPattern.R_EXACT_MATCH,
5020
		"aa".toCharArray(),
5036
		"aa".toCharArray(),
5021
		SearchPattern.R_CAMELCASE_MATCH,
5037
		SearchPattern.R_CAMELCASE_MATCH,
5022
		TYPE,
5038
		TYPE,
Lines 5037-5042 Link Here
5037
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5053
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5038
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5054
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5039
		null,
5055
		null,
5056
		SearchPattern.R_EXACT_MATCH,
5040
		"aa".toCharArray(),
5057
		"aa".toCharArray(),
5041
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH,
5058
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH,
5042
		TYPE,
5059
		TYPE,
Lines 5057-5062 Link Here
5057
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5074
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5058
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5075
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5059
		null,
5076
		null,
5077
		SearchPattern.R_EXACT_MATCH,
5060
		"aa".toCharArray(),
5078
		"aa".toCharArray(),
5061
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_CASE_SENSITIVE,
5079
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_CASE_SENSITIVE,
5062
		TYPE,
5080
		TYPE,
Lines 5076-5081 Link Here
5076
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5094
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5077
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5095
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5078
		null,
5096
		null,
5097
		SearchPattern.R_EXACT_MATCH,
5079
		"aa".toCharArray(),
5098
		"aa".toCharArray(),
5080
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE,
5099
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE,
5081
		TYPE,
5100
		TYPE,
Lines 5095-5100 Link Here
5095
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5114
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5096
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5115
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5097
		null,
5116
		null,
5117
		SearchPattern.R_EXACT_MATCH,
5098
		"aa".toCharArray(),
5118
		"aa".toCharArray(),
5099
		SearchPattern.R_PREFIX_MATCH,
5119
		SearchPattern.R_PREFIX_MATCH,
5100
		TYPE,
5120
		TYPE,
Lines 5115-5120 Link Here
5115
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5135
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5116
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5136
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5117
		null,
5137
		null,
5138
		SearchPattern.R_EXACT_MATCH,
5118
		"aa".toCharArray(),
5139
		"aa".toCharArray(),
5119
		SearchPattern.R_CASE_SENSITIVE,
5140
		SearchPattern.R_CASE_SENSITIVE,
5120
		TYPE,
5141
		TYPE,
Lines 5134-5139 Link Here
5134
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5155
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
5135
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5156
	new SearchEngine(this.workingCopies).searchAllTypeNames(
5136
		null,
5157
		null,
5158
		SearchPattern.R_EXACT_MATCH,
5137
		"aa".toCharArray(),
5159
		"aa".toCharArray(),
5138
		SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE,
5160
		SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE,
5139
		TYPE,
5161
		TYPE,
Lines 6339-6344 Link Here
6339
	TypeNameRequestor requestor =  new DeprecatedTypesRequestor();
6361
	TypeNameRequestor requestor =  new DeprecatedTypesRequestor();
6340
	new SearchEngine().searchAllTypeNames(
6362
	new SearchEngine().searchAllTypeNames(
6341
		null,
6363
		null,
6364
		SearchPattern.R_EXACT_MATCH,
6342
		null,
6365
		null,
6343
		SearchPattern.R_PATTERN_MATCH, // case insensitive
6366
		SearchPattern.R_PATTERN_MATCH, // case insensitive
6344
		TYPE,
6367
		TYPE,
Lines 6881-6886 Link Here
6881
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
6904
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
6882
	new SearchEngine(this.workingCopies).searchAllTypeNames(
6905
	new SearchEngine(this.workingCopies).searchAllTypeNames(
6883
		null,
6906
		null,
6907
		SearchPattern.R_EXACT_MATCH,
6884
		null,
6908
		null,
6885
		SearchPattern.R_PATTERN_MATCH, // case insensitive
6909
		SearchPattern.R_PATTERN_MATCH, // case insensitive
6886
		INTERFACE_AND_ANNOTATION,
6910
		INTERFACE_AND_ANNOTATION,
Lines 6958-6961 Link Here
6958
		"src/pack/Test.java void pack.Test.polymorphicSub(Sub) [toString()] EXACT_MATCH POLYMORPHIC"
6982
		"src/pack/Test.java void pack.Test.polymorphicSub(Sub) [toString()] EXACT_MATCH POLYMORPHIC"
6959
	);
6983
	);
6960
}
6984
}
6985
6986
/**
6987
 * Bug 156491: [1.5][search] interfaces and annotations could be found with only one requets of searchAllTypeName
6988
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491"
6989
 */
6990
public void _testSearchAllTypes_wc() throws CoreException {
6991
	resultCollector.showRule = true;
6992
	workingCopies = new ICompilationUnit[4];
6993
	workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/pack/I.java",
6994
		"package pack;\n" + 
6995
		"public interface I {}\n"
6996
	);
6997
	workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/pack/X.java",
6998
		"package pack;\n" + 
6999
		"public class X {}\n"
7000
	);
7001
	workingCopies[2] = getWorkingCopy("/JavaSearchBugs/src/pack/Sub.java",
7002
		"package pack;\n" + 
7003
		"public class Sub extends X {}\n"
7004
	);
7005
	workingCopies[3] = getWorkingCopy("/JavaSearchBugs/src/pack/Y.java",
7006
		"package pack;\n" + 
7007
		"public class Y {}\n"
7008
	);
7009
	new SearchEngine(this.workingCopies).searchAllTypeNames(
7010
		null, SearchPattern.R_EXACT_MATCH,
7011
		null, SearchPattern.R_EXACT_MATCH,
7012
		IJavaSearchConstants.TYPE,
7013
		getJavaSearchScopeBugs(),
7014
		this.resultCollector,
7015
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7016
		null);
7017
	assertSearchResults(
7018
		"???"
7019
	);
7020
}
7021
public void testONLY_SearchAllTypes_cu() throws CoreException {
7022
	SearchRequestor requestor = new SearchRequestor() {
7023
		public StringBuffer results = new StringBuffer();
7024
		public void acceptSearchMatch(SearchMatch match) throws CoreException {
7025
			TypeDeclarationNameMatch nameMatch = (TypeDeclarationNameMatch) match;
7026
			if (results.length() > 0) results.append('\n');
7027
			IType type = nameMatch.getType();
7028
			results.append(type==null?"null":type.toString());
7029
		}
7030
		public String toString() {
7031
			return this.results.toString();
7032
		}
7033
	};
7034
	new SearchEngine().searchAllTypeNames(
7035
		null, SearchPattern.R_EXACT_MATCH,
7036
		"Bug".toCharArray(), SearchPattern.R_PREFIX_MATCH,
7037
		IJavaSearchConstants.TYPE,
7038
		getJavaSearchScopeBugs(),
7039
		requestor,
7040
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7041
		null);
7042
	assertSearchResults(
7043
		"Bug148380 (not open) [in Bug148380.class [in <default> [in lib [in JavaSearchBugs]]]]",
7044
		requestor
7045
	);
7046
}
6961
}
7047
}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (+4 lines)
Lines 3610-3615 Link Here
3610
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3610
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3611
	new SearchEngine().searchAllTypeNames(
3611
	new SearchEngine().searchAllTypeNames(
3612
		null,
3612
		null,
3613
		SearchPattern.R_EXACT_MATCH,
3613
		"CNS".toCharArray(),
3614
		"CNS".toCharArray(),
3614
		SearchPattern.R_CAMELCASE_MATCH,
3615
		SearchPattern.R_CAMELCASE_MATCH,
3615
		TYPE,
3616
		TYPE,
Lines 3628-3633 Link Here
3628
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3629
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3629
	new SearchEngine().searchAllTypeNames(
3630
	new SearchEngine().searchAllTypeNames(
3630
		null,
3631
		null,
3632
		SearchPattern.R_EXACT_MATCH,
3631
		"AA".toCharArray(),
3633
		"AA".toCharArray(),
3632
		SearchPattern.R_CAMELCASE_MATCH,
3634
		SearchPattern.R_CAMELCASE_MATCH,
3633
		TYPE,
3635
		TYPE,
Lines 3650-3655 Link Here
3650
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3652
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3651
	new SearchEngine().searchAllTypeNames(
3653
	new SearchEngine().searchAllTypeNames(
3652
		null,
3654
		null,
3655
		SearchPattern.R_EXACT_MATCH,
3653
		"aa".toCharArray(),
3656
		"aa".toCharArray(),
3654
		SearchPattern.R_CAMELCASE_MATCH,
3657
		SearchPattern.R_CAMELCASE_MATCH,
3655
		TYPE,
3658
		TYPE,
Lines 3671-3676 Link Here
3671
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3674
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
3672
	new SearchEngine().searchAllTypeNames(
3675
	new SearchEngine().searchAllTypeNames(
3673
		null,
3676
		null,
3677
		SearchPattern.R_EXACT_MATCH,
3674
		"aa".toCharArray(),
3678
		"aa".toCharArray(),
3675
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH,
3679
		SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH,
3676
		TYPE,
3680
		TYPE,
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (+1 lines)
Lines 2304-2309 Link Here
2304
		try {
2304
		try {
2305
			engine.searchAllTypeNames(
2305
			engine.searchAllTypeNames(
2306
				null,
2306
				null,
2307
				SearchPattern.R_EXACT_MATCH,
2307
				"!@$#!@".toCharArray(),
2308
				"!@$#!@".toCharArray(),
2308
				SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE,
2309
				SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE,
2309
				IJavaSearchConstants.CLASS,
2310
				IJavaSearchConstants.CLASS,
(-)src/org/eclipse/jdt/core/tests/model/WorkingCopySearchTests.java (+6 lines)
Lines 128-133 Link Here
128
		SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
128
		SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
129
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllTypeNames(
129
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllTypeNames(
130
			null,
130
			null,
131
			SearchPattern.R_EXACT_MATCH,
131
			null,
132
			null,
132
			SearchPattern.R_PATTERN_MATCH, // case insensitive
133
			SearchPattern.R_PATTERN_MATCH, // case insensitive
133
			TYPE,
134
			TYPE,
Lines 159-164 Link Here
159
		SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
160
		SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
160
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllTypeNames(
161
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllTypeNames(
161
			null,
162
			null,
163
			SearchPattern.R_EXACT_MATCH,
162
			null,
164
			null,
163
			SearchPattern.R_PATTERN_MATCH, // case insensitive
165
			SearchPattern.R_PATTERN_MATCH, // case insensitive
164
			TYPE,
166
			TYPE,
Lines 195-200 Link Here
195
			SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
197
			SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
196
			new SearchEngine().searchAllTypeNames(
198
			new SearchEngine().searchAllTypeNames(
197
				"wc3".toCharArray(),
199
				"wc3".toCharArray(),
200
				SearchPattern.R_EXACT_MATCH,
198
				"X".toCharArray(),
201
				"X".toCharArray(),
199
				SearchPattern.R_PREFIX_MATCH, // case insensitive
202
				SearchPattern.R_PREFIX_MATCH, // case insensitive
200
				TYPE,
203
				TYPE,
Lines 232-237 Link Here
232
			SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
235
			SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
233
			new SearchEngine().searchAllTypeNames(
236
			new SearchEngine().searchAllTypeNames(
234
				"wc3".toCharArray(),
237
				"wc3".toCharArray(),
238
				SearchPattern.R_EXACT_MATCH,
235
				"X".toCharArray(),
239
				"X".toCharArray(),
236
				SearchPattern.R_PREFIX_MATCH, // case insensitive
240
				SearchPattern.R_PREFIX_MATCH, // case insensitive
237
				TYPE,
241
				TYPE,
Lines 266-271 Link Here
266
		SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
270
		SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
267
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllTypeNames(
271
		new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllTypeNames(
268
			null,
272
			null,
273
			SearchPattern.R_EXACT_MATCH,
269
			"A*".toCharArray(),
274
			"A*".toCharArray(),
270
			SearchPattern.R_PATTERN_MATCH, // case insensitive
275
			SearchPattern.R_PATTERN_MATCH, // case insensitive
271
			TYPE,
276
			TYPE,
Lines 308-313 Link Here
308
			IJavaSearchScope scope = 	SearchEngine.createJavaSearchScope(new IJavaElement[] { projects[1] });
313
			IJavaSearchScope scope = 	SearchEngine.createJavaSearchScope(new IJavaElement[] { projects[1] });
309
			new SearchEngine(this.workingCopies).searchAllTypeNames(
314
			new SearchEngine(this.workingCopies).searchAllTypeNames(
310
				null,
315
				null,
316
				SearchPattern.R_EXACT_MATCH,
311
				"A".toCharArray(),
317
				"A".toCharArray(),
312
				SearchPattern.R_PREFIX_MATCH,
318
				SearchPattern.R_PREFIX_MATCH,
313
				TYPE,
319
				TYPE,
(-)workspace/JavaSearchBugs/lib/Bug148380.class (+5 lines)
Added Link Here
1
Êþº¾1	Bug148380java/lang/Object<init>()VCode
2
	LineNumberTableLocalVariableTablethisLBug148380;
3
SourceFileBug148380.java!/*·±
4
5

Return to bug 148380