WeakHashMap<ICompilationUnit, Object> collection = (WeakHashMap<ICompilationUnit, Object>)mapValue;
List<ICompilationUnit> result = new ArrayList<ICompilationUnit>(collection.size());
Iterator<Map.Entry<ICompilationUnit, Object>> iter = collection.entrySet().iterator();
while (iter.hasNext())
{
ICompilationUnit compilationUnit = iter.next().getKey();
// We are dealing with a WeakHashMap, here so it
// is possible that the CompilationUnit has been gc'd.
if (compilationUnit != null)
{
// The CompilationUnit might not be in a project
// any more. We should only return CompilationUnit's
// that are in a project.
ICompilerProject projFromCU = compilationUnit.getProject();
if ((projFromCU != null) && (projFromCU == project))
{
result.add(compilationUnit);
iter.remove();
}
}
}
if (!collection.isEmpty())
map.put(sortKey, collection);
return Collections.unmodifiableList(result);
}
else
{
ICompilationUnit compilationUnit = ((WeakReference<ICompilationUnit>)mapValue).get();
if (compilationUnit == null)
return Collections.emptyList();
// if projects don't match, add the map value back in, otherwise return the
// removed CU
if ((compilationUnit != null) && (compilationUnit.getProject() == project))
return Collections.singletonList(compilationUnit);
else
map.put(sortKey, mapValue);
return Collections.emptyList();