void (@NotNull Collection<? extends ProjectTask> tasks, @NotNull Consumer<? super Collection<? extends ProjectTask>> consumer) { if (tasks.isEmpty()) return; for (ProjectTask child : tasks) { Collection<? extends ProjectTask> taskDependencies; if (child instanceof AbstractProjectTask) { taskDependencies = ((AbstractProjectTask)child).getDependsOn(); } else if (child instanceof ProjectTaskList) { taskDependencies = (ProjectTaskList)child; } else { taskDependencies = emptyList(); } visitTasks(taskDependencies, consumer); } consumer.accept(tasks); }