void (boolean anImport, boolean detectModuleBase) { final List<Module> modules; if (anImport) { modules = myContext.myModulesConfigurator.addImportModule(myTree); } else { // If the user creates a module when selecting an existing module in the project structure dialog, // they may expect that the new module "will be located under the selected one". // This is not completely correct from the project model point of view, as the modules cannot be located under each other, // but from the user perspective it makes sense. // // So, here we take the first content root of the selected module and use it as the base path for the new module. // In the majority of cases, there is only one content root, so the new module will be located there. // If there are multiple content roots, it still makes sense to place the new module under some of them. // // The base path is detected only if the add action was executed from the tree context action. If it was executed from the "plus" // button, we don't detect the module base. String basePath = null; if (detectModuleBase) { Module selectedModule = getSelectedModule(); if (selectedModule != null) { VirtualFile file = Arrays.stream(ModuleRootManager.getInstance(selectedModule).getContentRoots()).findFirst().orElse(null); if (file != null) { basePath = file.getPath(); } } } modules = myContext.myModulesConfigurator.addNewModule(basePath); } if (modules != null && !modules.isEmpty()) { //new module wizard may add yet another SDK to the project myProjectStructureConfigurable.getProjectJdksModel().syncSdks(); for (Module module : modules) { addModuleNode(module); } } }