com.intellij.openapi.module.ModuleManager Java Examples

The following examples show how to use com.intellij.openapi.module.ModuleManager. 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: DWCleanAction.java    From intellij-demandware with MIT License 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();

    if (project != null) {
        for (Module module : ModuleManager.getInstance(project).getModules()) {
            if (ModuleType.get(module) instanceof DWModuleType) {
                ModuleServiceManager.getService(module, DWServerConnection.class);
                ProgressManager.getInstance().run(
                        new DWCleanTask(project, module, "Cleaning cartridges...", true, PerformInBackgroundOption.ALWAYS_BACKGROUND)
                );

            }
        }
    }

}
 
Example #2
Source File: FormatChangedTextUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Allows to answer if any file that belongs to the given project has changes in comparison with VCS.
 *
 * @param project target project to check
 * @return <code>true</code> if any file that belongs to the given project has changes in comparison with VCS
 * <code>false</code> otherwise
 */
public static boolean hasChanges(@Nonnull final Project project) {
  ThrowableComputable<ModifiableModuleModel,RuntimeException> action = () -> ModuleManager.getInstance(project).getModifiableModel();
  final ModifiableModuleModel moduleModel = AccessRule.read(action);

  try {
    for (Module module : moduleModel.getModules()) {
      if (hasChanges(module)) {
        return true;
      }
    }
    return false;
  }
  finally {
    moduleModel.dispose();
  }
}
 
Example #3
Source File: ModuleDataService.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void removeData(@Nonnull final Collection<? extends Module> modules, @Nonnull final Project project, boolean synchronous) {
  if (modules.isEmpty()) {
    return;
  }
  ExternalSystemApiUtil.executeProjectChangeAction(synchronous, new DisposeAwareProjectChange(project) {
    @RequiredUIAccess
    @Override
    @RequiredWriteAction
    public void execute() {
      ModuleManager moduleManager = ModuleManager.getInstance(project);

      for (Module module : modules) {
        if (module.isDisposed()) continue;
        moduleManager.disposeModule(module);
      }
    }
  });
}
 
Example #4
Source File: TomcatSettingsEditor.java    From SmartTomcat with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: AndroidModuleLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void updateAndroidModuleLibraryDependencies(Module flutterModule) {
  for (final Module module : ModuleManager.getInstance(getProject()).getModules()) {
    if (module != flutterModule) {
      if (null != FacetManager.getInstance(module).findFacet(AndroidFacet.ID, "Android")) {
        Object circularModules = CircularModuleDependenciesDetector.addingDependencyFormsCircularity(module, flutterModule);
        if (circularModules == null) {
          ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
          if (!rootManager.isDependsOn(flutterModule)) {
            JavaProjectModelModifier[] modifiers = JavaProjectModelModifier.EP_NAME.getExtensions(getProject());
            for (JavaProjectModelModifier modifier : modifiers) {
              if (modifier instanceof IdeaProjectModelModifier) {
                modifier.addModuleDependency(module, flutterModule, DependencyScope.COMPILE, false);
              }
            }
          }
        }
      }
    }
  }
}
 
Example #6
Source File: VcsStructureChooser.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private Map<VirtualFile, String> calculateModules(@Nonnull List<VirtualFile> roots) {
  Map<VirtualFile, String> result = ContainerUtil.newHashMap();

  final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
  // assertion for read access inside
  Module[] modules = ApplicationManager.getApplication().runReadAction(new Computable<Module[]>() {
    public Module[] compute() {
      return moduleManager.getModules();
    }
  });

  TreeSet<VirtualFile> checkSet = new TreeSet<>(FilePathComparator.getInstance());
  checkSet.addAll(roots);
  for (Module module : modules) {
    VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
    for (VirtualFile file : files) {
      VirtualFile floor = checkSet.floor(file);
      if (floor != null) {
        result.put(file, module.getName());
      }
    }
  }
  return result;
}
 
Example #7
Source File: Platform.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@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 #8
Source File: AddReplAction.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Module getModule(AnActionEvent e) {
    Module module = e.getData(LangDataKeys.MODULE);
    if (module == null) {
        Project project = e.getData(LangDataKeys.PROJECT);
        if (project == null) {
            return null;
        }

        final Module[] modules = ModuleManager.getInstance(project).getModules();
        if (modules.length == 1) {
            module = modules[0];
        }
    }

    return module;
}
 
