Search in sources :

Example 16 with PsiManagerEx

use of com.intellij.psi.impl.PsiManagerEx in project intellij-community by JetBrains.

the class PsiModificationTrackerTest method testClassShouldNotAppearWithoutEvents_NoPsiGrandParentDirectory.

public void testClassShouldNotAppearWithoutEvents_NoPsiGrandParentDirectory() throws IOException {
    PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
    long count0 = tracker.getJavaStructureModificationCount();
    final PsiManagerEx psiManager = PsiManagerEx.getInstanceEx(getProject());
    VirtualFile parentDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(createTempDirectory());
    assertNull(((FileManagerImpl) psiManager.getFileManager()).getCachedDirectory(parentDir));
    File file = new File(parentDir.getPath() + "/foo", "Foo.java");
    FileUtil.writeToFile(file, "package foo; class Foo {}");
    assertNotNull(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file));
    assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.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 17 with PsiManagerEx

use of com.intellij.psi.impl.PsiManagerEx in project intellij-community by JetBrains.

the class PsiModificationTrackerTest method testVirtualFileRename_WithPsi.

public void testVirtualFileRename_WithPsi() throws IOException {
    PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
    final PsiManagerEx psiManager = PsiManagerEx.getInstanceEx(getProject());
    GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
    final VirtualFile file = addFileToProject("foo/Foo.java", "package foo; class Foo {}").getVirtualFile();
    assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", scope));
    long count1 = tracker.getModificationCount();
    long hc = psiManager.findFile(file).hashCode();
    long stamp1 = psiManager.findFile(file).getModificationStamp();
    rename(file, "Bar.java");
    assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", scope));
    assertTrue(count1 != tracker.getModificationCount());
    assertTrue(stamp1 != psiManager.findFile(file).getModificationStamp());
    assertEquals(hc, psiManager.findFile(file).hashCode());
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 18 with PsiManagerEx

use of com.intellij.psi.impl.PsiManagerEx 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 19 with PsiManagerEx

use of com.intellij.psi.impl.PsiManagerEx 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 20 with PsiManagerEx

use of com.intellij.psi.impl.PsiManagerEx 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

PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)25 PsiModificationTracker (com.intellij.psi.util.PsiModificationTracker)7 FileManager (com.intellij.psi.impl.file.impl.FileManager)6 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 FileElement (com.intellij.psi.impl.source.tree.FileElement)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 Document (com.intellij.openapi.editor.Document)2 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)2 XmlFile (com.intellij.psi.xml.XmlFile)2 File (java.io.File)2 ASTNode (com.intellij.lang.ASTNode)1 Disposable (com.intellij.openapi.Disposable)1 FileType (com.intellij.openapi.fileTypes.FileType)1 Project (com.intellij.openapi.project.Project)1 VirtualFileFilter (com.intellij.openapi.vfs.VirtualFileFilter)1 PsiClass (com.intellij.psi.PsiClass)1 PsiClassType (com.intellij.psi.PsiClassType)1 PsiElement (com.intellij.psi.PsiElement)1 PsiElementFactory (com.intellij.psi.PsiElementFactory)1