Search in sources :

Example 1 with PsiTreeChangePreprocessor

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

the class PsiEventsTest method testTreeChangePreprocessorThrowsException.

public void testTreeChangePreprocessorThrowsException() throws Exception {
    VirtualFile vFile = createFile("a.xml", "<tag/>").getVirtualFile();
    Document document = FileDocumentManager.getInstance().getDocument(vFile);
    assert document != null;
    PsiTreeChangePreprocessor preprocessor = event -> {
        if (!event.getCode().name().startsWith("BEFORE") && !event.isGenericChange()) {
            throw new NullPointerException();
        }
    };
    ((PsiManagerImpl) getPsiManager()).addTreeChangePreprocessor(preprocessor);
    try {
        WriteCommandAction.runWriteCommandAction(myProject, () -> document.insertString(0, " "));
        PsiDocumentManager.getInstance(myProject).commitAllDocuments();
        fail("NPE expected");
    } catch (NullPointerException ignore) {
    } finally {
        ((PsiManagerImpl) getPsiManager()).removeTreeChangePreprocessor(preprocessor);
    }
    WriteCommandAction.runWriteCommandAction(myProject, () -> document.insertString(0, " "));
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    assertEquals("  <tag/>", getPsiManager().findFile(vFile).getText());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) MemoryDumpHelper(com.intellij.util.MemoryDumpHelper) com.intellij.testFramework(com.intellij.testFramework) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) FileTypeManagerEx(com.intellij.openapi.fileTypes.ex.FileTypeManagerEx) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) WaitFor(com.intellij.util.WaitFor) ModuleRootModificationUtil(com.intellij.openapi.roots.ModuleRootModificationUtil) ReadOnlyAttributeUtil(com.intellij.util.io.ReadOnlyAttributeUtil) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PsiManagerImpl(com.intellij.psi.impl.PsiManagerImpl) PsiTreeChangeEventImpl(com.intellij.psi.impl.PsiTreeChangeEventImpl) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) FileUtil(com.intellij.openapi.util.io.FileUtil) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) PsiTreeChangePreprocessor(com.intellij.psi.impl.PsiTreeChangePreprocessor) PsiTreeChangePreprocessor(com.intellij.psi.impl.PsiTreeChangePreprocessor) PsiManagerImpl(com.intellij.psi.impl.PsiManagerImpl) Document(com.intellij.openapi.editor.Document)

Aggregations

ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Document (com.intellij.openapi.editor.Document)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)1 FileTypeManagerEx (com.intellij.openapi.fileTypes.ex.FileTypeManagerEx)1 ModuleRootModificationUtil (com.intellij.openapi.roots.ModuleRootModificationUtil)1 ThrowableComputable (com.intellij.openapi.util.ThrowableComputable)1 FileUtil (com.intellij.openapi.util.io.FileUtil)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 com.intellij.psi (com.intellij.psi)1 PsiManagerImpl (com.intellij.psi.impl.PsiManagerImpl)1 PsiTreeChangeEventImpl (com.intellij.psi.impl.PsiTreeChangeEventImpl)1 PsiTreeChangePreprocessor (com.intellij.psi.impl.PsiTreeChangePreprocessor)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 com.intellij.testFramework (com.intellij.testFramework)1 MemoryDumpHelper (com.intellij.util.MemoryDumpHelper)1 WaitFor (com.intellij.util.WaitFor)1 ReadOnlyAttributeUtil (com.intellij.util.io.ReadOnlyAttributeUtil)1