PsiType (PsiExpression expr, Function<PsiExpression, PsiType> f) { WeakReference<PsiType> ref; synchronized (PsiLock.LOCK) { ref = myCaclulatedlTypes.get(expr); } PsiType type = ref == null ? null : ref.get(); if (type == null) { type = f.fun(expr); synchronized (PsiLock.LOCK) { myCaclulatedlTypes.put(expr, new WeakReference<PsiType>(type)); } } return type; }