mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Replace usages of ProjectManagerImpl with ProjectManagerEx
IDEA-199211 Refactor code dependent on project model implementation IDEA-CR-36813
This commit is contained in:
@@ -18,6 +18,7 @@ import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ProjectBundle
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx
|
||||
import com.intellij.openapi.project.impl.ProjectManagerImpl
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.util.Key
|
||||
@@ -107,7 +108,7 @@ class StoreAwareProjectManager(virtualFileManager: VirtualFileManager, progressM
|
||||
return
|
||||
}
|
||||
|
||||
if (event.requestor is StateStorage.SaveSession || event.requestor is StateStorage || event.requestor is ProjectManagerImpl) {
|
||||
if (event.requestor is StateStorage.SaveSession || event.requestor is StateStorage || event.requestor is ProjectManagerEx) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -38,7 +38,6 @@ import com.intellij.openapi.progress.util.ProgressWindow;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.project.impl.ProjectManagerImpl;
|
||||
import com.intellij.openapi.ui.DialogEarthquakeShaker;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.MessageDialogBuilder;
|
||||
@@ -231,7 +230,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
|
||||
}
|
||||
|
||||
private boolean disposeSelf(final boolean checkCanCloseProject) {
|
||||
final ProjectManagerImpl manager = (ProjectManagerImpl)ProjectManagerEx.getInstanceEx();
|
||||
final ProjectManagerEx manager = ProjectManagerEx.getInstanceEx();
|
||||
if (manager == null) {
|
||||
saveSettings(true);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,9 @@ public abstract class ProjectManagerEx extends ProjectManager {
|
||||
|
||||
public abstract boolean openProject(@NotNull Project project);
|
||||
|
||||
@TestOnly
|
||||
public abstract boolean isDefaultProjectInitialized();
|
||||
|
||||
public abstract boolean isProjectOpened(Project project);
|
||||
|
||||
public abstract boolean canClose(@NotNull Project project);
|
||||
@@ -65,6 +68,12 @@ public abstract class ProjectManagerEx extends ProjectManager {
|
||||
@NotNull
|
||||
public abstract Collection<Project> closeTestProject(@NotNull Project project);
|
||||
|
||||
@TestOnly
|
||||
public abstract boolean forceCloseProject(@NotNull Project project, boolean dispose);
|
||||
|
||||
// return true if successful
|
||||
public abstract boolean closeAndDisposeAllProjects(boolean checkCanClose);
|
||||
|
||||
// returns true on success
|
||||
public abstract boolean closeAndDispose(@NotNull Project project);
|
||||
|
||||
@@ -74,6 +83,9 @@ public abstract class ProjectManagerEx extends ProjectManager {
|
||||
return newProject(name, path, true, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract Project findOpenProjectByHash(@Nullable String locationHash);
|
||||
|
||||
@Nullable
|
||||
public abstract Project convertAndLoadProject(@NotNull String filePath) throws IOException;
|
||||
|
||||
|
||||
@@ -333,6 +333,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
@TestOnly
|
||||
public synchronized boolean isDefaultProjectInitialized() {
|
||||
return myDefaultProject != null;
|
||||
@@ -469,6 +470,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Project findOpenProjectByHash(@Nullable String locationHash) {
|
||||
return myOpenProjectByHash.get(locationHash);
|
||||
@@ -621,12 +623,14 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
|
||||
return closeProject(project, true, true, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@TestOnly
|
||||
public boolean forceCloseProject(@NotNull Project project, boolean dispose) {
|
||||
return closeProject(project, false, false, dispose, false);
|
||||
}
|
||||
|
||||
// return true if successful
|
||||
@Override
|
||||
public boolean closeAndDisposeAllProjects(boolean checkCanClose) {
|
||||
for (Project project : getOpenProjects()) {
|
||||
if (!closeProject(project, true, false, true, checkCanClose)) {
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ProjectManagerListener;
|
||||
import com.intellij.openapi.project.impl.ProjectManagerImpl;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -86,7 +86,7 @@ public abstract class DummyCachingFileSystem<T extends VirtualFile> extends Dumm
|
||||
|
||||
@Nullable
|
||||
public Project getProject(@Nullable String projectId) {
|
||||
Project project = ((ProjectManagerImpl)ProjectManager.getInstance()).findOpenProjectByHash(projectId);
|
||||
Project project = ProjectManagerEx.getInstanceEx().findOpenProjectByHash(projectId);
|
||||
if (ApplicationManager.getApplication().isUnitTestMode() && project != null) {
|
||||
registerDisposeCallback(project);
|
||||
DISPOSE_CALLBACK.set(project, Boolean.TRUE);
|
||||
|
||||
@@ -17,8 +17,7 @@ package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.editor.impl.event.EditorEventMulticasterImpl;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.impl.ProjectManagerImpl;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingManager;
|
||||
import com.intellij.util.containers.hash.LinkedHashMap;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
@@ -40,13 +39,13 @@ public class EditorListenerTracker {
|
||||
public EditorListenerTracker() {
|
||||
EncodingManager.getInstance(); //adds listeners
|
||||
before = ((EditorEventMulticasterImpl)EditorFactory.getInstance().getEventMulticaster()).getListeners();
|
||||
myDefaultProjectInitialized = ((ProjectManagerImpl)ProjectManager.getInstance()).isDefaultProjectInitialized();
|
||||
myDefaultProjectInitialized = ProjectManagerEx.getInstanceEx().isDefaultProjectInitialized();
|
||||
}
|
||||
|
||||
public void checkListenersLeak() throws AssertionError {
|
||||
try {
|
||||
// listeners may hang on default project
|
||||
if (myDefaultProjectInitialized != ((ProjectManagerImpl)ProjectManager.getInstance()).isDefaultProjectInitialized()) return;
|
||||
if (myDefaultProjectInitialized != ProjectManagerEx.getInstanceEx().isDefaultProjectInitialized()) return;
|
||||
|
||||
EditorEventMulticasterImpl multicaster = (EditorEventMulticasterImpl)EditorFactory.getInstance().getEventMulticaster();
|
||||
Map<Class<? extends EventListener>, List<? extends EventListener>> after = multicaster.getListeners();
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.openapi.project.ex.ProjectEx
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx
|
||||
import com.intellij.openapi.project.impl.ProjectManagerImpl
|
||||
@@ -86,7 +85,7 @@ class ProjectRule(val projectDescriptor: LightProjectDescriptor = LightProjectDe
|
||||
val project = sharedProject ?: return
|
||||
sharedProject = null
|
||||
sharedModule = null
|
||||
(ProjectManager.getInstance() as ProjectManagerImpl).forceCloseProject(project, true)
|
||||
ProjectManagerEx.getInstanceEx().forceCloseProject(project, true)
|
||||
// TODO uncomment and figure out where to put this statement
|
||||
// (VirtualFilePointerManager.getInstance() as VirtualFilePointerManagerImpl).assertPointersAreDisposed()
|
||||
}
|
||||
@@ -94,7 +93,7 @@ class ProjectRule(val projectDescriptor: LightProjectDescriptor = LightProjectDe
|
||||
|
||||
public override fun after() {
|
||||
if (projectOpened.compareAndSet(true, false)) {
|
||||
sharedProject?.let { runInEdtAndWait { (ProjectManager.getInstance() as ProjectManagerImpl).forceCloseProject(it, false) } }
|
||||
sharedProject?.let { runInEdtAndWait { ProjectManagerEx.getInstanceEx().forceCloseProject(it, false) } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +225,7 @@ inline fun <T> Project.runInLoadComponentStateMode(task: () -> T): T {
|
||||
fun createHeavyProject(path: String, useDefaultProjectSettings: Boolean = false): Project = ProjectManagerEx.getInstanceEx().newProject(null, path, useDefaultProjectSettings, false)!!
|
||||
|
||||
fun Project.use(task: (Project) -> Unit) {
|
||||
val projectManager = ProjectManagerEx.getInstanceEx() as ProjectManagerImpl
|
||||
val projectManager = ProjectManagerEx.getInstanceEx()
|
||||
try {
|
||||
runInEdtAndWait { projectManager.openTestProject(this) }
|
||||
task(this)
|
||||
@@ -238,7 +237,7 @@ fun Project.use(task: (Project) -> Unit) {
|
||||
|
||||
class DisposeNonLightProjectsRule : ExternalResource() {
|
||||
override fun after() {
|
||||
val projectManager = if (ApplicationManager.getApplication().isDisposed) null else ProjectManager.getInstance() as ProjectManagerImpl
|
||||
val projectManager = if (ApplicationManager.getApplication().isDisposed) null else ProjectManagerEx.getInstanceEx()
|
||||
projectManager?.openProjects?.forEachGuaranteed {
|
||||
if (!ProjectManagerImpl.isLight(it)) {
|
||||
runInEdtAndWait { projectManager.forceCloseProject(it, true) }
|
||||
|
||||
@@ -479,7 +479,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
PsiDocumentManagerImpl documentManager = (PsiDocumentManagerImpl)PsiDocumentManager.getInstance(project);
|
||||
documentManager.clearUncommittedDocuments();
|
||||
|
||||
ProjectManagerImpl projectManager = (ProjectManagerImpl)ProjectManager.getInstance();
|
||||
ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
|
||||
if (projectManager.isDefaultProjectInitialized()) {
|
||||
Project defaultProject = projectManager.getDefaultProject();
|
||||
((PsiDocumentManagerImpl)PsiDocumentManager.getInstance(defaultProject)).clearUncommittedDocuments();
|
||||
|
||||
@@ -30,10 +30,8 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.project.impl.ProjectImpl;
|
||||
import com.intellij.openapi.project.impl.ProjectManagerImpl;
|
||||
import com.intellij.openapi.project.impl.TooManyProjectLeakedException;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
@@ -435,10 +433,9 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
((PsiManagerImpl)PsiManager.getInstance(project)).cleanupForNextTest();
|
||||
}
|
||||
|
||||
final ProjectManager projectManager = ProjectManager.getInstance();
|
||||
final ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
|
||||
assert projectManager != null : "The ProjectManager is not initialized yet";
|
||||
ProjectManagerImpl projectManagerImpl = (ProjectManagerImpl)projectManager;
|
||||
if (projectManagerImpl.isDefaultProjectInitialized()) {
|
||||
if (projectManager.isDefaultProjectInitialized()) {
|
||||
Project defaultProject = projectManager.getDefaultProject();
|
||||
((PsiManagerImpl)PsiManager.getInstance(defaultProject)).cleanupForNextTest();
|
||||
}
|
||||
@@ -570,12 +567,10 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
public static void closeAndDisposeProjectAndCheckThatNoOpenProjects(@NotNull final Project projectToClose) {
|
||||
RunAll runAll = new RunAll();
|
||||
ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
|
||||
if (projectManager instanceof ProjectManagerImpl) {
|
||||
for (Project project : projectManager.closeTestProject(projectToClose)) {
|
||||
runAll = runAll
|
||||
.append(() -> { throw new IllegalStateException("Test project is not disposed: " + project + ";\n created in: " + getCreationPlace(project)); })
|
||||
.append(() -> ((ProjectManagerImpl)projectManager).forceCloseProject(project, true));
|
||||
}
|
||||
for (Project project : projectManager.closeTestProject(projectToClose)) {
|
||||
runAll = runAll
|
||||
.append(() -> { throw new IllegalStateException("Test project is not disposed: " + project + ";\n created in: " + getCreationPlace(project)); })
|
||||
.append(() -> projectManager.forceCloseProject(project, true));
|
||||
}
|
||||
runAll.append(() -> WriteAction.run(() -> Disposer.dispose(projectToClose))).run();
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.impl.ProjectManagerImpl;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.ShutDownTracker;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -45,7 +44,7 @@ public class ThreadTracker {
|
||||
@TestOnly
|
||||
public ThreadTracker() {
|
||||
before = getThreads();
|
||||
myDefaultProjectInitialized = ((ProjectManagerImpl)ProjectManager.getInstance()).isDefaultProjectInitialized();
|
||||
myDefaultProjectInitialized = ProjectManagerEx.getInstanceEx().isDefaultProjectInitialized();
|
||||
}
|
||||
|
||||
private static final Method getThreads = ReflectionUtil.getDeclaredMethod(Thread.class, "getThreads");
|
||||
@@ -132,7 +131,7 @@ public class ThreadTracker {
|
||||
NettyUtil.awaitQuiescenceOfGlobalEventExecutor(100, TimeUnit.SECONDS);
|
||||
ShutDownTracker.getInstance().waitFor(100, TimeUnit.SECONDS);
|
||||
try {
|
||||
if (myDefaultProjectInitialized != ((ProjectManagerImpl)ProjectManager.getInstance()).isDefaultProjectInitialized()) return;
|
||||
if (myDefaultProjectInitialized != ProjectManagerEx.getInstanceEx().isDefaultProjectInitialized()) return;
|
||||
|
||||
Collection<Thread> after = new THashSet<>(getThreads());
|
||||
after.removeAll(before);
|
||||
|
||||
Reference in New Issue
Block a user