View | Details | Raw Unified | Return to bug 160323
Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/MultiTypeDeclarationPattern.java (-4 / +9 lines)
Lines 83-92 Link Here
83
	if (this.qualifications != null) {
83
	if (this.qualifications != null) {
84
		int count = 0;
84
		int count = 0;
85
		int max = this.qualifications.length;
85
		int max = this.qualifications.length;
86
		for (; count < max; count++)
86
		if (max == 0 && pattern.qualification.length > 0) {
87
			if (matchesName(this.qualifications[count], pattern.qualification))
87
			return false;
88
				break;
88
		}
89
		if (count == max) return false;
89
		if (max > 0) {
90
			for (; count < max; count++)
91
				if (matchesName(this.qualifications[count], pattern.qualification))
92
					break;
93
			if (count == max) return false;
94
		}
90
	}
95
	}
91
96
92
	// chekc simple name
97
	// chekc simple name
(-)search/org/eclipse/jdt/core/search/SearchEngine.java (-2 / +53 lines)
Lines 774-782 Link Here
774
	 * and type names in a case sensitive way.
774
	 * and type names in a case sensitive way.
775
	 * 
775
	 * 
776
	 * @param qualifications the qualified name of the package/enclosing type of the searched types.
776
	 * @param qualifications the qualified name of the package/enclosing type of the searched types.
777
	 *					May be <code>null</code>, then any package name is accepted.
777
	 *					If this parameter is <code>null</code>, then no type will be found.
778
	 * @param typeNames the simple names of the searched types.
778
	 * @param typeNames the simple names of the searched types.
779
	 *					May be <code>null</code>, then any type name is accepted.
779
	 *					If this parameter is <code>null</code>, then no type will be found.
780
	 * @param scope the scope to search in
780
	 * @param scope the scope to search in
781
	 * @param nameRequestor the requestor that collects the results of the search
781
	 * @param nameRequestor the requestor that collects the results of the search
782
	 * @param waitingPolicy one of
782
	 * @param waitingPolicy one of
Lines 816-821 Link Here
816
	}
816
	}
817
817
818
	/**
818
	/**
819
	 * Searches for all top-level types and member types in the given scope matching any of the given qualifications
820
	 * and type names in a case sensitive way.
821
	 * <p>
822
	 * Provided {@link TypeNameMatchRequestor} requestor will collect {@link TypeNameMatch}
823
	 * matches found during the search.
824
	 * </p>
825
	 * 
826
	 * @param qualifications the qualified name of the package/enclosing type of the searched types.
827
	 *					If this parameter is <code>null</code>, then no type will be found.
828
	 * @param typeNames the simple names of the searched types.
829
	 *					If this parameter is <code>null</code>, then no type will be found.
830
	 * @param scope the scope to search in
831
	 * @param nameMatchRequestor the {@link TypeNameMatchRequestor requestor} that collects
832
	 * 				{@link TypeNameMatch matches} of the search.
833
	 * @param waitingPolicy one of
834
	 * <ul>
835
	 *		<li>{@link IJavaSearchConstants#FORCE_IMMEDIATE_SEARCH} if the search should start immediately</li>
836
	 *		<li>{@link IJavaSearchConstants#CANCEL_IF_NOT_READY_TO_SEARCH} if the search should be cancelled if the
837
	 *			underlying indexer has not finished indexing the workspace</li>
838
	 *		<li>{@link IJavaSearchConstants#WAIT_UNTIL_READY_TO_SEARCH} if the search should wait for the
839
	 *			underlying indexer to finish indexing the workspace</li>
840
	 * </ul>
841
	 * @param progressMonitor the progress monitor to report progress to, or <code>null</code> if no progress
842
	 *							monitor is provided
843
	 * @exception JavaModelException if the search failed. Reasons include:
844
	 *	<ul>
845
	 *		<li>the classpath is incorrectly set</li>
846
	 *	</ul>
847
	 * @since 3.3
848
	 */
