boolean () { if (PsiTreeUtil.getParentOfType(myElement, PyImportStatement.class) != null) { return true; } ASTNode node = myElement.getNode(); while (node != null) { final IElementType nodeType = node.getElementType(); if (nodeType == PyTokenTypes.IMPORT_KEYWORD) { return true; } node = node.getTreeNext(); } return false; }