Search in sources :

Example 1 with PsiTreeChangeEvent

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

the class PsiEventsTest method testEditingInDocComment.

public void testEditingInDocComment() throws Exception {
    final Ref<Boolean> gotIt = new Ref<>(false);
    getPsiManager().addPsiTreeChangeListener(new PsiTreeChangeAdapter() {

        @Override
        public void childReplaced(@NotNull PsiTreeChangeEvent event) {
            gotIt.set(true);
        }
    });
    GroovyFile file = GroovyPsiElementFactory.getInstance(myProject).createGroovyFile("/** This is doc comment*/class C{}", true, null);
    final PsiDocumentManager docManager = PsiDocumentManager.getInstance(myProject);
    final Document doc = docManager.getDocument(file);
    assertNotNull(doc);
    CommandProcessor.getInstance().executeCommand(myProject, () -> ApplicationManager.getApplication().runWriteAction(() -> {
        doc.insertString(3, " ");
        docManager.commitDocument(doc);
    }), "file text set", this);
    assertTrue(gotIt.get());
}
Also used : Ref(com.intellij.openapi.util.Ref) PsiTreeChangeEvent(com.intellij.psi.PsiTreeChangeEvent) Document(com.intellij.openapi.editor.Document) PsiTreeChangeAdapter(com.intellij.psi.PsiTreeChangeAdapter) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Aggregations

Document (com.intellij.openapi.editor.Document)1 Ref (com.intellij.openapi.util.Ref)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1 PsiTreeChangeAdapter (com.intellij.psi.PsiTreeChangeAdapter)1 PsiTreeChangeEvent (com.intellij.psi.PsiTreeChangeEvent)1