}
}
@Override
public List<ModulesKey> getModulesWithToken(String token, IProgressMonitor monitor) {
FastStringBuffer temp = new FastStringBuffer();
ArrayList<ModulesKey> ret = new ArrayList<ModulesKey>();
if (monitor == null) {
monitor = new NullProgressMonitor();
}
if (token == null || token.length() == 0) {
return ret;
}
for (int i = 0; i < token.length(); i++) {
if (!Character.isJavaIdentifierPart(token.charAt(i))) {
throw new RuntimeException(com.aptana.shared_core.string.StringUtils.format("Token: %s is not a valid token to search for.", token));
}
}
synchronized (lock) {
FastStringBuffer bufProgress = new FastStringBuffer();
//Note that this operation is not as fast as the others, as it relies on a cache that is optimized
//for space and not for speed (but still, should be faster than having to do a text-search to know the
//tokens when the cache is available).
Tuple<List<Tuple<CompleteIndexKey, CompleteIndexValue>>, Collection<CompleteIndexKey>> memoryInfo = completeIndex
.getInMemoryInfo();
long last = System.currentTimeMillis();
int worked = 0;
try {
monitor.beginTask("Get modules with token", memoryInfo.o1.size() + memoryInfo.o2.size());
for (Tuple<CompleteIndexKey, CompleteIndexValue> tup : memoryInfo.o1) {
CompleteIndexKey indexKey = tup.o1;
CompleteIndexValue obj = tup.o2;
worked++;
if (monitor.isCanceled()) {
return ret;
}
long current = System.currentTimeMillis();
if (last + 200 < current) {
last = current;
monitor.setTaskName(bufProgress.clear().append("Searching: ").append(indexKey.key.name)
.toString());
monitor.worked(worked);
}
check(indexKey, obj, temp, token, ret);
}
for (CompleteIndexKey indexKey : memoryInfo.o2) {
worked++;
if (monitor.isCanceled()) {
return ret;
}
long current = System.currentTimeMillis();
if (last + 200 < current) {
last = current;
monitor.setTaskName(bufProgress.clear().append("Searching: ").append(indexKey.key.name)
.toString());
monitor.worked(worked);
}
check(indexKey, null, temp, token, ret);
}