Search in sources :

Example 1 with EncodingManagerImpl

use of com.intellij.openapi.vfs.encoding.EncodingManagerImpl in project intellij-community by JetBrains.

the class UsageViewTest method testUsageViewDoesNotHoldPsiFilesOrDocuments.

public void testUsageViewDoesNotHoldPsiFilesOrDocuments() throws Exception {
    boolean[] foundLeaksBeforeTest = new boolean[1];
    LeakHunter.checkLeak(ApplicationManager.getApplication(), PsiFileImpl.class, file -> {
        if (!file.isPhysical())
            return false;
        System.err.println("Can't start the test: leaking PsiFiles found:");
        foundLeaksBeforeTest[0] = true;
        return true;
    });
    if (foundLeaksBeforeTest[0]) {
        fail("Can't start the test: leaking PsiFiles found");
    }
    PsiFile psiFile = myFixture.addFileToProject("X.java", "public class X{} //iuggjhfg");
    Usage[] usages = new Usage[100];
    for (int i = 0; i < usages.length; i++) {
        usages[i] = createUsage(psiFile, i);
    }
    UsageView usageView = UsageViewManager.getInstance(getProject()).createUsageView(UsageTarget.EMPTY_ARRAY, usages, new UsageViewPresentation(), null);
    Disposer.register(myFixture.getTestRootDisposable(), usageView);
    ((EncodingManagerImpl) EncodingManager.getInstance()).clearDocumentQueue();
    FileDocumentManager.getInstance().saveAllDocuments();
    UIUtil.dispatchAllInvocationEvents();
    LeakHunter.checkLeak(usageView, PsiFileImpl.class, PsiFileImpl::isPhysical);
    LeakHunter.checkLeak(usageView, Document.class);
}
Also used : EncodingManagerImpl(com.intellij.openapi.vfs.encoding.EncodingManagerImpl) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) PsiFile(com.intellij.psi.PsiFile)

Aggregations

EncodingManagerImpl (com.intellij.openapi.vfs.encoding.EncodingManagerImpl)1 PsiFile (com.intellij.psi.PsiFile)1 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)1