### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/core/search/SearchEngine.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/SearchEngine.java,v retrieving revision 1.131 diff -u -r1.131 SearchEngine.java --- search/org/eclipse/jdt/core/search/SearchEngine.java 22 Jun 2006 14:12:26 -0000 1.131 +++ search/org/eclipse/jdt/core/search/SearchEngine.java 22 Sep 2006 17:24:33 -0000 @@ -588,6 +588,8 @@ *
  • the classpath is incorrectly set
  • * * @since 3.1 + * @deprecated Use {@link #searchAllTypeNames(char[], int, char[], int, int, IJavaSearchScope, TypeNameRequestor, int, IProgressMonitor)} + * instead */ public void searchAllTypeNames( final char[] packageExactName, @@ -599,8 +601,7 @@ int waitingPolicy, IProgressMonitor progressMonitor) throws JavaModelException { - TypeNameRequestorWrapper requestorWrapper = new TypeNameRequestorWrapper(nameRequestor); - this.basicEngine.searchAllTypeNames(packageExactName, SearchPattern.R_EXACT_MATCH, typeName, matchRule, searchFor, scope, requestorWrapper, waitingPolicy, progressMonitor); + searchAllTypeNames(packageExactName, SearchPattern.R_EXACT_MATCH, typeName, matchRule, searchFor, scope, nameRequestor, waitingPolicy, progressMonitor); } /** @@ -681,6 +682,89 @@ } /** + * Searches for all top-level types and member types in the given scope. + * The search can be selecting specific types (given a package name using specific match mode + * and/or a type name using another specific match mode). + *

    + * SearchRequestor needs to be provided to this method. It will accept a specific search match + * ({@link TypeDeclarationNameMatch}) which may compute model operation as resolving the type. + * Note that this operation should be used carefully as it will consume more memory than + * searchAllTypeNames with {@link TypeNameRequestor} (a match for each type + * found will be created). + * + * @param packageName the full name of the package of the searched types, or a prefix for this + * package, or a wild-carded string for this package. + * @param typeName the dot-separated qualified name of the searched type (the qualification include + * the enclosing types if the searched type is a member type), or a prefix + * for this type, or a wild-carded string for this type. + * @param packageMatchRule one of + *

    + * combined with {@link SearchPattern#R_CASE_SENSITIVE}, + * e.g. {@link SearchPattern#R_EXACT_MATCH} | {@link SearchPattern#R_CASE_SENSITIVE} if an exact and case sensitive match is requested, + * or {@link SearchPattern#R_PREFIX_MATCH} if a prefix non case sensitive match is requested. + * @param typeMatchRule one of + * + * combined with {@link SearchPattern#R_CASE_SENSITIVE}, + * e.g. {@link SearchPattern#R_EXACT_MATCH} | {@link SearchPattern#R_CASE_SENSITIVE} if an exact and case sensitive match is requested, + * or {@link SearchPattern#R_PREFIX_MATCH} if a prefix non case sensitive match is requested. + * @param searchFor determines the nature of the searched elements + * + * @param scope the scope to search in + * @param searchNameRequestor the search requestor that collects all the matches found during the search + * @param waitingPolicy one of + * + * @param progressMonitor the progress monitor to report progress to, or null if no progress + * monitor is provided + * @exception JavaModelException if the search failed. Reasons include: + * + * @since 3.3 + */ + public void searchAllTypeNames( + final char[] packageName, + final int packageMatchRule, + final char[] typeName, + final int typeMatchRule, + int searchFor, + IJavaSearchScope scope, + final SearchRequestor searchNameRequestor, + int waitingPolicy, + IProgressMonitor progressMonitor) throws JavaModelException { + + TypeNameSearchRequestor requestorWrapper = new TypeNameSearchRequestor(searchNameRequestor, scope); + this.basicEngine.searchAllTypeNames(packageName, packageMatchRule, typeName, typeMatchRule, searchFor, scope, requestorWrapper, waitingPolicy, progressMonitor); + } + + /** * Searches for all top-level types and member types in the given scope matching any of the given qualifications * and type names in a case sensitive way. * Index: search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java,v retrieving revision 1.38 diff -u -r1.38 BasicSearchEngine.java --- search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 7 Sep 2006 12:59:26 -0000 1.38 +++ search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 22 Sep 2006 17:24:34 -0000 @@ -625,7 +625,7 @@ * The search can be selecting specific types (given a package or a type name * prefix and match modes). * - * @see SearchEngine#searchAllTypeNames(char[], char[], int, int, IJavaSearchScope, TypeNameRequestor, int, IProgressMonitor) + * @see SearchEngine#searchAllTypeNames(char[], int, char[], int, int, IJavaSearchScope, TypeNameRequestor, int, IProgressMonitor) * for detailed comment */ public void searchAllTypeNames( Index: search/org/eclipse/jdt/internal/core/search/TypeNameRequestorWrapper.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/TypeNameRequestorWrapper.java,v retrieving revision 1.7 diff -u -r1.7 TypeNameRequestorWrapper.java --- search/org/eclipse/jdt/internal/core/search/TypeNameRequestorWrapper.java 22 Jun 2006 14:12:26 -0000 1.7 +++ search/org/eclipse/jdt/internal/core/search/TypeNameRequestorWrapper.java 22 Sep 2006 17:24:34 -0000 @@ -27,6 +27,7 @@ * org.eclipse.core.runtime.IProgressMonitor monitor) }. * from API method {@link org.eclipse.jdt.core.search.SearchEngine#searchAllTypeNames( * char[] packageName, + * int packageMatchRule, * char[] typeName, * int matchRule, * int searchFor, Index: search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java,v retrieving revision 1.50 diff -u -r1.50 JavaSearchScope.java --- search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java 13 Jun 2006 13:00:43 -0000 1.50 +++ search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java 22 Sep 2006 17:24:34 -0000 @@ -33,6 +33,7 @@ /* The paths of the resources in this search scope (or the classpath entries' paths if the resources are projects) */ + private String[] projectPaths; // projects in which some container paths (typically class folders) may be enclosed (e.g. /P) private String[] containerPaths; // path to the container (e.g. /P/src, /P/lib.jar, c:\temp\mylib.jar) private String[] relativePaths; // path relative to the container (e.g. x/y/Z.class, x/y, (empty)) private boolean[] isPkgPath; // in the case of packages, matches must be direct children of the folder @@ -124,7 +125,7 @@ IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { String pathToString = path.getDevice() == null ? path.toString() : path.toOSString(); - add("", pathToString, false/*not a package*/, access); //$NON-NLS-1$ + add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$ addEnclosingProjectOrJar(path); } } @@ -137,7 +138,7 @@ IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { String pathToString = path.getDevice() == null ? path.toString() : path.toOSString(); - add("", pathToString, false/*not a package*/, access); //$NON-NLS-1$ + add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$ addEnclosingProjectOrJar(path); } } @@ -156,7 +157,7 @@ if ((includeMask & SOURCES) != 0) { IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { - add(Util.relativePath(path,1/*remove project segment*/), projectPathString, false/*not a package*/, access); + add(projectPath.toString(), Util.relativePath(path,1/*remove project segment*/), projectPathString, false/*not a package*/, access); } } break; @@ -185,20 +186,22 @@ containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath; containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); IResource rootResource = root.getResource(); + String projectPath = root.getJavaProject().getPath().toString(); if (rootResource != null && rootResource.isAccessible()) { String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount()); - add(relativePath, containerPathToString, false/*not a package*/, null); + add(projectPath, relativePath, containerPathToString, false/*not a package*/, null); } else { - add("", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$ + add(projectPath, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$ } break; case IJavaElement.PACKAGE_FRAGMENT: root = (IPackageFragmentRoot)element.getParent(); + projectPath = root.getJavaProject().getPath().toString(); if (root.isArchive()) { String relativePath = Util.concatWith(((PackageFragment) element).names, '/'); containerPath = root.getPath(); containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); - add(relativePath, containerPathToString, true/*package*/, null); + add(projectPath, relativePath, containerPathToString, true/*package*/, null); } else { IResource resource = element.getResource(); if (resource != null) { @@ -210,7 +213,7 @@ } containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount()); - add(relativePath, containerPathToString, true/*package*/, null); + add(projectPath, relativePath, containerPathToString, true/*package*/, null); } } break; @@ -223,6 +226,7 @@ this.elements.add(element); } root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); + projectPath = root.getJavaProject().getPath().toString(); String relativePath; if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { containerPath = root.getParent().getPath(); @@ -232,7 +236,7 @@ relativePath = getPath(element, true/*relative path*/).toString(); } containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); - add(relativePath, containerPathToString, false/*not a package*/, null); + add(projectPath, relativePath, containerPathToString, false/*not a package*/, null); } if (containerPath != null) @@ -243,7 +247,7 @@ * Adds the given path to this search scope. Remember if subfolders need to be included * and associated access restriction as well. */ -private void add(String relativePath, String containerPath, boolean isPackage, AccessRuleSet access) { +private void add(String projectPath, String relativePath, String containerPath, boolean isPackage, AccessRuleSet access) { // normalize containerPath and relativePath containerPath = normalize(containerPath); relativePath = normalize(relativePath); @@ -257,6 +261,7 @@ index = 0; } } + this.projectPaths[index] = projectPath; this.relativePaths[index] = relativePath; this.containerPaths[index] = containerPath; this.isPkgPath[index] = isPackage; @@ -464,6 +469,7 @@ extraRoom++; this.relativePaths = new String[extraRoom]; this.containerPaths = new String[extraRoom]; + this.projectPaths = new String[extraRoom]; this.isPkgPath = new boolean[extraRoom]; this.pathRestrictions = null; // null to optimize case where no access rules are used @@ -526,15 +532,45 @@ } } +/** + * Returns the project path corresponding to a given resource path. + * + * @param resourcePathString path of the resource + * @return the project path of the resource + */ +public String projectPathFor(String resourcePathString) { + int index = -1; + int separatorIndex = resourcePathString.indexOf(JAR_FILE_ENTRY_SEPARATOR); + if (separatorIndex != -1) { + // internal or external jar (case 3, 4, or 5) + String jarPath = resourcePathString.substring(0, separatorIndex); + String relativePath = resourcePathString.substring(separatorIndex+1); + index = indexOf(jarPath, relativePath); + } else { + // resource in workspace (case 1 or 2) + index = indexOf(resourcePathString); + } + if (index >= 0) { + String path = this.projectPaths[index]; + if (path != null) return path; + path = this.containerPaths[index]; + int sep = path.indexOf('/', 1); // first char is a '/' + if (sep < 0) return path; + return path.substring(0, sep); + } + return null; +} + private void rehash() { JavaSearchScope newScope = new JavaSearchScope(this.pathsCount * 2); // double the number of expected elements String currentPath; for (int i = this.relativePaths.length; --i >= 0;) if ((currentPath = this.relativePaths[i]) != null) - newScope.add(currentPath, this.containerPaths[i], this.isPkgPath[i], this.pathRestrictions == null ? null : this.pathRestrictions[i]); + newScope.add(this.projectPaths[i], currentPath, this.containerPaths[i], this.isPkgPath[i], this.pathRestrictions == null ? null : this.pathRestrictions[i]); this.relativePaths = newScope.relativePaths; this.containerPaths = newScope.containerPaths; + this.projectPaths = newScope.projectPaths; this.isPkgPath = newScope.isPkgPath; this.pathRestrictions = newScope.pathRestrictions; this.threshold = newScope.threshold; Index: model/org/eclipse/jdt/core/JavaCore.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java,v retrieving revision 1.550 diff -u -r1.550 JavaCore.java --- model/org/eclipse/jdt/core/JavaCore.java 23 Jun 2006 13:44:54 -0000 1.550 +++ model/org/eclipse/jdt/core/JavaCore.java 22 Sep 2006 17:24:32 -0000 @@ -1322,6 +1322,31 @@ return JavaModelManager.create(file, null/*unknown java project*/); } /** + * Returns the Java element corresponding to the given file, its project being the given + * project. + * Returns null if unable to associate the given file + * with a Java element. + * + *

    The file must be one of:

    + *

    + * Creating a Java element has the side effect of creating and opening all of the + * element's parents if they are not yet open. + * + * @param file the given file + * @return the Java element corresponding to the given file, or + * null if unable to associate the given file + * with a Java element + * @since 3.3 + */ + public static IJavaElement create(IFile file, IJavaProject project) { + return JavaModelManager.create(file, project); + } + /** * Returns the package fragment or package fragment root corresponding to the given folder, or * null if unable to associate the given folder with a Java element. *

    @@ -2857,6 +2882,7 @@ try { engine.searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "!@$#!@".toCharArray(), //$NON-NLS-1$ SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.CLASS, Index: search/org/eclipse/jdt/core/search/TypeDeclarationNameMatch.java =================================================================== RCS file: search/org/eclipse/jdt/core/search/TypeDeclarationNameMatch.java diff -N search/org/eclipse/jdt/core/search/TypeDeclarationNameMatch.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ search/org/eclipse/jdt/core/search/TypeDeclarationNameMatch.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.search; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CharOperation; + +/** + * A Java search match that represents a type declaration name + * found in index files. + * The element is an IType only initialized when + * requested by clients. + *

    + * This class is intended to be instantiated and subclassed by clients. + *

    + * + * @since 3.3 + */ +public class TypeDeclarationNameMatch extends SearchMatch { + +private int modifiers; +private char[] packageName; +private char[] typeName; +private char[][] enclosingTypeNames; +private String path; +private String projectPath; +private boolean initialized; + +/** + * Creates a new type declaration name match. + */ +public TypeDeclarationNameMatch(int modifiers, char[] packageName, char[] typeName, char[][] enclosingTypeNames, String path, String project) { + super(null, A_ACCURATE, -1, -1, null, null); + this.modifiers = modifiers; + this.packageName = packageName; + this.typeName = typeName; + this.enclosingTypeNames = enclosingTypeNames; + this.path = path; + this.projectPath = project; +} + +/** + * Returns the enclosing type names (if any) of the type as they were found in the index. + * + * @return the type enclosing type names + */ +public char[][] getEnclosingTypeNames() { + return enclosingTypeNames; +} + +/** + * Returns the modifiers of the type as they were found in the index. + * + * @return the type modifiers + */ +public int getModifiers() { + return modifiers; +} + +/** + * Returns the full path of the resource as it was found in the index. + * This path may include the jar file path following by '|' separator + * if the type is a binary included in a jar. + * + * @return the full path of the resource + */ +public String getPath() { + return path; +} + +/** + * Returns the project path of the type. + * + * @return the project path + */ +public String getProjectPath() { + return projectPath; +} + +/** + * Returns the package name of the type as it was found in the index. + * + * @return the package name + */ +public char[] getPackageName() { + return packageName; +} + +/** + * Returns the name of the type as it was found in the index. + * + * @return the type name + */ +public char[] getTypeName() { + return typeName; +} + +/** + * Returns the type of the java model corresponding to information found + * in index. + * + * @return the java model type + * @throws JavaModelException happens when index information are not valid + */ +public IType getType() throws JavaModelException { + if (!this.initialized) { + initialize(); + } + return (IType) getElement(); +} + +/* + * Initialize type. + */ +private void initialize() throws JavaModelException { + this.initialized = true; + + // Find resource and project + IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); + int index = path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR); + IResource resource = index == -1 ? root.findMember(path) : null; + if (resource == null && this.projectPath == null) return; // no enough stored information, cannot initialize + IProject project = this.projectPath == null ? getResource().getProject() : root.getProject(projectPath); + IJavaProject javaProject = JavaCore.create(project); + if (javaProject == null) return; // cannot initialize without a project + setResource(resource == null ? project : resource); + + // Find type in project + String packageNameString = new String(packageName); + String qualifiedTypeName = this.enclosingTypeNames == null + ? new String(this.typeName) + : new String(CharOperation.concatWith(this.typeName, enclosingTypeNames, '.')); + IType type = javaProject.findType(packageNameString, qualifiedTypeName); + setElement(type); +} +} Index: search/org/eclipse/jdt/internal/core/search/TypeNameSearchRequestor.java =================================================================== RCS file: search/org/eclipse/jdt/internal/core/search/TypeNameSearchRequestor.java diff -N search/org/eclipse/jdt/internal/core/search/TypeNameSearchRequestor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ search/org/eclipse/jdt/internal/core/search/TypeNameSearchRequestor.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.core.search; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.search.IJavaSearchScope; +import org.eclipse.jdt.core.search.SearchRequestor; +import org.eclipse.jdt.core.search.TypeDeclarationNameMatch; +import org.eclipse.jdt.internal.compiler.env.AccessRestriction; + +/** + * Wrapper used to link {@link IRestrictedAccessTypeRequestor} with {@link SearchRequestor}. + * This wrapper specifically allows usage of internal method {@link BasicSearchEngine#searchAllTypeNames( + * char[] packageName, + * int packageMatchRule, + * char[] typeName, + * int typeMatchRule, + * int searchFor, + * org.eclipse.jdt.core.search.IJavaSearchScope scope, + * IRestrictedAccessTypeRequestor nameRequestor, + * int waitingPolicy, + * org.eclipse.core.runtime.IProgressMonitor monitor) }. + * from API method {@link org.eclipse.jdt.core.search.SearchEngine#searchAllTypeNames( + * char[] packageName, + * int packageMatchRule, + * char[] typeName, + * int matchRule, + * int searchFor, + * org.eclipse.jdt.core.search.IJavaSearchScope scope, + * SearchRequestor searchRequestor, + * int waitingPolicy, + * org.eclipse.core.runtime.IProgressMonitor monitor) }. + */ +public class TypeNameSearchRequestor implements IRestrictedAccessTypeRequestor { + SearchRequestor requestor; // need the search requestor to make the link + JavaSearchScope scope; // need a scope to get path of the project (not stored in index file) + + public TypeNameSearchRequestor(SearchRequestor requestor, IJavaSearchScope scope) { + this.requestor = requestor; + this.scope = (JavaSearchScope) scope; + } + + /** + * Accepting type from searchAllTypeNames query. + * Get project path from stored scope, create {@link TypeDeclarationNameMatch} and send it to search requestor. + */ + public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) { + if (access == null) { + try { + String projectPath = this.scope.projectPathFor(path); + TypeDeclarationNameMatch match = new TypeDeclarationNameMatch(modifiers, packageName, simpleTypeName, enclosingTypeNames, path, projectPath); + this.requestor.acceptSearchMatch(match); + } + catch (CoreException e) { + // skip + } + } + } +} #P org.eclipse.jdt.core.tests.performance Index: src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java,v retrieving revision 1.15 diff -u -r1.15 FullSourceWorkspaceModelTests.java --- src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java 27 Apr 2006 09:10:08 -0000 1.15 +++ src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java 22 Sep 2006 17:24:35 -0000 @@ -229,6 +229,7 @@ TypeNameCounter requestor = new TypeNameCounter(); new SearchEngine().searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_PREFIX_MATCH, // not case sensitive IJavaSearchConstants.TYPE, #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/CodeCorrectionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CodeCorrectionTests.java,v retrieving revision 1.20 diff -u -r1.20 CodeCorrectionTests.java --- src/org/eclipse/jdt/core/tests/model/CodeCorrectionTests.java 6 Sep 2006 08:32:44 -0000 1.20 +++ src/org/eclipse/jdt/core/tests/model/CodeCorrectionTests.java 22 Sep 2006 17:24:38 -0000 @@ -62,6 +62,7 @@ try { engine.searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "!@$#!@".toCharArray(), SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.CLASS, Index: src/org/eclipse/jdt/core/tests/model/SearchTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SearchTests.java,v retrieving revision 1.37 diff -u -r1.37 SearchTests.java --- src/org/eclipse/jdt/core/tests/model/SearchTests.java 3 Aug 2006 17:23:24 -0000 1.37 +++ src/org/eclipse/jdt/core/tests/model/SearchTests.java 22 Sep 2006 17:24:44 -0000 @@ -148,6 +148,7 @@ SearchTypeNameRequestor requestor = new SearchTypeNameRequestor(); searchEngine.searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_PATTERN_MATCH, // case insensitive TYPE, Index: src/org/eclipse/jdt/core/tests/model/ExistenceTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExistenceTests.java,v retrieving revision 1.23 diff -u -r1.23 ExistenceTests.java --- src/org/eclipse/jdt/core/tests/model/ExistenceTests.java 23 Jun 2006 09:26:27 -0000 1.23 +++ src/org/eclipse/jdt/core/tests/model/ExistenceTests.java 22 Sep 2006 17:24:38 -0000 @@ -12,14 +12,12 @@ import junit.framework.Test; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.*; -import org.eclipse.jdt.core.IClassFile; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.tests.util.Util; public class ExistenceTests extends ModifyingResourceTests { public ExistenceTests(String name) { @@ -96,6 +94,41 @@ this.deleteProject("P"); } } +public void testClassFileInLibraryInOtherProject() throws CoreException { + try { + this.createJavaProject("P2", new String[] {}, "bin"); + this.createFolder("P2/lib"); + String path = "P2/lib/X.class"; + IFile file = this.createFile(path, ""); + IJavaProject p1 = createJavaProject("P1", new String[] {}, new String[] {"/P2/lib"}, "bin"); + IClassFile nonExistingFile = getClassFile(path); + assertFalse(nonExistingFile.exists()); + IClassFile existingFile = (IClassFile)JavaCore.create(file, p1); + assertTrue(existingFile.exists()); + } finally { + this.deleteProject("P1"); + this.deleteProject("P2"); + } +} +public void testJarFile() throws Exception { + try { + IJavaProject p2 = createJavaProject("P2"); + String[] pathsAndContents = new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + "}", + }; + addLibrary(p2, "lib.jar", "libsrc.zip", pathsAndContents, JavaCore.VERSION_1_5); + IJavaProject p1 = createJavaProject("P1", new String[] {}, new String[] {"/P2/lib.jar"}, "bin"); + IPackageFragmentRoot root2 = getPackageFragmentRoot("/P2/lib.jar"); + assertTrue(root2.exists()); + assertEquals(p1.getPackageFragmentRoots()[0], root2); + } finally { + this.deleteProject("P1"); + this.deleteProject("P2"); + } +} /* * Ensure that an IClassFile handle created on a .class file in a source folder * doesn't not exist. Index: src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java,v retrieving revision 1.85 diff -u -r1.85 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 14 Sep 2006 17:10:18 -0000 1.85 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 22 Sep 2006 17:24:41 -0000 @@ -3017,6 +3017,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_PATTERN_MATCH, // case insensitive TYPE, @@ -3039,6 +3040,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, IIndexConstants.ONE_STAR, SearchPattern.R_PATTERN_MATCH, // case insensitive CLASS, @@ -3059,6 +3061,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_PATTERN_MATCH, // case insensitive CLASS_AND_INTERFACE, @@ -3080,6 +3083,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_PATTERN_MATCH, // case insensitive CLASS_AND_ENUM, @@ -3101,6 +3105,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_PATTERN_MATCH, // case insensitive INTERFACE, @@ -3120,6 +3125,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_PATTERN_MATCH, // case insensitive ENUM, @@ -3139,6 +3145,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_PATTERN_MATCH, // case insensitive ANNOTATION_TYPE, @@ -3674,6 +3681,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine().searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "E*".toCharArray(), SearchPattern.R_PATTERN_MATCH, TYPE, @@ -4870,6 +4878,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "AA".toCharArray(), SearchPattern.R_CAMELCASE_MATCH, TYPE, @@ -4892,6 +4901,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "AA".toCharArray(), SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH, TYPE, @@ -4914,6 +4924,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "AA".toCharArray(), SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_CASE_SENSITIVE, TYPE, @@ -4936,6 +4947,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "AA".toCharArray(), SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE, TYPE, @@ -4958,6 +4970,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "AA".toCharArray(), SearchPattern.R_PREFIX_MATCH, TYPE, @@ -4978,6 +4991,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "AA".toCharArray(), SearchPattern.R_CASE_SENSITIVE, TYPE, @@ -4997,6 +5011,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "AA".toCharArray(), SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE, TYPE, @@ -5017,6 +5032,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "aa".toCharArray(), SearchPattern.R_CAMELCASE_MATCH, TYPE, @@ -5037,6 +5053,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "aa".toCharArray(), SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH, TYPE, @@ -5057,6 +5074,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "aa".toCharArray(), SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_CASE_SENSITIVE, TYPE, @@ -5076,6 +5094,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "aa".toCharArray(), SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE, TYPE, @@ -5095,6 +5114,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "aa".toCharArray(), SearchPattern.R_PREFIX_MATCH, TYPE, @@ -5115,6 +5135,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "aa".toCharArray(), SearchPattern.R_CASE_SENSITIVE, TYPE, @@ -5134,6 +5155,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "aa".toCharArray(), SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE, TYPE, @@ -6339,6 +6361,7 @@ TypeNameRequestor requestor = new DeprecatedTypesRequestor(); new SearchEngine().searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_PATTERN_MATCH, // case insensitive TYPE, @@ -6881,6 +6904,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_PATTERN_MATCH, // case insensitive INTERFACE_AND_ANNOTATION, @@ -6958,4 +6982,66 @@ "src/pack/Test.java void pack.Test.polymorphicSub(Sub) [toString()] EXACT_MATCH POLYMORPHIC" ); } + +/** + * Bug 156491: [1.5][search] interfaces and annotations could be found with only one requets of searchAllTypeName + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491" + */ +public void _testSearchAllTypes_wc() throws CoreException { + resultCollector.showRule = true; + workingCopies = new ICompilationUnit[4]; + workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/pack/I.java", + "package pack;\n" + + "public interface I {}\n" + ); + workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/pack/X.java", + "package pack;\n" + + "public class X {}\n" + ); + workingCopies[2] = getWorkingCopy("/JavaSearchBugs/src/pack/Sub.java", + "package pack;\n" + + "public class Sub extends X {}\n" + ); + workingCopies[3] = getWorkingCopy("/JavaSearchBugs/src/pack/Y.java", + "package pack;\n" + + "public class Y {}\n" + ); + new SearchEngine(this.workingCopies).searchAllTypeNames( + null, SearchPattern.R_EXACT_MATCH, + null, SearchPattern.R_EXACT_MATCH, + IJavaSearchConstants.TYPE, + getJavaSearchScopeBugs(), + this.resultCollector, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); + assertSearchResults( + "???" + ); +} +public void testONLY_SearchAllTypes_cu() throws CoreException { + SearchRequestor requestor = new SearchRequestor() { + public StringBuffer results = new StringBuffer(); + public void acceptSearchMatch(SearchMatch match) throws CoreException { + TypeDeclarationNameMatch nameMatch = (TypeDeclarationNameMatch) match; + if (results.length() > 0) results.append('\n'); + IType type = nameMatch.getType(); + results.append(type==null?"null":type.toString()); + } + public String toString() { + return this.results.toString(); + } + }; + new SearchEngine().searchAllTypeNames( + null, SearchPattern.R_EXACT_MATCH, + "Bug".toCharArray(), SearchPattern.R_PREFIX_MATCH, + IJavaSearchConstants.TYPE, + getJavaSearchScopeBugs(), + requestor, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); + assertSearchResults( + "Bug148380 (not open) [in Bug148380.class [in [in lib [in JavaSearchBugs]]]]", + requestor + ); +} } \ No newline at end of file Index: src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java,v retrieving revision 1.153 diff -u -r1.153 JavaSearchTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 7 Sep 2006 07:27:04 -0000 1.153 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 22 Sep 2006 17:24:43 -0000 @@ -3610,6 +3610,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine().searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "CNS".toCharArray(), SearchPattern.R_CAMELCASE_MATCH, TYPE, @@ -3628,6 +3629,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine().searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "AA".toCharArray(), SearchPattern.R_CAMELCASE_MATCH, TYPE, @@ -3650,6 +3652,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine().searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "aa".toCharArray(), SearchPattern.R_CAMELCASE_MATCH, TYPE, @@ -3671,6 +3674,7 @@ TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine().searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "aa".toCharArray(), SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_PREFIX_MATCH, TYPE, Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v retrieving revision 1.171 diff -u -r1.171 AbstractJavaModelTests.java --- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 26 Jun 2006 17:16:04 -0000 1.171 +++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 22 Sep 2006 17:24:37 -0000 @@ -2304,6 +2304,7 @@ try { engine.searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "!@$#!@".toCharArray(), SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE, IJavaSearchConstants.CLASS, Index: src/org/eclipse/jdt/core/tests/model/WorkingCopySearchTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/WorkingCopySearchTests.java,v retrieving revision 1.32 diff -u -r1.32 WorkingCopySearchTests.java --- src/org/eclipse/jdt/core/tests/model/WorkingCopySearchTests.java 31 May 2006 15:08:42 -0000 1.32 +++ src/org/eclipse/jdt/core/tests/model/WorkingCopySearchTests.java 22 Sep 2006 17:24:44 -0000 @@ -128,6 +128,7 @@ SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_PATTERN_MATCH, // case insensitive TYPE, @@ -159,6 +160,7 @@ SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_PATTERN_MATCH, // case insensitive TYPE, @@ -195,6 +197,7 @@ SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine().searchAllTypeNames( "wc3".toCharArray(), + SearchPattern.R_EXACT_MATCH, "X".toCharArray(), SearchPattern.R_PREFIX_MATCH, // case insensitive TYPE, @@ -232,6 +235,7 @@ SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine().searchAllTypeNames( "wc3".toCharArray(), + SearchPattern.R_EXACT_MATCH, "X".toCharArray(), SearchPattern.R_PREFIX_MATCH, // case insensitive TYPE, @@ -266,6 +270,7 @@ SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(new ICompilationUnit[] {this.workingCopy}).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "A*".toCharArray(), SearchPattern.R_PATTERN_MATCH, // case insensitive TYPE, @@ -308,6 +313,7 @@ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { projects[1] }); new SearchEngine(this.workingCopies).searchAllTypeNames( null, + SearchPattern.R_EXACT_MATCH, "A".toCharArray(), SearchPattern.R_PREFIX_MATCH, TYPE, Index: workspace/JavaSearchBugs/lib/Bug148380.class =================================================================== RCS file: workspace/JavaSearchBugs/lib/Bug148380.class diff -N workspace/JavaSearchBugs/lib/Bug148380.class --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/JavaSearchBugs/lib/Bug148380.class 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ +Êþº¾1 Bug148380java/lang/Object()VCode + LineNumberTableLocalVariableTablethis LBug148380; +SourceFileBug148380.java!/*·± +  +