849
	public void searchAllTypeNames(
850
		final char[][] qualifications, 
851
		final char[][] typeNames,
852
		IJavaSearchScope scope, 
853
		final TypeNameMatchRequestor nameMatchRequestor,
854
		int waitingPolicy,
855
		IProgressMonitor progressMonitor)  throws JavaModelException {
856
857
		TypeNameMatchRequestorWrapper requestorWrapper = new TypeNameMatchRequestorWrapper(nameMatchRequestor, scope);
858
		this.basicEngine.searchAllTypeNames(
859
			qualifications,
860
			typeNames,
861
			SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
862
			IJavaSearchConstants.TYPE,
863
			scope,
864
			requestorWrapper,
865
			waitingPolicy,
866
			progressMonitor);
867
	}
868
869
	/**
819
	 * Searches for all top-level types and member types in the given scope.
870
	 * Searches for all top-level types and member types in the given scope.
820
	 * The search can be selecting specific types (given a package or a type name
871
	 * The search can be selecting specific types (given a package or a type name
821
	 * prefix and match modes). 
872
	 * prefix and match modes). 
(-)search/org/eclipse/jdt/core/search/TypeNameMatch.java (-44 / +73 lines)
Lines 10-19 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.search;
11
package org.eclipse.jdt.core.search;
12
12
13
import org.eclipse.jdt.core.IJavaElement;
13
import org.eclipse.core.runtime.Assert;
14
import org.eclipse.jdt.core.IPackageFragmentRoot;
14
import org.eclipse.jdt.core.*;
15
import org.eclipse.jdt.core.IType;
16
import org.eclipse.jdt.core.JavaModelException;
17
15
18
/**
16
/**
19
 * A match collected while searching for all type names using
17
 * A match collected while searching for all type names using
Lines 41-84 Link Here
41
/**
39
/**
42
 * Creates a new type name match.
40
 * Creates a new type name match.
43
 */
41
 */
44
public TypeNameMatch(IType type) {
45
	this.type = type;
46
}
47
48
public TypeNameMatch(IType type, int modifiers) {
42
public TypeNameMatch(IType type, int modifiers) {
49
	this(type);
43
	Assert.isNotNull(type, "Type cannot be null for a name match!"); //$NON-NLS-1$
44
	this.type = type;
50
	this.modifiers = modifiers;
45
	this.modifiers = modifiers;
51
}
46
}
52
47
53
/**
48
/**
54
 * Returns the java model type corresponding to fully qualified type name (based
49
 * Returns whether the stored type is equals to given object or not.
55
 * on package, enclosing types and simple name).
56
 * 
57
 * @return the java model type
58
 * @throws JavaModelException
59
 *             happens when type stored information are not valid
60
 */
50
 */
61
public IType getType() throws JavaModelException {
51
public boolean equals(Object obj) {
62
	return this.type;
52
	if (obj == null) return false;
63
}
53
	return this.type.equals(obj);
64
65
/*
66
 * (non-Javadoc)
67
 * 
68
 * @see java.lang.Object#toString()
69
 */
70
public String toString() {
71
	return this.type.toString();
72
}
73
74
public IPackageFragmentRoot getPackageFragmentRoot() {
75
	return (IPackageFragmentRoot) this.type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
76
}
54
}
77
55
78
/**
56
/**
79
 * Fully qualified name of type (e.g. package name + '.' enclosing type names +
57
 * Returns the fully qualified name of stored type
80
 * '.' simple name)
58
 * (e.g. package name + '.' enclosing type names + '.' simple name)
81
 * 
59
 * 
60
 * @see #getType()
61
 * @see IType#getFullyQualifiedName(char)
82
 * @return Fully qualified type name of the type
62
 * @return Fully qualified type name of the type
83
 */
63
 */
84
public String getFullyQualifiedName() {
64
public String getFullyQualifiedName() {
Lines 86-112 Link Here
86
}
66
}
87
67
88
/**
68
/**
89
 * Fully qualified name of type (e.g. package name + '.' enclosing type names +
69
 * Returns the stored modifiers of the type.
90
 * '.' simple name)
70
 * This is a handle-only method.
91
 * 
71
 * 
92
 * @return Fully qualified type name of the type
72
 * @return the type modifiers
93
 */
73
 */
