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