mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -2,11 +2,16 @@ package com.intellij.psi;
|
||||
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.impl.PsiManagerEx;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.testFramework.IdeaTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -143,4 +148,63 @@ public class PsiModificationTrackerTest extends LightPlatformCodeInsightFixtureT
|
||||
|
||||
assertEquals(count + 1, modificationTracker.getJavaStructureModificationCount());
|
||||
}
|
||||
|
||||
public void _testClassShouldNotAppearWithoutEvents() throws IOException {
|
||||
VirtualFile file = myFixture.getTempDirFixture().createFile("Foo.java", "");
|
||||
final Document document = FileDocumentManager.getInstance().getDocument(file);
|
||||
assertNotNull(document);
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
|
||||
PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
|
||||
long count1 = tracker.getJavaStructureModificationCount();
|
||||
|
||||
document.insertString(0, "class Foo {}");
|
||||
|
||||
assertEquals(count1, tracker.getJavaStructureModificationCount()); // no PSI changes yet
|
||||
//so the class should not exist
|
||||
assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
|
||||
assertFalse(count1 == tracker.getJavaStructureModificationCount());
|
||||
assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
public void _testClassShouldNotDisappearWithoutEvents() throws IOException {
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
|
||||
long count0 = tracker.getJavaStructureModificationCount();
|
||||
|
||||
VirtualFile file = myFixture.addFileToProject("Foo.java", "class Foo {}").getVirtualFile();
|
||||
final Document document = FileDocumentManager.getInstance().getDocument(file);
|
||||
assertNotNull(document);
|
||||
|
||||
assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
|
||||
long count1 = tracker.getJavaStructureModificationCount();
|
||||
assertFalse(count1 == count0);
|
||||
|
||||
document.deleteString(0, document.getTextLength());
|
||||
|
||||
// gc softly-referenced file and AST
|
||||
PlatformTestUtil.tryGcSoftlyReachableObjects();
|
||||
assertNull(((PsiManagerEx)PsiManager.getInstance(getProject())).getFileManager().getCachedPsiFile(file));
|
||||
|
||||
assertEquals(count1, tracker.getJavaStructureModificationCount()); // no PSI changes yet
|
||||
//so the class should exist
|
||||
assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
|
||||
assertFalse(count1 == tracker.getJavaStructureModificationCount());
|
||||
assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user