StringBuilder (@Nullable PsiExpression concatenation, boolean useStringValueOf, @NonNls StringBuilder out) { if (concatenation == null) return null; final PsiType type = concatenation.getType(); if (concatenation instanceof PsiPolyadicExpression polyadicExpression && type != null && type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) { final PsiExpression[] operands = polyadicExpression.getOperands(); boolean isConstant = true; boolean isPrimitiveOrBoxed = true; boolean isString = false; final StringBuilder builder = new StringBuilder(); for (PsiExpression operand : operands) { final PsiType operandType = operand.getType(); isConstant &= PsiUtil.isConstantExpression(operand); isPrimitiveOrBoxed &= PsiPrimitiveType.getOptionallyUnboxedType(operandType) != null; if (isConstant || !isString && isPrimitiveOrBoxed) { if (!builder.isEmpty()) { builder.append('+'); } if (operandType != null && operandType.equalsToText(CommonClassNames.JAVA_LANG_STRING)) { isString = true; } builder.append(CommentTracker.textWithSurroundingComments(operand)); } else if (!operand.textMatches("\"\"")) { if (!builder.isEmpty()) { append(builder, useStringValueOf && !isString, out); builder.setLength(0); } buildAppendExpression(operand, useStringValueOf, out); } } if (!builder.isEmpty()) { append(builder, false, out); } } else if (concatenation instanceof PsiParenthesizedExpression parenthesizedExpression) { final PsiExpression expression = parenthesizedExpression.getExpression(); if (expression != null) { return buildAppendExpression(expression, useStringValueOf, out); } } else { append(CommentTracker.textWithSurroundingComments(concatenation), useStringValueOf && (type == null || !type.equalsToText(CommonClassNames.JAVA_LANG_STRING)), out); } return out; }