boolean (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(CommonClassNames.JAVA_LANG_STRING_BUILDER) && !className.equals(CommonClassNames.JAVA_LANG_STRING_BUFFER)) { yield false; } yield !hasCharArrayParameter(method); } case "valueOf" -> { if (arguments.length != 1 || !CommonClassNames.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.PrintStream") || InheritanceUtil.isInheritor(containingClass, "java.io.PrintWriter"); } 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 CommonClassNames.JAVA_LANG_STRING.equals(className) || "java.util.Formatter".equals(className) || InheritanceUtil.isInheritor(containingClass, "java.io.PrintStream") || InheritanceUtil.isInheritor(containingClass, "java.io.PrintWriter"); } default -> false; }; } return false; }