94
public String getTypeQualifiedName() {
74
public int getModifiers() {
95
	return this.type.getTypeQualifiedName('.');
75
	return this.modifiers;
96
}
76
}
97
77
98
/**
78
/**
99
 * Returns the modifiers of the type.
79
 * Returns the package fragment root of the stored type.
80
 * Package fragment root cannot be null and <strong>does</strong> exist.
100
 * 
81
 * 
101
 * @return the type modifiers
82
 * @see #getType()
83
 * @see IJavaElement#getAncestor(int)
84
 * @return the existing java model package fragment root (ie. cannot be <code>null</code>
85
 * 	and will return <code>true</code> to <code>exists()</code> message).
102
 */
86
 */
103
public int getModifiers() {
87
public IPackageFragmentRoot getPackageFragmentRoot() {
104
	return this.modifiers;
88
	return (IPackageFragmentRoot) this.type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
105
}
89
}
106
90
107
/**
91
/**
108
 * Returns the package name of the type.
92
 * Returns the package name of the stored type.
109
 * 
93
 * 
94
 * @see #getType()
95
 * @see IType#getPackageFragment()
110
 * @return the package name
96
 * @return the package name
111
 */
97
 */
112
public String getPackageName() {
98
public String getPackageName() {
Lines 114-121 Link Here
114
}
100
}
115
101
116
/**
102
/**
117
 * Returns the name of the type.
103
 * Returns the name of the stored type.
118
 * 
104
 * 
105
 * @see #getType()
106
 * @see IJavaElement#getElementName()
119
 * @return the type name
107
 * @return the type name
120
 */
108
 */
121
public String getSimpleTypeName() {
109
public String getSimpleTypeName() {
Lines 123-130 Link Here
123
}
111
}
124
112
125
/**
113
/**
126
 * Name of the type container (e.g. enclosing type names + '.' + simple name)
114
 * Returns the stored java model type. As this match was built while searching
115
 * for all types in index files, the stored type cannot be null and does exist.
116
 * This is a handle-only method.
117
 * 
118
 * @see IType
119
 * @return the existing java model type (ie. cannot be <code>null</code>
120
 * 	and will return <code>true</code> to <code>exists()</code> message).
121
 */
122
public IType getType() {
123
	return this.type;
124
}
125
126
/**
127
 * Name of the type container (e.g. enclosing type names + '.' + simple name).
127
 * 
128
 * 
129
 * @see #getType()
130
 * @see IMember#getDeclaringType()
128
 * @return Name of the type container
131
 * @return Name of the type container
129
 */
132
 */
130
public String getTypeContainerName() {
133
public String getTypeContainerName() {
Lines 135-138 Link Here
135
		return this.type.getPackageFragment().getElementName();
138
		return this.type.getPackageFragment().getElementName();
136
	}
139
	}
137
}
140
}
141
142
/**
143
 * Returns the qualified name of type
144
 * (e.g. enclosing type names + '.' simple name).
145
 * 
146
 * @see #getType()
147
 * @see IType#getTypeQualifiedName(char)
148
 * @return Fully qualified type name of the type
149
 */
150
public String getTypeQualifiedName() {
151
	return this.type.getTypeQualifiedName('.');
152
}
153
154
/**
155
 * Returns stored type hashCode.
156
 */
157
public int hashCode() {
158
	return this.type.hashCode();
159
}
160
161
/**
162
 * Returns stored type string.
163
 */
164
public String toString() {
165
	return this.type.toString();
166
}
138
}
167
}
(-)search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java (-1 / +1 lines)
Lines 809-815 Link Here
809
							}
809
							}
