PyElement () { PyDocStringOwner owner = PsiTreeUtil.getParentOfType(getElement(), PyDocStringOwner.class); if (owner instanceof PyFunction) { return resolveParameter((PyFunction)owner); } if (owner instanceof PyClass pyClass) { final PyFunction init = pyClass.findMethodByName(PyNames.INIT, false, null); if (myType == ReferenceType.PARAMETER) { return init != null ? resolveParameter(init) : resolveClassVariable(pyClass); } if (myType == ReferenceType.INSTANCE_VARIABLE || myType == ReferenceType.VARIABLE || myType == ReferenceType.PARAMETER_TYPE) { if (myType == ReferenceType.PARAMETER_TYPE && init != null) { PyNamedParameter parameter = resolveParameter(init); if (parameter != null) { return parameter; } } final PyElement instanceAttr = resolveInstanceVariable(pyClass); return instanceAttr != null ? instanceAttr : resolveClassVariable(pyClass); } if (myType == ReferenceType.CLASS_VARIABLE) { return resolveClassVariable(pyClass); } } if (owner instanceof PyFile && myType == ReferenceType.GLOBAL_VARIABLE) { return resolveGlobalVariable(((PyFile)owner)); } return null; }