void (@NotNull final Project project, @NotNull ProjectSystemId projectSystemId, @NotNull ProjectData projectData, ProjectNode projectNode) { ExternalSystemApiUtil.getLocalSettings(project, projectSystemId). forgetExternalProjects(Collections.singleton(projectData.getLinkedExternalProjectPath())); ExternalSystemApiUtil.getSettings(project, projectSystemId).unlinkExternalProject(projectData.getLinkedExternalProjectPath()); ExternalProjectsManagerImpl.getInstance(project).forgetExternalProjectData(projectSystemId, projectData.getLinkedExternalProjectPath()); // Process orphan modules. List<Module> orphanModules = new ArrayList<>(); for (Module module : ModuleManager.getInstance(project).getModules()) { if (!ExternalSystemApiUtil.isExternalSystemAwareModule(projectSystemId, module)) continue; String path = ExternalSystemApiUtil.getExternalRootProjectPath(module); if (projectData.getLinkedExternalProjectPath().equals(path)) { orphanModules.add(module); } } if (!orphanModules.isEmpty()) { if (projectNode != null) { projectNode.getGroup().remove(projectNode); } ProjectDataManagerImpl.getInstance().removeData( ProjectKeys.MODULE, orphanModules, Collections.emptyList(), projectData, project, false); } }