PsiType (@NotNull final GrVariable var) { return RecursionManager.doPreventingRecursion(var, false, (NullableComputable<PsiType>)() -> { final Collection<PsiReference> all = ReferencesSearch.search(var, var.getUseScope()).findAll(); final GrExpression initializer = var.getInitializerGroovy(); if (initializer == null && all.isEmpty()) { return var.getDeclaredType(); } PsiType result = initializer != null ? initializer.getType() : null; final PsiManager manager = var.getManager(); for (PsiReference reference : all) { final PsiElement ref = reference.getElement(); if (ref instanceof GrReferenceExpression && PsiUtil.isLValue(((GrReferenceExpression)ref))) { result = TypesUtil.getLeastUpperBoundNullable(result, TypeInferenceHelper.getInitializerTypeFor(ref), manager); } } return result; }); }