Example #9
Source File: ModuleGroup.java    From consulo with Apache License 2.0 6 votes vote down vote up
public Collection<ModuleGroup> childGroups(ModifiableModuleModel model, Project project) {
  final Module[] allModules;
  if ( model != null ) {
    allModules = model.getModules();
  } else {
    allModules = ModuleManager.getInstance(project).getModules();
  }

  Set<ModuleGroup> result = new THashSet<ModuleGroup>();
  for (Module module : allModules) {
    String[] group;
    if ( model != null ) {
      group = model.getModuleGroupPath(module);
    } else {
      group = ModuleManager.getInstance(project).getModuleGroupPath(module);
    }
    if (group == null) continue;
    final String[] directChild = directChild(myGroupPath, group);
    if (directChild != null) {
      result.add(new ModuleGroup(directChild));
    }
  }

  return result;
}
 
Example #10
Source File: RenameProjectAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final DataContext dataContext = e.getDataContext();
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  LOG.assertTrue(project instanceof ProjectEx);
  Module module;
  Module[] modules = ModuleManager.getInstance(project).getModules();
  if (modules.length == 1 && project.getName().equals(modules[0].getName())) {
    module = modules[0];
  }
  else {
    module = null;
  }
  Messages.showInputDialog(project, RefactoringBundle.message("enter.new.project.name"), RefactoringBundle.message("rename.project"),
                           Messages.getQuestionIcon(),
                           project.getName(),
                           new RenameProjectHandler.MyInputValidator((ProjectEx)project, module));
}
 
Example #11
Source File: BlazeSampleDataDirectoryProviderTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
  setProjectView(
      "directories:",
      "  com/google/example",
      "targets:",
      "  //com/google/example:main",
      "android_sdk_platform: android-25");
  MockSdkUtil.registerSdk(workspace, "25");

  workspaceDir = workspace.createDirectory(new WorkspacePath("com/google/example"));
  resDir = workspace.createFile(new WorkspacePath("com/google/example/res"));

  setTargetMap(android_binary("//com/google/example:main").res("res"));
  runFullBlazeSync();

  ModuleManager moduleManager = ModuleManager.getInstance(getProject());
  workspaceModule = moduleManager.findModuleByName(".workspace");
  resModule = moduleManager.findModuleByName("com.google.example.main");
}
 
Example #12
Source File: ModulesConfigurator.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
public void resetModuleEditors() {
  myModuleModel = ModuleManager.getInstance(myProject).getModifiableModel();

  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      if (!myModuleEditors.isEmpty()) {
        LOG.error("module editors was not disposed");
        myModuleEditors.clear();
      }
      final Module[] modules = myModuleModel.getModules();
      if (modules.length > 0) {
        for (Module module : modules) {
          getOrCreateModuleEditor(module);
        }
        Collections.sort(myModuleEditors, myModuleEditorComparator);
      }
    }
  });
  myModified = false;
}
 
Example #13
Source File: CompileDriver.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean validateOutputAndSourcePathsIntersection() {
  final Module[] allModules = ModuleManager.getInstance(myProject).getModules();
  List<VirtualFile> allOutputs = new ArrayList<>();
  ContainerUtil.addAll(allOutputs, CompilerPathsImpl.getOutputDirectories(allModules));
  for (Artifact artifact : ArtifactManager.getInstance(myProject).getArtifacts()) {
    ContainerUtil.addIfNotNull(artifact.getOutputFile(), allOutputs);
  }
  final Set<VirtualFile> affectedOutputPaths = new HashSet<>();
  CompilerUtil.computeIntersectingPaths(myProject, allOutputs, affectedOutputPaths);
  affectedOutputPaths.addAll(ArtifactCompilerUtil.getArtifactOutputsContainingSourceFiles(myProject));

  if (!affectedOutputPaths.isEmpty()) {
    if (CompilerUtil.askUserToContinueWithNoClearing(myProject, affectedOutputPaths)) {
      myShouldClearOutputDirectory = false;
      return true;
    }
    else {
      return false;
    }
  }
  return true;
}
 
