TextRange (@NotNull PsiLiteralExpression expression) { int length = expression.getTextLength(); if (expression.isTextBlock()) { final String text = expression.getText(); int startOffset = findBlockStart(text); return startOffset < 0 ? new TextRange(0, length) : new TextRange(startOffset, length - (text.endsWith("\"\"\"") ? 3 : 0)); } // avoid calling PsiLiteralExpression.getValue(): it allocates new string, it returns null for invalid escapes final PsiType type = expression.getType(); boolean isQuoted = PsiTypes.charType().equals(type) || type != null && type.equalsToText(CommonClassNames.JAVA_LANG_STRING); return isQuoted ? new TextRange(1, Math.max(1, length - 1)) : TextRange.from(0, length); }