### 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 27 Jan 2007 10:32:22 -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 27 Jan 2007 10:32:23 -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 27 Jan 2007 10:32:23 -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; // in case of IJavaSearchScope defined by clients, use an HandleFactory instead
/**
* Cache package fragment root information to optimize speed performance.
@@ -66,6 +70,9 @@
public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) {
this.requestor = requestor;
this.scope = scope;
+ if (!(scope instanceof JavaSearchScope)) {
+ this.handleFactory = new HandleFactory();
+ }
}
/* (non-Javadoc)
@@ -73,10 +80,32 @@
*/
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, this.scope);
+ if (openable == null) return;
+ switch (openable.getElementType()) {
+ case IJavaElement.COMPILATION_UNIT:
+ ICompilationUnit cu = (ICompilationUnit) openable;
+ if (enclosingTypeNames != null && enclosingTypeNames.length > 0) {
+ type = cu.getType(new String(enclosingTypeNames[0]));
+ for (int j=1, l=enclosingTypeNames.length; j resourcePath.length()
|| !resourcePath.startsWith(this.lastPkgFragmentRootPath)) {
String jarPath= resourcePath.substring(0, separatorIndex);
- IPackageFragmentRoot root= ((JavaSearchScope)scope).packageFragmentRoot(resourcePath);
+ IPackageFragmentRoot root= ((JavaSearchScope)this.scope).packageFragmentRoot(resourcePath);
if (root == null) return null;
this.lastPkgFragmentRootPath= jarPath;
this.lastPkgFragmentRoot= root;
@@ -123,7 +152,7 @@
|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath)
&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
&& resourcePath.charAt(rootPathLength) == '/')) {
- IPackageFragmentRoot root= ((JavaSearchScope)scope).packageFragmentRoot(resourcePath);
+ IPackageFragmentRoot root = ((JavaSearchScope)this.scope).packageFragmentRoot(resourcePath);
if (root == null) return null;
this.lastPkgFragmentRoot = root;
this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString();
Index: buildnotes_jdt-core.html
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v
retrieving revision 1.5654
diff -u -r1.5654 buildnotes_jdt-core.html
--- buildnotes_jdt-core.html 26 Jan 2007 20:44:50 -0000 1.5654
+++ buildnotes_jdt-core.html 27 Jan 2007 10:32:22 -0000
@@ -50,7 +50,6 @@
Eclipse SDK 3.3M5 - ??? January 2007
Project org.eclipse.jdt.core v_733
(cvs).
-
What's new in this drop
- New API added in
org.eclipse.jdt.core.compiler.CharOperation
:
@@ -192,7 +191,9 @@
Problem Reports Fixed
-141830
+167190
+[search] TypeNameMatchRequestorWrapper causing ClassCastException
+
141830
[1.3][compiler] Severe runtime errors with anonymous classes
171634
[formatter] doesn't add line feed at end of file
#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 27 Jan 2007 10:32:09 -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,57 @@
"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,
+ "C".toCharArray(), // need a prefix which returns most of different types (class file, CU, member,...)
+ SearchPattern.R_PREFIX_MATCH,
+ IJavaSearchConstants.TYPE,
+ scope,
+ requestor,
+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
+ null);
+ assertSearchResults(
+ "C (not open) [in C.class [in test [in lib/b124469.jar [in JavaSearchBugs]]]]\n" +
+ "C (not open) [in C.java [in b137984 [in src [in JavaSearchBugs]]]]\n" +
+ "C (not open) [in C.java [in b137984 [in src [in JavaSearchBugs]]]]\n" +
+ "C (not open) [in C.java [in b163984 [in src [in JavaSearchBugs]]]]\n" +
+ "C2 (not open) [in C [in C.java [in b137984 [in src [in JavaSearchBugs]]]]]\n" +
+ "C86293 (not open) [in C86293.class [in [in lib/b86293.jar [in JavaSearchBugs]]]]\n" +
+ "CJ (not open) [in CJ.class [in [in lib/b137984.jar [in JavaSearchBugs]]]]\n" +
+ "CJ2 (not open) [in CJ$CJ2.class [in [in lib/b137984.jar [in JavaSearchBugs]]]]\n" +
+ "CJ3 (not open) [in CJ$CJ2$CJ3.class [in [in lib/b137984.jar [in JavaSearchBugs]]]]\n" +
+ "C_124645 (not open) [in T_124645.java [in b124645 [in src [in JavaSearchBugs]]]]\n" +
+ "CharSequence (not open) [in CharSequence.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
+ "Class (not open) [in Class.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
+ "CloneNotSupportedException (not open) [in CloneNotSupportedException.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
+ "Collection (not open) [in Collection.class [in b87627 [in lib/b87627.jar [in JavaSearchBugs]]]]\n" +
+ "Comparable (not open) [in Comparable.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" +
+ "Test (not open) [in Test.java [in b95794 [in src [in JavaSearchBugs]]]]",
+ requestor
+ );
+}
}
\ No newline at end of file