ModuleRootManagerEx for sophisticated getModifiableModel

IDEA-CR-36815
IDEA-199211 Refactor code dependent on project model implementation
This commit is contained in:
Leonid Shalupov
2018-10-02 11:48:02 +03:00
parent eade077bfc
commit e46526ae4c
3 changed files with 19 additions and 3 deletions
@@ -16,7 +16,6 @@ import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.ModuleConfigurableEP;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.ModuleRootManagerImpl;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.impl.libraries.LibraryTableBase;
import com.intellij.openapi.roots.libraries.Library;
@@ -128,7 +127,7 @@ public abstract class ModuleEditor implements Place.Navigator, Disposable {
if (myModifiableRootModel == null) {
final Module module = getModule();
if (module != null) {
myModifiableRootModel = ((ModuleRootManagerImpl)ModuleRootManager.getInstance(module)).getModifiableModel(new UIRootConfigurationAccessor(myProject));
myModifiableRootModel = ModuleRootManagerEx.getInstanceEx(module).getModifiableModel(new UIRootConfigurationAccessor(myProject));
}
}
return myModifiableRootModel;
@@ -0,0 +1,16 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.roots;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.impl.RootConfigurationAccessor;
import org.jetbrains.annotations.NotNull;
public abstract class ModuleRootManagerEx extends ModuleRootManager {
@NotNull
public abstract ModifiableRootModel getModifiableModel(@NotNull RootConfigurationAccessor accessor);
public static ModuleRootManagerEx getInstanceEx(@NotNull Module module) {
return (ModuleRootManagerEx) module.getComponent(ModuleRootManager.class);
}
}
@@ -32,7 +32,7 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
import java.util.*;
public class ModuleRootManagerImpl extends ModuleRootManager implements Disposable {
public class ModuleRootManagerImpl extends ModuleRootManagerEx implements Disposable {
protected static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.ModuleRootManagerImpl");
private final Module myModule;
@@ -96,6 +96,7 @@ public class ModuleRootManagerImpl extends ModuleRootManager implements Disposab
return getModifiableModel(new RootConfigurationAccessor());
}
@Override
@NotNull
public ModifiableRootModel getModifiableModel(@NotNull RootConfigurationAccessor accessor) {
ApplicationManager.getApplication().assertReadAccessAllowed();