ModuleDescriptor (final ModuleDescriptor descriptor, String newModuleName, final Collection<? extends File> contentsToExtract) { ModuleDescriptor newModule = null; for (File root : contentsToExtract) { final Collection<DetectedSourceRoot> sources = descriptor.removeContentRoot(root); if (newModule == null) { newModule = createModuleDescriptor(root, sources != null ? sources : new HashSet<>()); } else { if (sources != null && sources.size() > 0) { for (DetectedSourceRoot source : sources) { newModule.addSourceRoot(root, source); } } else { newModule.addContentRoot(root); } } } if (newModule != null) { newModule.setName(newModuleName); myModules.add(newModule); } else { return null; } final Map<File, ModuleDescriptor> contentRootToModule = new HashMap<>(); for (ModuleDescriptor module : myModules) { final Set<File> roots = module.getContentRoots(); for (File root : roots) { contentRootToModule.put(root, module); } module.clearModuleDependencies(); module.clearLibraryFiles(); } buildModuleDependencies(contentRootToModule); return newModule; }