PsiElement (PsiFile file, int selectionStart, int selectionEnd) { final PsiElement elementAtSelectionStart = file.findElementAt(selectionStart); final PsiElement elementAtSelectionEnd = file.findElementAt(selectionEnd); if (elementAtSelectionStart == null || elementAtSelectionEnd == null || elementAtSelectionEnd.getNode().getElementType() != elementAtSelectionStart.getNode().getElementType()) { return null; } if (!isStringLiteral(elementAtSelectionStart) && !isCharLiteral(elementAtSelectionStart) && !isTextBlock(elementAtSelectionStart)) { return null; } final TextRange startTextRange = getEscapedRange(elementAtSelectionStart); final TextRange endTextRange = getEscapedRange(elementAtSelectionEnd); if (startTextRange == null || endTextRange == null || !startTextRange.containsOffset(selectionStart) || !endTextRange.containsOffset(selectionEnd)) { return null; } return elementAtSelectionStart; }