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 (-6 / +35 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; // in case of IJavaSearchScope defined by clients, use an HandleFactory instead
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
	if (!(scope instanceof JavaSearchScope)) {
74
		this.handleFactory = new HandleFactory();
75
	}
69
}
76
}
70
77
71
/* (non-Javadoc)
78
/* (non-Javadoc)
Lines 73-82 Link Here
73
 */
80
 */
74
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
81
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
75
	try {
82
	try {
76
		int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
83
		IType type = null;
77
		IType type = separatorIndex == -1
84
		if (this.handleFactory != null) {
78
			? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames)
85
			Openable openable = this.handleFactory.createOpenable(path, this.scope);
79
			: createTypeFromJar(path, separatorIndex);
86
			if (openable == null) return;
87
			switch (openable.getElementType()) {
88
				case IJavaElement.COMPILATION_UNIT:
89
					ICompilationUnit cu = (ICompilationUnit) openable;
90
					if (enclosingTypeNames != null && enclosingTypeNames.length > 0) {
91
						type = cu.getType(new String(enclosingTypeNames[0]));
92
						for (int j=1, l=enclosingTypeNames.length; j<l; j++) {
93
							type = type.getType(new String(enclosingTypeNames[j]));
94
						}
95
					} else {
96
						type = cu.getType(new String(simpleTypeName));
97
					}
98
					break;
99
				case IJavaElement.CLASS_FILE:
100
					type = ((IClassFile)openable).getType();
101
					break;
102
			}
103
		} else {
104
			int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
105
			type = separatorIndex == -1
106
				? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames)
107
				: createTypeFromJar(path, separatorIndex);
108
		}
80
		if (type != null) {
109
		if (type != null) {
81
			this.requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, modifiers));
110
			this.requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, modifiers));
82
		}
111
		}
Lines 91-97 Link Here
91
			|| this.lastPkgFragmentRootPath.length() > resourcePath.length()
120
			|| this.lastPkgFragmentRootPath.length() > resourcePath.length()
92
			|| !resourcePath.startsWith(this.lastPkgFragmentRootPath)) {
121
			|| !resourcePath.startsWith(this.lastPkgFragmentRootPath)) {
93
		String jarPath= resourcePath.substring(0, separatorIndex);
122
		String jarPath= resourcePath.substring(0, separatorIndex);
94
		IPackageFragmentRoot root= ((JavaSearchScope)scope).packageFragmentRoot(resourcePath);
123
		IPackageFragmentRoot root= ((JavaSearchScope)this.scope).packageFragmentRoot(resourcePath);
95
		if (root == null) return null;
124
		if (root == null) return null;
96
		this.lastPkgFragmentRootPath= jarPath;
125
		this.lastPkgFragmentRootPath= jarPath;
97
		this.lastPkgFragmentRoot= root;
126
		this.lastPkgFragmentRoot= root;
Lines 123-129 Link Here
123
		|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath) 
152
		|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath) 
124
			&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
153
			&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
125
			&& resourcePath.charAt(rootPathLength) == '/')) {
154
			&& resourcePath.charAt(rootPathLength) == '/')) {
126
		IPackageFragmentRoot root= ((JavaSearchScope)scope).packageFragmentRoot(resourcePath);
155
		IPackageFragmentRoot root = ((JavaSearchScope)this.scope).packageFragmentRoot(resourcePath);
127
		if (root == null) return null;
156
		if (root == null) return null;
128
		this.lastPkgFragmentRoot = root;
157
		this.lastPkgFragmentRoot = root;
129
		this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString();
158
		this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString();
(-)buildnotes_jdt-core.html (-2 / +3 lines)
Lines 50-56 Link Here
50
Eclipse SDK 3.3M5 - ??? January 2007
50
Eclipse SDK 3.3M5 - ??? January 2007
51
<br>Project org.eclipse.jdt.core v_733
51
<br>Project org.eclipse.jdt.core v_733
52
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_733">cvs</a>).
52
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_733">cvs</a>).
53
54
<h2>What's new in this drop</h2>
53
<h2>What's new in this drop</h2>
55
<ul>
54
<ul>
56
<li>New API added in <code>org.eclipse.jdt.core.compiler.CharOperation</code>:<br>
55
<li>New API added in <code>org.eclipse.jdt.core.compiler.CharOperation</code>:<br>
Lines 192-198 Link Here
192
</ul>
191
</ul>
193
192
194
<h3>Problem Reports Fixed</h3>
193
<h3>Problem Reports Fixed</h3>
195
<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=141830">141830</a>
194
<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=167190">167190</a>
195
[search] TypeNameMatchRequestorWrapper causing ClassCastException
196
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=141830">141830</a>
196
[1.3][compiler] Severe runtime errors with anonymous classes
197
[1.3][compiler] Severe runtime errors with anonymous classes
197
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=171634">171634</a>
198
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=171634">171634</a>
198
[formatter] doesn't add line feed at end of file
199
[formatter] doesn't add line feed at end of file
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+54 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
		"C".toCharArray(), // need a prefix which returns most of different types (class file, CU, member,...)
7837
		SearchPattern.R_PREFIX_MATCH,
7838
		IJavaSearchConstants.TYPE,
7839
		scope,
7840
		requestor,
7841
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7842
		null);
7843
	assertSearchResults(
7844
		"C (not open) [in C.class [in test [in lib/b124469.jar [in JavaSearchBugs]]]]\n" + 
7845
		"C (not open) [in C.java [in b137984 [in src [in JavaSearchBugs]]]]\n" + 
7846
		"C (not open) [in C.java [in b137984 [in src [in JavaSearchBugs]]]]\n" + 
7847
		"C (not open) [in C.java [in b163984 [in src [in JavaSearchBugs]]]]\n" + 
7848
		"C2 (not open) [in C [in C.java [in b137984 [in src [in JavaSearchBugs]]]]]\n" + 
7849
		"C86293 (not open) [in C86293.class [in <default> [in lib/b86293.jar [in JavaSearchBugs]]]]\n" + 
7850
		"CJ (not open) [in CJ.class [in <default> [in lib/b137984.jar [in JavaSearchBugs]]]]\n" + 
7851
		"CJ2 (not open) [in CJ$CJ2.class [in <default> [in lib/b137984.jar [in JavaSearchBugs]]]]\n" + 
7852
		"CJ3 (not open) [in CJ$CJ2$CJ3.class [in <default> [in lib/b137984.jar [in JavaSearchBugs]]]]\n" + 
7853
		"C_124645 (not open) [in T_124645.java [in b124645 [in src [in JavaSearchBugs]]]]\n" + 
7854
		"CharSequence (not open) [in CharSequence.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + 
7855
		"Class (not open) [in Class.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + 
7856
		"CloneNotSupportedException (not open) [in CloneNotSupportedException.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + 
7857
		"Collection (not open) [in Collection.class [in b87627 [in lib/b87627.jar [in JavaSearchBugs]]]]\n" + 
7858
		"Comparable (not open) [in Comparable.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]\n" + 
7859
		"Test (not open) [in Test.java [in b95794 [in src [in JavaSearchBugs]]]]",
7860
		requestor
7861
	);
7862
}
7809
}
7863
}

Return to bug 167190