PsiExpression () { SelectionModel selectionModel = getEditor().getSelectionModel(); if (selectionModel.hasSelection()) { return IntroduceVariableUtil.getSelectedExpression(getProject(), getFile(), selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()); } final PsiExpression expression = super.getExpressionFromEditor(); if (expression != null) { return expression; } final PsiExpression expr = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiExpression.class); if (expr == null && InjectedLanguageManager.getInstance(getProject()).isInjectedFragment(getFile())) { PsiElement element = getFile(); return PsiTreeUtil.getParentOfType(InjectedLanguageManager.getInstance(element.getProject()).getTopLevelFile(element) .findElementAt(InjectedLanguageUtil.getTopLevelEditor(getEditor()).getCaretModel().getOffset()), PsiExpression.class); } return expr instanceof PsiLiteralExpression ? expr : null; }