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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (-7 / +57 lines)
Lines 26-31 Link Here
26
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
26
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
27
import org.eclipse.jdt.internal.core.ClassFile;
27
import org.eclipse.jdt.internal.core.ClassFile;
28
import org.eclipse.jdt.internal.core.SourceMethod;
28
import org.eclipse.jdt.internal.core.SourceMethod;
29
import org.eclipse.jdt.internal.core.search.AbstractSearchScope;
29
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
30
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
30
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
31
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
31
import org.eclipse.jdt.internal.core.search.matching.PatternLocator;
32
import org.eclipse.jdt.internal.core.search.matching.PatternLocator;
Lines 87-96 Link Here
87
class TypeNameMatchCollector extends TypeNameMatchRequestor {
88
class TypeNameMatchCollector extends TypeNameMatchRequestor {
88
	List matches = new ArrayList();
89
	List matches = new ArrayList();
89
	public void acceptTypeNameMatch(TypeNameMatch match) {
90
	public void acceptTypeNameMatch(TypeNameMatch match) {
90
		IType type = match.getType();
91
//		IType type = match.getType();
91
		if (type != null) {
92
//		if (type != null) {
92
			this.matches.add(type);
93
//			this.matches.add(type);
93
		}
94
//		}
95
		this.matches.add(match);
94
	}
96
	}
95
	public int size() {
97
	public int size() {
96
		return this.matches.size();
98
		return this.matches.size();
Lines 100-113 Link Here
100
		if (size == 0) return "";
102
		if (size == 0) return "";
101
		String[] strings = new String[size];
103
		String[] strings = new String[size];
102
		for (int i=0; i<size; i++) {
104
		for (int i=0; i<size; i++) {
103
			IType type = (IType) this.matches.get(i);
105
			TypeNameMatch match = (TypeNameMatch) this.matches.get(i);
106
			IType type = match.getType();
104
			switch (kind) {
107
			switch (kind) {
105
				case 1: // fully qualified name
108
				case 1: // fully qualified name
106
					strings[i] = type.getFullyQualifiedName();
109
					if (type != null) {
110
						strings[i] = type.getFullyQualifiedName();
111
					} else {
112
						strings[i] = match.getFullyQualifiedName();
113
					}
107
					break;
114
					break;
108
				case 0:
115
				case 0:
109
				default:
116
				default:
110
					strings[i] = type.toString();
117
					if (type != null) {
118
						strings[i] = type.toString();
119
					} else {
120
						strings[i] = match.toString();
121
					}
122
					break;
111
			}
123
			}
112
		}
124
		}
113
		Arrays.sort(strings);
125
		Arrays.sort(strings);
Lines 7782-7785 Link Here
7782
		"lib/b166348.jar test.Test166348 [No source] EXACT_MATCH"
7794
		"lib/b166348.jar test.Test166348 [No source] EXACT_MATCH"
7783
	);
7795
	);
7784
}
7796
}
7797
7798
/**
7799
 * @bug 167190: [search] TypeNameMatchRequestorWrapper causing ClassCastException
7800
 * @test Ensure that types are found even when scope is not a {@link org.eclipse.jdt.internal.core.search.JavaSearchScope}
7801
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=167190"
7802
 */
7803
public void testBug167190() throws CoreException, JavaModelException {
7804
	IJavaSearchScope scope = new AbstractSearchScope() {
7805
		IJavaSearchScope jsScope = getJavaSearchScopeBugs();
7806
		public void processDelta(IJavaElementDelta delta) {
7807
			// we should have no delta on this test case
7808
		}
7809
		public boolean encloses(String resourcePath) {
7810
			return this.jsScope.encloses(resourcePath);
7811
		}
7812
		public boolean encloses(IJavaElement element) {
7813
			return this.jsScope.encloses(element);
7814
		}
7815
		public IPath[] enclosingProjectsAndJars() {
7816
			return this.jsScope.enclosingProjectsAndJars();
7817
		}
7818
	};
7819
	TypeNameMatchCollector requestor = new TypeNameMatchCollector();
7820
	new SearchEngine().searchAllTypeNames(
7821
		null,
7822
		SearchPattern.R_EXACT_MATCH,
7823
		"Bug".toCharArray(),
7824
		SearchPattern.R_PREFIX_MATCH,
7825
		IJavaSearchConstants.TYPE,
7826
		scope,
7827
		requestor,
7828
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7829
		null);
7830
	assertSearchResults(
7831
		"Bug148380",
7832
		requestor
7833
	);
7834
}
7785
}
7835
}
(-)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 (-1 / +6 lines)
Lines 19-24 Link Here
19
import org.eclipse.jdt.core.JavaModelException;
19
import org.eclipse.jdt.core.JavaModelException;
20
import org.eclipse.jdt.core.compiler.CharOperation;
20
import org.eclipse.jdt.core.compiler.CharOperation;
21
import org.eclipse.jdt.core.search.IJavaSearchScope;
21
import org.eclipse.jdt.core.search.IJavaSearchScope;
22
import org.eclipse.jdt.core.search.NoTypeNameMatch;
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;
Lines 65-77 Link Here
65
66
66
public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) {
67
public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) {
67
	this.requestor = requestor;
68
	this.requestor = requestor;
68
	this.scope = scope;
69
	this.scope = (scope instanceof JavaSearchScope) ? scope : null;
69
}
70
}
70
71
71
/* (non-Javadoc)
72
/* (non-Javadoc)
72
 * @see org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor#acceptType(int, char[], char[], char[][], java.lang.String, org.eclipse.jdt.internal.compiler.env.AccessRestriction)
73
 * @see org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor#acceptType(int, char[], char[], char[][], java.lang.String, org.eclipse.jdt.internal.compiler.env.AccessRestriction)
73
 */
