PyStringElement (@NotNull Editor editor, @NotNull PsiFile file) { PsiElement elementUnderCaret = file.findElementAt(editor.getCaretModel().getOffset()); if (elementUnderCaret == null) return null; IElementType elementType = elementUnderCaret.getNode().getElementType(); if (!(PyTokenTypes.STRING_NODES.contains(elementType) || PyTokenTypes.FSTRING_TOKENS.contains(elementType))) return null; PyStringElement stringElement = PsiTreeUtil.getParentOfType(elementUnderCaret, PyStringElement.class, false, PyExpression.class); return stringElement != null && PyQuotesUtil.canBeConverted(stringElement, true) ? stringElement : null; }