PsiElement (@NotNull PsiExpression expression, @NotNull @NonNls String newExpressionText) { final Project project = expression.getProject(); final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); final PsiElementFactory factory = psiFacade.getElementFactory(); final PsiExpression newExpression = factory.createExpressionFromText(newExpressionText, expression); final PsiElement replacementExp = expression.replace(newExpression); final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(project); javaCodeStyleManager.shortenClassReferences(replacementExp); final CodeStyleManager styleManager = CodeStyleManager.getInstance(project); return styleManager.reformat(replacementExp); }