inplace refactoring: fix project leak (IDEA-224673)

GitOrigin-RevId: 16ebacb09165a7a8dc48dd2452c85cf3de34b43c
This commit is contained in:
Anna.Kozlova
2019-10-17 06:31:25 +00:00
committed by intellij-monorepo-bot
parent 10a378dcc0
commit 9a07910541
5 changed files with 30 additions and 13 deletions
@@ -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<Project, StartMarkAction> ourCurrentMarks = new HashMap<>();
public static final Key<StartMarkAction> 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;
}
}
@@ -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();
@@ -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);
@@ -317,8 +317,6 @@ public abstract class UsefulTestCase extends TestCase {
currentCodeStyleSettings.clearCodeStyleSettings();
}
})
.append(() -> InplaceRefactoring.checkCleared())
.append(() -> StartMarkAction.checkCleared())
.run();
}
@@ -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);