PsiType (PsiExpression expr, Function<PsiExpression, PsiType> f) { WeakReference<PsiType> ref = myCaclulatedlTypes.get(expr); PsiType type = ref == null ? null : ref.get(); if (type == null) { type = f.fun(expr); WeakReference<PsiType> existingRef = ConcurrencyUtil.cacheOrGet(myCaclulatedlTypes, expr, new WeakReference<PsiType>(type)); PsiType existing = existingRef.get(); if (existing != null) type = existing; } assert type == null || type.isValid(); return type; }