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 2bda6c555a28..d0bc8450a658 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 @@ -8,13 +8,11 @@ import com.intellij.openapi.command.undo.UndoManager; 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.TestOnly; -import java.util.HashMap; -import java.util.Map; - public class StartMarkAction extends BasicUndoableAction { - private static final Map ourCurrentMarks = new HashMap<>(); + public static final Key START_MARK_ACTION_KEY = Key.create("current.inplace.refactorings.mark"); private String myCommandName; private boolean myGlobal; private Document myDocument; @@ -55,17 +53,19 @@ public class StartMarkAction extends BasicUndoableAction { } @TestOnly - public static void checkCleared() { + public static void checkCleared(Project project) { + if (project == null) return; try { - assert ourCurrentMarks.isEmpty() : ourCurrentMarks.values(); + StartMarkAction markAction = project.getUserData(START_MARK_ACTION_KEY); + assert markAction == null : markAction.myDocument; } finally { - ourCurrentMarks.clear(); + project.putUserData(START_MARK_ACTION_KEY, null); } } public static StartMarkAction start(Editor editor, Project project, String commandName) throws AlreadyStartedException { - final StartMarkAction existingMark = ourCurrentMarks.get(project); + final StartMarkAction existingMark = project.getUserData(START_MARK_ACTION_KEY); if (existingMark != null) { throw new AlreadyStartedException(existingMark.myCommandName, existingMark.myDocument, @@ -73,17 +73,18 @@ public class StartMarkAction extends BasicUndoableAction { } final StartMarkAction markAction = new StartMarkAction(editor, commandName); UndoManager.getInstance(project).undoableActionPerformed(markAction); - ourCurrentMarks.put(project, markAction); + project.putUserData(START_MARK_ACTION_KEY, markAction); return markAction; } public static StartMarkAction canStart(Project project) { - return ourCurrentMarks.get(project); + return project.getUserData(START_MARK_ACTION_KEY); } static void markFinished(Project project) { - final StartMarkAction existingMark = ourCurrentMarks.remove(project); + StartMarkAction existingMark = project.getUserData(START_MARK_ACTION_KEY); if (existingMark != null) { + project.putUserData(START_MARK_ACTION_KEY, null); existingMark.myDocument = null; } } diff --git a/platform/testFramework/src/com/intellij/testFramework/HeavyPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/HeavyPlatformTestCase.java index 15a992f36f7b..e2371c144043 100644 --- a/platform/testFramework/src/com/intellij/testFramework/HeavyPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/HeavyPlatformTestCase.java @@ -21,6 +21,7 @@ import com.intellij.openapi.application.impl.NonBlockingReadActionImpl; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.command.impl.DocumentReferenceManagerImpl; +import com.intellij.openapi.command.impl.StartMarkAction; import com.intellij.openapi.command.impl.UndoManagerImpl; import com.intellij.openapi.command.undo.DocumentReferenceManager; import com.intellij.openapi.command.undo.UndoManager; @@ -62,6 +63,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.impl.PsiDocumentManagerBase; import com.intellij.psi.impl.PsiManagerImpl; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl; +import com.intellij.refactoring.rename.inplace.InplaceRefactoring; import com.intellij.util.MemoryDumpHelper; import com.intellij.util.PathUtil; import com.intellij.util.PlatformUtils; @@ -570,6 +572,10 @@ public abstract class HeavyPlatformTestCase extends UsefulTestCase implements Da InjectedLanguageManagerImpl.checkInjectorsAreDisposed(project); } }) + .append(() -> { + StartMarkAction.checkCleared(project); + InplaceRefactoring.checkCleared(); + }) .append(() -> { JarFileSystemImpl.cleanupForNextTest(); diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 197c8e39cb81..e4320a045fdc 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -28,6 +28,7 @@ import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.application.ex.ApplicationEx; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.command.impl.DocumentReferenceManagerImpl; +import com.intellij.openapi.command.impl.StartMarkAction; import com.intellij.openapi.command.impl.UndoManagerImpl; import com.intellij.openapi.command.undo.DocumentReferenceManager; import com.intellij.openapi.command.undo.UndoManager; @@ -79,6 +80,7 @@ import com.intellij.psi.impl.PsiDocumentManagerImpl; import com.intellij.psi.impl.PsiManagerImpl; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl; import com.intellij.psi.templateLanguages.TemplateDataLanguageMappings; +import com.intellij.refactoring.rename.inplace.InplaceRefactoring; import com.intellij.ui.UiInterceptors; import com.intellij.util.IncorrectOperationException; import com.intellij.util.LocalTimeCounter; @@ -399,6 +401,10 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da myCodeStyleSettingsTracker.checkForSettingsDamage(); } }, + () -> { + StartMarkAction.checkCleared(project); + InplaceRefactoring.checkCleared(); + }, () -> { if (project != null && ourApplication != null) { doTearDown(project, ourApplication); diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index a5e50bdd9613..8eb062823728 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -317,8 +317,6 @@ public abstract class UsefulTestCase extends TestCase { currentCodeStyleSettings.clearCodeStyleSettings(); } }) - .append(() -> InplaceRefactoring.checkCleared()) - .append(() -> StartMarkAction.checkCleared()) .run(); } diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java index 07cb3a584a58..44bc4491eedc 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java @@ -5,6 +5,7 @@ import com.intellij.application.options.CodeStyle; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.idea.IdeaTestApplication; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.command.impl.StartMarkAction; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; @@ -12,6 +13,7 @@ import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; import com.intellij.psi.codeStyle.CodeStyleSchemes; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl; +import com.intellij.refactoring.rename.inplace.InplaceRefactoring; import com.intellij.testFramework.*; import com.intellij.testFramework.fixtures.LightIdeaTestFixture; import org.jetbrains.annotations.NotNull; @@ -61,6 +63,10 @@ public final class LightIdeaTestFixtureImpl extends BaseFixture implements Light myCodeStyleSettingsTracker.checkForSettingsDamage(); } }) + .append(() -> { + StartMarkAction.checkCleared(project); + InplaceRefactoring.checkCleared(); + }) .append(() -> { if (project != null) { HeavyPlatformTestCase.waitForProjectLeakingThreads(project, 10, TimeUnit.SECONDS);