Example #14
Source File: SdkComboBox.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@SuppressWarnings("unchecked")
public <T extends MutableModuleExtension<?>> void insertModuleItems(@Nonnull T moduleExtension,
                                                                    @Nonnull NullableFunction<T, MutableModuleInheritableNamedPointer<Sdk>> sdkPointerFunction) {

  for (Module module : ModuleManager.getInstance(moduleExtension.getModule().getProject()).getModules()) {
    // dont add self module
    if (module == moduleExtension.getModule()) {
      continue;
    }

    ModuleExtension extension = ModuleUtilCore.getExtension(module, moduleExtension.getId());
    if (extension == null) {
      continue;
    }
    MutableModuleInheritableNamedPointer<Sdk> sdkPointer = sdkPointerFunction.fun((T)extension);
    if (sdkPointer != null) {
      // recursive depend
      if (sdkPointer.getModule() == moduleExtension.getModule()) {
        continue;
      }
      addItem(new ModuleExtensionSdkComboBoxItem(extension, sdkPointer));
    }
  }
}
 
Example #15
Source File: PantsSystemProjectResolver.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
private void queueFocusOnImportDirectory() {
  directoryFocusHandle = PantsUtil.scheduledThreadPool.scheduleWithFixedDelay(() -> {
    if (ModuleManager.getInstance(myProject).getModules().length == 0 ||
        !ProjectView.getInstance(myProject).getCurrentViewId().equals(ProjectFilesViewPane.ID)) {
      return;
    }
    ApplicationManager.getApplication().invokeLater(() -> {
      final VirtualFile pathImported = LocalFileSystem.getInstance().findFileByPath(myProjectPath);
      // Skip focusing if directory is not found.
      if (pathImported != null) {
        VirtualFile importDirectory = pathImported.isDirectory() ? pathImported : pathImported.getParent();
        SelectInContext selectInContext = new FileSelectInContext(myProject, importDirectory);
        for (SelectInTarget selectInTarget : ProjectView.getInstance(myProject).getSelectInTargets()) {
          if (selectInTarget instanceof PantsProjectPaneSelectInTarget) {
            selectInTarget.selectIn(selectInContext, false);
            break;
          }
        }
      }
      final boolean mayInterruptIfRunning = true;
      directoryFocusHandle.cancel(mayInterruptIfRunning);
    });
  }, 0, 1, TimeUnit.SECONDS);
}
 
Example #16
Source File: LibraryUsageCollector.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Set<UsageDescriptor> getProjectUsages(@Nonnull Project project) {
  final Set<LibraryKind> usedKinds = new HashSet<LibraryKind>();
  final Processor<Library> processor = new Processor<Library>() {
    @Override
    public boolean process(Library library) {
      usedKinds.addAll(LibraryPresentationManagerImpl.getLibraryKinds(library, null));
      return true;
    }
  };
  for (Module module : ModuleManager.getInstance(project).getModules()) {
    ModuleRootManager.getInstance(module).orderEntries().librariesOnly().forEachLibrary(processor);
  }

  final HashSet<UsageDescriptor> usageDescriptors = new HashSet<UsageDescriptor>();
  for (LibraryKind kind : usedKinds) {
    usageDescriptors.add(new UsageDescriptor(kind.getKindId(), 1));
  }
  return usageDescriptors;
}
 
Example #17
Source File: TranslatingCompilerFilesMonitorImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private VirtualFile[] getRootsForScan(Project project) {
  List<VirtualFile> list = new ArrayList<>();
  Module[] modules = ModuleManager.getInstance(project).getModules();
  List<TranslatingCompilerFilesMonitorHelper> extensions = TranslatingCompilerFilesMonitorHelper.EP_NAME.getExtensionList();
  for (Module module : modules) {
    for (TranslatingCompilerFilesMonitorHelper extension : extensions) {
      VirtualFile[] rootsForModule = extension.getRootsForModule(module);
      if (rootsForModule != null) {
        Collections.addAll(list, rootsForModule);
      }
    }

    VirtualFile[] contentFolderFiles = ModuleRootManager.getInstance(module).getContentFolderFiles(ContentFolderScopes.all(false));
    Collections.addAll(list, contentFolderFiles);
  }
  return VfsUtil.toVirtualFileArray(list);
}
 
