diff --git a/java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java b/java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java index f04dc8491ec9..2274af5b711a 100644 --- a/java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java +++ b/java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java @@ -34,7 +34,6 @@ import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.testFramework.LeakHunter; import com.intellij.testFramework.PlatformTestCase; import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; -import com.intellij.util.Processor; public class LoadProjectTest extends PlatformTestCase { @Override @@ -82,12 +81,8 @@ public class LoadProjectTest extends PlatformTestCase { FileEditorManager.getInstance(getProject()).closeFile(b); ProjectManagerEx.getInstanceEx().closeAndDispose(getProject()); - LeakHunter.checkLeak(ApplicationManager.getApplication(), PsiFileImpl.class, new Processor() { - @Override - public boolean process(PsiFileImpl psiFile) { - return psiFile.getViewProvider().getVirtualFile().getFileSystem() instanceof LocalFileSystem; - } - }); + LeakHunter.checkLeak(ApplicationManager.getApplication(), PsiFileImpl.class, + psiFile -> psiFile.getViewProvider().getVirtualFile().getFileSystem() instanceof LocalFileSystem); } @Override diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java index 8e76bf4cb914..c9f8d7e76001 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java @@ -15,9 +15,7 @@ */ package com.intellij.psi.impl.file.impl; -import com.intellij.ide.IdeEventQueue; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.impl.LaterInvocator; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileTypes.FileTypeManager; @@ -193,9 +191,7 @@ public class PsiEventsTest extends PsiTestCase { return directory.getVirtualFile().equals(myPrjDir1); } }; - LeakHunter.checkLeak(ApplicationManager.getApplication(), PsiDirectory.class, isReallyLeak); - LeakHunter.checkLeak(IdeEventQueue.getInstance(), PsiDirectory.class, isReallyLeak); - LeakHunter.checkLeak(LaterInvocator.getLaterInvocatorQueue(), PsiDirectory.class, isReallyLeak); + LeakHunter.checkLeak(LeakHunter.allRoots(), PsiDirectory.class, isReallyLeak); String dumpPath = FileUtil.createTempFile( new File(System.getProperty("teamcity.build.tempDir", System.getProperty("java.io.tmpdir"))), "testRenameFileWithoutDir", ".hprof", @@ -792,7 +788,7 @@ public class PsiEventsTest extends PsiTestCase { assertTrue(documentManager.isCommitted(document)); } - private void checkCommitted(boolean shouldBeCommitted, PsiTreeChangeEvent event) { + private static void checkCommitted(boolean shouldBeCommitted, PsiTreeChangeEvent event) { PsiFile file = event.getFile(); PsiDocumentManager documentManager = PsiDocumentManager.getInstance(file.getProject()); Document document = documentManager.getDocument(file); diff --git a/platform/testFramework/src/com/intellij/testFramework/LeakHunter.java b/platform/testFramework/src/com/intellij/testFramework/LeakHunter.java index 3aac1cc0dfdb..ee7ffa897cdc 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LeakHunter.java +++ b/platform/testFramework/src/com/intellij/testFramework/LeakHunter.java @@ -15,10 +15,12 @@ */ package com.intellij.testFramework; +import com.intellij.ide.IdeEventQueue; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.application.impl.LaterInvocator; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.impl.ProjectImpl; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.UserDataHolder; import com.intellij.openapi.util.UserDataHolderEx; @@ -88,7 +90,7 @@ public class LeakHunter { return !project.isDefault() && !((ProjectImpl)project).isLight(); } }; - Collection roots = new ArrayList(Arrays.asList(ApplicationManager.getApplication(), Extensions.getRootArea())); + Collection roots = new ArrayList(allRoots()); ClassLoader classLoader = LeakHunter.class.getClassLoader(); Vector allLoadedClasses = ReflectionUtil.getField(classLoader.getClass(), classLoader, Vector.class, "classes"); roots.addAll(allLoadedClasses); // inspect static fields of all loaded classes @@ -142,4 +144,9 @@ public class LeakHunter { public static void checkLeak(@NotNull Object root, @NotNull Class suspectClass, @Nullable final Processor isReallyLeak) throws AssertionError { checkLeak(Collections.singletonList(root), suspectClass, isReallyLeak); } + + @NotNull + public static List allRoots() { + return Arrays.asList(ApplicationManager.getApplication(), Disposer.getTree(), IdeEventQueue.getInstance(), LaterInvocator.getLaterInvocatorQueue()); + } }