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

Collapse All | Expand All

(-)search/org/eclipse/jdt/core/search/TypeNameMatch.java (-2 / +2 lines)
Lines 108-114 Link Here
108
108
109
/**
109
/**
110
 * Name of the type container using '.' character
110
 * Name of the type container using '.' character
111
 * as separator (e.g. enclosing type names + '.' + simple name).
111
 * as separator (e.g. package name + '.' + enclosing type names).
112
 * 
112
 * 
113
 * @see #getType()
113
 * @see #getType()
114
 * @see IMember#getDeclaringType()
114
 * @see IMember#getDeclaringType()
Lines 127-133 Link Here
127
127
128
/**
128
/**
129
 * Returns the matched type qualified name using '.' character
129
 * Returns the matched type qualified name using '.' character
130
 * as separator (e.g. enclosing type names + '.' simple name).
130
 * as separator (e.g. enclosing type names + '.' + simple name).
131
 * 
131
 * 
132
 * @see #getType()
132
 * @see #getType()
133
 * @see IType#getTypeQualifiedName(char)
133
 * @see IType#getTypeQualifiedName(char)
(-)search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java (-3 / +4 lines)
Lines 556-565 Link Here
556
}
556
}
557
557
558
/**
558
/**
559
 * Returns the project path corresponding to a given resource path.
559
 * Returns the package fragment root corresponding to a given resource path.
560
 * 
560
 * 
561
 * @param resourcePathString path of the resource
561
 * @param resourcePathString path of expected package fragment root.
562
 * @return the project path of the resource
562
 * @return the {@link IPackageFragmentRoot package fragment root} which path
563
 * 	match the given one or <code>null</code> if none was found.
563
 */
564
 */
564
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString) {
565
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString) {
565
	int index = -1;
566
	int index = -1;
(-)search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java (-4 / +22 lines)
Lines 13-18 Link Here
13
import org.eclipse.core.runtime.Path;
13
import org.eclipse.core.runtime.Path;
14
import org.eclipse.jdt.core.IClassFile;
14
import org.eclipse.jdt.core.IClassFile;
15
import org.eclipse.jdt.core.ICompilationUnit;
15
import org.eclipse.jdt.core.ICompilationUnit;
16
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.core.IPackageFragment;
17
import org.eclipse.jdt.core.IPackageFragment;
17
import org.eclipse.jdt.core.IPackageFragmentRoot;
18
import org.eclipse.jdt.core.IPackageFragmentRoot;
18
import org.eclipse.jdt.core.IType;
19
import org.eclipse.jdt.core.IType;
Lines 22-28 Link Here
22
import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
23
import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
23
import org.eclipse.jdt.core.search.TypeNameRequestor;
24
import org.eclipse.jdt.core.search.TypeNameRequestor;
24
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
25
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
26
import org.eclipse.jdt.internal.core.Openable;
25
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
27
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
28
import org.eclipse.jdt.internal.core.util.HandleFactory;
26
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject;
29
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject;
27
30
28
/**
31
/**
Lines 51-56 Link Here
51
public class TypeNameMatchRequestorWrapper implements IRestrictedAccessTypeRequestor {
54
public class TypeNameMatchRequestorWrapper implements IRestrictedAccessTypeRequestor {
52
	TypeNameMatchRequestor requestor;
55
	TypeNameMatchRequestor requestor;
53
	private IJavaSearchScope scope; // scope is needed to retrieve project path for external resource
56
	private IJavaSearchScope scope; // scope is needed to retrieve project path for external resource
57
	private HandleFactory handleFactory;
54
58
55
	/**
59
	/**
56
	 * Cache package fragment root information to optimize speed performance.
60
	 * Cache package fragment root information to optimize speed performance.
Lines 66-71 Link Here
66
public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) {
70
public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) {
67
	this.requestor = requestor;
71
	this.requestor = requestor;
68
	this.scope = scope;
72
	this.scope = scope;
73
	this.handleFactory = (scope instanceof JavaSearchScope) ? null : new HandleFactory();
69
}
74
}
70
75
71
/* (non-Javadoc)
76
/* (non-Javadoc)
Lines 73-82 Link Here
73
 */
78
 */
74
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
79
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
75
	try {
80
	try {
76
		int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
81
		IType type = null;
77
		IType type = separatorIndex == -1
82
		if (this.handleFactory != null) {
78
			? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames)
83
			Openable openable = this.handleFactory.createOpenable(path, scope);
79
			: createTypeFromJar(path, separatorIndex);
84
			switch (openable.getElementType()) {
85
				case IJavaElement.COMPILATION_UNIT:
86
					type = ((ICompilationUnit)openable).getType(new String(simpleTypeName));
87
					break;
88
				case IJavaElement.CLASS_FILE:
89
					type = ((IClassFile)openable).getType();
90
					break;
91
			}
92
		} else {
93
			int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
94
			type = separatorIndex == -1
95
				? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames)
96
				: createTypeFromJar(path, separatorIndex);
97
		}
80
		if (type != null) {
98
		if (type != null) {
81
			this.requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, modifiers));
99
			this.requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, modifiers));
