private static List<PsiReferenceExpression> collectReferences(@NotNull PsiVariable variable) {
    List<PsiReferenceExpression> references = new ArrayList<>(VariableAccessUtils.getVariableReferences(variable));
    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)));
  }
private static List<PsiReferenceExpression> collectReferences(@NotNull PsiVariable variable)