810
							if (match(typeSuffix, packageName, typeName, typeMatchRule, kind, packageDeclaration, simpleName)) {
810
							if (match(typeSuffix, packageName, typeName, typeMatchRule, kind, packageDeclaration, simpleName)) {
811
								if (nameRequestor instanceof TypeNameMatchRequestorWrapper) {
811
								if (nameRequestor instanceof TypeNameMatchRequestorWrapper) {
812
									((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new TypeNameMatch(type));
812
									((TypeNameMatchRequestorWrapper)nameRequestor).requestor.acceptTypeNameMatch(new TypeNameMatch(type, type.getFlags()));
813
								} else {
813
								} else {
814
									nameRequestor.acceptType(type.getFlags(), packageDeclaration, simpleName, enclosingTypeNames, path, null);
814
									nameRequestor.acceptType(type.getFlags(), packageDeclaration, simpleName, enclosingTypeNames, path, null);
815
								}
815
								}
(-)buildnotes_jdt-core.html (+40 lines)
Lines 51-58 Link Here
51
<br>Project org.eclipse.jdt.core v_717
51
<br>Project org.eclipse.jdt.core v_717
52
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_717">cvs</a>).
52
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_717">cvs</a>).
53
<h2>What's new in this drop</h2>
53
<h2>What's new in this drop</h2>
54
<ul>
55
<li>Added new <code>SearchEngine</code> API method for search all type names with multiple qualifications and type names
56
(see bug <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=160324">160324</a>).<br>
57
Only requestor differs from already existing corresponding <code>searchAllTypeNames</code> method:
58
<pre>
59
/**
60
 * Searches for all top-level types and member types in the given scope matching any of the given qualifications
61
 * and type names in a case sensitive way.
62
 *
63
 * Provided {@link TypeNameMatchRequestor} requestor will collect {@link TypeNameMatch}
64
 * matches found during the search.
65
...
66
 * @param nameMatchRequestor the {@link TypeNameMatchRequestor requestor} that collects
67
 * 				{@link TypeNameMatch matches} of the search.
68
...
69
 * @since 3.3
70
 */
71
public void searchAllTypeNames(
72
	final char[][] qualifications, 
73
	final char[][] typeNames,
74
	IJavaSearchScope scope, 
75
	final TypeNameMatchRequestor nameMatchRequestor,
76
	int waitingPolicy,
77
	IProgressMonitor progressMonitor)  throws JavaModelException
78
</pre>
79
Similarily to previous added <code>searchAllTypeNames</code> new API method, clients have to provide
80
a new requestor: <code>TypeNameMatchRequestor</code> in order to get matches collected during the search.
81
</li>
82
</ul>
54
83
55
<h3>Problem Reports Fixed</h3>
84
<h3>Problem Reports Fixed</h3>
85
<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=160494">160494</a>
86
[search] searchAllTypeNames(char[][], char[][],...) fails to find types in default package
87
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=160328">160328</a>
88
[search] Remove constructor TypeNameMatch(IType)
89
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=160327">160327</a>
90
[search] Add specification for TypeNameMatch.getType
91
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=160324">160324</a>
92
[search] SearchEngine.searchAllTypeNames(char[][], char[][], TypeNameMatchRequestor
93
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=160323">160323</a>
94
[search] TypeNameMatch: support hashCode/equals
95
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=160352">160352</a>
56
<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=90600">90600</a>
96
<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=90600">90600</a>
57
[model] CreateElementInCUOperation.apply: should use project options for rewriter
97
[model] CreateElementInCUOperation.apply: should use project options for rewriter
58
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=160352">160352</a>
98
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=160352">160352</a>
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (-17 / +184 lines)
Lines 85-118 Link Here
85
}
85
}
86
86
87
class TypeNameMatchCollector extends TypeNameMatchRequestor {
87
class TypeNameMatchCollector extends TypeNameMatchRequestor {
88
	private int index = -1;
88
	List matches = new ArrayList();
89
	public String[] results = new String[10];
90
	public void acceptTypeNameMatch(TypeNameMatch match) {
89
	public void acceptTypeNameMatch(TypeNameMatch match) {
91
		int length = results.length;
90
		IType type = match.getType();
92
		if (++index > length) {
91
		if (type != null) {
93
			System.arraycopy(results, 0, results = new String[length+10], 0, length);
92
			this.matches.add(type);
94
		}
93
		}
95
		try {
94
	}
96
			IType type = match.getType();
95
	public int size() {
97
			if (type != null) {
96
		return this.matches.size();
98
				results[index] = type.toString();
97
	}
98
	private String toString(int kind) {
99
		int size = size();
100
		if (size == 0) return "";
101
		String[] strings = new String[size];
102
		for (int i=0; i<size; i++) {
103
			IType type = (IType) this.matches.get(i);
104
			switch (kind) {
105
				case 1: // fully qualified name
106
					strings[i] = type.getFullyQualifiedName();
107
					break;
108
				case 0:
109
				default:
110
					strings[i] = type.toString();
99
			}
111
			}
100
		}
112
		}
101
		catch (JavaModelException jme) {
102
			assertTrue("We should not have any JavaModel exception! Message:"+jme.getMessage(), false);
103
		}
104
	}
105
	public String toString() {
106
		String[] strings = new String[index+1];
107
		System.arraycopy(results, 0, strings, 0, index+1);
108
		Arrays.sort(strings);
113
		Arrays.sort(strings);
109
		StringBuffer buffer = new StringBuffer();
114
		StringBuffer buffer = new StringBuffer();
110
		for (int i=0; i<=index; i++) {
115
		for (int i=0; i<size; i++) {
111
			if (i>0) buffer.append('\n');
116
			if (i>0) buffer.append('\n');
112
			buffer.append(strings[i]);
117
			buffer.append(strings[i]);
113
		}
118
		}
114
		return buffer.toString();
119
		return buffer.toString();
115
	}
120
	}
121
	public String toString() {
122
		return toString(0);
123
	}
124
	public String toFullyQualifiedNamesString() {
125
		return toString(1);
126
	}
116
}
127
}
117
IJavaSearchScope getJavaSearchScopeBugs() {
128
IJavaSearchScope getJavaSearchScopeBugs() {
118
	return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")});
129
	return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")});
Lines 7145-7148 Link Here
7145
	);
7156
	);
7146
}
7157
}
7147
7158
7159
/**
7160
 * @bug 160323: [search] TypeNameMatch: support hashCode/equals
7161
 * @test Ensure that match equals and hashCode methods return same values than those of stored {@link IType}.
7162
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=160323"
7163
 */
7164
public void testBug160323() throws CoreException {
7165
	// Search all type names with TypeNameMatchRequestor
7166
	TypeNameMatchCollector collector = new TypeNameMatchCollector() {
7167
		public void acceptTypeNameMatch(TypeNameMatch match) {
7168
			assertTrue("Problem with equals method for match "+match, match.equals(match.getType()));
7169
			assertEquals("Problem with hashCode method for match "+match, match.getType().hashCode(), match.hashCode());
7170
			super.acceptTypeNameMatch(match);
7171
		}
7172
		public String toString(){
7173
			return toFullyQualifiedNamesString();
7174
		}
7175
	};
7176
	new SearchEngine().searchAllTypeNames(
7177
		null,
7178
		SearchPattern.R_EXACT_MATCH,
7179
		null,
7180
		SearchPattern.R_PREFIX_MATCH,
7181
		IJavaSearchConstants.TYPE,
7182
		getJavaSearchScopeBugs(),
7183
		collector,
7184
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7185
		null);
7186
	// Search all type names with TypeNameRequestor
7187
	TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
7188
	new SearchEngine().searchAllTypeNames(
7189
		null,
7190
		SearchPattern.R_EXACT_MATCH,
7191
		null,
7192
		SearchPattern.R_PREFIX_MATCH,
7193
		IJavaSearchConstants.TYPE,
7194
		getJavaSearchScopeBugs(),
7195
		requestor,
7196
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7197
		null);
7198
	// Should have same types with these 2 searches
7199
	assertTrue("We should get some types!", collector.size() > 0);
7200
	assertEquals("Found types sounds not to be correct", requestor.toString(), collector.toString());
7201
}
7202
/**
7203
 * @bug 160324: [search] SearchEngine.searchAllTypeNames(char[][], char[][], TypeNameMatchRequestor
7204
 * @test Ensure that types found using {@link SearchEngine#searchAllTypeNames(char[][], char[][], IJavaSearchScope, TypeNameMatchRequestor, int, org.eclipse.core.runtime.IProgressMonitor) new API method}
7205
 * 	are the same than with already existing API method using {@link TypeNameRequestor}...
7206
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=160324"
7207
 */
7208
public void testBug160324a() throws CoreException {
7209
	// Search all type names with new API
7210
	TypeNameMatchCollector collector = new TypeNameMatchCollector() {
7211
		public void acceptTypeNameMatch(TypeNameMatch match) {
7212
			assertTrue("Problem with equals method for match "+match, match.equals(match.getType()));
7213
			assertEquals("Problem with hashCode method for match "+match, match.getType().hashCode(), match.hashCode());
7214
			super.acceptTypeNameMatch(match);
7215
		}
7216
		public String toString(){
7217
			return toFullyQualifiedNamesString();
7218
		}
7219
	};
7220
	new SearchEngine().searchAllTypeNames(
7221
		null,
7222
		null,
7223
		getJavaSearchScopeBugs(),
7224
		collector,
7225
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7226
		null);
7227
	assertEquals("We should not find any type", "", collector.toString());
7228
	// Search all type names with old API
7229
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
7230
	new SearchEngine().searchAllTypeNames(
7231
		null,
7232
		null,
7233
		getJavaSearchScopeBugs(),
7234
		requestor,
7235
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7236
		null);
7237
	assertEquals("We should not find any type", "", requestor.toString());
7238
}
7239
public void testBug160324b() throws CoreException {
7240
	// Search all type names with new API
7241
	TypeNameMatchCollector collector = new TypeNameMatchCollector() {
7242
		public String toString(){
7243
			return toFullyQualifiedNamesString();
7244
		}
7245
	};
7246
	new SearchEngine().searchAllTypeNames(
7247
		null,
7248
		new char[][] { "Test".toCharArray() },
7249
		getJavaSearchScopeBugs(),
7250
		collector,
7251
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7252
		null);
7253
	// Search all type names with old API
7254
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
7255
	new SearchEngine().searchAllTypeNames(
7256
		null,
7257
		new char[][] { "Test".toCharArray() },
7258
		getJavaSearchScopeBugs(),
7259
		requestor,
7260
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7261
		null);
7262
	// Should have same types with these 2 searches
7263
	assertTrue("We should get some types!", collector.size() > 0);
7264
	assertEquals("Found types sounds not to be correct", requestor.toString(), collector.toString());
7265
}
7266
7267
/**
7268
 * @bug 160494: [search] searchAllTypeNames(char[][], char[][],...) fails to find types in default package
7269
 * @test Ensure that types of default packge are found when empty package is specified in package lists
7270
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=160494"
7271
 */
7272
public void testBug160324c() throws CoreException {
7273
	boolean debug = false;
7274
	char[][] packagesList = new char[][] {
7275
			CharOperation.NO_CHAR,
7276
			"b110422".toCharArray(),
7277
			"b123679.test".toCharArray(),
7278
			"b89848".toCharArray(),
7279
			"b95794".toCharArray(),
7280
			"pack".toCharArray(),
7281
			"pack.age".toCharArray()
7282
	};
7283
	char[][] typesList = new char[][] {
7284
		"Test".toCharArray(),
7285
		"TestPrefix".toCharArray()
7286
	};
7287
	// Search all type names with new API
7288
	TypeNameMatchCollector collector = new TypeNameMatchCollector() {
7289
		public String toString(){
7290
			return toFullyQualifiedNamesString();
7291
		}
7292
	};
7293
	new SearchEngine().searchAllTypeNames(
7294
		packagesList,
7295
		typesList,
7296
		getJavaSearchScopeBugs(),
7297
		collector,
7298
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7299
		null);
7300
	if (debug) System.out.println("TypeNameMatchRequestor results: \n"+collector);
7301
	// Search all type names with old API
7302
	TypeNameRequestor requestor =  new SearchTests.SearchTypeNameRequestor();
7303
	new SearchEngine().searchAllTypeNames(
7304
		packagesList,
7305
		typesList,
7306
		getJavaSearchScopeBugs(),
7307
		requestor,
7308
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
7309
		null);
7310
	if (debug) System.out.println("TypeNameRequestor results: \n"+requestor);
7311
	// Should have same types with these 2 searches
7312
	assertEquals("Wrong number of found types!", packagesList.length, collector.size());
7313
	assertEquals("Found types sounds not to be correct", requestor.toString(), collector.toString());
7314
}
7148
}
7315
}

Return to bug 160323