TextRange (PsiExpression expression, int from, int to) { if (to < 0 || from > to) return null; if (expression == null || !TypeUtils.isJavaLangString(expression.getType())) return null; if (expression instanceof PsiLiteralExpression literalExpression) { String value = tryCast(literalExpression.getValue(), String.class); if (value == null || value.length() < from || value.length() < to) return null; String text = expression.getText(); if (literalExpression.isTextBlock()) { int indent = PsiLiteralUtil.getTextBlockIndent(literalExpression); if (indent == -1) return null; return PsiLiteralUtil.mapBackTextBlockRange(text, from, to, indent); } return PsiLiteralUtil.mapBackStringRange(expression.getText(), from, to); } if (expression instanceof PsiParenthesizedExpression) { PsiExpression operand = ((PsiParenthesizedExpression)expression).getExpression(); TextRange range = findStringLiteralRange(operand, from, to); return range == null ? null : range.shiftRight(operand.getStartOffsetInParent()); } if (expression instanceof PsiPolyadicExpression concatenation) { if (concatenation.getOperationTokenType() != JavaTokenType.PLUS) return null; PsiExpression[] operands = concatenation.getOperands(); for (PsiExpression operand : operands) { Object constantValue = computeConstantExpression(operand); if (constantValue == null) return null; String stringValue = constantValue.toString(); if (from < stringValue.length()) { if (to > stringValue.length()) return null; TextRange range = findStringLiteralRange(operand, from, to); return range == null ? null : range.shiftRight(operand.getStartOffsetInParent()); } from -= stringValue.length(); to -= stringValue.length(); } } return null; }