diff options
Diffstat (limited to 'python/src/com/jetbrains/python/psi/PyUtil.java')
-rw-r--r-- | python/src/com/jetbrains/python/psi/PyUtil.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/python/src/com/jetbrains/python/psi/PyUtil.java b/python/src/com/jetbrains/python/psi/PyUtil.java index 877da8df6dd9..cd4e582bb6f2 100644 --- a/python/src/com/jetbrains/python/psi/PyUtil.java +++ b/python/src/com/jetbrains/python/psi/PyUtil.java @@ -901,6 +901,20 @@ public class PyUtil { } /** + * Returns first child psi element with specified element type or {@code null} if no such element exists. + * Semantically it's the same as {@code getChildByFilter(element, TokenSet.create(type), 0)}. + * + * @param element tree parent node + * @param type element type expected + * @return child element described + */ + @Nullable + public static PsiElement getFirstChildOfType(@NotNull final PsiElement element, @NotNull PyElementType type) { + final ASTNode child = element.getNode().findChildByType(type); + return child != null ? child.getPsi() : null; + } + + /** * If argument is a PsiDirectory, turn it into a PsiFile that points to __init__.py in that directory. * If there's no __init__.py there, null is returned, there's no point to resolve to a dir which is not a package. * Alas, resolve() and multiResolve() can't return anything but a PyFile or PsiFileImpl.isPsiUpToDate() would fail. @@ -1645,6 +1659,11 @@ public class PyUtil { return Collections2.filter(pyMemberInfos, new ObjectPredicate(false)); } + public static boolean isStarImportableFrom(@NotNull String name, @NotNull PyFile file) { + final List<String> dunderAll = file.getDunderAll(); + return dunderAll != null ? dunderAll.contains(name) : !name.startsWith("_"); + } + /** * Filters only pyclass object (new class) */ |