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 |
} |