### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: search/org/eclipse/jdt/core/search/TypeNameMatch.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/TypeNameMatch.java,v
retrieving revision 1.6
diff -u -r1.6 TypeNameMatch.java
--- search/org/eclipse/jdt/core/search/TypeNameMatch.java 16 Oct 2006 15:59:27 -0000 1.6
+++ search/org/eclipse/jdt/core/search/TypeNameMatch.java 26 Jan 2007 17:47:24 -0000
@@ -108,7 +108,7 @@
/**
* Name of the type container using '.' character
- * as separator (e.g. enclosing type names + '.' + simple name).
+ * as separator (e.g. package name + '.' + enclosing type names).
*
* @see #getType()
* @see IMember#getDeclaringType()
@@ -127,7 +127,7 @@
/**
* Returns the matched type qualified name using '.' character
- * as separator (e.g. enclosing type names + '.' simple name).
+ * as separator (e.g. enclosing type names + '.' + simple name).
*
* @see #getType()
* @see IType#getTypeQualifiedName(char)
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.54
diff -u -r1.54 JavaSearchScope.java
--- search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java 17 Dec 2006 17:24:35 -0000 1.54
+++ search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java 26 Jan 2007 17:47:24 -0000
@@ -556,10 +556,11 @@
}
/**
- * Returns the project path corresponding to a given resource path.
+ * Returns the package fragment root corresponding to a given resource path.
*
- * @param resourcePathString path of the resource
- * @return the project path of the resource
+ * @param resourcePathString path of expected package fragment root.
+ * @return the {@link IPackageFragmentRoot package fragment root} which path
+ * match the given one or null
if none was found.
*/
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString) {
int index = -1;
Index: search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java,v
retrieving revision 1.5
diff -u -r1.5 TypeNameMatchRequestorWrapper.java
--- search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 17 Oct 2006 13:23:17 -0000 1.5
+++ search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 26 Jan 2007 17:47:24 -0000
@@ -13,6 +13,7 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
@@ -22,7 +23,9 @@
import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
import org.eclipse.jdt.core.search.TypeNameRequestor;
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
+import org.eclipse.jdt.internal.core.Openable;
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
+import org.eclipse.jdt.internal.core.util.HandleFactory;
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject;
/**
@@ -51,6 +54,7 @@
public class TypeNameMatchRequestorWrapper implements IRestrictedAccessTypeRequestor {
TypeNameMatchRequestor requestor;
private IJavaSearchScope scope; // scope is needed to retrieve project path for external resource
+ private HandleFactory handleFactory;
/**
* Cache package fragment root information to optimize speed performance.
@@ -66,6 +70,7 @@
public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) {
this.requestor = requestor;
this.scope = scope;
+ this.handleFactory = (scope instanceof JavaSearchScope) ? null : new HandleFactory();
}
/* (non-Javadoc)
@@ -73,10 +78,23 @@
*/
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
try {
- int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
- IType type = separatorIndex == -1
- ? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames)
- : createTypeFromJar(path, separatorIndex);
+ IType type = null;
+ if (this.handleFactory != null) {
+ Openable openable = this.handleFactory.createOpenable(path, scope);
+ switch (openable.getElementType()) {
+ case IJavaElement.COMPILATION_UNIT:
+ type = ((ICompilationUnit)openable).getType(new String(simpleTypeName));
+ break;
+ case IJavaElement.CLASS_FILE:
+ type = ((IClassFile)openable).getType();
+ break;
+ }
+ } else {
+ int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
+ type = separatorIndex == -1
+ ? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames)
+ : createTypeFromJar(path, separatorIndex);
+ }
if (type != null) {
this.requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, modifiers));
}
Index: .settings/org.eclipse.jdt.core.prefs
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/.settings/org.eclipse.jdt.core.prefs,v
retrieving revision 1.8
diff -u -r1.8 org.eclipse.jdt.core.prefs
--- .settings/org.eclipse.jdt.core.prefs 19 Jan 2007 13:46:16 -0000 1.8
+++ .settings/org.eclipse.jdt.core.prefs 26 Jan 2007 17:47:24 -0000
@@ -1,4 +1,4 @@
-#Fri Jan 19 14:33:51 CET 2007
+#Fri Jan 26 12:47:58 CET 2007
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
#P org.eclipse.jdt.core.tests.model
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.99
diff -u -r1.99 JavaSearchBugsTests.java
--- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 18 Jan 2007 14:49:37 -0000 1.99
+++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 26 Jan 2007 17:47:53 -0000
@@ -25,6 +25,7 @@
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.core.ClassFile;
import org.eclipse.jdt.internal.core.SourceMethod;
+import org.eclipse.jdt.internal.core.search.AbstractSearchScope;
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
import org.eclipse.jdt.internal.core.search.matching.PatternLocator;
@@ -7806,4 +7807,42 @@
"lib/b166348.jar test.Test166348 [No source] EXACT_MATCH"
);
}
+
+/**
+ * @bug 167190: [search] TypeNameMatchRequestorWrapper causing ClassCastException
+ * @test Ensure that types are found even when scope is not a {@link org.eclipse.jdt.internal.core.search.JavaSearchScope}
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=167190"
+ */
+public void testBug167190() throws CoreException, JavaModelException {
+ IJavaSearchScope scope = new AbstractSearchScope() {
+ IJavaSearchScope jsScope = getJavaSearchScopeBugs();
+ public void processDelta(IJavaElementDelta delta) {
+ // we should have no delta on this test case
+ }
+ public boolean encloses(String resourcePath) {
+ return this.jsScope.encloses(resourcePath);
+ }
+ public boolean encloses(IJavaElement element) {
+ return this.jsScope.encloses(element);
+ }
+ public IPath[] enclosingProjectsAndJars() {
+ return this.jsScope.enclosingProjectsAndJars();
+ }
+ };
+ TypeNameMatchCollector requestor = new TypeNameMatchCollector();
+ new SearchEngine().searchAllTypeNames(
+ null,
+ SearchPattern.R_EXACT_MATCH,
+ "Bug".toCharArray(),
+ SearchPattern.R_PREFIX_MATCH,
+ IJavaSearchConstants.TYPE,
+ scope,
+ 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