PsiLiteralExpression (@Nullable final PsiLiteralExpression expression) { if (expression == null) return null; final Object value = expression.getValue(); if (value == null) return expression; final @NonNls StringBuilder newExpression = new StringBuilder(); final String leftText = value.toString(); if (expression.isTextBlock()) { final String indent = StringUtil.repeat(" ", PsiLiteralUtil.getTextBlockIndent(expression)); newExpression.append("\"\"\"").append('\n').append(indent); newExpression.append(leftText.replace("\n", "\n" + indent)); newExpression.append("%n"); newExpression.append("\"\"\""); } else { newExpression.append('"'); newExpression.append(StringUtil.escapeStringCharacters(leftText)); newExpression.append("%n"); newExpression.append('"'); } final PsiElementFactory factory = JavaPsiFacade.getElementFactory(expression.getProject()); return (PsiLiteralExpression)factory.createExpressionFromText(newExpression.toString(), null); }