PsiLocalVariable (@NotNull PsiLocalVariable variable, @NotNull PsiAssignmentExpression assignment) { PsiExpression initializer = getInitializerExpression(variable, assignment); PsiElement elementToReplace = assignment.getParent(); if (elementToReplace != null) { PsiLocalVariable varCopy = copyVarWithInitializer(variable, initializer); if (varCopy != null) { String text = varCopy.getText(); CommentTracker tracker = new CommentTracker(); tracker.markUnchanged(initializer); tracker.markUnchanged(variable); tracker.delete(variable); PsiDeclarationStatement decl = (PsiDeclarationStatement)tracker.replaceAndRestoreComments(elementToReplace, text); return ((PsiLocalVariable)decl.getDeclaredElements()[0]); } } return variable; }