PsiExpression (@NotNull PsiReferenceExpression referenceExpression, @Nullable PsiVariable variable) { if (variable == null) { final PsiElement target = referenceExpression.resolve(); if (!(target instanceof PsiVariable)) { return null; } variable = (PsiVariable)target; } final PsiCodeBlock block = PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class); if (block == null) { return null; } final PsiElement[] defs = DefUseUtil.getDefs(block, variable, referenceExpression); if (defs.length != 1) { return null; } final PsiElement def = defs[0]; if (def instanceof PsiVariable) { final PsiVariable target = (PsiVariable)def; final PsiExpression initializer = target.getInitializer(); return PsiUtil.skipParenthesizedExprDown(initializer); } else if (def instanceof PsiReferenceExpression) { final PsiElement parent = def.getParent(); if (!(parent instanceof PsiAssignmentExpression assignmentExpression)) { return null; } if (assignmentExpression.getOperationTokenType() != JavaTokenType.EQ) { return null; } return PsiUtil.skipParenthesizedExprDown(assignmentExpression.getRExpression()); } return null; }