public static boolean isImplicitToStringCall(PsiExpression expression) {
    if (isStringConcatenationOperand(expression)) return true;

    PsiElement parent = PsiUtil.skipParenthesizedExprUp(expression.getParent());
    while (parent instanceof PsiConditionalExpression &&
           !PsiTreeUtil.isAncestor(((PsiConditionalExpression)parent).getCondition(), expression, false)) {
      parent = PsiUtil.skipParenthesizedExprUp(parent.getParent());
    }

    if (parent instanceof PsiExpressionList expressionList &&
        expressionList.getParent() instanceof PsiMethodCallExpression call &&
        IMPLICIT_TO_STRING_METHOD_NAMES.contains(call.getMethodExpression().getReferenceName())) {
      final PsiExpression[] arguments = expressionList.getExpressions();
      final PsiMethod method = call.resolveMethod();
      if (method == null) return false;
      @NonNls final String methodName = method.getName();
      final PsiClass containingClass = method.getContainingClass();
      if (containingClass == null) return false;
      final String className = containingClass.getQualifiedName();
      if (className == null) return false;
      return switch (methodName) {
        case "append" -> {
          if (arguments.length != 1) yield false;
          if (!className.equals(JAVA_LANG_STRING_BUILDER) &&
              !className.equals(JAVA_LANG_STRING_BUFFER)) {
            yield false;
          }
          yield !hasCharArrayParameter(method);
        }
        case "valueOf" -> {
          if (arguments.length != 1 || !JAVA_LANG_STRING.equals(className)) yield false;
          yield !hasCharArrayParameter(method);
        }
        case "print", "println" -> {
          if (arguments.length != 1 || hasCharArrayParameter(method)) yield false;
          yield JAVA_UTIL_FORMATTER.equals(className) ||
                InheritanceUtil.isInheritor(containingClass, JAVA_IO_PRINT_STREAM) ||
                InheritanceUtil.isInheritor(containingClass, JAVA_IO_PRINT_WRITER);
        }
        case "printf", "format" -> {
          if (arguments.length < 1) yield false;
          final PsiParameter[] parameters = method.getParameterList().getParameters();
          if (parameters.length == 0) yield false;
          final PsiParameter parameter = parameters[0];
          final PsiType firstParameterType = parameter.getType();
          final int minArguments = firstParameterType.equalsToText("java.util.Locale") ? 4 : 3;
          if (arguments.length < minArguments) yield false;
          yield JAVA_LANG_STRING.equals(className) || JAVA_UTIL_FORMATTER.equals(className) ||
                InheritanceUtil.isInheritor(containingClass, JAVA_IO_PRINT_STREAM) ||
                InheritanceUtil.isInheritor(containingClass, JAVA_IO_PRINT_WRITER);
        }
        default -> false;
      };
    }
    return false;
  }
public static boolean isImplicitToStringCall(PsiExpression expression)