PsiElement (PsiReference ref, Resolver resolver, boolean needToPreventRecursion, boolean incompleteCode) { ProgressManager.getInstance().checkCanceled(); int clearCountOnStart; synchronized (PsiLock.LOCK) { clearCountOnStart = myClearCount; } boolean physical = ref.getElement().isPhysical(); final Reference<PsiElement> cached = getCachedResolve(ref, physical, incompleteCode); if (cached != null) return cached.get(); if (incompleteCode) { final PsiElement results = resolveWithCaching(ref, resolver, needToPreventRecursion, false); if (results != null) { setCachedResolve(ref, results, physical, true, clearCountOnStart); return results; } } if (!lockElement(ref, needToPreventRecursion)) return null; PsiElement result = null; try { result = resolver.resolve(ref, incompleteCode); } finally{ unlockElement(ref, needToPreventRecursion); } setCachedResolve(ref, result, physical, incompleteCode, clearCountOnStart); return result; }