Search in sources :

Example 6 with PsiModificationTracker

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

the class PsiModificationTrackerTest method testClassShouldNotDisappearWithoutEvents_ParentVirtualDirectoryDeleted.

public void testClassShouldNotDisappearWithoutEvents_ParentVirtualDirectoryDeleted() throws Exception {
    PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
    final PsiManagerEx psiManager = PsiManagerEx.getInstanceEx(getProject());
    final VirtualFile file = addFileToProject("foo/Foo.java", "package foo; class Foo {}").getVirtualFile();
    assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.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.getParent());
    assertNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", GlobalSearchScope.allScope(getProject())));
    assertFalse(count1 == tracker.getJavaStructureModificationCount());
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 7 with PsiModificationTracker

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

the class PsiModificationTrackerTest method testClassShouldNotAppearWithoutEvents_InCodeBlock.

public void testClassShouldNotAppearWithoutEvents_InCodeBlock() throws Exception {
    PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
    String barStr = "class Bar {}";
    PsiFile file = addFileToProject("Foo.java", "class Foo {{" + "}}");
    JBIterable<PsiClass> barQuery = SyntaxTraverser.psiTraverser(file).filter(PsiClass.class).filter(o -> "Bar".equals(o.getName()));
    assertNull(barQuery.first());
    Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
    int index = document.getText().indexOf("}}");
    long count1 = tracker.getJavaStructureModificationCount();
    WriteCommandAction.runWriteCommandAction(getProject(), () -> document.insertString(index, barStr));
    PsiDocumentManager.getInstance(getProject()).commitDocument(document);
    assertNotNull(barQuery.first());
    assertFalse(count1 == tracker.getJavaStructureModificationCount());
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) Document(com.intellij.openapi.editor.Document)

Example 8 with PsiModificationTracker

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

the class DataBindingUtil method invalidateJavaCodeOnOpenDataBindingProjects.

private static void invalidateJavaCodeOnOpenDataBindingProjects() {
    ourDataBindingEnabledModificationCount.incrementAndGet();
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        DataBindingProjectComponent component = project.getComponent(DataBindingProjectComponent.class);
        if (component == null) {
            continue;
        }
        boolean invalidated = invalidateAllSources(component);
        if (!invalidated) {
            return;
        }
        PsiModificationTracker tracker = PsiManager.getInstance(project).getModificationTracker();
        if (tracker instanceof PsiModificationTrackerImpl) {
            ((PsiModificationTrackerImpl) tracker).incCounter();
        }
        FileContentUtil.reparseFiles(project, Collections.EMPTY_LIST, true);
    }
    ourDataBindingEnabledModificationCount.incrementAndGet();
}
Also used : Project(com.intellij.openapi.project.Project) PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) PsiModificationTrackerImpl(com.intellij.psi.impl.PsiModificationTrackerImpl)

Example 9 with PsiModificationTracker

use of com.intellij.psi.util.PsiModificationTracker 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 10 with PsiModificationTracker

use of com.intellij.psi.util.PsiModificationTracker 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)

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