Example #18
Source File: ChooseLibrariesDialogBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void collectChildren(Object element, final List<Object> result) {
  if (element instanceof Application) {
    Collections.addAll(result, ProjectManager.getInstance().getOpenProjects());
    final LibraryTablesRegistrar instance = LibraryTablesRegistrar.getInstance();
    result.add(instance.getLibraryTable()); //1
    result.addAll(instance.getCustomLibraryTables()); //2
  }
  else if (element instanceof Project) {
    Collections.addAll(result, ModuleManager.getInstance((Project)element).getModules());
    result.add(LibraryTablesRegistrar.getInstance().getLibraryTable((Project)element));
  }
  else if (element instanceof LibraryTable) {
    Collections.addAll(result, ((LibraryTable)element).getLibraries());
  }
  else if (element instanceof Module) {
    for (OrderEntry entry : ModuleRootManager.getInstance((Module)element).getOrderEntries()) {
      if (entry instanceof LibraryOrderEntry) {
        final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)entry;
        if (LibraryTableImplUtil.MODULE_LEVEL.equals(libraryOrderEntry.getLibraryLevel())) {
          final Library library = libraryOrderEntry.getLibrary();
          result.add(library);
        }
      }
    }
  }
}
 
Example #19
Source File: RunConfigurationEditor.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Called when application loaded/ when cancelling the settings
 * @param configuration
 */
@Override
protected void resetEditorFrom(EmbeddedLinuxJVMRunConfiguration configuration) {

    getMainClassField().setText(configuration.getRunnerParameters().getMainclass() != null ?
            configuration.getRunnerParameters().getMainclass().replaceAll("\\$", "\\.") : "");

    EmbeddedLinuxJVMRunConfigurationRunnerParameters parameters = configuration.getRunnerParameters();
    Module moduleParam = null;
    if (parameters.getModuleName() != null && parameters.getModuleName().length() > 0) {
        moduleParam = ModuleManager.getInstance(myProject).findModuleByName(parameters.getModuleName());
    }
    vmParameters.setText(parameters.getVmParameters());
    programArguments.setText(parameters.getProgramArguments());
    hostName.setText(parameters.getHostname());
    runAsRootCheckBox.setSelected(parameters.isRunAsRoot());
    usingKey.setSelected(parameters.isUsingKey());
    keyfile.setText(parameters.getKeyPath());
    debugPort.setText(parameters.getPort());
    username.setText(parameters.getUsername());
    password.setText(parameters.getPassword());
    sshPort.setText(Integer.toString(parameters.getSshPort()));
    sshStatus.setVisible(false);
    myModule.getComponent().setSelectedModule(moduleParam);
    keyFileStateChange();
}
 
Example #20
Source File: DirectoryUrl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Object[] createPath(final Project project) {
  if (moduleName != null) {
    final Module module = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {
      @Nullable
      @Override
      public Module compute() {
        return ModuleManager.getInstance(project).findModuleByName(moduleName);
      }
    });
    if (module == null) return null;
  }
  final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();
  final VirtualFile file = virtualFileManager.findFileByUrl(url);
  if (file == null) return null;
  final PsiDirectory directory = ApplicationManager.getApplication().runReadAction(new Computable<PsiDirectory>() {
    @Nullable
    @Override
    public PsiDirectory compute() {
      return PsiManager.getInstance(project).findDirectory(file);
    }
  });
  if (directory == null) return null;
  return new Object[]{directory};
}
 
Example #21
Source File: Unity3dProjectService.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@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 #22
Source File: DirectoryChooserModuleTreeView.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void addItem(DirectoryChooser.ItemWrapper itemWrapper) {
  myItems.add(itemWrapper);
  final PsiDirectory directory = itemWrapper.getDirectory();
  final Module module = myFileIndex.getModuleForFile(directory.getVirtualFile());
  DefaultMutableTreeNode node = myModuleNodes.get(module);
  if (node == null) {
    node = new DefaultMutableTreeNode(module, true);
    final String[] groupPath = module != null ? ModuleManager.getInstance(myProject).getModuleGroupPath(module) : null;
    if (groupPath == null || groupPath.length == 0){
      insertNode(node, myRootNode);
    } else {
      final DefaultMutableTreeNode parentNode = ModuleGroupUtil.buildModuleGroupPath(new ModuleGroup(groupPath),
                                                                                     myRootNode,
                                                                                     myModuleGroupNodes,
                                                                                     new Consumer<ModuleGroupUtil.ParentChildRelation<DefaultMutableTreeNode>>() {
                                                                                       @Override
                                                                                       public void consume(final ModuleGroupUtil.ParentChildRelation<DefaultMutableTreeNode> parentChildRelation) {
                                                                                         insertNode(parentChildRelation.getChild(), parentChildRelation.getParent());
                                                                                       }
                                                                                     },
                                                                                     new Function<ModuleGroup, DefaultMutableTreeNode>() {
                                                                                       @Override
                                                                                       public DefaultMutableTreeNode fun(final ModuleGroup moduleGroup) {
                                                                                         return new DefaultMutableTreeNode(moduleGroup, true);
                                                                                       }
                                                                                     });
      insertNode(node, parentNode);
    }
    myModuleNodes.put(module, node);
  }
  final DefaultMutableTreeNode itemNode = new DefaultMutableTreeNode(itemWrapper, false);
  myItemNodes.put(itemWrapper, itemNode);
  insertNode(itemNode, node);
  ((DefaultTreeModel)myTree.getModel()).nodeStructureChanged(node);
}
 