74
 */
74
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
75
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
76
	if (this.scope == null) {
77
		this.requestor.acceptTypeNameMatch(new NoTypeNameMatch(modifiers, packageName, simpleTypeName, enclosingTypeNames));
78
		return;
79
	}
75
	try {
80
	try {
76
		int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
81
		int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR);
77
		IType type = separatorIndex == -1
82
		IType type = separatorIndex == -1
(-)search/org/eclipse/jdt/core/search/NoTypeNameMatch.java (+125 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.search;
12
13
import org.eclipse.jdt.core.IPackageFragmentRoot;
14
import org.eclipse.jdt.core.IType;
15
16
public class NoTypeNameMatch extends TypeNameMatch {
17
18
private int modifiers = -1; // store modifiers to avoid java model population
19
private char[] packageName;
20
private char[] simpleTypeName;
21
private char[][] enclosingTypeNames;
22
23
/**
24
 * Specific type name match with no type.
25
 */
26
public NoTypeNameMatch(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames) {
27
	this.modifiers = modifiers;
28
	this.packageName = packageName;
29
	this.simpleTypeName = simpleTypeName;
30
	this.enclosingTypeNames = enclosingTypeNames;
31
}
32
33
/* (non-Javadoc)
34
 * @see org.eclipse.jdt.core.search.TypeNameMatch#getFullyQualifiedName()
35
 */
36
public String getFullyQualifiedName() {
37
	StringBuffer buffer = new StringBuffer(getTypeContainerName());
38
	if (buffer.length() > 0) buffer.append('.');
39
	buffer.append(this.simpleTypeName);
40
	return buffer.toString();
41
}
42
43
/* (non-Javadoc)
44
 * @see org.eclipse.jdt.core.search.TypeNameMatch#getModifiers()
45
 */
46
public int getModifiers() {
47
	return this.modifiers;
48
}
49
50
/* (non-Javadoc)
51
 * @see org.eclipse.jdt.core.search.TypeNameMatch#getPackageFragmentRoot()
52
 */
53
public IPackageFragmentRoot getPackageFragmentRoot() {
54
	return null;
55
}
56
57
/* (non-Javadoc)
58
 * @see org.eclipse.jdt.core.search.TypeNameMatch#getPackageName()
59
 */
60
public String getPackageName() {
61
	if (this.packageName == null) return null;
62
	return new String(this.packageName);
63
}
64
65
/* (non-Javadoc)
66
 * @see org.eclipse.jdt.core.search.TypeNameMatch#getSimpleTypeName()
67
 */
68
public String getSimpleTypeName() {
69
	if (this.simpleTypeName == null) return null;
70
	return new String(this.simpleTypeName);
71
}
72
73
/* (non-Javadoc)
74
 * @see org.eclipse.jdt.core.search.TypeNameMatch#getType()
75
 */
76
public IType getType() {
77
	return null;
78
}
79
80
/* (non-Javadoc)
81
 * @see org.eclipse.jdt.core.search.TypeNameMatch#getTypeContainerName()
82
 */
83
public String getTypeContainerName() {
84
	StringBuffer buffer = new StringBuffer();
85
	if (this.packageName != null && this.packageName.length > 0) {
86
		buffer.append(packageName);
87
	}
88
	if (this.enclosingTypeNames != null) {
89
		int length = this.enclosingTypeNames.length;
90
		for (int i=0; i<length; i++) {
91
			if (buffer.length() > 0) buffer.append('.');
92
			buffer.append(this.enclosingTypeNames[i]);
93
		}
94
	}
95
	return buffer.toString();
96
}
97
98
/* (non-Javadoc)
99
 * @see org.eclipse.jdt.core.search.TypeNameMatch#getTypeQualifiedName()
100
 */
101
public String getTypeQualifiedName() {
102
	StringBuffer buffer = new StringBuffer();
103
	if (this.enclosingTypeNames != null) {
104
		int length = this.enclosingTypeNames.length;
105
		for (int i=0; i<length; i++) {
106
			if (i>0) buffer.append('.');
107
			buffer.append(this.enclosingTypeNames[i]);
108
		}
109
	}
110
	if (this.simpleTypeName != null && this.simpleTypeName.length > 0) {
111
		if (buffer.length() > 0) buffer.append('.');
112
		buffer.append(this.simpleTypeName);
113
	}
114
	return buffer.toString();
115
}
116
117
/* (non-Javadoc)
118
 * Returns the string of the matched type.
119
 * @see java.lang.Object#toString()
120
 */
121
public String toString() {
122
	return getFullyQualifiedName();
123
}
124
125
}

Return to bug 167190