mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
allow to load AST inside childrenChanged() (EA-106953 - SOE: AbstractFileViewProvider$PsiFileContent.getText)
This commit is contained in:
@@ -27,6 +27,7 @@ import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiDocumentManagerImpl;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.impl.source.tree.LazyParseableElement;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
@@ -390,4 +391,26 @@ public class MiscPsiTest extends LightCodeInsightFixtureTestCase {
|
||||
assertEquals("Foo", bar.getSuperClass().getName());
|
||||
PsiUtilCore.ensureValid(bar.getSuperClass());
|
||||
}
|
||||
|
||||
public void testLoadingNodeDuringCommitWithoutReparse_Stress() {
|
||||
// it's a stress test to disable test checks that load file content prematurely (AbstractFileViewProvider.checkLengthConsistency)
|
||||
PsiFile file = myFixture.addFileToProject("a.java", "class Foo {}");
|
||||
|
||||
myFixture.getPsiManager().addPsiTreeChangeListener(new PsiTreeChangeAdapter() {
|
||||
@Override
|
||||
public void childrenChanged(@NotNull PsiTreeChangeEvent event) {
|
||||
PsiElement parent = event.getParent();
|
||||
if (parent == file) {
|
||||
assertNotNull(file.getNode());
|
||||
}
|
||||
}
|
||||
}, getTestRootDisposable());
|
||||
WriteCommandAction.runWriteCommandAction(getProject(), () -> {
|
||||
Document document = file.getViewProvider().getDocument();
|
||||
document.insertString(0, " ");
|
||||
((PsiDocumentManagerImpl)PsiDocumentManager.getInstance(getProject())).doCommitWithoutReparse(document);
|
||||
});
|
||||
|
||||
assertEquals(" class Foo {}", file.getText());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,14 +275,14 @@ public abstract class AbstractFileViewProvider extends UserDataHolderBase implem
|
||||
}
|
||||
}
|
||||
|
||||
contentsSynchronized();
|
||||
|
||||
for (PsiTreeChangeEventImpl event : events) {
|
||||
((PsiManagerImpl)getManager()).childrenChanged(event);
|
||||
}
|
||||
for (PsiTreeChangeEventImpl event : genericEvents) {
|
||||
((PsiManagerImpl)getManager()).childrenChanged(event);
|
||||
}
|
||||
|
||||
contentsSynchronized();
|
||||
}
|
||||
|
||||
private PsiTreeChangeEventImpl createChildrenChangeEvent(PsiFile file, boolean generic) {
|
||||
|
||||
Reference in New Issue
Block a user