PyImportStatementBase (final PsiElement element) { final PyImportStatementBase statement = PsiTreeUtil.getParentOfType(element, PyImportStatementBase.class, false); if (statement == null) { return null; } for (PyImportElement importElement : statement.getImportElements()) { if (element == importElement || element == importElement.getImportReferenceExpression()){ return statement; } } return null; }