void (@NotNull PsiReferenceExpression referenceExpression) { if (calculateTypeForComplexReferences) { final Project project = referenceExpression.getProject(); final JavaResolveResult resolveResult = referenceExpression.advancedResolve(false); final PsiElement element = resolveResult.getElement(); PsiSubstitutor substitutor = resolveResult.getSubstitutor(); final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); if (element instanceof PsiField field) { if (!isAccessibleFrom(field, referenceExpression)) { return; } final PsiClass aClass = field.getContainingClass(); if (aClass == null) { return; } final PsiElementFactory factory = psiFacade.getElementFactory(); expectedType = factory.createType(aClass, substitutor); } else if (element instanceof PsiMethod method) { final PsiElement parent = referenceExpression.getParent(); final PsiType returnType; if (parent instanceof PsiMethodCallExpression methodCallExpression) { final PsiType type = methodCallExpression.getType(); if (!PsiTypes.voidType().equals(type)) { returnType = findExpectedType(methodCallExpression, true); } else { returnType = null; } } else { returnType = null; } final PsiClass methodContainingClass = method.getContainingClass(); if (methodContainingClass == null) { return; } final PsiMethod superMethod = findDeepestVisibleSuperMethod(method, returnType, referenceExpression); final PsiClass aClass; if (superMethod != null) { aClass = superMethod.getContainingClass(); if (aClass == null) { return; } substitutor = TypeConversionUtil.getSuperClassSubstitutor(aClass, methodContainingClass, substitutor); } else { aClass = methodContainingClass; } final PsiElementFactory factory = psiFacade.getElementFactory(); expectedType = factory.createType(aClass, substitutor); } else { expectedType = null; } } }