PsiExpression (@NotNull PsiExpression expression, String stringToReplace, String replaceByString) { Project project = expression.getProject(); final ReplaceOptions options = new ReplaceOptions(); final MatchOptions matchOptions = options.getMatchOptions(); matchOptions.setFileType(JavaFileType.INSTANCE); final String replacement = Replacer.testReplace(expression.getText(), stringToReplace, replaceByString, options, project); return (PsiExpression)JavaCodeStyleManager.getInstance(project).shortenClassReferences(expression.replace( JavaPsiFacade.getElementFactory(project).createExpressionFromText(replacement, expression))); }