void (PsiVariable variable, PsiVariable builderVariable, PsiAssignmentExpression assignment, CommentTracker ct) { PsiExpression rValue = PsiUtil.skipParenthesizedExprDown(assignment.getRExpression()); String builderName = Objects.requireNonNull(builderVariable.getName()); if(assignment.getOperationTokenType().equals(JavaTokenType.EQ)) { if (rValue instanceof PsiPolyadicExpression concat && ((PsiPolyadicExpression)rValue).getOperationTokenType().equals(JavaTokenType.PLUS)) { PsiExpression[] operands = concat.getOperands(); if (operands.length > 1) { // s = s + ...; if (ExpressionUtils.isReferenceTo(operands[0], variable)) { StreamEx.iterate(operands[1], nonNull(), PsiElement::getNextSibling).forEach(ct::markUnchanged); replaceAll(variable, builderVariable, rValue, ct, operands[0]::equals); StringBuilder replacement = ChangeToAppendUtil.buildAppendExpression(rValue, false, new StringBuilder(builderName)); if (replacement != null) { PsiMethodCallExpression result = (PsiMethodCallExpression)ct.replace(assignment, replacement.toString()); PsiMethodCallExpression append = getDeepestQualifierCall(result); PsiExpression qualifier = append.getMethodExpression().getQualifierExpression(); if (qualifier != null) { append.replace(qualifier); } makeNullSafe(operands[0], result); } return; } // s = ... + s; PsiExpression lastOp = operands[operands.length - 1]; if (ExpressionUtils.isReferenceTo(lastOp, variable)) { ct.delete(concat.getTokenBeforeOperand(lastOp), lastOp); replaceAll(variable, builderVariable, rValue, ct); makeNullSafe(lastOp, (PsiMethodCallExpression)ct.replace(assignment, builderName + ".insert(0," + ct.text(rValue) + ")")); return; } } } } if(rValue != null) { replaceAll(variable, builderVariable, rValue, ct); rValue = assignment.getRExpression(); } if(assignment.getOperationTokenType().equals(JavaTokenType.PLUSEQ)) { // s += ...; String replacement = ""; if (rValue != null) { StringBuilder sb = ChangeToAppendUtil.buildAppendExpression(ct.markUnchanged(rValue), false, new StringBuilder(builderName)); if (sb != null) { replacement = sb.toString(); } } makeNullSafe(assignment.getLExpression(), (PsiMethodCallExpression)ct.replace(assignment, replacement)); } else if(assignment.getOperationTokenType().equals(JavaTokenType.EQ)) { JavaCodeStyleManager.getInstance(variable.getProject()) .shortenClassReferences(ct.replace(assignment, builderName + "=" + generateNewStringBuilder(rValue, ct))); } }