PsiExpressionStatement (@NotNull PsiElement parent, @NotNull PsiElement anchor, @NotNull String varName, @NotNull PsiExpression initializer) { PsiElementFactory elementFactory = PsiElementFactory.getInstance(parent.getProject()); String assignmentText = varName + "=" + initializer.getText() + ";"; PsiExpressionStatement assignment = (PsiExpressionStatement)elementFactory.createStatementFromText(assignmentText, parent); assignment = (PsiExpressionStatement)parent.addBefore(assignment, anchor); JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(parent.getProject()); return (PsiExpressionStatement)codeStyleManager.shortenClassReferences(assignment); }