/** * Enumerate an inheritance chain from [ bottom, top ). * * @param bottom bottom of the inheritance chain * @param top top of the inheritance chain */ public static PowerlessArray<String> upto(final Class<?> bottom, final Class<?> top) { if (bottom == top || // fast path Promise.class.isAssignableFrom(bottom) || // hide implementation Brand.class.isAssignableFrom(bottom)) { // hide implementation return PowerlessArray.array(); } // simplify the knot at the top of the world final Class<?> limit = Struct.class.isAssignableFrom(bottom) ? Struct.class : Proxy.class.isAssignableFrom(bottom) ? Proxy.class : RuntimeException.class.isAssignableFrom(bottom) ? (Exception.class.isAssignableFrom(top) ? RuntimeException.class : Exception.class) : Exception.class.isAssignableFrom(bottom) ? Throwable.class : Object.class; final PowerlessArray.Builder<String> r = PowerlessArray.builder(4); for (Class<?> i = bottom; limit != i && top != i; i = i.getSuperclass()) { ifaces(top, i, r); } return r.snapshot(); }
/** List a class and all its implemented interfaces. */ private static void ifaces( final Class<?> top, final Class<?> type, final PowerlessArray.Builder<String> r) { if (Modifier.isPublic(type.getModifiers())) { try { if (org.joe_e.Selfless.class != type && org.joe_e.Equatable.class != type && org.joe_e.Powerless.class != type && org.joe_e.Immutable.class != type && org.ref_send.Record.class != type && java.lang.Comparable.class != type && java.io.Serializable.class != type) { r.append(name(type)); } } catch (final Exception e) { // Skip any type that does not have a deterministic name. } } for (final Class<?> i : type.getInterfaces()) { if (!i.isAssignableFrom(top)) { ifaces(top, i, r); } } }