Java Code Examples for com.intellij.openapi.module.ModuleManager#getModules()
The following examples show how to use
com.intellij.openapi.module.ModuleManager#getModules() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Platform.java From reasonml-idea-plugin with MIT License | 6 votes |
@NotNull private static Map<Module, VirtualFile> findContentRootsFor(@NotNull Project project, @NotNull String filename) { Map<Module, VirtualFile> rootContents = new HashMap<>(); ModuleManager moduleManager = ModuleManager.getInstance(project); for (Module module : moduleManager.getModules()) { for (VirtualFile contentRoot : ModuleRootManager.getInstance(module).getContentRoots()) { VirtualFile packageJson = contentRoot.findChild(filename); if (packageJson != null && !rootContents.containsKey(module)) { rootContents.put(module, packageJson); } } } return rootContents; }
Example 2
Source File: TomcatSettingsEditor.java From SmartTomcat with Apache License 2.0 | 6 votes |
@Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { ModuleManager moduleManager = ModuleManager.getInstance(project); Module[] modules = moduleManager.getModules(); for (Module module : modules) { VirtualFile[] excludeRoots = ModuleRootManager.getInstance(module).getExcludeRoots(); for (VirtualFile excludeFile : excludeRoots) { if (excludeFile.getCanonicalPath().equals(file.getCanonicalPath())) { return false; } } } return super.isFileVisible(file, showHiddenFiles); }
Example 3
Source File: FileReferenceNode.java From protobuf-jetbrains-plugin with Apache License 2.0 | 6 votes |
/** * Returns target proto PSI file root node. */ @Nullable public ProtoPsiFileRoot getTarget() { String filename = getFilename(); if (filename == null) { return null; } Module module = ModuleUtilCore.findModuleForPsiElement(this); if (module != null) { return getTarget(filename, module); } // fallback: if we are inside of a dependency, current module is null // in this case we try to resolve reference in all dependencies of all modules // (might be not fully correct, but better than nothing) ModuleManager moduleManager = ModuleManager.getInstance(getProject()); Module[] modules = moduleManager.getModules(); for (Module m : modules) { ProtoPsiFileRoot target = getTarget(filename, m); if (target != null) { return target; } } return null; }
Example 4
Source File: Unity3dProjectService.java From consulo-unity3d with Apache License 2.0 | 6 votes |
@Nullable @RequiredReadAction private static Module findRootModuleImpl(@Nonnull Project project) { VirtualFile baseDir = project.getBaseDir(); if(baseDir == null) { return null; } ModuleManager moduleManager = ModuleManager.getInstance(project); for(Module module : moduleManager.getModules()) { if(baseDir.equals(module.getModuleDir())) { return module; } } return null; }
Example 5
Source File: LogicalRootsManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
private synchronized Map<Module, MultiValuesMap<LogicalRootType, LogicalRoot>> getRoots(final ModuleManager moduleManager) { if (myRoots == null) { myRoots = new THashMap<Module, MultiValuesMap<LogicalRootType, LogicalRoot>>(); final Module[] modules = moduleManager.getModules(); for (Module module : modules) { final MultiValuesMap<LogicalRootType, LogicalRoot> map = new MultiValuesMap<LogicalRootType, LogicalRoot>(); for (Map.Entry<LogicalRootType, Collection<NotNullFunction>> entry : myProviders.entrySet()) { final Collection<NotNullFunction> functions = entry.getValue(); for (NotNullFunction function : functions) { map.putAll(entry.getKey(), (List<LogicalRoot>) function.fun(module)); } } myRoots.put(module, map); } } return myRoots; }
Example 6
Source File: TomcatRunConfiguration.java From SmartTomcat with Apache License 2.0 | 5 votes |
@Override @NotNull public Module[] getModules() { ModuleManager moduleManager = ModuleManager.getInstance(getProject()); Module[] modules = moduleManager.getModules(); return modules; }
Example 7
Source File: MuleConfigUtils.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
public static List<Module> getMuleModules(Project project, boolean includeDomains) { final List<Module> muleModules = new ArrayList<>(); final ModuleManager moduleManager = ModuleManager.getInstance(project); Module[] allModules = moduleManager.getModules(); for (Module m : allModules) { if (MuleConfigUtils.isMuleModule(m) || (includeDomains && MuleConfigUtils.isMuleDomainModule(m))) muleModules.add(m); } return muleModules; }
Example 8
Source File: Utils.java From idea-gitignore with MIT License | 5 votes |
/** * Searches for excluded roots in given {@link Project}. * * @param project current project * @return list of excluded roots */ public static List<VirtualFile> getExcludedRoots(@NotNull Project project) { List<VirtualFile> roots = new ArrayList<>(); ModuleManager manager = ModuleManager.getInstance(project); for (Module module : manager.getModules()) { ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel(); if (model.isDisposed()) { continue; } Collections.addAll(roots, model.getExcludeRoots()); model.dispose(); } return roots; }
Example 9
Source File: ModuleExtensionConditionImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean value(Project project) { ModuleManager moduleManager = ModuleManager.getInstance(project); for (Module module : moduleManager.getModules()) { ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); for (String extensionId : myExtensionIds) { ModuleExtension<?> extension = moduleRootManager.getExtension(extensionId); if(extension != null) { return true; } } } return false; }
Example 10
Source File: NewModuleAction.java From consulo with Apache License 2.0 | 5 votes |
@Override @RequiredUIAccess public void actionPerformed(@Nonnull AnActionEvent e) { final Project project = getEventProject(e); if (project == null) { return; } final VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE); final ModuleManager moduleManager = ModuleManager.getInstance(project); FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false, false) { @Override @RequiredUIAccess public boolean isFileSelectable(VirtualFile file) { if (!super.isFileSelectable(file)) { return false; } for (Module module : moduleManager.getModules()) { VirtualFile moduleDir = module.getModuleDir(); if (moduleDir != null && moduleDir.equals(file)) { return false; } } return true; } }; fileChooserDescriptor.setTitle(ProjectBundle.message("choose.module.home")); AsyncResult<VirtualFile> chooseAsync = FileChooser.chooseFile(fileChooserDescriptor, project, virtualFile != null && virtualFile.isDirectory() ? virtualFile : null); chooseAsync.doWhenDone(moduleDir -> { NewProjectDialog dialog = new NewProjectDialog(project, moduleDir); dialog.showAsync().doWhenDone(() -> { NewProjectPanel panel = dialog.getProjectPanel(); NewOrImportModuleUtil.doCreate(panel, project, moduleDir); }); }); }
Example 11
Source File: DirectoryIndexImpl.java From consulo with Apache License 2.0 | 5 votes |
@RequiredReadAction private void markContentRootsForRefresh(ModuleManager moduleManager) { Module[] modules = moduleManager.getModules(); for (Module module : modules) { VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots(); for (VirtualFile contentRoot : contentRoots) { if (contentRoot instanceof NewVirtualFile) { ((NewVirtualFile)contentRoot).markDirtyRecursively(); } } } }
Example 12
Source File: RunAnythingChooseContextAction.java From consulo with Apache License 2.0 | 5 votes |
private static List<RunAnythingContext> projectAndModulesContexts(Project project) { List<RunAnythingContext> contexts = new ArrayList<>(); contexts.add(new RunAnythingContext.ProjectContext(project)); ModuleManager manager = ModuleManager.getInstance(project); Module[] modules = manager.getModules(); if(modules.length == 1) { contexts.add(new RunAnythingContext.ModuleContext(modules[0])); } return contexts; }
Example 13
Source File: ProjectSettingsComponent.java From Plugin with MIT License | 4 votes |
private void syncGears(){ //Load settings SettingsManager.getInstance().loadSettings(); //Get all projects ProjectManager pm = ProjectManager.getInstance(); Project[] targetProjects = pm.getOpenProjects(); Project p = targetProjects[0]; //Load project settings SettingsManager.getInstance().loadProjectSettings(p); //Get all modules ModuleManager mm = ModuleManager.getInstance(p); Module[] targetModules = mm.getModules(); //Get main module String mainModule = SettingsManager.getInstance().getMainModule(); if (!mainModule.equals("")){ //Find the module object from module name for (int ii = 0; ii < targetModules.length; ii++){ //If module name matches target module, sync if (targetModules[ii].getName().equals(mainModule)){ //Sync gears if (SettingsManager.getInstance().getAutoSync()){ SyncGears syncWorker = new SyncGears(p, targetModules[ii]){ @Override protected void done() { super.done(); //Possibly show toast here... } }; syncWorker.execute(); } break; } } } }
Example 14
Source File: ContactPopMenu.java From saros with GNU General Public License v2.0 | 4 votes |
/** * Creates the menu entries for the modules contained in the project. Returns the created entries * grouped by whether the described module is shareable or not. * * <p>Shareable module entries trigger the session negotiation when interacted with. Non-shareable * module entries are disabled and carry a tooltip explaining why the module can not be shared. * * @param project the project for whose modules to create menu entries * @return a <code>Pair</code> containing the entries for sharable modules (first element) and the * entries for non-shareable modules (second element) or <code>null</code> if the module * information for the project can not be read */ @Nullable private Pair<List<JMenuItem>, List<JMenuItem>> createModuleEntries(Project project) { ModuleManager moduleManager = ModuleManager.getInstance(project); if (moduleManager == null) { NotificationPanel.showError( MessageFormat.format( Messages.Contact_saros_message_conditional, Messages.ContactPopMenu_unsupported_ide_message_condition), Messages.ContactPopMenu_unsupported_ide_title); return null; } List<JMenuItem> shownModules = new ArrayList<>(); List<JMenuItem> nonCompliantModules = new ArrayList<>(); for (Module module : moduleManager.getModules()) { String moduleName = module.getName(); String fullModuleName = project.getName() + File.separator + moduleName; // TODO adjust once sharing multiple reference points is supported try { VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots(); if (contentRoots.length != 1) { throw new IllegalArgumentException("Unsupported number of content roots"); } VirtualFile contentRoot = contentRoots[0]; IReferencePoint wrappedModule = new IntellijReferencePoint(project, contentRoot); JMenuItem moduleItem = new JMenuItem(moduleName); moduleItem.setToolTipText(Messages.ContactPopMenu_menu_tooltip_share_module); moduleItem.addActionListener(new ShareDirectoryAction(project, moduleName, wrappedModule)); shownModules.add(moduleItem); } catch (IllegalArgumentException exception) { log.debug( "Ignoring module " + fullModuleName + " as it has multiple content roots and can't necessarily be completely shared."); JMenuItem invalidModuleEntry = new JMenuItem(moduleName); invalidModuleEntry.setEnabled(false); invalidModuleEntry.setToolTipText(Messages.ContactPopMenu_menu_tooltip_invalid_module); nonCompliantModules.add(invalidModuleEntry); } } return new Pair<>(shownModules, nonCompliantModules); }