void (PsiVariable variable, PsiJavaCodeReferenceElement stringBuilderClassReference) { final List<PsiReferenceExpression> references = VariableAccessUtils.getVariableReferences(variable, PsiUtil.getVariableCodeBlock(variable, null)); for (PsiReference reference : references) { final PsiElement referenceElement = PsiUtil.skipParenthesizedExprUp(reference.getElement().getParent()); if (referenceElement instanceof PsiAssignmentExpression assignmentExpression) { final PsiExpression rhs = assignmentExpression.getRExpression(); final PsiExpression newExpression = getNewStringBuffer(rhs); if (!(newExpression instanceof PsiNewExpression)) { continue; } final PsiJavaCodeReferenceElement classReference = ((PsiNewExpression)newExpression).getClassReference(); if (classReference == null) { continue; } classReference.replace(stringBuilderClassReference); } } }