@Nullable
  private List<PsiExpression> getMentionedExpressions(@NotNull PsiVariable var, @NotNull LocalSearchScope scope, @NotNull List<? extends PsiVariable> inputVariables) {
    if (myMentionedInExpressions.containsKey(var)) return myMentionedInExpressions.get(var);
    final PsiElement[] scopeElements = scope.getScope();

    List<PsiExpression> expressions = null;
    Boolean arrayAccess = null;
    List<PsiElement> refExpressions = ReferencesSearch.search(var, scope).findAll().stream()
      .map(ref -> ref.getElement())
      .sorted(Comparator.comparingInt(element -> element.getTextRange().getStartOffset()))
      .toList();
    for (PsiElement expression : refExpressions) {
      if (expressions == null) {
        expressions = new ArrayList<>();
        while (expression instanceof PsiExpression) {
          if (isAccessedForWriting((PsiExpression)expression)) {
            return null;
          }
          if (isAncestor(expression, scopeElements)) {
            break;
          }
          if (dependsOnLocals(expression, inputVariables)) {
            break;
          }
          final PsiElement parent = expression.getParent();
          if (parent instanceof PsiExpressionStatement) {
            break;
          }
          final PsiType expressionType = ((PsiExpression)expression).getType();
          if (expressionType == null || PsiTypes.voidType().equals(expressionType)) {
            break;
          }
          if (isTooLongExpressionChain(expression)) {
            break;
          }
          if (!isMethodNameExpression(expression)) {
            expressions.add((PsiExpression)expression);
          }
          if (expression instanceof PsiArrayAccessExpression && (arrayAccess == null || arrayAccess)) {
            arrayAccess = isSafeToFoldArrayAccess(scope, expression);
          }
          expression = PsiTreeUtil.getParentOfType(expression, PsiExpression.class);
        }
      }
      else {
        for (Iterator<PsiExpression> iterator = expressions.iterator(); iterator.hasNext();) {
          PsiExpression equivalent = findEquivalent(iterator.next(), expression);
          if (equivalent == null) {
            iterator.remove();
          }
          else if (equivalent instanceof PsiArrayAccessExpression && (arrayAccess == null || arrayAccess)) {
            arrayAccess = isSafeToFoldArrayAccess(scope, equivalent);
          }
        }
      }
    }
    if (arrayAccess != null && arrayAccess) {
      myFoldingSelectedByDefault = true;
    }
    myMentionedInExpressions.put(var, expressions);
    return expressions;
  }
@Nullable
  private List<PsiExpression> getMentionedExpressions(@NotNull PsiVariable var, @NotNull LocalSearchScope scope, @NotNull List<? extends PsiVariable> inputVariables)