File (final ModuleDescriptor module, final File contentRoot) { final Set<File> moduleRoots = module.getContentRoots(); for (File moduleRoot : moduleRoots) { if (FileUtil.isAncestor(moduleRoot, contentRoot, false)) { return moduleRoot; // no need to include a separate root } if (FileUtil.isAncestor(contentRoot, moduleRoot, true)) { final Collection<DetectedSourceRoot> currentSources = module.getSourceRoots(moduleRoot); module.removeContentRoot(moduleRoot); module.addContentRoot(contentRoot); for (DetectedSourceRoot source : currentSources) { module.addSourceRoot(contentRoot, source); } return contentRoot; // no need to include a separate root } } module.addContentRoot(contentRoot); return contentRoot; }