Search in sources :

Example 1 with EditorEventMulticaster

use of com.intellij.openapi.editor.event.EditorEventMulticaster in project intellij-community by JetBrains.

the class SmartPsiElementPointersTest method testCreatePointerInBeforeDocumentChange.

public void testCreatePointerInBeforeDocumentChange() {
    final PsiClass aClass = myJavaFacade.findClass("AClass", GlobalSearchScope.allScope(getProject()));
    assertNotNull(aClass);
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(aClass.getContainingFile());
    final SmartPsiElementPointer[] pointer = new SmartPsiElementPointer[1];
    int offset = aClass.getTextOffset();
    DocumentListener listener = new DocumentListener() {

        @Override
        public void beforeDocumentChange(DocumentEvent event) {
            pointer[0] = createPointer(aClass);
        }

        @Override
        public void documentChanged(DocumentEvent event) {
        }
    };
    EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster();
    multicaster.addDocumentListener(listener);
    try {
        insertString(document, offset, "/******/");
    } finally {
        multicaster.removeDocumentListener(listener);
    }
    pointer[0].getElement();
    insertString(document, 0, "/**/");
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    PsiElement element = pointer[0].getElement();
    assertNotNull(element);
    assertTrue(element instanceof PsiClass);
    assertTrue(element.isValid());
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) EditorEventMulticaster(com.intellij.openapi.editor.event.EditorEventMulticaster) Document(com.intellij.openapi.editor.Document) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Aggregations

Document (com.intellij.openapi.editor.Document)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 DocumentListener (com.intellij.openapi.editor.event.DocumentListener)1 EditorEventMulticaster (com.intellij.openapi.editor.event.EditorEventMulticaster)1