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