protected void doDetachModules(@NotNull Project project,
                                 Module @Nullable [] modules,
                                 @Nullable List<? extends UnloadedModuleDescription> unloadedModules) {
    final ModuleManager moduleManager = ModuleManager.getInstance(project);
    final Module[] currentModules = moduleManager.getModules();
    final ModifiableModuleModel modifiableModuleModel = moduleManager.getModifiableModel();
    final Map<Module, ModifiableRootModel> otherModuleRootModels = new HashMap<>();
    Set<String> moduleNamesToDelete = getModuleNamesToDelete(modules, unloadedModules);
    for (final Module otherModule : currentModules) {
      if (!moduleNamesToDelete.contains(otherModule.getName())) {
        otherModuleRootModels.put(otherModule, ModuleRootManager.getInstance(otherModule).getModifiableModel());
      }
    }
    removeDependenciesOnModules(moduleNamesToDelete, otherModuleRootModels.values());
    if (modules != null) {
      ProjectAttachProcessor attachProcessor = ProjectAttachProcessor.getProcessor(null, null, null);
      for (final Module module : modules) {
        if (attachProcessor != null) {
          attachProcessor.beforeDetach(module);
        }
        modifiableModuleModel.disposeModule(module);
      }
    }
    final ModifiableRootModel[] modifiableRootModels = otherModuleRootModels.values().toArray(new ModifiableRootModel[0]);
    ModifiableModelCommitter.multiCommit(modifiableRootModels, modifiableModuleModel);
    if (unloadedModules != null) {
      moduleManager.removeUnloadedModules(unloadedModules);
    }
  }
protected void doDetachModules(@NotNull Project project,
                                 Module @Nullable [] modules,
                                 @Nullable List<? extends UnloadedModuleDescription> unloadedModules)