List<PsiReferenceExpression> (@NotNull PsiVariable variable) { PsiElement context = variable instanceof PsiField ? ((PsiField)variable).getContainingClass() : PsiUtil.getVariableCodeBlock(variable, null); List<PsiReferenceExpression> references = new ArrayList<>(VariableAccessUtils.getVariableReferences(variable, context)); references.removeIf(ref -> !PsiUtil.isAccessedForWriting(ref)); return ContainerUtil.filter(references, r1 -> (r1.getParent() instanceof PsiAssignmentExpression assignment && !ExpressionUtils.isVoidContext(assignment)) || !ContainerUtil.exists(references, r2 -> r1 != r2 && PsiTreeUtil.isAncestor(r2.getParent(), r1, true))); }