82
		}
100
		}
(-).settings/org.eclipse.jdt.core.prefs (-1 / +1 lines)
Lines 1-4 Link Here
1
#Fri Jan 19 14:33:51 CET 2007
1
#Fri Jan 26 12:47:58 CET 2007
2
eclipse.preferences.version=1
2
eclipse.preferences.version=1
3
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
3
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
4
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
4
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+39 lines)
Lines 25-30 Link Here
25
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
25
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
26
import org.eclipse.jdt.internal.core.ClassFile;
26
import org.eclipse.jdt.internal.core.ClassFile;
27
import org.eclipse.jdt.internal.core.SourceMethod;
27
import org.eclipse.jdt.internal.core.SourceMethod;
28
import org.eclipse.jdt.internal.core.search.AbstractSearchScope;
28
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
29
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
29
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
30
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
30
import org.eclipse.jdt.internal.core.search.matching.PatternLocator;
31
import org.eclipse.jdt.internal.core.search.matching.PatternLocator;
Lines 7806-7809 Link Here
7806
		"lib/b166348.jar test.Test166348 [No source] EXACT_MATCH"
7807
		"lib/b166348.jar test.Test166348 [No source] EXACT_MATCH"
7807
	);
7808
	);
7808
}
7809
}
7810
7811
/**
7812
 * @bug 167190: [search] TypeNameMatchRequestorWrapper causing ClassCastException
7813
 * @test Ensure that types are found even when scope is not a {@link org.eclipse.jdt.internal.core.search.JavaSearchScope}
7814
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=167190"
7815
 */
7816
public void testBug167190() throws CoreException, JavaModelException {
7817
	IJavaSearchScope scope = new AbstractSearchScope() {
7818
		IJavaSearchScope jsScope = getJavaSearchScopeBugs();
7819
		public void processDelta(IJavaElementDelta delta) {
7820
			// we should have no delta on this test case
7821
		}
7822
		public boolean encloses(String resourcePath) {
7823
			return this.jsScope.encloses(resourcePath);
7824
		}
7825
		public boolean encloses(IJavaElement element) {
7826
			return this.jsScope.encloses(element);
7827
		}
7828
		public IPath[] enclosingProjectsAndJars() {
7829
			return this.jsScope.enclosingProjectsAndJars();
7830
		}
7831
	};
7832
	TypeNameMatchCollector requestor = new TypeNameMatchCollector();
7833
	new SearchEngine().searchAllTypeNames(
7834
		null,
7835
		SearchPattern.R_EXACT_MATCH,
7836
		"Bug".toCharArray(),
7837
		SearchPattern.R_PREFIX_MATCH,
7838
		IJavaSearchConstants.TYPE,
7839
		scope,
7840
		requestor,
7841
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7842
		null);
7843
	assertSearchResults(
7844
		"Bug148380 (not open) [in Bug148380.class [in <default> [in lib [in JavaSearchBugs]]]]",
7845
		requestor
7846
	);
7847
}
7809
}
7848
}

Return to bug 167190