public static boolean isExpressionUsed(PsiElement expr) {
    while (expr.getParent() instanceof GrParenthesizedExpression) expr = expr.getParent();

    PsiElement parent = expr.getParent();
    if (parent instanceof GrBinaryExpression ||
        parent instanceof GrUnaryExpression ||
        parent instanceof GrConditionalExpression ||
        parent instanceof GrAssignmentExpression ||
        parent instanceof GrInstanceOfExpression ||
        parent instanceof GrSafeCastExpression ||
        parent instanceof GrTuple ||
        parent instanceof GrArgumentList ||
        parent instanceof GrReturnStatement ||
        parent instanceof GrAssertStatement ||
        parent instanceof GrThrowStatement ||
        parent instanceof GrSwitchStatement ||
        parent instanceof GrVariable ||
        parent instanceof GrWhileStatement) {
      return true;
    }

    if (parent instanceof GrReferenceExpression) {
      if (ResolveUtil.isClassReference(parent)) {
        parent = parent.getParent();
      }
      if (parent instanceof GrReferenceExpression) {
        PsiElement resolved = ((GrReferenceExpression)parent).resolve();
        if (resolved instanceof PsiMember) {
          PsiClass containingClass = ((PsiMember)resolved).getContainingClass();
          return containingClass != null && JAVA_LANG_CLASS.equals(containingClass.getQualifiedName());
        }
      }
      return true;
    }

    if (parent instanceof GrTraditionalForClause forClause) {
      return expr == forClause.getCondition();
    }

    return isReturnStatement(expr);
  }
public static boolean isExpressionUsed(PsiElement expr)