Search in sources :

Example 11 with PsiModificationTracker

use of com.intellij.psi.util.PsiModificationTracker in project intellij-community by JetBrains.

the class PsiModificationTrackerTest method testClassShouldNotDisappearWithoutEvents_NoDocument.

public void testClassShouldNotDisappearWithoutEvents_NoDocument() throws IOException {
    PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
    final PsiManagerEx psiManager = PsiManagerEx.getInstanceEx(getProject());
    final VirtualFile file = addFileToProject("Foo.java", "class Foo {}").getVirtualFile();
    assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
    long count1 = tracker.getJavaStructureModificationCount();
    // gc softly-referenced file and document
    PlatformTestUtil.tryGcSoftlyReachableObjects();
    assertNull(FileDocumentManager.getInstance().getCachedDocument(file));
    assertNull(psiManager.getFileManager().getCachedPsiFile(file));
    setFileText(file, "");
    assertNull(FileDocumentManager.getInstance().getCachedDocument(file));
    assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
    assertFalse(count1 == tracker.getJavaStructureModificationCount());
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 12 with PsiModificationTracker

use of com.intellij.psi.util.PsiModificationTracker in project intellij-community by JetBrains.

the class PsiModificationTrackerTest method testRootsChangeIncreasesCounts.

public void testRootsChangeIncreasesCounts() {
    PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
    long mc = tracker.getModificationCount();
    long js = tracker.getJavaStructureModificationCount();
    long ocb = tracker.getOutOfCodeBlockModificationCount();
    WriteAction.run(() -> ProjectRootManagerEx.getInstanceEx(getProject()).makeRootsChange(EmptyRunnable.INSTANCE, false, true));
    assertTrue(mc != tracker.getModificationCount());
    assertTrue(js != tracker.getJavaStructureModificationCount());
    assertTrue(ocb != tracker.getOutOfCodeBlockModificationCount());
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker)

Example 13 with PsiModificationTracker

use of com.intellij.psi.util.PsiModificationTracker in project intellij-community by JetBrains.

the class PsiModificationTrackerTest method testClassShouldNotAppearWithoutEvents_NoPsiDirectory.

public void testClassShouldNotAppearWithoutEvents_NoPsiDirectory() throws IOException {
    PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
    long count0 = tracker.getJavaStructureModificationCount();
    final PsiManagerEx psiManager = PsiManagerEx.getInstanceEx(getProject());
    VirtualFile parentDir = createChildDirectory(getProject().getBaseDir(), "tmp");
    assertNull(((FileManagerImpl) psiManager.getFileManager()).getCachedDirectory(parentDir));
    File file = new File(parentDir.getPath(), "Foo.java");
    FileUtil.writeToFile(file, "class Foo {}");
    assertNotNull(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file));
    assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
    assertFalse(count0 == tracker.getJavaStructureModificationCount());
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) File(java.io.File) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 14 with PsiModificationTracker

use of com.intellij.psi.util.PsiModificationTracker in project intellij-community by JetBrains.

the class PsiModificationTrackerTest method testNoIncrementOnWorkspaceFileChange.

public void testNoIncrementOnWorkspaceFileChange() throws Exception {
    FixtureRuleKt.runInLoadComponentStateMode(myProject, () -> {
        ProjectKt.getStateStore(myProject).save(new SmartList<>());
        PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
        long mc = tracker.getModificationCount();
        VirtualFile ws = myProject.getWorkspaceFile();
        assertNotNull(ws);
        new WriteCommandAction.Simple(myProject) {

            @Override
            protected void run() throws Throwable {
                VfsUtil.saveText(ws, VfsUtilCore.loadText(ws) + " ");
            }
        }.execute();
        assertEquals(mc, tracker.getModificationCount());
        return null;
    });
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker)

Example 15 with PsiModificationTracker

use of com.intellij.psi.util.PsiModificationTracker in project intellij-community by JetBrains.

the class PsiModificationTrackerTest method testClassShouldNotDisappearWithoutEvents_VirtualFileDeleted.

public void testClassShouldNotDisappearWithoutEvents_VirtualFileDeleted() throws IOException {
    PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
    final PsiManagerEx psiManager = PsiManagerEx.getInstanceEx(getProject());
    final VirtualFile file = addFileToProject("Foo.java", "class Foo {}").getVirtualFile();
    assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
    long count1 = tracker.getJavaStructureModificationCount();
    // gc softly-referenced file and document
    PlatformTestUtil.tryGcSoftlyReachableObjects();
    assertNull(FileDocumentManager.getInstance().getCachedDocument(file));
    assertNull(psiManager.getFileManager().getCachedPsiFile(file));
    delete(file);
    assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
    assertFalse(count1 == tracker.getJavaStructureModificationCount());
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Aggregations

PsiModificationTracker (com.intellij.psi.util.PsiModificationTracker)18 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)7 Document (com.intellij.openapi.editor.Document)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 File (java.io.File)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Project (com.intellij.openapi.project.Project)1 PsiModificationTrackerImpl (com.intellij.psi.impl.PsiModificationTrackerImpl)1 PsiEventType (com.intellij.psi.impl.PsiTreeChangeEventImpl.PsiEventType)1