Example #23
Source File: ModuleEditorImpl.java    From intellij with Apache License 2.0 5 votes vote down vote up
public ModuleEditorImpl(Project project, BlazeImportSettings importSettings) {
  this.project = project;
  this.moduleModel = ModuleManager.getInstance(project).getModifiableModel();

  this.imlDirectory = getImlDirectory(importSettings);
  if (!FileOperationProvider.getInstance().exists(imlDirectory)) {
    if (!imlDirectory.mkdirs()) {
      logger.error("Could not make directory: " + imlDirectory.getPath());
    }
  }
}
 
Example #24
Source File: CompilerUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void computeIntersectingPaths(final Project project,
                                            final Collection<VirtualFile> outputPaths,
                                            final Collection<VirtualFile> result) {
  for (Module module : ModuleManager.getInstance(project).getModules()) {
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    final VirtualFile[] sourceRoots = rootManager.getContentFolderFiles(ContentFolderScopes.productionAndTest());
    for (final VirtualFile outputPath : outputPaths) {
      for (VirtualFile sourceRoot : sourceRoots) {
        if (VfsUtilCore.isAncestor(outputPath, sourceRoot, true) || VfsUtilCore.isAncestor(sourceRoot, outputPath, false)) {
          result.add(outputPath);
        }
      }
    }
  }
}
 
Example #25
Source File: ModuleExtensionHelperImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void checkInit() {
  if(myExtensions == null) {
    myExtensions = new MultiMap<Class<? extends ModuleExtension>, ModuleExtension>();
    for (Module o : ModuleManager.getInstance(myProject).getModules()) {
      for (ModuleExtension moduleExtension : ModuleRootManager.getInstance(o).getExtensions()) {
        myExtensions.putValue(moduleExtension.getClass(), moduleExtension);
      }
    }
  }
}
 
Example #26
Source File: PubRootCache.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
public List<PubRoot> getRoots(@NotNull Project project) {
  final List<PubRoot> result = new ArrayList<>();
  for (Module module : ModuleManager.getInstance(project).getModules()) {
    result.addAll(getRoots(module));
  }
  return result;
}
 
Example #27
Source File: PantsCompileAllTargetsAction.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public Stream<String> getTargets(@NotNull AnActionEvent e, @NotNull Project project) {
  Module[] modules = ModuleManager.getInstance(project).getModules();
  return Arrays.stream(modules)
    .map(PantsUtil::getNonGenTargetAddresses)
    .flatMap(Collection::stream);
}
 
Example #28
Source File: RenameModuleHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private ModifiableModuleModel renameModule(String inputString) {
  final ModifiableModuleModel modifiableModel = ModuleManager.getInstance(myProject).getModifiableModel();
  try {
    modifiableModel.renameModule(myModule, inputString);
  }
  catch (ModuleWithNameAlreadyExistsException moduleWithNameAlreadyExists) {
    Messages.showErrorDialog(myProject, IdeBundle.message("error.module.already.exists", inputString),
                             IdeBundle.message("title.rename.module"));
    return null;
  }
  return modifiableModel;
}
 
Example #29
Source File: FlutterSdkUtil.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Do a best-effort basis to enable Dart support for the given project.
 */
public static void enableDartSdk(@NotNull final Project project) {
  final Module[] modules = ModuleManager.getInstance(project).getModules();
  if (modules.length == 1) {
    DartPlugin.enableDartSdk(modules[0]);
  }
}
 
Example #30
Source File: ExternalSystemTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
protected Module createModule(final String name, final ModuleType type) {
  try {
    return WriteCommandAction.writeCommandAction(myProject).compute(() -> {
      VirtualFile f = createProjectSubFile(name + "/" + name + ".iml");
      Module module = ModuleManager.getInstance(myProject).newModule(f.getPath(), type.getId());
      PsiTestUtil.addContentRoot(module, f.getParent());
      return module;
    });
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }
}