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());
}
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());
}
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());
}
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;
});
}
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());
}
Aggregations