/** * Adds type and description representation from function docstring * * @param parameter parameter of a function * @return true if type from docstring was added */ private boolean addTypeAndDescriptionFromDocstring(@NotNull final PyNamedParameter parameter) { final PyFunction function = PsiTreeUtil.getParentOfType(parameter, PyFunction.class); if (function != null) { final String docString = PyPsiUtils.strValue(function.getDocStringExpression()); final Pair<String, String> typeAndDescr = getTypeAndDescription(docString, parameter); final String type = typeAndDescr.first; final String description = typeAndDescr.second; if (type != null) { final PyType pyType = PyTypeParser.getTypeByName(parameter, type); if (pyType instanceof PyClassType) { myBody .addItem(": ") .addWith( new LinkWrapper(PythonDocumentationProvider.LINK_TYPE_PARAM), $(pyType.getName())); } else { myBody.addItem(": ").addItem(type); } } if (description != null) { myEpilog.addItem(BR).addItem(description); } return type != null; } return false; }
public PyFunctionStub createStub(@NotNull final PyFunction psi, final StubElement parentStub) { PyFunctionImpl function = (PyFunctionImpl) psi; String message = function.extractDeprecationMessage(); final PyStringLiteralExpression docStringExpression = function.getDocStringExpression(); return new PyFunctionStubImpl( psi.getName(), PyPsiUtils.strValue(docStringExpression), message == null ? null : StringRef.fromString(message), parentStub, getStubElementType()); }