class BuildListCalculator {
    public ProjectBuildList calculateProjectBuilds(MavenSession session, List<TaskSegment> taskSegments) {<FILL_FUNCTION_BODY>}
}

        List<ProjectSegment> projectBuilds = new ArrayList<>();

        MavenProject rootProject = session.getTopLevelProject();

        for (TaskSegment taskSegment : taskSegments) {
            List<MavenProject> projects;

            if (taskSegment.isAggregating()) {
                projects = Collections.singletonList(rootProject);
            } else {
                projects = session.getProjects();
            }
            for (MavenProject project : projects) {
                ClassLoader tccl = Thread.currentThread().getContextClassLoader();
                MavenProject currentProject = session.getCurrentProject();
                try {
                    BuilderCommon.attachToThread(project); // Not totally sure if this is needed for anything
                    session.setCurrentProject(project);
                    projectBuilds.add(new ProjectSegment(project, taskSegment, session));
                } finally {
                    session.setCurrentProject(currentProject);
                    Thread.currentThread().setContextClassLoader(tccl);
                }
            }
        }
        return new ProjectBuildList(projectBuilds);
    
<no_super_class>