PsiVariable (@NotNull PsiExpression expression) { final PsiElement parent = getParent(expression); if (parent instanceof PsiAssignmentExpression assignment) { final PsiExpression lhs = assignment.getLExpression(); if (!(lhs instanceof PsiReferenceExpression referenceExpression)) { return null; } final PsiElement referent = referenceExpression.resolve(); if (!(referent instanceof PsiVariable)) { return null; } return (PsiVariable)referent; } if (parent instanceof PsiVariable) { return (PsiVariable)parent; } if (parent instanceof PsiConditionalExpression) { return getVariable((PsiExpression)parent); } return null; }