private List<Type> compact(LoadingCache<TypeElement, Type> cache) {
// had some weird race condition when using the live view on the values
final ArrayList<Type> copy = new ArrayList<>(cache.asMap().values());
for (Type type : copy) {
Type current = type;
while (true) {
final Element element = current.getElement().getEnclosingElement();
if (element instanceof PackageElement) {
break;
}
final Type parent;
try {
parent = cache.get((TypeElement) element);
} catch (ExecutionException e) {
throw new AssertionError(e);
}
parent.getTypes().add(current);
current = parent;
}
}
final List<Type> types = new ArrayList<>(cache.asMap().values());