diff --git a/java/java-tests/testSrc/com/intellij/scopes/PackageSetTest.java b/java/java-tests/testSrc/com/intellij/scopes/PackageSetTest.java index 58a32a8b85d0..04e9e46da552 100644 --- a/java/java-tests/testSrc/com/intellij/scopes/PackageSetTest.java +++ b/java/java-tests/testSrc/com/intellij/scopes/PackageSetTest.java @@ -1,5 +1,4 @@ - -// 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. +// Copyright 2000-2020 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.scopes; import com.intellij.ide.scopeView.NamedScopeFilter; diff --git a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/util/ExternalSystemTestUtil.kt b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/util/ExternalSystemTestUtil.kt index 6fd59fc528b3..74172bf4d546 100644 --- a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/util/ExternalSystemTestUtil.kt +++ b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/util/ExternalSystemTestUtil.kt @@ -1,9 +1,9 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.externalSystem.util -import com.intellij.openapi.application.invokeAndWaitIfNeeded import com.intellij.openapi.project.Project import com.intellij.openapi.project.ex.ProjectManagerEx +import com.intellij.testFramework.runInEdtAndWait fun Project.use(save: Boolean = false, action: (Project) -> Unit) { val project = this@use @@ -11,7 +11,7 @@ fun Project.use(save: Boolean = false, action: (Project) -> Unit) { action(project) } finally { - invokeAndWaitIfNeeded { + runInEdtAndWait { val projectManager = ProjectManagerEx.getInstanceEx() if (save) { projectManager.closeAndDispose(project) diff --git a/platform/platform-api/src/com/intellij/openapi/rd/DisposableEx.kt b/platform/platform-api/src/com/intellij/openapi/rd/DisposableEx.kt index 02a7501dec5f..77ec64d8f22c 100644 --- a/platform/platform-api/src/com/intellij/openapi/rd/DisposableEx.kt +++ b/platform/platform-api/src/com/intellij/openapi/rd/DisposableEx.kt @@ -53,7 +53,7 @@ internal fun Lifetime.createNestedDisposable(debugName: String = "lifetimeToDisp } @Suppress("ObjectLiteralToLambda") -fun Disposable.attach(disposable: () -> Unit) { +inline fun Disposable.attach(crossinline disposable: () -> Unit) { Disposer.register(this, object : Disposable { override fun dispose() { disposable() diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/StartMarkAction.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/StartMarkAction.java index f839692dc673..c9f0a6310cd2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/StartMarkAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/StartMarkAction.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2020 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.command.impl; import com.intellij.ide.IdeBundle; @@ -10,9 +10,10 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; +import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; -public class StartMarkAction extends BasicUndoableAction { +public final class StartMarkAction extends BasicUndoableAction { public static final Key START_MARK_ACTION_KEY = Key.create("current.inplace.refactorings.mark"); private String myCommandName; private boolean myGlobal; @@ -54,8 +55,10 @@ public class StartMarkAction extends BasicUndoableAction { } @TestOnly - public static void checkCleared(Project project) { - if (project == null) return; + public static void checkCleared(@Nullable Project project) { + if (project == null) { + return; + } try { StartMarkAction markAction = project.getUserData(START_MARK_ACTION_KEY); assert markAction == null : markAction.myDocument; diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/impl/EditorHistoryManagerTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/impl/EditorHistoryManagerTest.kt index a92e10d99a23..e2ba3c4d1c88 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/impl/EditorHistoryManagerTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/impl/EditorHistoryManagerTest.kt @@ -91,8 +91,6 @@ private fun openProjectPerformTaskCloseProject(projectDir: Path, task: (Project) } } finally { - runInEdtAndWait { - ProjectManagerEx.getInstanceEx().forceCloseProject(project) - } + PlatformTestUtil.forceCloseProjectWithoutSaving(project) } } \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/module/ModulesConfigurationTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/module/ModulesConfigurationTest.java index 63445864fff8..02dc7d0fd165 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/module/ModulesConfigurationTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/module/ModulesConfigurationTest.java @@ -6,8 +6,6 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.module.impl.ProjectLoadingErrorsHeadlessNotifier; import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; -import com.intellij.openapi.project.impl.ProjectManagerImpl; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; @@ -79,7 +77,7 @@ public class ModulesConfigurationTest extends HeavyPlatformTestCase { if (isSave) { StateStorageManagerKt.saveComponentManager(project, true); } - ((ProjectManagerImpl)ProjectManager.getInstance()).forceCloseProject(project); + PlatformTestUtil.forceCloseProjectWithoutSaving(project); } private void closeOnTearDown(Project project) { diff --git a/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt b/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt index 08fe9faf2e16..eca3178774a1 100644 --- a/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt +++ b/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt @@ -76,8 +76,7 @@ class ProjectRule(val projectDescriptor: LightProjectDescriptor = LightProjectDe val errors: MutableList = SmartList() val tasks: MutableList> = SmartList() for (project in openProjects) { - errors.add(IllegalStateException( - "Test project is not disposed: $project;\n created in: ${getCreationPlace(project)}")) + errors.add(IllegalStateException("Test project is not disposed: $project;\n created in: ${getCreationPlace(project)}")) tasks.add(ThrowableRunnable { projectManager.forceCloseProject(project) }) } RunAll(tasks).run(errors) @@ -407,6 +406,16 @@ class DisposableRule : ExternalResource() { val disposable: Disposable get() = _disposable.value + + @Suppress("ObjectLiteralToLambda") + inline fun register(crossinline disposable: () -> Unit) { + Disposer.register(this.disposable, object : Disposable { + override fun dispose() { + disposable() + } + }) + } + override fun after() { if (_disposable.isInitialized()) { Disposer.dispose(_disposable.value) diff --git a/platform/testFramework/src/com/intellij/testFramework/rules/ProjectModelRule.kt b/platform/testFramework/src/com/intellij/testFramework/rules/ProjectModelRule.kt index 5e49fcaf4af5..7b0b44137bfb 100644 --- a/platform/testFramework/src/com/intellij/testFramework/rules/ProjectModelRule.kt +++ b/platform/testFramework/src/com/intellij/testFramework/rules/ProjectModelRule.kt @@ -8,7 +8,6 @@ import com.intellij.openapi.module.ModifiableModuleModel import com.intellij.openapi.module.Module import com.intellij.openapi.module.ModuleManager import com.intellij.openapi.project.Project -import com.intellij.openapi.project.ex.ProjectManagerEx import com.intellij.openapi.projectRoots.* import com.intellij.openapi.rd.attach import com.intellij.openapi.roots.ModuleRootModificationUtil @@ -61,9 +60,7 @@ class ProjectModelRule(private val forceEnableWorkspaceModel: Boolean = false) : } override fun after() { - runInEdtAndWait { - ProjectManagerEx.getInstanceEx().forceCloseProject(project) - } + PlatformTestUtil.forceCloseProjectWithoutSaving(project) } } private val ruleChain = RuleChain(baseProjectDir, projectResource, disposableRule) diff --git a/platform/workspaceModel/ide/tests/testSrc/com/intellij/workspaceModel/ide/ModuleBridgesTest.kt b/platform/workspaceModel/ide/tests/testSrc/com/intellij/workspaceModel/ide/ModuleBridgesTest.kt index c6263002b40a..5e191f3aff5a 100644 --- a/platform/workspaceModel/ide/tests/testSrc/com/intellij/workspaceModel/ide/ModuleBridgesTest.kt +++ b/platform/workspaceModel/ide/tests/testSrc/com/intellij/workspaceModel/ide/ModuleBridgesTest.kt @@ -13,7 +13,6 @@ import com.intellij.openapi.module.ModuleManager import com.intellij.openapi.module.ModuleType import com.intellij.openapi.module.ModuleTypeId import com.intellij.openapi.project.Project -import com.intellij.openapi.project.ex.ProjectManagerEx import com.intellij.openapi.project.rootManager import com.intellij.openapi.rd.attach import com.intellij.openapi.roots.* @@ -415,7 +414,7 @@ class ModuleBridgesTest { WorkspaceModelInitialTestContent.withInitialContent(builder.toStorage()) { val project = PlatformTestUtil.loadAndOpenProject(iprFile) Disposer.register(disposableRule.disposable, Disposable { - invokeAndWaitIfNeeded { ProjectManagerEx.getInstanceEx().forceCloseProject(project) } + PlatformTestUtil.forceCloseProjectWithoutSaving(project) }) val module = ModuleManager.getInstance(project).findModuleByName("test") @@ -451,7 +450,7 @@ class ModuleBridgesTest { WorkspaceModelInitialTestContent.withInitialContent(builder.toStorage()) { val project = PlatformTestUtil.loadAndOpenProject(iprFile) Disposer.register(disposableRule.disposable, Disposable { - invokeAndWaitIfNeeded { ProjectManagerEx.getInstanceEx().forceCloseProject(project) } + PlatformTestUtil.forceCloseProjectWithoutSaving(project) }) val projectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(project) @@ -667,6 +666,6 @@ internal fun createEmptyTestProject(temporaryDirectory: TemporaryDirectory, disp val project = WorkspaceModelInitialTestContent.withInitialContent(WorkspaceEntityStorageBuilder.create()) { PlatformTestUtil.loadAndOpenProject(projectDir.resolve("testProject.ipr")) } - disposableRule.disposable.attach { invokeAndWaitIfNeeded { ProjectManagerEx.getInstanceEx().forceCloseProject(project) } } + disposableRule.disposable.attach { PlatformTestUtil.forceCloseProjectWithoutSaving(project) } return project } diff --git a/platform/workspaceModel/ide/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelPerformanceTest.kt b/platform/workspaceModel/ide/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelPerformanceTest.kt index 57eda19c41dc..af203ba1ac95 100644 --- a/platform/workspaceModel/ide/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelPerformanceTest.kt +++ b/platform/workspaceModel/ide/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelPerformanceTest.kt @@ -2,32 +2,28 @@ package com.intellij.workspaceModel.ide import com.intellij.openapi.application.impl.ApplicationInfoImpl -import com.intellij.openapi.application.invokeAndWaitIfNeeded import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.module.EmptyModuleType import com.intellij.openapi.module.Module import com.intellij.openapi.module.ModuleManager import com.intellij.openapi.module.impl.ModuleManagerComponent import com.intellij.openapi.project.Project -import com.intellij.openapi.project.ex.ProjectManagerEx -import com.intellij.openapi.rd.attach import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.ModuleRootModificationUtil import com.intellij.openapi.roots.OrderRootType import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar import com.intellij.openapi.util.Disposer -import com.intellij.openapi.util.registry.Registry import com.intellij.testFramework.ApplicationRule import com.intellij.testFramework.DisposableRule import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.TemporaryDirectory import com.intellij.testFramework.rules.ProjectModelRule +import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerComponentBridge +import com.intellij.workspaceModel.storage.WorkspaceEntityStorageBuilder import com.intellij.workspaceModel.storage.bridgeEntities.ModuleDependencyItem import com.intellij.workspaceModel.storage.bridgeEntities.ModuleEntity -import com.intellij.workspaceModel.storage.WorkspaceEntityStorageBuilder import com.intellij.workspaceModel.storage.bridgeEntities.addModuleEntity -import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerComponentBridge import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Ignore @@ -227,10 +223,8 @@ class WorkspaceModelPerformanceTest(private val modulesCount: Int) { val project = logExecutionTimeInMillis("Project load") { PlatformTestUtil.loadAndOpenProject(projectDir) } - disposableRule.disposable.attach { - invokeAndWaitIfNeeded { - ProjectManagerEx.getInstanceEx().forceCloseProject(project) - } + disposableRule.register { + PlatformTestUtil.forceCloseProjectWithoutSaving(project) } return project } diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleSettingsImportingTest.java b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleSettingsImportingTest.java index 3fb31f24e54b..66c1bc393755 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleSettingsImportingTest.java +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleSettingsImportingTest.java @@ -23,7 +23,6 @@ import com.intellij.openapi.externalSystem.service.project.settings.FacetConfigu import com.intellij.openapi.externalSystem.service.project.settings.RunConfigurationImporter; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ex.ProjectManagerEx; import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.SourceFolder; import com.intellij.openapi.util.Ref; @@ -34,6 +33,7 @@ import com.intellij.openapi.vfs.encoding.EncodingProjectManager; import com.intellij.openapi.vfs.encoding.EncodingProjectManagerImpl; import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.testFramework.ExtensionTestUtil; +import com.intellij.testFramework.PlatformTestUtil; import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.settings.GradleProjectSettings; @@ -541,7 +541,7 @@ public class GradleSettingsImportingTest extends GradleSettingsImportingTestCase assertFalse(sourceFolderManager.isDisposed()); } finally { - application.invokeAndWait(() -> ProjectManagerEx.getInstanceEx().forceCloseProject(project)); + PlatformTestUtil.forceCloseProjectWithoutSaving(project); } assertTrue(project.isDisposed()); assertTrue(sourceFolderManager.isDisposed()); diff --git a/tools/index-tools/src/org/jetbrains/index/stubs/StubsSdkGenerator.kt b/tools/index-tools/src/org/jetbrains/index/stubs/StubsSdkGenerator.kt index aa4fb6111474..3f160f1a70a6 100644 --- a/tools/index-tools/src/org/jetbrains/index/stubs/StubsSdkGenerator.kt +++ b/tools/index-tools/src/org/jetbrains/index/stubs/StubsSdkGenerator.kt @@ -1,6 +1,7 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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 org.jetbrains.index.stubs +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.PathManager import com.intellij.openapi.application.WriteAction import com.intellij.openapi.module.Module @@ -11,7 +12,6 @@ import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil import com.intellij.openapi.roots.OrderRootType import com.intellij.openapi.vfs.VirtualFile import com.intellij.testFramework.TestApplicationManager -import com.intellij.util.ui.UIUtil import java.io.File import kotlin.system.exitProcess @@ -54,7 +54,7 @@ abstract class ProjectSdkStubsGenerator { stubsGenerator.buildStubsForRoots(roots) } finally { - UIUtil.invokeAndWaitIfNeeded(Runnable { + ApplicationManager.getApplication().invokeAndWait(Runnable { ProjectManagerEx.getInstanceEx().forceCloseProject(project) WriteAction.run { SdkConfigurationUtil.removeSdk(sdk!!)