Search in sources :

Example 16 with PsiModificationTracker

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

the class PsiModificationTrackerTest method testJavaStructureModificationChangesAfterPackageDelete.

public void testJavaStructureModificationChangesAfterPackageDelete() throws IOException {
    final VirtualFile baseDir = getProject().getBaseDir();
    VirtualFile virtualFile = createChildData(createChildDirectory(createChildDirectory(baseDir, "x"), "y"), "Z.java");
    setFileText(virtualFile, "text");
    configureByFile(virtualFile);
    PsiFile file = getFile();
    PsiModificationTracker modificationTracker = PsiManager.getInstance(getProject()).getModificationTracker();
    long count = modificationTracker.getJavaStructureModificationCount();
    ApplicationManager.getApplication().runWriteAction(() -> file.getContainingDirectory().delete());
    assertTrue(count + ":" + modificationTracker.getJavaStructureModificationCount(), modificationTracker.getJavaStructureModificationCount() > count);
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker)

Example 17 with PsiModificationTracker

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

the class PsiModificationTrackerTest method doTest.

private void doTest(@NonNls String text, Processor<PsiFile> run) {
    PsiFile file = configureByText(JavaFileType.INSTANCE, text);
    PsiModificationTracker modificationTracker = PsiManager.getInstance(getProject()).getModificationTracker();
    long count = modificationTracker.getModificationCount();
    WriteCommandAction.runWriteCommandAction(getProject(), () -> {
        run.process(file);
    });
    assertFalse(modificationTracker.getModificationCount() == count);
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker)

Example 18 with PsiModificationTracker

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

the class JavaCodeBlockModificationListener method onTreeChanged.

@Override
protected void onTreeChanged(@NotNull PsiTreeChangeEventImpl event) {
    PsiModificationTracker tracker = myPsiManager.getModificationTracker();
    long cur = tracker.getOutOfCodeBlockModificationCount();
    super.onTreeChanged(event);
    if (cur == tracker.getOutOfCodeBlockModificationCount()) {
        PsiEventType code = event.getCode();
        if (code == PsiEventType.CHILD_ADDED || code == PsiEventType.CHILD_REMOVED || code == PsiEventType.CHILD_REPLACED) {
            if (hasClassesInside(event.getOldChild()) || event.getOldChild() != event.getChild() && hasClassesInside(event.getChild())) {
                onOutOfCodeBlockModification(event);
                doIncOutOfCodeBlockCounter();
            }
        }
    }
}
Also used : PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) PsiEventType(com.intellij.psi.impl.PsiTreeChangeEventImpl.PsiEventType)

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