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());
}
Aggregations