Document (final @NotNull Project project, @NotNull XExpression expression, final @Nullable XSourcePosition sourcePosition, @NotNull EvaluationMode mode) { String text = expression.getExpression().trim(); final PyExpressionCodeFragmentImpl fragment = new PyExpressionCodeFragmentImpl(project, "fragment.py", text, true); // Bind to context final PsiElement element = getContextElement(project, sourcePosition); fragment.setContext(element); return PsiDocumentManager.getInstance(project).getDocument(fragment); }