boolean (@NotNull String name, @NotNull PsiElement startElement, @Nullable PsiElement call) { if (startElement instanceof PsiFile) { return true; } PsiElement prevSibling = startElement.getPrevSibling(); while (prevSibling != null) { if (!isValidNameDown(name, prevSibling, call)) { return false; } prevSibling = prevSibling.getPrevSibling(); } PsiElement parent = startElement.getParent(); return parent == null || parent instanceof PsiDirectory || isValidNameUp(name, parent, call); }