From 15500d6412b3999bea390fd7df875a464c6fea03 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 10 Apr 2018 17:08:47 +0200 Subject: [PATCH] =?UTF-8?q?ExecutionTargetTest=20=E2=80=94=20use=20Disposa?= =?UTF-8?q?bleRule=20to=20ensure=20that=20always=20disposed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/intellij/testFramework/FixtureRule.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt b/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt index f877329280ef..26ea93d276b5 100644 --- a/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt +++ b/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt @@ -3,6 +3,7 @@ package com.intellij.testFramework import com.intellij.ide.highlighter.ProjectFileType import com.intellij.idea.IdeaTestApplication +import com.intellij.openapi.Disposable import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.runUndoTransparentWriteAction import com.intellij.openapi.components.ComponentManager @@ -16,6 +17,7 @@ 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 +import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS import com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl @@ -305,4 +307,17 @@ fun createOrLoadProject(tempDirManager: TemporaryDirectory, projectCreator: ((Vi fun ComponentManager.saveStore() { stateStore.save(SmartList(), true) +} + +class DisposableRule : ExternalResource() { + private var _disposable = lazy { Disposer.newDisposable() } + + val disposable: Disposable + get() = _disposable.value + + override fun after() { + if (_disposable.isInitialized()) { + Disposer.dispose(_disposable.value) + } + } } \ No newline at end of file