Search in sources :

Example 1 with EclipseContextFactory

use of org.eclipse.e4.core.contexts.EclipseContextFactory in project eclipse.pde by eclipse-pde.

the class ContextSpyHelper method getAllBundleContexts.

/**
 * Get all the contexts created by EclipseContextFactory. It get values from
 * field introspection. Should be rewritten if internal structure changes
 *
 * @return a collection of contexts created by EclipseContextFactory
 */
public static Collection<IEclipseContext> getAllBundleContexts() {
    Collection<IEclipseContext> result = Collections.emptyList();
    try {
        // Must use introspection to get the weak hash map (no getter).
        // $NON-NLS-1$
        Field f = EclipseContextFactory.class.getDeclaredField("serviceContexts");
        f.setAccessible(true);
        @SuppressWarnings("unchecked") Map<BundleContext, IEclipseContext> ctxs = (Map<BundleContext, IEclipseContext>) f.get(null);
        result = ctxs.values();
    } catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : Field(java.lang.reflect.Field) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Map(java.util.Map) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Field (java.lang.reflect.Field)1 Map (java.util.Map)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 BundleContext (org.osgi.framework.BundleContext)1