PyExpression () { String qualifiedName = myElement.getText(); if (qualifiedName == null) { return null; } String description; try { description = myCommunication.getDescription(qualifiedName); if (Strings.isNullOrEmpty(description)) { return null; } } catch (ProcessCanceledException e) { return null; } catch (Exception e) { LOG.warn(e); return null; } PyElementGenerator generator = PyElementGenerator.getInstance(myElement.getProject()); PyFile dummyFile = (PyFile)generator.createDummyFile(LanguageLevel.forElement(myElement), description); Module module = ModuleUtilCore.findModuleForPsiElement(myElement); if (module != null) { dummyFile.putUserData(ModuleUtilCore.KEY_MODULE, module); } List<PyStatement> statements = dummyFile.getStatements(); PyStatement pyStatement = statements.get(statements.size() - 1); return pyStatement instanceof PyExpressionStatement ? ((PyExpressionStatement)pyStatement).getExpression() : null; }