Search in sources :

Example 1 with EditorEventMulticasterImpl

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

the class EditorListenerTracker method checkListenersLeak.

public void checkListenersLeak() throws AssertionError {
    try {
        // listeners may hang on default project
        if (myDefaultProjectInitialized != ((ProjectManagerImpl) ProjectManager.getInstance()).isDefaultProjectInitialized())
            return;
        EditorEventMulticasterImpl multicaster = (EditorEventMulticasterImpl) EditorFactory.getInstance().getEventMulticaster();
        Map<Class, List> after = multicaster.getListeners();
        Map<Class, List> leaked = new LinkedHashMap<>();
        for (Map.Entry<Class, List> entry : after.entrySet()) {
            Class aClass = entry.getKey();
            List beforeList = before.get(aClass);
            List afterList = entry.getValue();
            if (beforeList != null) {
                afterList.removeAll(beforeList);
            }
            if (!afterList.isEmpty()) {
                leaked.put(aClass, afterList);
            }
        }
        for (Map.Entry<Class, List> entry : leaked.entrySet()) {
            Class aClass = entry.getKey();
            List list = entry.getValue();
            Assert.fail("Listeners leaked for " + aClass + ":\n" + list);
        }
    } finally {
        before.clear();
    }
}
Also used : List(java.util.List) EditorEventMulticasterImpl(com.intellij.openapi.editor.impl.event.EditorEventMulticasterImpl) Map(java.util.Map) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap)

Aggregations

EditorEventMulticasterImpl (com.intellij.openapi.editor.impl.event.EditorEventMulticasterImpl)1 LinkedHashMap (com.intellij.util.containers.hash.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1