Java Code Examples for com.intellij.openapi.roots.ModuleRootManager#getModifiableModel()

The following examples show how to use com.intellij.openapi.roots.ModuleRootManager#getModifiableModel() . 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: ProtostuffPluginController.java    From protobuf-jetbrains-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Add global protobuf library to given module. Visible for testing.
 */
public void addLibrary(Module module) {
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    ModifiableRootModel modifiableRootModel = moduleRootManager.getModifiableModel();
    AtomicBoolean found = new AtomicBoolean(false);
    OrderEnumerator.orderEntries(module).forEachLibrary(library1 -> {
        if (LIB_NAME.equals(library1.getName())) {
            found.set(true);
            return false;
        }
        return true;
    });
    if (!found.get()) {
        ApplicationManager.getApplication().runWriteAction(() -> {
            modifiableRootModel.addLibraryEntry(globalLibrary);
            modifiableRootModel.commit();
        });
    }
}
 
Example 2
Source File: CS0227.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredWriteAction
public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException
{
	Module moduleForPsiElement = ModuleUtilCore.findModuleForPsiElement(file);
	if(moduleForPsiElement == null)
	{
		return;
	}

	ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(moduleForPsiElement);

	final ModifiableRootModel modifiableModel = moduleRootManager.getModifiableModel();
	CSharpSimpleMutableModuleExtension cSharpModuleExtension = modifiableModel.getExtension(CSharpSimpleMutableModuleExtension.class);
	if(cSharpModuleExtension != null)
	{
		cSharpModuleExtension.setAllowUnsafeCode(true);
	}

	modifiableModel.commit();
}
 
Example 3
Source File: HaxelibClasspathUtils.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
/**
 * Get the classpath for the given module.  This does not include any
 * paths from projects or SDKs.
 *
 * @param module to look up haxelib for.
 * @return a (possibly empty) collection of classpaths.  These are NOT
 *         necessarily properly ordered, but they are unique.
 */
@NotNull
public static HaxeClasspath getModuleClasspath(@NotNull Module module) {
  ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
  if (null == rootManager) return HaxeClasspath.EMPTY_CLASSPATH;

  ModifiableRootModel rootModel = rootManager.getModifiableModel();
  LibraryTable libraryTable = rootModel.getModuleLibraryTable();
  HaxeClasspath moduleClasspath = loadClasspathFrom(libraryTable);
  rootModel.dispose();    // MUST dispose of the model.
  return moduleClasspath;
}