void (@NotNull Project project, @NotNull PsiElement startElement, @NotNull ModPsiUpdater updater) { PsiExpression expression = PsiTreeUtil.getParentOfType(startElement, PsiExpression.class); if (expression == null) return; if (!(getAppendedVariable(expression) instanceof PsiLocalVariable variable)) return; variable.normalizeDeclaration(); PsiTypeElement typeElement = variable.getTypeElement(); CommentTracker ct = new CommentTracker(); StringBuilderReplacer replacer = new StringBuilderReplacer(myTargetType, myNullSafe); replacer.replaceAll(variable, variable, null, ct); ct.replace(typeElement, myTargetType); PsiExpression initializer = variable.getInitializer(); if (initializer != null) { JavaCodeStyleManager.getInstance(project) .shortenClassReferences(ct.replace(initializer, replacer.generateNewStringBuilder(initializer, ct))); } PsiStatement commentPlace = PsiTreeUtil.getParentOfType(variable, PsiStatement.class); ct.insertCommentsBefore(commentPlace == null ? variable : commentPlace); }